diff --git a/powerline/config_files/colorschemes/vim/default.json b/powerline/config_files/colorschemes/vim/default.json index cd7090a7..254383a1 100644 --- a/powerline/config_files/colorschemes/vim/default.json +++ b/powerline/config_files/colorschemes/vim/default.json @@ -1,36 +1,39 @@ { "name": "Default color scheme", "groups": { - "background": { "fg": "white", "bg": "gray2" }, - "background:divider": { "fg": "gray6", "bg": "gray2" }, - "mode": { "fg": "darkestgreen", "bg": "brightgreen", "attr": ["bold"] }, - "visual_range": { "fg": "brightestorange", "bg": "darkorange", "attr": ["bold"] }, - "modified_indicator": { "fg": "brightyellow", "bg": "gray4", "attr": ["bold"] }, - "paste_indicator": { "fg": "white", "bg": "mediumorange", "attr": ["bold"] }, - "readonly_indicator": { "fg": "brightestred", "bg": "gray4" }, - "branch": { "fg": "gray9", "bg": "gray4" }, - "branch_dirty": { "fg": "brightyellow", "bg": "gray4" }, - "branch_clean": { "fg": "gray9", "bg": "gray4" }, - "branch:divider": { "fg": "gray7", "bg": "gray4" }, - "file_directory": { "fg": "gray9", "bg": "gray4" }, - "file_name": { "fg": "white", "bg": "gray4", "attr": ["bold"] }, - "file_size": { "fg": "gray8", "bg": "gray2" }, - "file_name_no_file": { "fg": "gray9", "bg": "gray4", "attr": ["bold"] }, - "file_name_empty": { "fg": "gray9", "bg": "gray4" }, - "file_format": { "fg": "gray8", "bg": "gray2" }, - "file_encoding": { "fg": "gray8", "bg": "gray2" }, - "file_type": { "fg": "gray8", "bg": "gray2" }, - "file_vcs_status": { "fg": "brightestred", "bg": "gray4" }, - "file_vcs_status_M": { "fg": "brightyellow", "bg": "gray4" }, - "file_vcs_status_A": { "fg": "brightgreen", "bg": "gray4" }, - "line_percent": { "fg": "gray9", "bg": "gray4" }, - "line_percent_gradient": { "fg": "green_yellow_red", "bg": "gray4" }, - "line_current": { "fg": "gray1", "bg": "gray10", "attr": ["bold"] }, - "line_current_symbol": { "fg": "gray1", "bg": "gray10" }, + "background": { "fg": "white", "bg": "gray2" }, + "background:divider": { "fg": "gray6", "bg": "gray2" }, + "mode": { "fg": "darkestgreen", "bg": "brightgreen", "attr": ["bold"] }, + "visual_range": { "fg": "brightestorange", "bg": "darkorange", "attr": ["bold"] }, + "modified_indicator": { "fg": "brightyellow", "bg": "gray4", "attr": ["bold"] }, + "paste_indicator": { "fg": "white", "bg": "mediumorange", "attr": ["bold"] }, + "readonly_indicator": { "fg": "brightestred", "bg": "gray4" }, + "branch": { "fg": "gray9", "bg": "gray4" }, + "branch_dirty": { "fg": "brightyellow", "bg": "gray4" }, + "branch_clean": { "fg": "gray9", "bg": "gray4" }, + "branch:divider": { "fg": "gray7", "bg": "gray4" }, + "file_directory": { "fg": "gray9", "bg": "gray4" }, + "file_name": { "fg": "white", "bg": "gray4", "attr": ["bold"] }, + "file_size": { "fg": "gray8", "bg": "gray2" }, + "file_name_no_file": { "fg": "gray9", "bg": "gray4", "attr": ["bold"] }, + "file_name_empty": { "fg": "gray9", "bg": "gray4" }, + "file_format": { "fg": "gray8", "bg": "gray2" }, + "file_encoding": { "fg": "gray8", "bg": "gray2" }, + "file_type": { "fg": "gray8", "bg": "gray2" }, + "file_vcs_status": { "fg": "brightestred", "bg": "gray4" }, + "file_vcs_status_M": { "fg": "brightyellow", "bg": "gray4" }, + "file_vcs_status_A": { "fg": "brightgreen", "bg": "gray4" }, + "line_percent": { "fg": "gray9", "bg": "gray4" }, + "line_percent_gradient": { "fg": "green_yellow_red", "bg": "gray4" }, + "line_current": { "fg": "gray1", "bg": "gray10", "attr": ["bold"] }, + "line_current_symbol": { "fg": "gray1", "bg": "gray10" }, "virtcol_current_gradient": { "fg": "dark_GREEN_Orange_red", "bg": "gray10" }, - "col_current": { "fg": "gray6", "bg": "gray10" }, - "modified_buffers": { "fg": "brightyellow", "bg": "gray2" }, - "environment": { "fg": "gray8", "bg": "gray2" } + "col_current": { "fg": "gray6", "bg": "gray10" }, + "modified_buffers": { "fg": "brightyellow", "bg": "gray2" }, + "environment": { "fg": "gray8", "bg": "gray2" }, + "error": { "fg": "brightestred", "bg": "darkred", "attr": ["bold"] }, + "warning": { "fg": "brightyellow", "bg": "darkorange", "attr": ["bold"] }, + "current_tag": { "fg": "gray9", "bg": "gray2" } }, "mode_translations": { "nc": { @@ -68,9 +71,9 @@ "green_yellow_red": "gray5" }, "groups": { - "mode": { "fg": "darkestcyan", "bg": "white", "attr": ["bold"] }, + "mode": { "fg": "darkestcyan", "bg": "white", "attr": ["bold"] }, "background:divider": { "fg": "darkcyan", "bg": "darkestblue" }, - "branch:divider": { "fg": "darkcyan", "bg": "darkblue" } + "branch:divider": { "fg": "darkcyan", "bg": "darkblue" } } }, "v": { diff --git a/powerline/config_files/colorschemes/vim/solarized.json b/powerline/config_files/colorschemes/vim/solarized.json index 28bc2bb3..881953d7 100644 --- a/powerline/config_files/colorschemes/vim/solarized.json +++ b/powerline/config_files/colorschemes/vim/solarized.json @@ -29,7 +29,10 @@ "line_current_symbol": { "fg": "gray13", "bg": "lightyellow" }, "virtcol_current_gradient": { "fg": "GREEN_Orange_red", "bg": "gray10" }, "col_current": { "fg": "azure4", "bg": "lightyellow" }, - "environment": { "fg": "gray61", "bg": "royalblue5" } + "environment": { "fg": "gray61", "bg": "royalblue5" }, + "error": { "fg": "oldlace", "bg": "red", "attr": ["bold"] }, + "warning": { "fg": "oldlace", "bg": "orange", "attr": ["bold"] } + "current_tag": { "fg": "oldlace", "bg": "royalblue5", "attr": ["bold"] } }, "mode_translations": { "nc": { diff --git a/powerline/config_files/config.json b/powerline/config_files/config.json index a70922ff..e9a627e7 100644 --- a/powerline/config_files/config.json +++ b/powerline/config_files/config.json @@ -37,7 +37,12 @@ "local_themes": { "cmdwin": "cmdwin", "help": "help", - "quickfix": "quickfix" + "quickfix": "quickfix", + + "powerline.matchers.plugin.nerdtree.nerdtree": "plugin/nerdtree", + "powerline.matchers.plugin.ctrlp.ctrlp": "plugin/ctrlp", + "powerline.matchers.plugin.gundo.gundo": "plugin/gundo", + "powerline.matchers.plugin.gundo.gundo_preview": "plugin/gundo-preview" } }, "wm": { diff --git a/powerline/config_files/themes/vim/default.json b/powerline/config_files/themes/vim/default.json index 1380fe13..5f10912d 100644 --- a/powerline/config_files/themes/vim/default.json +++ b/powerline/config_files/themes/vim/default.json @@ -58,6 +58,19 @@ "name": "modified_indicator", "before": " " }, + { + "exclude_modes": ["nc"], + "module": "powerline.segments.plugin.syntastic", + "name": "syntastic", + "priority": 50 + }, + { + "exclude_modes": ["nc"], + "module": "powerline.segments.plugin.tagbar", + "name": "current_tag", + "draw_soft_divider": false, + "priority": 50 + }, { "type": "string", "highlight_group": ["background"], 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..02015b78 --- /dev/null +++ b/powerline/config_files/themes/vim/plugin/ctrlp.json @@ -0,0 +1,28 @@ +{ + "default_module": "powerline.segments.plugin.ctrlp", + "segments": { + "left": [ + { + "name": "ctrlp", + "args": { + "side": "left" + } + }, + { + "type": "string", + "highlight_group": ["ctrlp.background", "background"], + "draw_soft_divider": false, + "draw_hard_divider": false, + "width": "auto" + } + ], + "right": [ + { + "name": "ctrlp", + "args": { + "side": "right" + } + } + ] + } +} diff --git a/powerline/config_files/themes/vim/plugin/gundo-preview.json b/powerline/config_files/themes/vim/plugin/gundo-preview.json new file mode 100644 index 00000000..3ce202ea --- /dev/null +++ b/powerline/config_files/themes/vim/plugin/gundo-preview.json @@ -0,0 +1,19 @@ +{ + "default_module": "powerline.segments.plugin.gundo", + "segments": { + "left": [ + { + "type": "string", + "highlight_group": ["gundo.name", "file_name"], + "contents": "Undo diff" + }, + { + "type": "string", + "highlight_group": ["gundo.background", "background"], + "draw_soft_divider": false, + "draw_hard_divider": false, + "width": "auto" + } + ] + } +} diff --git a/powerline/config_files/themes/vim/plugin/gundo.json b/powerline/config_files/themes/vim/plugin/gundo.json new file mode 100644 index 00000000..0c1a336a --- /dev/null +++ b/powerline/config_files/themes/vim/plugin/gundo.json @@ -0,0 +1,19 @@ +{ + "default_module": "powerline.segments.plugin.gundo", + "segments": { + "left": [ + { + "type": "string", + "highlight_group": ["gundo.name", "file_name"], + "contents": "Undo tree" + }, + { + "type": "string", + "highlight_group": ["gundo.background", "background"], + "draw_soft_divider": false, + "draw_hard_divider": false, + "width": "auto" + } + ] + } +} diff --git a/powerline/config_files/themes/vim/plugin/nerdtree.json b/powerline/config_files/themes/vim/plugin/nerdtree.json new file mode 100644 index 00000000..95495db1 --- /dev/null +++ b/powerline/config_files/themes/vim/plugin/nerdtree.json @@ -0,0 +1,17 @@ +{ + "default_module": "powerline.segments.plugin.nerdtree", + "segments": { + "left": [ + { + "name": "nerdtree" + }, + { + "type": "string", + "highlight_group": ["background"], + "draw_soft_divider": false, + "draw_hard_divider": false, + "width": "auto" + } + ] + } +} diff --git a/powerline/matchers/__init__.py b/powerline/matchers/__init__.py index e69de29b..3ad9513f 100644 --- a/powerline/matchers/__init__.py +++ b/powerline/matchers/__init__.py @@ -0,0 +1,2 @@ +from pkgutil import extend_path +__path__ = extend_path(__path__, __name__) diff --git a/powerline/matchers/plugin/__init__.py b/powerline/matchers/plugin/__init__.py new file mode 100644 index 00000000..3ad9513f --- /dev/null +++ b/powerline/matchers/plugin/__init__.py @@ -0,0 +1,2 @@ +from pkgutil import extend_path +__path__ = extend_path(__path__, __name__) diff --git a/powerline/matchers/plugin/ctrlp.py b/powerline/matchers/plugin/ctrlp.py new file mode 100644 index 00000000..50b374a7 --- /dev/null +++ b/powerline/matchers/plugin/ctrlp.py @@ -0,0 +1,21 @@ +# 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/matchers/plugin/gundo.py b/powerline/matchers/plugin/gundo.py new file mode 100644 index 00000000..1992f711 --- /dev/null +++ b/powerline/matchers/plugin/gundo.py @@ -0,0 +1,13 @@ +# vim:fileencoding=utf-8:noet + +import os + + +def gundo(matcher_info): + name = matcher_info['buffer'].name + return name and os.path.basename(name) == '__Gundo__' + + +def gundo_preview(matcher_info): + name = matcher_info['buffer'].name + return name and os.path.basename(name) == '__Gundo_Preview__' diff --git a/powerline/matchers/plugin/nerdtree.py b/powerline/matchers/plugin/nerdtree.py new file mode 100644 index 00000000..a9f8f0bc --- /dev/null +++ b/powerline/matchers/plugin/nerdtree.py @@ -0,0 +1,9 @@ +# vim:fileencoding=utf-8:noet + +import os +import re + + +def nerdtree(matcher_info): + name = matcher_info['buffer'].name + return name and re.match(r'NERD_tree_\d+', os.path.basename(name)) diff --git a/powerline/segments/__init__.py b/powerline/segments/__init__.py index e69de29b..3ad9513f 100644 --- a/powerline/segments/__init__.py +++ b/powerline/segments/__init__.py @@ -0,0 +1,2 @@ +from pkgutil import extend_path +__path__ = extend_path(__path__, __name__) diff --git a/powerline/segments/plugin/__init__.py b/powerline/segments/plugin/__init__.py new file mode 100644 index 00000000..3ad9513f --- /dev/null +++ b/powerline/segments/plugin/__init__.py @@ -0,0 +1,2 @@ +from pkgutil import extend_path +__path__ = extend_path(__path__, __name__) diff --git a/powerline/segments/plugin/ctrlp.py b/powerline/segments/plugin/ctrlp.py new file mode 100644 index 00000000..d8b4e3d8 --- /dev/null +++ b/powerline/segments/plugin/ctrlp.py @@ -0,0 +1,89 @@ +# vim:fileencoding=utf-8:noet + +import vim +from powerline.bindings.vim import getbufvar + + +def ctrlp(pl, side): + ctrlp_type = getbufvar('%', 'powerline_ctrlp_type') + ctrlp_args = getbufvar('%', 'powerline_ctrlp_args') + + return globals()['ctrlp_stl_{0}_{1}'.format(side, 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, + 'align': 'c', + }, + { + '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'], + }, + ] diff --git a/powerline/segments/plugin/nerdtree.py b/powerline/segments/plugin/nerdtree.py new file mode 100644 index 00000000..c12ce777 --- /dev/null +++ b/powerline/segments/plugin/nerdtree.py @@ -0,0 +1,18 @@ +# vim:fileencoding=utf-8:noet + +import vim + +from powerline.bindings.vim import getbufvar +from powerline.segments.vim import window_cached + + +@window_cached +def nerdtree(pl): + ntr = getbufvar('%', 'NERDTreeRoot') + if not ntr: + return + path_str = vim.eval('getbufvar("%", "NERDTreeRoot").path.str()') + return [{ + 'contents': path_str, + 'highlight_group': ['nerdtree.path', 'file_name'], + }] diff --git a/powerline/segments/plugin/syntastic.py b/powerline/segments/plugin/syntastic.py new file mode 100644 index 00000000..4c470dd9 --- /dev/null +++ b/powerline/segments/plugin/syntastic.py @@ -0,0 +1,28 @@ +# vim:fileencoding=utf-8:noet + +import vim + +from powerline.segments.vim import window_cached + + +@window_cached +def syntastic(pl): + if not int(vim.eval('exists("g:SyntasticLoclist")')): + return + has_errors = int(vim.eval('g:SyntasticLoclist.current().hasErrorsOrWarningsToDisplay()')) + if not has_errors: + return + errors = vim.eval('g:SyntasticLoclist.current().errors()') + warnings = vim.eval('g:SyntasticLoclist.current().warnings()') + segments = [] + if errors: + segments.append({ + 'contents': 'ERR:  {line} ({num}) '.format(line=errors[0]['lnum'], num=len(errors)), + 'highlight_group': ['syntastic.error', 'error', 'background'], + }) + if warnings: + segments.append({ + 'contents': 'WARN:  {line} ({num}) '.format(line=warnings[0]['lnum'], num=len(warnings)), + 'highlight_group': ['syntastic.warning', 'warning', 'background'], + }) + return segments diff --git a/powerline/segments/plugin/tagbar.py b/powerline/segments/plugin/tagbar.py new file mode 100644 index 00000000..07e260f8 --- /dev/null +++ b/powerline/segments/plugin/tagbar.py @@ -0,0 +1,12 @@ +# vim:fileencoding=utf-8:noet + +import vim + +from powerline.segments.vim import window_cached + + +@window_cached +def current_tag(pl): + if not int(vim.eval('exists(":Tagbar")')): + return + return vim.eval('tagbar#currenttag("%s", "")') diff --git a/tests/test_configuration.py b/tests/test_configuration.py index f8053fb6..19b9bb04 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -19,9 +19,16 @@ class TestConfig(TestCase): def test_vim(self): from powerline.vim import VimPowerline cfg_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'powerline', 'config_files') - buffers = ((('bufoptions',), {'buftype': 'help'}), (('bufname', '[Command Line]'), {}), (('bufoptions',), {'buftype': 'quickfix'})) + buffers = ( + (('bufoptions',), {'buftype': 'help'}), + (('bufname', '[Command Line]'), {}), + (('bufoptions',), {'buftype': 'quickfix'}), + ) with open(os.path.join(cfg_path, 'config.json'), 'r') as f: - self.assertEqual(len(buffers), len(json.load(f)['ext']['vim']['local_themes'])) + 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() if not '.' in k) + self.assertEqual(len(buffers), len(local_themes)) outputs = {} i = 0 diff --git a/tests/vim.py b/tests/vim.py index beec40de..91a94886 100644 --- a/tests/vim.py +++ b/tests/vim.py @@ -156,6 +156,9 @@ def command(cmd): elif cmd.startswith('hi '): sp = cmd.split() _highlights[sp[1]] = sp[2:] + elif cmd.startswith('function! Powerline_plugin_ctrlp'): + # Ignore CtrlP updating functions + pass else: raise NotImplementedError @@ -169,6 +172,8 @@ def eval(expr): elif expr.startswith('PowerlineRegisterCachePurgerEvent'): _buf_purge_events.add(expr[expr.find('"') + 1:expr.rfind('"') - 1]) return "0" + elif expr.startswith('exists('): + return '0' raise NotImplementedError