Skip to content
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

Add ctrlp_create_func #448

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
13 changes: 12 additions & 1 deletion autoload/ctrlp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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', []],
Expand Down Expand Up @@ -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)
Expand All @@ -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' :
Expand Down
8 changes: 8 additions & 0 deletions doc/ctrlp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:~
Expand Down Expand Up @@ -846,6 +847,13 @@ Example: >
*'g:ctrlp_brief_prompt'*
When this is set to 1, the <bs> 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: >
Expand Down