Do not use segment_info['buffer'].name ever

This results in UnicodeDecodeErrors for non-unicode filenames
This commit is contained in:
ZyX 2014-09-14 14:05:01 +04:00
parent a4e711dae7
commit f8b9ad4ac4
2 changed files with 26 additions and 19 deletions

View File

@ -489,7 +489,7 @@ def branch(pl, segment_info, create_watcher, status_colors=False):
Divider highlight group used: ``branch:divider``. Divider highlight group used: ``branch:divider``.
''' '''
name = segment_info['buffer'].name name = buffer_name(segment_info)
skip = not (name and (not vim_getbufoption(segment_info, 'buftype'))) skip = not (name and (not vim_getbufoption(segment_info, 'buftype')))
if not skip: if not skip:
repo = guess(path=name, create_watcher=create_watcher) repo = guess(path=name, create_watcher=create_watcher)
@ -513,7 +513,7 @@ def file_vcs_status(pl, segment_info, create_watcher):
Highlight groups used: ``file_vcs_status``. Highlight groups used: ``file_vcs_status``.
''' '''
name = segment_info['buffer'].name name = buffer_name(segment_info)
skip = not (name and (not vim_getbufoption(segment_info, 'buftype'))) skip = not (name and (not vim_getbufoption(segment_info, 'buftype')))
if not skip: if not skip:
repo = guess(path=name, create_watcher=create_watcher) repo = guess(path=name, create_watcher=create_watcher)

View File

@ -146,23 +146,30 @@ class VimPowerline(Powerline):
self.update_renderer() self.update_renderer()
__main__.powerline = self __main__.powerline = self
if ( try:
bool(int(vim.eval("has('gui_running') && argc() == 0"))) if (
and not vim.current.buffer.name bool(int(vim.eval("has('gui_running') && argc() == 0")))
and len(vim.windows) == 1 and not vim.current.buffer.name
): and len(vim.windows) == 1
# Hack to show startup screen. Problems in GUI: ):
# - Defining local value of &statusline option while computing global # Hack to show startup screen. Problems in GUI:
# value purges startup screen. # - Defining local value of &statusline option while computing
# - Defining highlight group while computing statusline purges startup # global value purges startup screen.
# screen. # - Defining highlight group while computing statusline purges
# This hack removes the “while computing statusline” part: both things # startup screen.
# are defined, but they are defined right now. # This hack removes the “while computing statusline” part: both
# # things are defined, but they are defined right now.
# The above condition disables this hack if no GUI is running, Vim did #
# not open any files and there is only one window. Without GUI # The above condition disables this hack if no GUI is running,
# everything works, in other cases startup screen is not shown. # Vim did not open any files and there is only one window.
self.new_window() # Without GUI everything works, in other cases startup screen is
# not shown.
self.new_window()
except UnicodeDecodeError:
# vim.current.buffer.name may raise UnicodeDecodeError when using
# Python-3*. Fortunately, this means that current buffer is not
# empty buffer, so the above condition should be False.
pass
# Cannot have this in one line due to weird newline handling (in :execute # Cannot have this in one line due to weird newline handling (in :execute
# context newline is considered part of the command in just the same cases # context newline is considered part of the command in just the same cases