Skip to content

Commit c742acc

Browse files
committed
vim: Type search in :MerlinSearch and update the doc
':MerlinSearch' switches between polarity search and search by type depending on the first character of the query, like is done in the emacs plugin. Documentation about the three search functions is added.
1 parent fc7cdb4 commit c742acc

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

vim/merlin/autoload/merlin.vim

+13-4
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ function! merlin#SearchByType(debug,query)
301301
endif
302302
endfunction
303303

304+
" Do a polarity search or a search by type depending on the first character of
305+
" the query.
306+
function! merlin#Search(debug, query)
307+
if a:query =~ "^[-+]"
308+
call merlin#PolaritySearch(a:debug, a:query)
309+
else
310+
call merlin#SearchByType(a:debug, a:query)
311+
endif
312+
endfunction
313+
304314
function! s:StopHighlight()
305315
if exists('w:enclosing_zone') && w:enclosing_zone != -1
306316
call matchdelete(w:enclosing_zone)
@@ -821,11 +831,10 @@ function! merlin#Register()
821831
command! -buffer -nargs=0 MerlinGotoDotMerlin call merlin#GotoDotMerlin()
822832
command! -buffer -nargs=0 MerlinEchoDotMerlin call merlin#EchoDotMerlin()
823833

824-
""" Polarity search
825-
command! -buffer -complete=customlist,merlin#ExpandTypePrefix -nargs=+ MerlinSearch call merlin#PolaritySearch(0,<q-args>)
826-
827-
""" Search by type
834+
""" Search
835+
command! -buffer -complete=customlist,merlin#ExpandTypePrefix -nargs=+ MerlinSearchPolarity call merlin#PolaritySearch(0,<q-args>)
828836
command! -buffer -complete=customlist,merlin#ExpandTypePrefix -nargs=+ MerlinSearchType call merlin#SearchByType(0,<q-args>)
837+
command! -buffer -complete=customlist,merlin#ExpandTypePrefix -nargs=+ MerlinSearch call merlin#Search(0,<q-args>)
829838

830839
""" debug --------------------------------------------------------------------
831840
command! -buffer -nargs=0 MerlinDebugLastCommands MerlinPy merlin.vim_last_commands()

vim/merlin/doc/merlin.txt

+38
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,44 @@ Act either as *:py* or *:py3* depending on the version of python is used
158158
by the vim plugin.
159159
This is only useful if you want to write custom merlin extensions.
160160

161+
:MerlinSearch *:MerlinSearch*
162+
163+
Act either as :MerlinSearchPolarity or :MerlinSearchType depending on the first
164+
character of the query. If the query starts with '-' or '+', then
165+
:MerlinSearchPolarity is used, otherwise, :MerlinSearchType is used.
166+
167+
>
168+
:MerlinSearch -int +string
169+
:MerlinSearch int -> string
170+
<
171+
172+
:MerlinSearchPolarity *:MerlinSearchPolarity*
173+
174+
Search for values in the current scope that have a type matching the query.
175+
The results are displayed in a completion menu.
176+
177+
The query language is simply a list of path identifiers prefixed by `+` or `-`,
178+
e.g. `-int`, `-int +string`, `-Hashtbl.t +int`.
179+
180+
`-` is interpreted as "consuming" and `+` as "producing": `-int +string` looks
181+
for functions consuming an `int` and producing a `string`.
182+
183+
>
184+
:MerlinSearchPolarity -int +string
185+
<
186+
187+
:MerlinSearchType *:MerlinSearchType*
188+
189+
Works similarly to :MerlinSearchPolarity but uses a different query language.
190+
The results are displayed in a completion menu.
191+
192+
The query language is a list of type constructors separated by '->'.
193+
Type parameters and functions are allowed: `('a -> bool) -> 'a list -> bool`.
194+
195+
>
196+
:MerlinSearchType int -> string
197+
<
198+
161199
==============================================================================
162200
OPTIONS *merlin-options*
163201

0 commit comments

Comments
 (0)