Skip to content

Commit

Permalink
Add g:FerretExecutableArguments and ferret#get_default_arguments()
Browse files Browse the repository at this point in the history
Closes: #46
Closes: #55
  • Loading branch information
wincent committed Dec 25, 2018
1 parent a6fcc78 commit 09290a2
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 11 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ Example:
let g:FerretExecutable='ag,rg'
```

<p align="right"><a name="gferretexecutablearguments" href="#user-content-gferretexecutablearguments"><code>g:FerretExecutableArguments</code></a></p>

### `g:FerretExecutableArguments` (dict, default: {})<a name="ferret-gferretexecutablearguments-dict-default-" href="#user-content-ferret-gferretexecutablearguments-dict-default-"></a>

Allows you to override the default arguments that get passed to the underlying search executables. For example, to add `-s` to the default arguments passed to `ack` (`--column --with-filename`):

```
let g:FerretExecutableArguments = {
\ 'ack': '--column --with-filename -s'
\ }
```

To find out the default arguments for a given executable, see <strong>`ferret#get_default_arguments()`</strong>.

<p align="right"><a name="gferretmaxresults" href="#user-content-gferretmaxresults"><code>g:FerretMaxResults</code></a></p>

### `g:FerretMaxResults` (number, default: 100000)<a name="ferret-gferretmaxresults-number-default-100000" href="#user-content-ferret-gferretmaxresults-number-default-100000"></a>
Expand Down Expand Up @@ -375,6 +389,21 @@ let g:FerretQFCommands=0
Sets the '<strong>`grepformat`</strong>' used by Ferret.


## Functions<a name="ferret-functions" href="#user-content-ferret-functions"></a>

<p align="right"><a name="ferretgetdefaultarguments" href="#user-content-ferretgetdefaultarguments"><code>ferret#get_default_arguments()()</code></a></p>

### `ferret#get_default_arguments()()`<a name="ferret-ferretgetdefaultarguments" href="#user-content-ferret-ferretgetdefaultarguments"></a>

Call this with an executable name to find out the default arguments that will be passed when invoking that executable. For example:

```
echo ferret#get_default_arguments('rg')
```

This may be useful if you wish to extend or otherwise modify the arguments by setting <strong>`g:FerretExecutableArguments`</strong>.


## Custom autocommands<a name="ferret-custom-autocommands" href="#user-content-ferret-custom-autocommands"></a>

<p align="right"><a name="ferretdidwrite" href="#user-content-ferretdidwrite"><code>FerretDidWrite</code></a> <a name="ferretwillwrite" href="#user-content-ferretwillwrite"><code>FerretWillWrite</code></a></p>
Expand Down Expand Up @@ -582,6 +611,7 @@ Other contributors that have submitted patches include (in alphabetical order):

