From 0c3b83161314579c15e5eb4c96db515daa89a0a3 Mon Sep 17 00:00:00 2001 From: Alisue Date: Sat, 3 Jul 2021 18:10:24 +0900 Subject: [PATCH] Add "=" variants to several actions for providing default value through mappings --- autoload/fern/mapping.vim | 9 +++ autoload/fern/mapping/filter.vim | 13 +++- autoload/fern/mapping/node.vim | 8 +++ autoload/fern/scheme/file/mapping.vim | 24 +++++-- autoload/fern/scheme/file/mapping/ex.vim | 10 ++- autoload/fern/scheme/file/mapping/grep.vim | 10 ++- doc/fern.txt | 80 +++++++++++++++++++--- 7 files changed, 135 insertions(+), 19 deletions(-) diff --git a/autoload/fern/mapping.vim b/autoload/fern/mapping.vim index ed26c9dd..80de4db3 100644 --- a/autoload/fern/mapping.vim +++ b/autoload/fern/mapping.vim @@ -13,6 +13,15 @@ function! fern#mapping#call(fn, ...) abort endtry endfunction +function! fern#mapping#call_without_guard(fn, ...) abort + try + call s:Promise.resolve(call('fern#helper#call', [a:fn] + a:000)) + \.catch({ e -> fern#logger#error(e) }) + catch + call fern#logger#error(v:exception) + endtry +endfunction + function! fern#mapping#init(scheme) abort let disable_default_mappings = g:fern#disable_default_mappings for name in g:fern#mapping#mappings diff --git a/autoload/fern/mapping/filter.vim b/autoload/fern/mapping/filter.vim index 93191bb4..16934cfc 100644 --- a/autoload/fern/mapping/filter.vim +++ b/autoload/fern/mapping/filter.vim @@ -2,8 +2,10 @@ function! fern#mapping#filter#init(disable_default_mappings) abort nnoremap (fern-action-hidden:set) :call call('hidden_set') nnoremap (fern-action-hidden:unset) :call call('hidden_unset') nnoremap (fern-action-hidden:toggle) :call call('hidden_toggle') - nnoremap (fern-action-include) :call call('include') - nnoremap (fern-action-exclude) :call call('exclude') + nnoremap (fern-action-include) :call call('include') + nnoremap (fern-action-exclude) :call call('exclude') + nnoremap (fern-action-include=) :call call_without_guard('include') + nnoremap (fern-action-exclude=) :call call_without_guard('exclude') " Alias nmap (fern-action-hidden) (fern-action-hidden:toggle) @@ -30,6 +32,13 @@ function! s:call(name, ...) abort \) endfunction +function! s:call_without_guard(name, ...) abort + return call( + \ 'fern#mapping#call_without_guard', + \ [funcref(printf('s:map_%s', a:name))] + a:000, + \) +endfunction + function! s:map_hidden_set(helper) abort return a:helper.async.set_hidden(1) \.then({ -> a:helper.async.redraw() }) diff --git a/autoload/fern/mapping/node.vim b/autoload/fern/mapping/node.vim index 0bcbd5f3..978ce059 100644 --- a/autoload/fern/mapping/node.vim +++ b/autoload/fern/mapping/node.vim @@ -9,6 +9,7 @@ function! fern#mapping#node#init(disable_default_mappings) abort nnoremap (fern-action-expand:in) :call call('expand_in') nnoremap (fern-action-collapse) :call call('collapse') nnoremap (fern-action-reveal) :call call('reveal') + nnoremap (fern-action-reveal=) :call call_without_guard('reveal') nnoremap (fern-action-focus:parent) :call call('focus_parent') nnoremap (fern-action-enter) :call call('enter') @@ -36,6 +37,13 @@ function! s:call(name, ...) abort \) endfunction +function! s:call_without_guard(name, ...) abort + return call( + \ 'fern#mapping#call_without_guard', + \ [funcref(printf('s:map_%s', a:name))] + a:000, + \) +endfunction + function! s:map_debug(helper) abort let node = a:helper.sync.get_cursor_node() redraw | echo fern#internal#node#debug(node) diff --git a/autoload/fern/scheme/file/mapping.vim b/autoload/fern/scheme/file/mapping.vim index d06d3e8e..f60c1dfc 100644 --- a/autoload/fern/scheme/file/mapping.vim +++ b/autoload/fern/scheme/file/mapping.vim @@ -2,13 +2,16 @@ let s:Promise = vital#fern#import('Async.Promise') let s:Prompt = vital#fern#import('Prompt') function! fern#scheme#file#mapping#init(disable_default_mappings) abort - nnoremap (fern-action-new-path) :call call('new_path') - nnoremap (fern-action-new-file) :call call('new_file') - nnoremap (fern-action-new-dir) :call call('new_dir') - nnoremap (fern-action-copy) :call call('copy') - nnoremap (fern-action-move) :call call('move') - nnoremap (fern-action-trash) :call call('trash') - nnoremap (fern-action-remove) :call call('remove') + nnoremap (fern-action-new-path) :call call('new_path') + nnoremap (fern-action-new-file) :call call('new_file') + nnoremap (fern-action-new-dir) :call call('new_dir') + nnoremap (fern-action-new-path=) :call call_without_guard('new_path') + nnoremap (fern-action-new-file=) :call call_without_guard('new_file') + nnoremap (fern-action-new-dir=) :call call_without_guard('new_dir') + nnoremap (fern-action-copy) :call call('copy') + nnoremap (fern-action-move) :call call('move') + nnoremap (fern-action-trash) :call call('trash') + nnoremap (fern-action-remove) :call call('remove') if !a:disable_default_mappings nmap N (fern-action-new-file) @@ -26,6 +29,13 @@ function! s:call(name, ...) abort \) endfunction +function! s:call_without_guard(name, ...) abort + return call( + \ 'fern#mapping#call_without_guard', + \ [funcref(printf('s:map_%s', a:name))] + a:000, + \) +endfunction + function! s:map_cd(helper, command) abort let path = a:helper.sync.get_cursor_node()._path if a:command ==# 'tcd' && !exists(':tcd') diff --git a/autoload/fern/scheme/file/mapping/ex.vim b/autoload/fern/scheme/file/mapping/ex.vim index 77580b76..98623541 100644 --- a/autoload/fern/scheme/file/mapping/ex.vim +++ b/autoload/fern/scheme/file/mapping/ex.vim @@ -1,7 +1,8 @@ let s:Promise = vital#fern#import('Async.Promise') function! fern#scheme#file#mapping#ex#init(disable_default_mappings) abort - nnoremap (fern-action-ex) :call call('ex') + nnoremap (fern-action-ex) :call call('ex') + nnoremap (fern-action-ex=) :call call_without_guard('ex') endfunction function! s:call(name, ...) abort @@ -11,6 +12,13 @@ function! s:call(name, ...) abort \) endfunction +function! s:call_without_guard(name, ...) abort + return call( + \ 'fern#mapping#call_without_guard', + \ [funcref(printf('s:map_%s', a:name))] + a:000, + \) +endfunction + function! s:map_ex(helper) abort let nodes = a:helper.sync.get_selected_nodes() let nodes = filter(copy(nodes), { -> v:val._path isnot# v:null }) diff --git a/autoload/fern/scheme/file/mapping/grep.vim b/autoload/fern/scheme/file/mapping/grep.vim index 34841f45..ce940f73 100644 --- a/autoload/fern/scheme/file/mapping/grep.vim +++ b/autoload/fern/scheme/file/mapping/grep.vim @@ -3,7 +3,8 @@ let s:Promise = vital#fern#import('Async.Promise') let s:Process = vital#fern#import('Async.Promise.Process') function! fern#scheme#file#mapping#grep#init(disable_default_mappings) abort - nnoremap (fern-action-grep) :call call('grep') + nnoremap (fern-action-grep) :call call('grep') + nnoremap (fern-action-grep=) :call call_without_guard('grep') endfunction function! s:call(name, ...) abort @@ -13,6 +14,13 @@ function! s:call(name, ...) abort \) endfunction +function! s:call_without_guard(name, ...) abort + return call( + \ 'fern#mapping#call_without_guard', + \ [funcref(printf('s:map_%s', a:name))] + a:000, + \) +endfunction + function! s:map_grep(helper) abort let pattern = input('Grep: ', '') if empty(pattern) diff --git a/doc/fern.txt b/doc/fern.txt index 4cad9a04..c549b240 100644 --- a/doc/fern.txt +++ b/doc/fern.txt @@ -823,13 +823,29 @@ GLOBAL *fern-mapping-global* DEPRECATED: Use |(fern-action-hidden:toggle)| instead. *(fern-action-include)* +*(fern-action-include=)* Open a prompt to enter include filter. Users can type a |pattern| to filter nodes recursively. - + You can use a "=" variant to apply values to the prompt and/or submit + a value like: +> + " Automatically apply "foo" to the prompt and submit. + nmap + \ (my-include) + \ (fern-action-include=)foo +< *(fern-action-exclude)* +*(fern-action-exclude=)* Open a prompt to enter exclude filter. Users can type a |pattern| to filter nodes recursively. - + You can use a "=" variant to apply values to the prompt and/or submit + a value like: +> + " Automatically apply "foo" to the prompt and submit. + nmap + \ (my-exclude) + \ (fern-action-exclude=)foo +< *(fern-action-mark:clear)* Clear existing marks. @@ -895,8 +911,16 @@ GLOBAL *fern-mapping-global* Collapse on a cursor node. *(fern-action-reveal)* +*(fern-action-reveal=)* Open a prompt to reveal a node in a tree. - + You can use a "=" variant to apply values to the prompt and/or submit + a value like: +> + " Automatically apply "foo" to the prompt and submit. + nmap + \ (my-reveal) + \ (fern-action-reveal=)foo +< *(fern-action-focus:parent)* Focus the parent of the cursor node. @@ -1103,26 +1127,58 @@ FILE *fern-mapping-file* The following mappings/actions are only available on file:// scheme. *(fern-action-ex)* +*(fern-action-ex=)* Open a prompt to execute an Ex command with a path of cursor node or paths of marked nodes. - + You can use a "=" variant to apply values to the prompt and/or submit + a value like: +> + " Automatically apply "foo" to the prompt and submit. + nmap + \ (my-ex) + \ (fern-action-ex=)foo +< *(fern-action-new-path)* +*(fern-action-new-path=)* Open a prompt to ask a path and create a file/directory of the input path from the path of a cursor node. Any intermediate directories of the destination will be created. If the path ends with "/", it creates a directory. Otherwise it creates a file. - + You can use a "=" variant to apply values to the prompt and/or submit + a value like: +> + " Automatically apply "foo" to the prompt and submit. + nmap + \ (my-new-path) + \ (fern-action-new-path=)foo +< *(fern-action-new-file)* +*(fern-action-new-file=)* Open a prompt to ask a path and create a file of the input path from the path of a cursor node. Any intermediate directories of the destination will be created. - + You can use a "=" variant to apply values to the prompt and/or submit + a value like: +> + " Automatically apply "foo" to the prompt and submit. + nmap + \ (my-new-file) + \ (fern-action-new-file=)foo +< *(fern-action-new-dir)* +*(fern-action-new-dir=)* Open a prompt to ask a path and create a directory of the input path from the path of a cursor node. Any intermediate directories of the destination will be created. - + You can use a "=" variant to apply values to the prompt and/or submit + a value like: +> + " Automatically apply "foo" to the prompt and submit. + nmap + \ (my-new-dir) + \ (fern-action-new-dir=)foo +< *(fern-action-copy)* Open a prompt to ask a path and copy a file/directory of the cursor node or marked node path(s) to the input path(s). @@ -1195,9 +1251,17 @@ The following mappings/actions are only available on file:// scheme. Note that this action has NO-relation with the system clipboard. *(fern-action-grep)* +*(fern-action-grep=)* Open a prompt to ask a grep pattern and execute grep command under the cursor node. It respects the value of 'grepprg' and 'grepformat'. - + You can use a "=" variant to apply values to the prompt and/or submit + a value like: +> + " Automatically apply "foo" to the prompt and submit. + nmap + \ (my-grep) + \ (fern-action-grep=)foo +< *(fern-action-rename:select)* *(fern-action-rename:split)* *(fern-action-rename:vsplit)*