diff --git a/powerline/bindings/vim/__init__.py b/powerline/bindings/vim/__init__.py index 15543f04..cf06b4eb 100644 --- a/powerline/bindings/vim/__init__.py +++ b/powerline/bindings/vim/__init__.py @@ -398,3 +398,16 @@ def on_bwipe(): environ = VimEnviron() + + +def create_ruby_dpowerline(): + vim.command(( + ''' + ruby + if $powerline == nil + class Powerline + end + $powerline = Powerline.new + end + ''' + )) diff --git a/powerline/config_files/colorschemes/vim/__main__.json b/powerline/config_files/colorschemes/vim/__main__.json index 6adb61ce..02a8e094 100644 --- a/powerline/config_files/colorschemes/vim/__main__.json +++ b/powerline/config_files/colorschemes/vim/__main__.json @@ -26,6 +26,11 @@ "buf_nc:file_directory": "tab_nc:file_directory", "buf_nc:file_name": "tab_nc:file_name", "buf_nc:bufnr": "tab_nc:tabnr", - "buf_nc:modified_indicator": "tab_nc:modified_indicator" + "buf_nc:modified_indicator": "tab_nc:modified_indicator", + + "commandt:label": "file_name", + "commandt:background": "background", + "commandt:finder": "file_name", + "commandt:path": "file_directory" } } diff --git a/powerline/config_files/config.json b/powerline/config_files/config.json index a5389b6c..2bb53b9d 100644 --- a/powerline/config_files/config.json +++ b/powerline/config_files/config.json @@ -36,6 +36,7 @@ "powerline.matchers.vim.plugin.nerdtree.nerdtree": "plugin_nerdtree", "powerline.matchers.vim.plugin.ctrlp.ctrlp": "plugin_ctrlp", + "powerline.matchers.vim.plugin.commandt.commandt": "plugin_commandt", "powerline.matchers.vim.plugin.gundo.gundo": "plugin_gundo", "powerline.matchers.vim.plugin.gundo.gundo_preview": "plugin_gundo-preview" } diff --git a/powerline/config_files/themes/vim/plugin_commandt.json b/powerline/config_files/themes/vim/plugin_commandt.json new file mode 100644 index 00000000..a9ad7c99 --- /dev/null +++ b/powerline/config_files/themes/vim/plugin_commandt.json @@ -0,0 +1,26 @@ +{ + "segments": { + "left": [ + { + "type": "string", + "contents": "Command-T", + "highlight_group": ["commandt:label"] + }, + { + "function": "powerline.segments.vim.plugin.commandt.finder" + }, + { + "function": "powerline.segments.vim.plugin.commandt.path" + }, + { + "type": "string", + "highlight_group": ["commandt:background"], + "draw_soft_divider": false, + "draw_hard_divider": false, + "width": "auto" + } + ], + "right": [ + ] + } +} diff --git a/powerline/matchers/vim/plugin/commandt.py b/powerline/matchers/vim/plugin/commandt.py new file mode 100644 index 00000000..e4236f3e --- /dev/null +++ b/powerline/matchers/vim/plugin/commandt.py @@ -0,0 +1,11 @@ +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +import os + +from powerline.bindings.vim import buffer_name + + +def commandt(matcher_info): + name = buffer_name(matcher_info) + return name and os.path.basename(name) == b'GoToFile' diff --git a/powerline/segments/vim/plugin/commandt.py b/powerline/segments/vim/plugin/commandt.py new file mode 100644 index 00000000..96ed134c --- /dev/null +++ b/powerline/segments/vim/plugin/commandt.py @@ -0,0 +1,78 @@ +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +try: + import vim +except ImportError: + vim = object() + +from powerline.bindings.vim import create_ruby_dpowerline + + +def initialize(): + global initialized + if initialized: + return + initialized = True + create_ruby_dpowerline() + vim.command(( + # When using :execute (vim.command uses the same code) one should not + # use << EOF. + ''' + ruby + if (not ($command_t.respond_to? 'active_finder')) + def $command_t.active_finder + @active_finder.class.name + end + end + if (not ($command_t.respond_to? 'path')) + def $command_t.path + @path + end + end + def $powerline.commandt_set_active_finder + ::VIM::command "let g:powerline_commandt_reply = '#{$command_t.active_finder}'" + end + def $powerline.commandt_set_path + ::VIM::command "let g:powerline_commandt_reply = '#{$command_t.path.gsub(/'/, "''")}'" + end + ''' + )) + + +initialized = False + + +def finder(pl): + '''Display Command-T finder name + + Requires $command_t.active_finder and .path methods (code above may + monkey-patch $command_t to add them). + ''' + initialize() + vim.command('ruby $powerline.commandt_set_active_finder') + return [{ + 'highlight_group': ['commandt:finder'], + 'contents': vim.eval('g:powerline_commandt_reply').replace('CommandT::', '') + }] + + +FINDERS_WITHOUT_PATH = set(( + 'CommandT::MRUBufferFinder', + 'CommandT::BufferFinder', + 'CommandT::TagFinder', + 'CommandT::JumpFinder', +)) + + +def path(pl): + initialize() + vim.command('ruby $powerline.commandt_set_active_finder') + finder = vim.eval('g:powerline_commandt_reply') + if finder in FINDERS_WITHOUT_PATH: + return None + vim.command('ruby $powerline.commandt_set_path') + return [{ + 'highlight_group': ['commandt:path'], + 'contents': vim.eval('g:powerline_commandt_reply') + }] diff --git a/tests/test_provided_config_files.py b/tests/test_provided_config_files.py index ace5d14b..d0752d0e 100644 --- a/tests/test_provided_config_files.py +++ b/tests/test_provided_config_files.py @@ -55,12 +55,15 @@ class TestVimConfig(TestCase): (('bufname', '__Gundo__'), {}), (('bufname', '__Gundo_Preview__'), {}), (('bufname', 'ControlP'), {}), + # No Command-T tests here: requires +ruby or emulation + # No tabline here: tablines are tested separately ) with open(os.path.join(cfg_path, 'config.json'), 'r') as f: local_themes_raw = json.load(f)['ext']['vim']['local_themes'] # Don’t run tests on external/plugin segments local_themes = dict((k, v) for (k, v) in local_themes_raw.items()) - self.assertEqual(len(buffers), len(local_themes) - 1) + # See end of the buffers definition above for `- 2` + self.assertEqual(len(buffers), len(local_themes) - 2) outputs = {} i = 0