Work around vim bugs in appending to buffers

This commit is contained in:
Ben Jackson 2018-12-20 16:55:28 +00:00
commit cbff48c959

View file

@ -202,6 +202,7 @@ def AskForInput( prompt ):
def AppendToBuffer( buf, line_or_lines, modified=False ): def AppendToBuffer( buf, line_or_lines, modified=False ):
try:
# After clearing the buffer (using buf[:] = None) there is always a single # After clearing the buffer (using buf[:] = None) there is always a single
# empty line in the buffer object and no "is empty" method. # empty line in the buffer object and no "is empty" method.
if len( buf ) > 1 or buf[ 0 ]: if len( buf ) > 1 or buf[ 0 ]:
@ -213,7 +214,15 @@ def AppendToBuffer( buf, line_or_lines, modified=False ):
else: else:
line = 1 line = 1
buf[:] = line_or_lines buf[:] = line_or_lines
except vim.error as e:
# 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: if not modified:
buf.options[ 'modified' ] = False buf.options[ 'modified' ] = False
@ -221,6 +230,7 @@ def AppendToBuffer( buf, line_or_lines, modified=False ):
return line return line
def ClearBuffer( buf ): def ClearBuffer( buf ):
buf[:] = None buf[:] = None