From 0b5b81774f15a32546d0635e8620858acd0d0f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20Silkeb=C3=A6kken?= Date: Tue, 20 Aug 2013 15:29:09 +0200 Subject: [PATCH] Add Control-P statuslines This hacks around the way CtrlP handles statuslines. Powerline will always override the statusline, but CtrlP doesn't make its details available as buffer variables so separate functions assign the details to buffer variables each statusline redraw. Currently this statusline only uses a couple of highlight groups, colorschemes should add the HL groups to make this prettier. --- powerline/config_files/config.json | 3 +- .../config_files/themes/vim/plugin/ctrlp.json | 22 +++++ powerline/matchers/plugin/ctrlp.py | 27 ++++++ powerline/segments/plugin/ctrlp.py | 94 +++++++++++++++++++ 4 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 powerline/config_files/themes/vim/plugin/ctrlp.json create mode 100644 powerline/matchers/plugin/ctrlp.py create mode 100644 powerline/segments/plugin/ctrlp.py diff --git a/powerline/config_files/config.json b/powerline/config_files/config.json index b825f9b0..aace2c63 100644 --- a/powerline/config_files/config.json +++ b/powerline/config_files/config.json @@ -39,7 +39,8 @@ "help": "help", "quickfix": "quickfix", - "powerline.matchers.plugin.nerdtree.nerdtree": "plugin/nerdtree" + "powerline.matchers.plugin.nerdtree.nerdtree": "plugin/nerdtree", + "powerline.matchers.plugin.ctrlp.ctrlp": "plugin/ctrlp" } }, "wm": { diff --git a/powerline/config_files/themes/vim/plugin/ctrlp.json b/powerline/config_files/themes/vim/plugin/ctrlp.json new file mode 100644 index 00000000..da43736a --- /dev/null +++ b/powerline/config_files/themes/vim/plugin/ctrlp.json @@ -0,0 +1,22 @@ +{ + "default_module": "powerline.segments.plugin.ctrlp", + "segments": { + "left": [ + { + "name": "ctrlp_left" + }, + { + "type": "string", + "highlight_group": ["ctrlp.background", "background"], + "draw_soft_divider": false, + "draw_hard_divider": false, + "width": "auto" + } + ], + "right": [ + { + "name": "ctrlp_right" + } + ] + } +} diff --git a/powerline/matchers/plugin/ctrlp.py b/powerline/matchers/plugin/ctrlp.py new file mode 100644 index 00000000..525a0d95 --- /dev/null +++ b/powerline/matchers/plugin/ctrlp.py @@ -0,0 +1,27 @@ +# vim:fileencoding=utf-8:noet + +import os +import vim + +vim.command(''' +function! Powerline_plugin_ctrlp_main(...) + let b:powerline_ctrlp_type = 'main' + let b:powerline_ctrlp_args = a:000 +endfunction +''') + +vim.command(''' +function! Powerline_plugin_ctrlp_prog(...) + let b:powerline_ctrlp_type = 'prog' + let b:powerline_ctrlp_args = a:000 +endfunction +''') + +vim.command(''' +let g:ctrlp_status_func = { 'main': 'Powerline_plugin_ctrlp_main', 'prog': 'Powerline_plugin_ctrlp_prog' } +''') + + +def ctrlp(matcher_info): + name = matcher_info['buffer'].name + return name and os.path.basename(name) == 'ControlP' diff --git a/powerline/segments/plugin/ctrlp.py b/powerline/segments/plugin/ctrlp.py new file mode 100644 index 00000000..f696f233 --- /dev/null +++ b/powerline/segments/plugin/ctrlp.py @@ -0,0 +1,94 @@ +# vim:fileencoding=utf-8:noet + +import vim + + +def ctrlp_left(pl): + ctrlp_type = vim.eval('getbufvar("%", "powerline_ctrlp_type")') + ctrlp_args = vim.eval('getbufvar("%", "powerline_ctrlp_args")') + + return globals()['ctrlp_stl_left_' + ctrlp_type](pl, *ctrlp_args) + + +def ctrlp_right(pl): + ctrlp_type = vim.eval('getbufvar("%", "powerline_ctrlp_type")') + ctrlp_args = vim.eval('getbufvar("%", "powerline_ctrlp_args")') + + return globals()['ctrlp_stl_right_' + ctrlp_type](pl, *ctrlp_args) + + +def ctrlp_stl_left_main(pl, focus, byfname, regex, prev, item, next, marked): + marked = marked[2:-1] + segments = [] + + if int(regex): + segments.append({ + 'contents': 'regex', + 'highlight_group': ['ctrlp.regex', 'background'], + }) + + segments += [ + { + 'contents': prev + ' ', + 'highlight_group': ['ctrlp.prev', 'background'], + 'draw_inner_divider': True, + 'priority': 40, + }, + { + 'contents': item, + 'highlight_group': ['ctrlp.item', 'file_name'], + 'draw_inner_divider': True, + 'width': 10, + }, + { + 'contents': ' ' + next, + 'highlight_group': ['ctrlp.next', 'background'], + 'draw_inner_divider': True, + 'priority': 40, + }, + ] + + if marked != '-': + segments.append({ + 'contents': marked, + 'highlight_group': ['ctrlp.marked', 'background'], + 'draw_inner_divider': True, + }) + + return segments + + +def ctrlp_stl_right_main(pl, focus, byfname, regex, prev, item, next, marked): + segments = [ + { + 'contents': focus, + 'highlight_group': ['ctrlp.focus', 'background'], + 'draw_inner_divider': True, + 'priority': 50, + }, + { + 'contents': byfname, + 'highlight_group': ['ctrlp.byfname', 'background'], + 'priority': 50, + }, + ] + + return segments + + +def ctrlp_stl_left_prog(pl, progress): + return [ + { + 'contents': 'Loading...', + 'highlight_group': ['ctrlp.progress', 'file_name'], + }, + ] + + +def ctrlp_stl_right_prog(pl, progress): + return [ + { + 'contents': progress, + 'highlight_group': ['ctrlp.progress', 'file_name'], + }, + ]