From 920928a4ea7be92b597d15fb87795e0ed73f9493 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Wed, 13 Jun 2018 19:05:12 +0900 Subject: [PATCH] Add ctrlp_create_func closes #438 --- autoload/ctrlp.vim | 13 ++++++++++++- doc/ctrlp.txt | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index c5d721e0..b1016948 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -80,6 +80,7 @@ let [s:pref, s:bpref, s:opts, s:new_opts, s:lc_opts] = \ 'open_func': ['s:openfunc', {}], \ 'open_multi': ['s:opmul', '1v'], \ 'open_new_file': ['s:newfop', 'v'], + \ 'create_func': ['s:createfunc', {}], \ 'prompt_mappings': ['s:urprtmaps', 0], \ 'regexp_search': ['s:regexp', 0], \ 'root_markers': ['s:rmarkers', []], @@ -1224,7 +1225,7 @@ fu! s:CreateNewFile(...) let md = s:argmaps(md, 1) if md == 'cancel' | retu | en en - let str = s:sanstail(str) + let [inp, str] = [str, s:sanstail(str)] let [base, fname] = s:headntail(str) if fname =~ '^[\/]$' | retu | en if exists('s:marked') && len(s:marked) @@ -1237,9 +1238,19 @@ fu! s:CreateNewFile(...) let optyp = str | en | el | let optyp = fname en if !exists('optyp') | retu | en + + if s:createfunc != {} && has_key(s:createfunc, s:ctype) + let type = has_key(s:createfunc, 'arg_type') ? s:createfunc['arg_type'] : 'dict' + let argms = type == 'dict' ? [{ 'action': md, 'line': inp }] + \ : [md, inp] + cal s:PrtExit() + cal call(s:createfunc[s:ctype], argms, s:createfunc) | retu + en + let [filpath, tail] = [fnamemodify(optyp, ':p'), s:tail()] if !stridx(filpath, s:dyncwd) | cal s:insertcache(str) | en cal s:PrtExit() + let cmd = md == 'r' ? ctrlp#normcmd('e') : \ s:newfop =~ '1\|t' || ( a:0 && a:1 == 't' ) || md == 't' ? 'tabe' : \ s:newfop =~ '2\|h' || ( a:0 && a:1 == 'h' ) || md == 'h' ? 'new' : diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index 4090e836..4ac46e0e 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -94,6 +94,7 @@ Overview:~ |ctrlp_status_func|...........Change CtrlP's two statuslines. |ctrlp_buffer_func|...........Call custom functions in the CtrlP buffer. |ctrlp_match_func|............Replace the built-in matching algorithm. + |ctrlp_create_func|...........Use custom file creating functions. ------------------------------------------------------------------------------- Detailed descriptions and default values:~ @@ -846,6 +847,13 @@ Example: > *'g:ctrlp_brief_prompt'* When this is set to 1, the on empty prompt exit CtrlP. + *'g:ctrlp_create_func'* +Define a custom function to create the selected file. This is same as +|ctrlp_open_func|. This function passes string entered by the user as it is. +And not record to cache file. So you can create function to open URL with +browser: > + let g:ctrlp_create_func = {} +< *ctrlp-default-value* Otherwise, you can use below to change default value. Example: >