From 4ed1a7e5619bd2546307f999a20e23693f4e5942 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 14 Sep 2014 13:53:31 +0400 Subject: [PATCH] Compare bytes() objects in matcher functions Fixes #1071 --- powerline/matchers/vim/__init__.py | 6 +++--- powerline/matchers/vim/plugin/ctrlp.py | 9 ++++++--- powerline/matchers/vim/plugin/gundo.py | 10 ++++++---- powerline/matchers/vim/plugin/nerdtree.py | 9 +++++++-- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/powerline/matchers/vim/__init__.py b/powerline/matchers/vim/__init__.py index d7e9b48d..b2bad4cc 100644 --- a/powerline/matchers/vim/__init__.py +++ b/powerline/matchers/vim/__init__.py @@ -3,7 +3,7 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct import os -from powerline.bindings.vim import vim_getbufoption +from powerline.bindings.vim import vim_getbufoption, buffer_name def help(matcher_info): @@ -11,8 +11,8 @@ def help(matcher_info): def cmdwin(matcher_info): - name = matcher_info['buffer'].name - return name and os.path.basename(name) == '[Command Line]' + name = buffer_name(matcher_info) + return name and os.path.basename(name) == b'[Command Line]' def quickfix(matcher_info): diff --git a/powerline/matchers/vim/plugin/ctrlp.py b/powerline/matchers/vim/plugin/ctrlp.py index f2b05980..56028649 100644 --- a/powerline/matchers/vim/plugin/ctrlp.py +++ b/powerline/matchers/vim/plugin/ctrlp.py @@ -3,10 +3,13 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct import os +from powerline.bindings.vim import buffer_name + + try: import vim except ImportError: - vim = object() + pass else: vim.command(''' function! Powerline_plugin_ctrlp_main(...) @@ -26,5 +29,5 @@ else: def ctrlp(matcher_info): - name = matcher_info['buffer'].name - return name and os.path.basename(name) == 'ControlP' + name = buffer_name(matcher_info) + return name and os.path.basename(name) == b'ControlP' diff --git a/powerline/matchers/vim/plugin/gundo.py b/powerline/matchers/vim/plugin/gundo.py index 356ffd65..e0fe3776 100644 --- a/powerline/matchers/vim/plugin/gundo.py +++ b/powerline/matchers/vim/plugin/gundo.py @@ -3,12 +3,14 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct import os +from powerline.bindings.vim import buffer_name + def gundo(matcher_info): - name = matcher_info['buffer'].name - return name and os.path.basename(name) == '__Gundo__' + name = buffer_name(matcher_info) + return name and os.path.basename(name) == b'__Gundo__' def gundo_preview(matcher_info): - name = matcher_info['buffer'].name - return name and os.path.basename(name) == '__Gundo_Preview__' + name = buffer_name(matcher_info) + return name and os.path.basename(name) == b'__Gundo_Preview__' diff --git a/powerline/matchers/vim/plugin/nerdtree.py b/powerline/matchers/vim/plugin/nerdtree.py index aeb2c24c..3ec423df 100644 --- a/powerline/matchers/vim/plugin/nerdtree.py +++ b/powerline/matchers/vim/plugin/nerdtree.py @@ -4,7 +4,12 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct import os import re +from powerline.bindings.vim import buffer_name + + +NERD_TREE_RE = re.compile(b'NERD_TREE_\\d+') + def nerdtree(matcher_info): - name = matcher_info['buffer'].name - return name and re.match(r'NERD_tree_\d+', os.path.basename(name)) + name = buffer_name(matcher_info) + return name and NERD_TREE_RE.match(os.path.basename(name))