Skip to content
Open
54 changes: 46 additions & 8 deletions plugin/blog.vim
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import urllib
import xmlrpclib
import re
import os
import sys, traceback
import mimetypes
import webbrowser
import tempfile
Expand All @@ -105,6 +106,23 @@ except ImportError:
markdown = markdown_stub()


# 2016-12-06: JSTEWART: ADJUST LINE NUMBERS FOR UNHANDLED EXCEPTIONS
# UNROLL STACK UP TO 14 ITEMS DEEP
def MsgException(e) :

exc_type, exc_value, exc_traceback = sys.exc_info()

szMsg = "{}\n".format(repr(e))
i = 1

for (szFile, nLine, szMod, szLine) in traceback.extract_tb(exc_traceback, 14) :
# OFFSET LINE NUMBER TO BEGINNING OF PYTHON TEXT
szMsg += "[{}] {}:{}\n".format(i, "VimRepress", nLine + 81)
i +=1

echoerr(szMsg)


def exception_check(func):
def __check(*args, **kwargs):
try:
Expand All @@ -118,8 +136,8 @@ def exception_check(func):
echoerr("xmlrpc error: %s" % e.faultString.encode("utf-8"))
except IOError, e:
echoerr("network error: %s" % e)
except Exception, e:
echoerr("something wrong: %s" % e)
except Exception as e:
MsgException(e)
raise

return __check
Expand Down Expand Up @@ -623,14 +641,20 @@ def vim_encoding_check(func):
"correctly.")
elif orig_enc != "utf-8":
modified = vim.eval("&modified")

# CONVERTS CURRENT BUFFER TO UTF-8
buf_list = '\n'.join(vim.current.buffer).decode(orig_enc).encode('utf-8').splitlines()
del vim.current.buffer[:]
vim.command("setl encoding=utf-8")
vim.current.buffer[0] = buf_list[0]
if len(buf_list) > 1:
vim.current.buffer.append(buf_list[1:])

# 2016-12-05: JSTEWART: FIXED INDEX ERROR BY CHANGING FROM 1 TO 0
# REFILL BUFFER AFTER CONVERSION
if len(buf_list) > 0:
vim.current.buffer.append(buf_list[0:])

if modified == '0':
vim.command('setl nomodified')

return func(*args, **kw)
return __check

Expand Down Expand Up @@ -679,14 +703,28 @@ def blog_wise_open_view():
"""
Wisely decides whether to wipe out the content of current buffer or open a new splited window.
"""
if vim.current.buffer.name is None and \
(vim.eval('&modified') == '0' or
len(vim.current.buffer) == 1):

curBuf = vim.current.buffer
bufname = curBuf.name
bEmpty = False
bNoMod = False

if( vim.eval('&modified') == '0' ):
bNoMod = True

if( (len(curBuf) <= 1) and (len(curBuf[0]) <= 1) ):
bEmpty = True

# 2016-12-05: JSTEWART: BUFFER NAME LENGTH CHECK IN ADDITION TO None CHECK
# WINDOWS WERE MULTIPLYING LIKE RABBITS SINCE
# buffer.name NEVER SEEMS TO EVALUATE TO None
if ( ((bufname is None) or (len(bufname) == 0)) and (bNoMod or bEmpty) ):
vim.command('setl modifiable')
del vim.current.buffer[:]
vim.command('setl nomodified')
else:
vim.command(":new")

vim.command('setl syntax=blogsyntax')
vim.command('setl completefunc=Completable')

Expand Down