- Try to avoid &quot;press ENTER to continue&quot; prompts.
- Put search term in <strong>`w:quickfix_title`</strong> for use in statuslines (https://github.com/wincent/ferret/pull/57).
- Add <strong>`g:FerretExecutableArguments`</strong> and <strong>`ferret#get_default_arguments()`</strong> (https://github.com/wincent/ferret/pull/46).


### 3.0.3 (23 March 2018)<a name="ferret-303-23-march-2018" href="#user-content-ferret-303-23-march-2018"></a>
Expand Down
19 changes: 19 additions & 0 deletions autoload/ferret.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
" Copyright 2018-present Greg Hurrell. All rights reserved.
" Licensed under the terms of the BSD 2-clause license.

""
" @function ferret#get_default_arguments()
"
" Call this with an executable name to find out the default arguments that will
" be passed when invoking that executable. For example:
"
" ```
" echo ferret#get_default_arguments('rg')
" ```
"
" This may be useful if you wish to extend or otherwise modify the arguments
" by setting |g:FerretExecutableArguments|.
"
function! ferret#get_default_arguments(executable) abort
return get(ferret#private#executables(), a:executable, '')
endfunction
28 changes: 27 additions & 1 deletion autoload/ferret/private.vim
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ let s:executables={

let s:init_done=0

function! ferret#private#executables() abort
return copy(s:executables)
endfunction

function! ferret#private#init() abort
if s:init_done
return
Expand Down Expand Up @@ -666,7 +670,29 @@ function! ferret#private#executable() abort
endif
for l:executable in l:executables
if executable(l:executable)
return l:executable . ' ' . s:executables[l:executable]
""
" @option g:FerretExecutableArguments dict {}
"
" Allows you to override the default arguments that get passed to the
" underlying search executables. For example, to add `-s` to the default
" arguments passed to `ack` (`--column --with-filename`):
"
" ```
" let g:FerretExecutableArguments = {
" \ 'ack': '--column --with-filename -s'
" \ }
" ```
"
" To find out the default arguments for a given executable, see
" |ferret#get_default_arguments()|.
"
let l:overrides=get(g:, 'FerretExecutableArguments', {})
let l:type=exists('v:t_dict') ? v:t_dict : 4
if type(l:overrides) == l:type && has_key(l:overrides, l:executable)
return l:executable . ' ' . l:overrides[l:executable]
else
return l:executable . ' ' . s:executables[l:executable]
endif
endif
endfor
return ''
Expand Down
51 changes: 41 additions & 10 deletions doc/ferret.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ CONTENTS *ferret-contents*
3. Commands |ferret-commands|
4. Mappings |ferret-mappings|
5. Options |ferret-options|
6. Custom autocommands |ferret-custom-autocommands|
7. Overrides |ferret-overrides|
8. Troubleshooting |ferret-troubleshooting|
9. FAQ |ferret-faq|
10. Related |ferret-related|
11. Website |ferret-website|
12. License |ferret-license|
13. Development |ferret-development|
14. Authors |ferret-authors|
15. History |ferret-history|
6. Functions |ferret-functions|
7. Custom autocommands |ferret-custom-autocommands|
8. Overrides |ferret-overrides|
9. Troubleshooting |ferret-troubleshooting|
10. FAQ |ferret-faq|
11. Related |ferret-related|
12. Website |ferret-website|
13. License |ferret-license|
14. Development |ferret-development|
15. Authors |ferret-authors|
16. History |ferret-history|

INTRO *ferret-intro*

Expand Down Expand Up @@ -326,6 +327,21 @@ Example:
let g:FerretExecutable='ag,rg'
<

*g:FerretExecutableArguments*
|g:FerretExecutableArguments| dict (default: {})

Allows you to override the default arguments that get passed to the
underlying search executables. For example, to add `-s` to the default
arguments passed to `ack` (`--column --with-filename`):
>
let g:FerretExecutableArguments = {
\ 'ack': '--column --with-filename -s'
\ }
<
To find out the default arguments for a given executable, see
|ferret#get_default_arguments()|.


*g:FerretMaxResults*
|g:FerretMaxResults| number (default: 100000)

Expand Down Expand Up @@ -437,6 +453,19 @@ set to 0:

Sets the '|grepformat|' used by Ferret.

FUNCTIONS *ferret-functions*

*ferret#get_default_arguments()()*
ferret#get_default_arguments()() ~

Call this with an executable name to find out the default arguments that
will be passed when invoking that executable. For example:
>
echo ferret#get_default_arguments('rg')
<
This may be useful if you wish to extend or otherwise modify the arguments
by setting |g:FerretExecutableArguments|.

CUSTOM AUTOCOMMANDS *ferret-custom-autocommands*


Expand Down Expand Up @@ -662,6 +691,8 @@ master (not yet released) ~
- Try to avoid "press ENTER to continue" prompts.
- Put search term in |w:quickfix_title| for use in statuslines
(https://github.com/wincent/ferret/pull/57).
- Add |g:FerretExecutableArguments| and |ferret#get_default_arguments()|
(https://github.com/wincent/ferret/pull/46).

3.0.3 (23 March 2018) ~

Expand Down
2 changes: 2 additions & 0 deletions plugin/ferret.vim
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@
" - Try to avoid "press ENTER to continue" prompts.
" - Put search term in |w:quickfix_title| for use in statuslines
" (https://github.com/wincent/ferret/pull/57).
" - Add |g:FerretExecutableArguments| and |ferret#get_default_arguments()|
" (https://github.com/wincent/ferret/pull/46).
"
" ## 3.0.3 (23 March 2018)
"
Expand Down

0 comments on commit 09290a2

Please sign in to comment.