mirror of
https://github.com/vim/vim.git
synced 2025-10-07 05:54:16 -04:00
patch 8.2.0915: search() cannot skip over matches like searchpair() can
Problem: Search() cannot skip over matches like searchpair() can. Solution: Add an optional "skip" argument. (Christian Brabandt, closes #861)
This commit is contained in:
@@ -772,4 +772,54 @@ func Test_syntax_foldlevel()
|
||||
quit!
|
||||
endfunc
|
||||
|
||||
func Test_search_syntax_skip()
|
||||
new
|
||||
let lines =<< trim END
|
||||
|
||||
/* This is VIM */
|
||||
Another Text for VIM
|
||||
let a = "VIM"
|
||||
END
|
||||
call setline(1, lines)
|
||||
syntax on
|
||||
syntax match Comment "^/\*.*\*/"
|
||||
syntax match String '".*"'
|
||||
|
||||
" Skip argument using string evaluation.
|
||||
1
|
||||
call search('VIM', 'w', '', 0, 'synIDattr(synID(line("."), col("."), 1), "name") =~? "comment"')
|
||||
call assert_equal('Another Text for VIM', getline('.'))
|
||||
1
|
||||
call search('VIM', 'w', '', 0, 'synIDattr(synID(line("."), col("."), 1), "name") !~? "string"')
|
||||
call assert_equal(' let a = "VIM"', getline('.'))
|
||||
|
||||
" Skip argument using Lambda.
|
||||
1
|
||||
call search('VIM', 'w', '', 0, { -> synIDattr(synID(line("."), col("."), 1), "name") =~? "comment"})
|
||||
call assert_equal('Another Text for VIM', getline('.'))
|
||||
|
||||
1
|
||||
call search('VIM', 'w', '', 0, { -> synIDattr(synID(line("."), col("."), 1), "name") !~? "string"})
|
||||
call assert_equal(' let a = "VIM"', getline('.'))
|
||||
|
||||
" Skip argument using funcref.
|
||||
func InComment()
|
||||
return synIDattr(synID(line("."), col("."), 1), "name") =~? "comment"
|
||||
endfunc
|
||||
func InString()
|
||||
return synIDattr(synID(line("."), col("."), 1), "name") !~? "string"
|
||||
endfunc
|
||||
1
|
||||
call search('VIM', 'w', '', 0, function('InComment'))
|
||||
call assert_equal('Another Text for VIM', getline('.'))
|
||||
|
||||
1
|
||||
call search('VIM', 'w', '', 0, function('InString'))
|
||||
call assert_equal(' let a = "VIM"', getline('.'))
|
||||
|
||||
delfunc InComment
|
||||
delfunc InString
|
||||
bwipe!
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
Reference in New Issue
Block a user