Work around vim bugs in appending to buffers
This commit is contained in:
parent
0cfe1ec99b
commit
cbff48c959
1 changed files with 24 additions and 14 deletions
|
|
@ -202,25 +202,35 @@ def AskForInput( prompt ):
|
||||||
|
|
||||||
|
|
||||||
def AppendToBuffer( buf, line_or_lines, modified=False ):
|
def AppendToBuffer( buf, line_or_lines, modified=False ):
|
||||||
# After clearing the buffer (using buf[:] = None) there is always a single
|
try:
|
||||||
# empty line in the buffer object and no "is empty" method.
|
# After clearing the buffer (using buf[:] = None) there is always a single
|
||||||
if len( buf ) > 1 or buf[ 0 ]:
|
# empty line in the buffer object and no "is empty" method.
|
||||||
line = len( buf ) + 1
|
if len( buf ) > 1 or buf[ 0 ]:
|
||||||
buf.append( line_or_lines )
|
line = len( buf ) + 1
|
||||||
elif isinstance( line_or_lines, str ):
|
buf.append( line_or_lines )
|
||||||
line = 1
|
elif isinstance( line_or_lines, str ):
|
||||||
buf[-1] = line_or_lines
|
line = 1
|
||||||
else:
|
buf[-1] = line_or_lines
|
||||||
line = 1
|
else:
|
||||||
buf[:] = line_or_lines
|
line = 1
|
||||||
|
buf[:] = line_or_lines
|
||||||
if not modified:
|
except vim.error as e:
|
||||||
buf.options[ 'modified' ] = False
|
# There seem to be a lot of Vim bugs that lead to E351, whose help says that
|
||||||
|
# this is an internal error. Ignore the error, but write a trace to the log.
|
||||||
|
if 'E315' in str( e ):
|
||||||
|
logging.getLogger( __name__ ).exception(
|
||||||
|
'Internal error while updating buffer' )
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
finally:
|
||||||
|
if not modified:
|
||||||
|
buf.options[ 'modified' ] = False
|
||||||
|
|
||||||
# Return the first Vim line number (1-based) that we just set.
|
# Return the first Vim line number (1-based) that we just set.
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def ClearBuffer( buf ):
|
def ClearBuffer( buf ):
|
||||||
buf[:] = None
|
buf[:] = None
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue