diff options
author | Bram Moolenaar <Bram@vim.org> | 2014-06-17 17:48:32 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2014-06-17 17:48:32 +0200 |
commit | b3414595c713ca161f082776f89417faddec7d2d (patch) | |
tree | 5f03f600e04a2455ce84033c49db30b680d571c6 /runtime | |
parent | ec1561cac59006213dd5405d164a94dc7d002806 (diff) | |
download | vim-git-b3414595c713ca161f082776f89417faddec7d2d.tar.gz |
updated for version 7.4.330v7.4.330
Problem: Using a regexp pattern to highlight a specific position can be
slow.
Solution: Add matchaddpos() to highlight specific positions efficiently.
(Alexey Radkov)
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/eval.txt | 37 | ||||
-rw-r--r-- | runtime/doc/usr_41.txt | 1 | ||||
-rw-r--r-- | runtime/plugin/matchparen.vim | 14 |
3 files changed, 47 insertions, 5 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 1ffd7ed01..cf221070f 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1887,6 +1887,8 @@ match( {expr}, {pat}[, {start}[, {count}]]) Number position where {pat} matches in {expr} matchadd( {group}, {pattern}[, {priority}[, {id}]]) Number highlight {pattern} with {group} +matchaddpos( {group}, {list}[, {priority}[, {id}]]) + Number highlight positions with {group} matcharg( {nr}) List arguments of |:match| matchdelete( {id}) Number delete match identified by {id} matchend( {expr}, {pat}[, {start}[, {count}]]) @@ -4380,6 +4382,41 @@ matchadd({group}, {pattern}[, {priority}[, {id}]]) available from |getmatches()|. All matches can be deleted in one operation by |clearmatches()|. +matchaddpos({group}, {pos}[, {priority}[, {id}]]) *matchaddpos()* + Same as |matchadd()|, but requires a list of positions {pos} + instead of a pattern. This command is faster than |matchadd()| + because it does not require to handle regular expressions and + sets buffer line boundaries to redraw screen. It is supposed + to be used when fast match additions and deletions are + required, for example to highlight matching parentheses. + + The list {pos} can contain one of these items: + - A number. This while line will be highlighted. The first + line has number 1. + - A list with one number, e.g., [23]. The whole line with this + number will be highlighted. + - A list with two numbers, e.g., [23, 11]. The first number is + the line number, the second one the column number (first + column is 1). The character at this position will be + highlighted. + - A list with three numbers, e.g., [23, 11, 3]. As above, but + the third number gives the length of the highlight in screen + cells. + + The maximum number of positions is 8. + + Example: > + :highlight MyGroup ctermbg=green guibg=green + :let m = matchaddpos("MyGroup", [[23, 24], 34]) +< Deletion of the pattern: > + :call matchdelete(m) + +< Matches added by |matchaddpos()| are returned by + |getmatches()| with an entry "pos1", "pos2", etc., with the + value a list like the {pos} item. + These matches cannot be set via |setmatches()|, however they + can still be deleted by |clearmatches()|. + matcharg({nr}) *matcharg()* Selects the {nr} match item, as set with a |:match|, |:2match| or |:3match| command. diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt index effe6db0a..f30b79a2e 100644 --- a/runtime/doc/usr_41.txt +++ b/runtime/doc/usr_41.txt @@ -827,6 +827,7 @@ Syntax and highlighting: *syntax-functions* *highlighting-functions* synconcealed() get info about concealing diff_hlID() get highlight ID for diff mode at a position matchadd() define a pattern to highlight (a "match") + matchaddpos() define a list of positions to highlight matcharg() get info about |:match| arguments matchdelete() delete a match defined by |matchadd()| or a |:match| command diff --git a/runtime/plugin/matchparen.vim b/runtime/plugin/matchparen.vim index 0fdfef164..b490f45eb 100644 --- a/runtime/plugin/matchparen.vim +++ b/runtime/plugin/matchparen.vim @@ -1,6 +1,6 @@ " Vim plugin for showing matching parens " Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2013 May 08 +" Last Change: 2014 Jun 17 " Exit quickly when: " - this plugin was already loaded (or disabled) @@ -39,7 +39,7 @@ set cpo-=C function! s:Highlight_Matching_Pair() " Remove any previous match. if exists('w:paren_hl_on') && w:paren_hl_on - 3match none + silent! call matchdelete(3) let w:paren_hl_on = 0 endif @@ -152,14 +152,18 @@ function! s:Highlight_Matching_Pair() " If a match is found setup match highlighting. if m_lnum > 0 && m_lnum >= stoplinetop && m_lnum <= stoplinebottom - exe '3match MatchParen /\(\%' . c_lnum . 'l\%' . (c_col - before) . - \ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/' + if exists('*matchaddpos') + call matchaddpos('MatchParen', [[c_lnum, c_col - before], [m_lnum, m_col]], 10, 3) + else + exe '3match MatchParen /\(\%' . c_lnum . 'l\%' . (c_col - before) . + \ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/' + endif let w:paren_hl_on = 1 endif endfunction " Define commands that will disable and enable the plugin. -command! NoMatchParen windo 3match none | unlet! g:loaded_matchparen | +command! NoMatchParen windo silent! call matchdelete(3) | unlet! g:loaded_matchparen | \ au! matchparen command! DoMatchParen runtime plugin/matchparen.vim | windo doau CursorMoved |