From 4e6b0a7ec8f2fa54053e4162c8b604a85e8d667d Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 6 Jan 2015 03:57:38 +0300 Subject: [PATCH] Remove Control-P plugin support If somebody needs to readd it he should make better code, specifically: - Functions and variables necessary for supporting Control-P need to be defined in a separate initialiazation function that is only called if Control-P was found. - Segments that show different information must be defined as separate segments that may be put into configuration file. - Segment functions must not know side they are on. - Segment functions must not emit `priority`, it must go to configuration file. - Segment functions must have proper documentation. - Segment functions must not emit `width` and `align` keys. - String `Loading...` or the equivalent must be overridable from configuration, same for other interface strings (e.g. what is shown when `regex` is true). - Segment functions must have names that make it clear what they emit. Closes #1244 --- docs/source/configuration/segments/vim.rst | 6 - powerline/config_files/config.json | 1 - .../config_files/themes/vim/plugin_ctrlp.json | 28 ----- powerline/matchers/vim/plugin/ctrlp.py | 33 ----- powerline/segments/vim/plugin/ctrlp.py | 116 ------------------ tests/test_ctrlp_plugin.vim | 17 --- tests/test_provided_config_files.py | 5 - tests/vim.py | 6 - 8 files changed, 212 deletions(-) delete mode 100644 powerline/config_files/themes/vim/plugin_ctrlp.json delete mode 100644 powerline/matchers/vim/plugin/ctrlp.py delete mode 100644 powerline/segments/vim/plugin/ctrlp.py delete mode 100755 tests/test_ctrlp_plugin.vim diff --git a/docs/source/configuration/segments/vim.rst b/docs/source/configuration/segments/vim.rst index eeadd4f1..b0f52c18 100644 --- a/docs/source/configuration/segments/vim.rst +++ b/docs/source/configuration/segments/vim.rst @@ -15,12 +15,6 @@ Syntastic segments .. automodule:: powerline.segments.vim.plugin.syntastic :members: -Ctrl-P segments ---------------- - -.. automodule:: powerline.segments.vim.plugin.ctrlp - :members: - Command-T segments ------------------ diff --git a/powerline/config_files/config.json b/powerline/config_files/config.json index 2bb53b9d..9502129a 100644 --- a/powerline/config_files/config.json +++ b/powerline/config_files/config.json @@ -35,7 +35,6 @@ "quickfix": "quickfix", "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_ctrlp.json b/powerline/config_files/themes/vim/plugin_ctrlp.json deleted file mode 100644 index 25e16e79..00000000 --- a/powerline/config_files/themes/vim/plugin_ctrlp.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "default_module": "powerline.segments.vim.plugin.ctrlp", - "segments": { - "left": [ - { - "function": "ctrlp", - "args": { - "side": "left" - } - }, - { - "type": "string", - "highlight_group": ["ctrlp.background", "background"], - "draw_soft_divider": false, - "draw_hard_divider": false, - "width": "auto" - } - ], - "right": [ - { - "function": "ctrlp", - "args": { - "side": "right" - } - } - ] - } -} diff --git a/powerline/matchers/vim/plugin/ctrlp.py b/powerline/matchers/vim/plugin/ctrlp.py deleted file mode 100644 index 56028649..00000000 --- a/powerline/matchers/vim/plugin/ctrlp.py +++ /dev/null @@ -1,33 +0,0 @@ -# vim:fileencoding=utf-8:noet -from __future__ import (unicode_literals, division, absolute_import, print_function) - -import os - -from powerline.bindings.vim import buffer_name - - -try: - import vim -except ImportError: - pass -else: - 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 = buffer_name(matcher_info) - return name and os.path.basename(name) == b'ControlP' diff --git a/powerline/segments/vim/plugin/ctrlp.py b/powerline/segments/vim/plugin/ctrlp.py deleted file mode 100644 index 651e0b74..00000000 --- a/powerline/segments/vim/plugin/ctrlp.py +++ /dev/null @@ -1,116 +0,0 @@ -# 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 getbufvar -from powerline.segments.vim import window_cached - - -@window_cached -def ctrlp(pl, side): - ''' - - Highlight groups used: ``ctrlp.regex`` or ``background``, ``ctrlp.prev`` or ``background``, ``ctrlp.item`` or ``file_name``, ``ctrlp.next`` or ``background``, ``ctrlp.marked`` or ``background``, ``ctrlp.focus`` or ``background``, ``ctrlp.byfname`` or ``background``, ``ctrlp.progress`` or ``file_name``, ``ctrlp.progress`` or ``file_name``. - ''' - 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): - ''' - - Highlight groups used: ``ctrlp.regex`` or ``background``, ``ctrlp.prev`` or ``background``, ``ctrlp.item`` or ``file_name``, ``ctrlp.next`` or ``background``, ``ctrlp.marked`` or ``background``. - ''' - 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): - ''' - - Highlight groups used: ``ctrlp.focus`` or ``background``, ``ctrlp.byfname`` or ``background``. - ''' - 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): - ''' - - Highlight groups used: ``ctrlp.progress`` or ``file_name``. - ''' - return [ - { - 'contents': 'Loading...', - 'highlight_group': ['ctrlp.progress', 'file_name'], - }, - ] - - -def ctrlp_stl_right_prog(pl, progress): - ''' - - Highlight groups used: ``ctrlp.progress`` or ``file_name``. - ''' - return [ - { - 'contents': str(progress), - 'highlight_group': ['ctrlp.progress', 'file_name'], - }, - ] diff --git a/tests/test_ctrlp_plugin.vim b/tests/test_ctrlp_plugin.vim deleted file mode 100755 index 484b8d68..00000000 --- a/tests/test_ctrlp_plugin.vim +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/vim -S -set nocompatible -set columns=80 -execute 'source' fnameescape(expand(':p:h').'/vim_utils.vim') -call EnablePlugins('ctrlp') -call SourcePowerline() -let g:statusline_values = [] -call PyFile('setup_statusline_catcher') -execute 'CtrlP'|call feedkeys("\") -call RunPython('powerline.render = _powerline_old_render') -let g:expected_statusline = '%#Pl_231_16777215_236_3158064_NONE# mru  %#Pl_236_3158064_240_5789784_NONE# %#Pl_231_16777215_240_5789784_bold#  files    %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE# buf                                          prt  path ' -if index(g:statusline_values, g:expected_statusline) == -1 - call CheckStatuslineValue(g:statusline_values[-1], g:expected_statusline) - cquit -endif -call CheckMessages() -qall diff --git a/tests/test_provided_config_files.py b/tests/test_provided_config_files.py index d0752d0e..50aef95b 100644 --- a/tests/test_provided_config_files.py +++ b/tests/test_provided_config_files.py @@ -54,7 +54,6 @@ class TestVimConfig(TestCase): (('bufname', 'NERD_tree_1'), {}), (('bufname', '__Gundo__'), {}), (('bufname', '__Gundo_Preview__'), {}), - (('bufname', 'ControlP'), {}), # No Command-T tests here: requires +ruby or emulation # No tabline here: tablines are tested separately ) @@ -95,10 +94,6 @@ class TestVimConfig(TestCase): i += 1 if mode in exclude: continue - if mode == 'nc' and args == ('bufname', 'ControlP'): - # ControlP window is not supposed to not - # be in the focus - continue with vim_module._with(*args, **kwargs): check_output(mode, args, kwargs) finally: diff --git a/tests/vim.py b/tests/vim.py index f3d84355..142d6929 100644 --- a/tests/vim.py +++ b/tests/vim.py @@ -191,9 +191,6 @@ 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 elif cmd.startswith('augroup'): augroup = cmd.partition(' ')[2] if augroup.upper() == 'END': @@ -858,9 +855,6 @@ class _WithBufName(object): self.buffer = buffer self.old = buffer.name buffer.name = self.new - if buffer.name and os.path.basename(buffer.name) == 'ControlP': - buffer.vars['powerline_ctrlp_type'] = 'main' - buffer.vars['powerline_ctrlp_args'] = ['focus', 'byfname', '0', 'prev', 'item', 'next', 'marked'] def __exit__(self, *args): self.buffer.name = self.old