From 9efb7755b261d3cdbaa376904710b122bf9ee1e7 Mon Sep 17 00:00:00 2001 From: Hongbo Liu Date: Wed, 16 May 2018 18:51:48 -0400 Subject: [PATCH] add command `CmdPaletteReload` to reload commands list --- after/plugin/ctrlp.vim | 1 + autoload/ctrlp/cmdpalette.vim | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/after/plugin/ctrlp.vim b/after/plugin/ctrlp.vim index d98d3ca..9c74dd4 100644 --- a/after/plugin/ctrlp.vim +++ b/after/plugin/ctrlp.vim @@ -6,6 +6,7 @@ let s:save_cpo = &cpo set cpo&vim command! CtrlPCmdPalette call ctrlp#init(ctrlp#cmdpalette#id()) +command! -nargs=0 CmdPaletteReload call ctrlp#cmdpalette#load_commands_info() let &cpo = s:save_cpo unlet s:save_cpo diff --git a/autoload/ctrlp/cmdpalette.vim b/autoload/ctrlp/cmdpalette.vim index 3b48a13..a4129fb 100644 --- a/autoload/ctrlp/cmdpalette.vim +++ b/autoload/ctrlp/cmdpalette.vim @@ -38,22 +38,25 @@ endif " inspired by the same done in the python-mode plugin if has('python') - command! -nargs=1 CmdPalettePython python + let s:python_cmd = "python" elseif has('python3') - command! -nargs=1 CmdPalettePython python3 + let s:python_cmd = "python3" else echo "Could't initialize CtrlP CmdPalette: needs a python interpreter in vim" finish endif +let s:path_to_commands = printf("%s/%s", expand(":p:h"), "internal_commands.txt") -CmdPalettePython << endofpython +function! ctrlp#cmdpalette#load_commands_info() + +execute s:python_cmd . "<< endofpython" import vim import json # obtain the internal commands (file distributed with the plugin) -path_to_script = vim.eval('expand("")') -path_to_commands = path_to_script.replace('cmdpalette.vim', 'internal_commands.txt') +path_to_script = vim.eval('expand(":p")') +path_to_commands = vim.eval('s:path_to_commands') with open(path_to_commands) as commands_file: internal_commands = [l.strip() for l in commands_file.readlines()] @@ -74,12 +77,15 @@ vim.command('let s:cmdpalette_commands = %s' % json.dumps(internal_commands + cu endofpython +endfunction + +call ctrlp#cmdpalette#load_commands_info() " Append s:cmdpalette_var to g:ctrlp_ext_vars if exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) - let g:ctrlp_ext_vars = add(g:ctrlp_ext_vars, s:cmdpalette_var) + let g:ctrlp_ext_vars = add(g:ctrlp_ext_vars, s:cmdpalette_var) else - let g:ctrlp_ext_vars = [s:cmdpalette_var] + let g:ctrlp_ext_vars = [s:cmdpalette_var] endif