Skip to content

Add new command to reload the commands list #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions after/plugin/ctrlp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 13 additions & 7 deletions autoload/ctrlp/cmdpalette.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,25 @@ endif

" inspired by the same done in the python-mode plugin
if has('python')
command! -nargs=1 CmdPalettePython python <args>
let s:python_cmd = "python"
elseif has('python3')
command! -nargs=1 CmdPalettePython python3 <args>
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("<sfile>: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("<sfile>")')
path_to_commands = path_to_script.replace('cmdpalette.vim', 'internal_commands.txt')
path_to_script = vim.eval('expand("<sfile>: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()]

Expand All @@ -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


Expand Down