Add support for Command-T
This commit is contained in:
parent
7139021c45
commit
28435f05d2
|
@ -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
|
||||
'''
|
||||
))
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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": [
|
||||
]
|
||||
}
|
||||
}
|
|
@ -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'
|
|
@ -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')
|
||||
}]
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue