Skip to content

Commit

Permalink
feature: enable g:far#ignore_files, default in far.vim/farignore
Browse files Browse the repository at this point in the history
  • Loading branch information
hyliang96 committed Feb 11, 2020
1 parent 32135ae commit 7b10a42
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 206 deletions.
21 changes: 20 additions & 1 deletion autoload/far.vim
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ call far#tools#setdefault('g:far#sources.vimgrep.args.escape_pattern', '/')

call far#tools#setdefault('g:far#mode_open', { "regex" : 1, "case_sensitive" : 0, "word" : 0, "substitute": 0 } )

let s:farvim_dir = resolve(expand('<sfile>:p:h:h'))
call far#tools#setdefault('g:far#ignore_files', [s:farvim_dir. (has('unix')? '/' : '\') . 'farignore'])


if executable('ag')
let cmd = ['ag', '--nogroup', '--column', '--nocolor', '--silent', '--vimgrep',
Expand All @@ -68,6 +71,8 @@ if executable('ag')
call far#tools#setdefault('g:far#sources.ag.args.submatch', 'all')
call far#tools#setdefault('g:far#sources.ag.args.items_file_min', 30)
call far#tools#setdefault('g:far#sources.ag.args.expand_cmdargs', 1)
call far#tools#setdefault('g:far#sources.ag.args.ignore_files', g:far#ignore_files)
call far#tools#setdefault('g:far#sources.ag.args.max_columns', g:far#max_columns)

if has('nvim')
call far#tools#setdefault('g:far#sources.agnvim', {})
Expand All @@ -79,6 +84,8 @@ if executable('ag')
call far#tools#setdefault('g:far#sources.agnvim.args.submatch', 'all')
call far#tools#setdefault('g:far#sources.agnvim.args.items_file_min', 30)
call far#tools#setdefault('g:far#sources.agnvim.args.expand_cmdargs', 1)
call far#tools#setdefault('g:far#sources.agnvim.args.ignore_files', g:far#ignore_files)
call far#tools#setdefault('g:far#sources.agnvim.args.max_columns', g:far#max_columns)
endif
endif

Expand All @@ -104,6 +111,8 @@ if executable('ack')
call far#tools#setdefault('g:far#sources.ack.args.submatch', 'first')
call far#tools#setdefault('g:far#sources.ack.args.items_file_min', 30)
call far#tools#setdefault('g:far#sources.ack.args.expand_cmdargs', 1)
call far#tools#setdefault('g:far#sources.ack.args.ignore_files', g:far#ignore_files)
call far#tools#setdefault('g:far#sources.ack.args.max_columns', g:far#max_columns)

if has('nvim')
call far#tools#setdefault('g:far#sources.acknvim', {})
Expand All @@ -115,6 +124,8 @@ if executable('ack')
call far#tools#setdefault('g:far#sources.acknvim.args.submatch', 'first')
call far#tools#setdefault('g:far#sources.acknvim.args.items_file_min', 30)
call far#tools#setdefault('g:far#sources.acknvim.args.expand_cmdargs', 1)
call far#tools#setdefault('g:far#sources.acknvim.args.ignore_files', g:far#ignore_files)
call far#tools#setdefault('g:far#sources.acknvim.args.max_columns', g:far#max_columns)
endif
endif

Expand All @@ -137,6 +148,8 @@ if executable('rg')
call far#tools#setdefault('g:far#sources.rg.args.submatch', 'all')
call far#tools#setdefault('g:far#sources.rg.args.items_file_min', 30)
call far#tools#setdefault('g:far#sources.rg.args.expand_cmdargs', 1)
call far#tools#setdefault('g:far#sources.rg.args.ignore_files', g:far#ignore_files)
call far#tools#setdefault('g:far#sources.rg.args.max_columns', g:far#max_columns)

if has('nvim')
call far#tools#setdefault('g:far#sources.rgnvim', {})
Expand All @@ -148,6 +161,8 @@ if executable('rg')
call far#tools#setdefault('g:far#sources.rgnvim.args.submatch', 'all')
call far#tools#setdefault('g:far#sources.rgnvim.args.items_file_min', 30)
call far#tools#setdefault('g:far#sources.rgnvim.args.expand_cmdargs', 1)
call far#tools#setdefault('g:far#sources.rgnvim.args.ignore_files', g:far#ignore_files)
call far#tools#setdefault('g:far#sources.rgnvim.args.max_columns', g:far#max_columns)
endif
endif

Expand All @@ -160,7 +175,6 @@ function! s:create_far_params() abort
\ 'regex': g:far#regex,
\ 'case_sensitive': g:far#case_sensitive,
\ 'word_boundary': g:far#word_boundary,
\ 'max_columns': g:far#max_columns,
\ }
endfunction

Expand Down Expand Up @@ -1635,6 +1649,11 @@ function! s:assemble_context_callback(exec_ctx) abort "{{{
return
endif

if !empty(get(a:exec_ctx, 'warning', ''))
call far#tools#echo_warn(a:exec_ctx.warning)
" sleep 1
endif

let far_ctx = a:exec_ctx.far_ctx
let far_ctx['search_time'] = printf('%.3fms', reltimefloat(reltime()) - a:exec_ctx.start_ts)

Expand Down
6 changes: 6 additions & 0 deletions autoload/far/executors/nvim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ endfunction
function! far#executors#nvim#callback(result, ctx_idx) abort
let ctx = remove(g:far#executors#nvim#contexts, a:ctx_idx)
let error = get(a:result, 'error', '')
let warning = get(a:result, 'warning', '')
if !empty(warning)
let ctx['warning'] = 'source warning: '. warning
endif

if !empty(error)
let ctx['error'] = 'source error: '.error
elseif get(a:result, 'items_file', '') != ''
Expand All @@ -56,6 +61,7 @@ function! far#executors#nvim#callback(result, ctx_idx) abort
endfor
endfor
endif

call call(ctx.async_callback, [ctx])
endfunction

Expand Down
8 changes: 8 additions & 0 deletions autoload/far/tools.vim
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ function! far#tools#echo_err(msg) abort "{{{
echohl None
endfunction "}}}

function! far#tools#echo_warn(msg) abort "{{{
execute 'normal! \<Esc>'
echohl ErrorMsg
echomsg 'Warning: ' . a:msg .' | Press any key to continue'
echohl None
call getchar()
endfunction "}}}

function! far#tools#echo_msg(msg) abort "{{{
execute 'normal! \<Esc>'
echomsg a:msg
Expand Down
169 changes: 52 additions & 117 deletions doc/far.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,9 @@ FILE MASK *far-file-mask*
The format of {filemask} is different for different source searchers.

{filemask} for all source searchers:
'vimgrep' : see |far-vimgrep-file-mask|
'rg' 'rgnvim' : see |far-rg-file-mask|
'ack' 'acknvim' : see |far-ack-file-mask|
'ag' 'agnvim' : see |far-ag-file-mask|
'vimgrep' : see |far-vimgrep-file-mask|
'rg' 'rgnvim' 'ack' 'acknvim' 'ag' 'agnvim' : see |far-glob|


NOTE: To set glob source in '.vimrc', see |g:far#source|.
NOTE: To set source in command, see '--source' in |far-params|.
Expand Down Expand Up @@ -377,140 +376,76 @@ FILE MASK *far-file-mask*


------------------------------------------------------------------------------
'rg' 'rgnvim' *far-rg-file-mask*
'rg' 'rgnvim' 'ag' 'agnvim' 'ack' ''acknvim' *far-glob*

Uses the glob syntax for the file-mask
Those searhing engines use far.vim's own glob expression supported by
python 'pathlib.glob'. The rule is different from the that for 'vimgrep'.
It searchs all visiable and hidden dirs and files excepted ignored.
Ignoring rule are

'%' : the current file
NOTE: 'xx': a glob expression, can contain '/', doesn't end with '/'.
NOTE: 'yy': a glob expression, can contain '/', doesn't start with '/'.
NOTE: 'zz': a glob expression, can contain/start with/end with '/'.

'* :
any zero or more chars, its regex is ".*"
can not contain dir seperator.
can contain '.', can be hidden
heading

'**':
any zero or more chars,
can contain dir seperator
can contain '.', can be hidden

'**/':
any zero or more chars,
can contain dir seperator
can contain '.', can not be hidden
'/xx'
'xx' is directly udner the 'root' dir

'**/' with '--hidden'
any zero or more chars,
can contain dir seperator
can contain '.', can be hidden

-------------------------------------------------------------------------
args root subdir subdir file file
filemask - dir #layer visible visible regex
-------------------------------------------------------------------------
'[xx/]' =
'' cwd >=0
'/' cwd 0
'<path>/' <path> 0
-------------------------------------------------------------------------
'[xx/]*' - [xx/] 0 - Y/N '^.*$'
'[xx/]*/yy' - [xx/] 1 Y - -
'[xx/]*/yy' --hidden [xx/] 1 Y/N - -
-------------------------------------------------------------------------
'[xx/]**' - [xx/] >=0 Y/N Y/N '^.*$'
'[xx/]**/yy' - [xx/] >=0 Y - -
'[xx/]**/yy' --hidden [xx/] >=0 Y/N - -
-------------------------------------------------------------------------
'[xx]/*' - [xx/] 0 - Y/N '^.*$'
'[xx]/*.*' - [xx/] 0 - Y/N '^.*\..*$'
'[xx]/*.sh' - [xx/] 0 - Y/N '^.*\.sh$'
'[xx]/*yy*' - [xx/] 0 - Y/N '^.*yy.*$'
'[xx]/*yy*zz' - [xx/] 0 - Y/N '^.*yy.*zz$'
-------------------------------------------------------------------------
e.g.
'/*' - cwd 0 - Y/N '^.*$'
'/*.*' - cwd 0 - Y/N '^.*\..*$'
'/*.sh' - cwd 0 - Y/N '^.*\.sh$'
'*''**/*''**''/**' - cwd >=0 Y/N Y/N '^.*$'
'*.*' '**/*.*' - cwd >=0 Y/N Y/N '^.*\..*$'
'*.sh' '**/*.sh' - cwd >=0 Y Y/N '^.*\.sh$'
'*.sh' '**/*.sh' --hidden cwd >=0 Y/N Y/N '^.*\.sh$'
-------------------------------------------------------------------------
'xx'
'xx' is recursively udner the 'root' dir

------------------------------------------------------------------------------
'ack' 'acknvim' *far-ack-file-mask*
tailing

Uses the glob syntax for the file-mask
'xx'
File.

'%' : the current file
'xx/'
Dir. Far.vim returns all files recursively under the dir.

'* :
any zero or more chars, its regex is ".*"
can not contain dir seperator.
can contain '.', can be hidden
special chars

'**' '**/':
any zero or more chars,
can contain dir seperator
can contain '.', can be hidden
'%'
The current file.

-------------------------------------------------------------------------
args root subdir subdir file file
filemask - dir #layer visible visible regex
-------------------------------------------------------------------------
'[xx/]' =
'' cwd 0
'<path>/' <path> 0
-------------------------------------------------------------------------
'[xx/]*' - [xx/] 0 - Y/N '^.*$'
'[xx/]*/yy' - [xx/] 1 Y/N - -
-------------------------------------------------------------------------
'[xx/]**' - [xx/] >=0 Y/N Y/N '^.*$'
'[xx/]**/yy' - [xx/] >=0 Y/N - -
-------------------------------------------------------------------------
'[xx]/*' - [xx/] 0 - Y/N '^.*$'
'[xx]/*.*' - [xx/] 0 - Y/N '^.*\..*$'
'[xx]/*.sh' - [xx/] 0 - Y/N '^.*\.sh$'
'[xx]/*yy*' - [xx/] 0 - Y/N '^.*yy.*$'
'[xx]/*yy*zz' - [xx/] 0 - Y/N '^.*yy.*zz$'
-------------------------------------------------------------------------
e.g.
'*' - cwd 0 - Y/N '^.*$'
'*.*' - cwd 0 - Y/N '^.*\..*$'
'*.sh' - cwd 0 - Y/N '^.*\.sh$'
'**' '**/*' - cwd >=0 Y/N Y/N '^.*$'
'**/*.*' - cwd >=0 Y/N Y/N '^.*\..*$'
'**/*.sh' - cwd >=0 Y/N Y/N '^.*\.sh$'
-------------------------------------------------------------------------
'*'
Any >=0 chars except the path separator '/'.

------------------------------------------------------------------------------
'ag' 'agnvim' *far-ag-file-mask*
'?'
Any one char except the path separator '/'.

Uses regex patterns
'xx/**'
All dirs recursively under 'xx' dir include 'xx' dir itself.
Far.vim returns the same result as 'xx/'.

Options:
'xx/**/yy'
'yy' glob experession recursively under 'xx' dir.

`--hidden`
Search hidden files and search under hidden dirs.
Default: without this option
Regex:
examples

'^\./xx'
root = cwd
'/' '*' '**' '**/*'
All files under the 'root' dir.

'xx'
xx recursively under cwd
'*.sh'
All files with '.sh' extenstion, recursively under cwd.
Including 'xx.sh' '.sh' '.xx.sh'

'xx$'
file end with 'xx'
'*.*'
All files with '.' in name, recursively under cwd.
Including '.xx','xx.','xx.xx'

'.'
any char that is not newline char
'/*.sh'
All '*.sh' files directly under cwd.

'\.'
char '.'
'/xx/*test*/'
All dirs with 'test' in name, directly under '<cwd>/xx/' dir.
Including '/xx/test/' '/xx/test2/' '/xx/1test2/' '/xx/test/'

'[^/]+\.yy$'
file end with '.yy'
only for ignore_rules:
'zz'
ignore-rule, to ignores xx
'zz'
exception-rule, to never ignore xx, overrides all ignore-rules


==============================================================================
Expand Down
70 changes: 0 additions & 70 deletions doc/temp.txt

This file was deleted.

Loading

0 comments on commit 7b10a42

Please sign in to comment.