From 2b28a895e81bfc8fa1032d9afb1846f7f7dc8d12 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 13 Jul 2018 12:14:26 +0200 Subject: [PATCH] vim: matchit: sync with latest version in Debian sid --- vim/vim/bundle/matchit/doc/matchit.txt | 18 +++---- vim/vim/bundle/matchit/plugin/matchit.vim | 63 +++++++++++++---------- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/vim/vim/bundle/matchit/doc/matchit.txt b/vim/vim/bundle/matchit/doc/matchit.txt index 8a3a96e..ea6fd11 100644 --- a/vim/vim/bundle/matchit/doc/matchit.txt +++ b/vim/vim/bundle/matchit/doc/matchit.txt @@ -4,7 +4,7 @@ For instructions on installing this file, type :help matchit-install inside Vim. -For Vim version 6.3. Last change: 2007 Aug 29 +For Vim version 6.3. Last change: 2017 May 14 VIM REFERENCE MANUAL by Benji Fisher @@ -152,13 +152,10 @@ setting |b:match_skip|. ============================================================================== 2. Activation *matchit-activate* -You can use this script as a plugin, by copying it to your plugin directory. -See |add-global-plugin| for instructions. You can also add a line to your -|vimrc| file, such as > - :source $VIMRUNTIME/macros/matchit.vim -or > - :runtime macros/matchit.vim -Either way, the script should start working the next time you start up Vim. +To use the matchit plugin add this line to your |vimrc|: > + packadd! matchit + +The script should start working the next time you start Vim. (Earlier versions of the script did nothing unless a |buffer-variable| named |b:match_words| was defined. Even earlier versions contained autocommands @@ -245,7 +242,7 @@ Examples: In LaTeX, since "%" is used as the comment character, you can > :let b:match_skip = 'r:%' < Unfortunately, this will skip anything after "\%", an escaped "%". To - allow for this, and also "\\%" (an excaped backslash followed by the + allow for this, and also "\\%" (an escaped backslash followed by the comment character) you can > :let b:match_skip = 'r:\(^\|[^\\]\)\(\\\\\)*%' < @@ -395,7 +392,8 @@ a while. Moral: if a bug (known or not) bothers you, let me know. The various |:vmap|s defined in the script (%, |g%|, |[%|, |]%|, |a%|) may have undesired effects in Select mode |Select-mode-mapping|. At least, if you want to replace the selection with any character in "ag%[]" there will be a -pause of |'updatetime'| first. +pause of |'updatetime'| first. E.g., "yV%" would normally work linewise, but +the plugin mapping makes it characterwise. It would be nice if "\0" were recognized as the entire pattern. That is, it would be nice if "foo:\end\0" had the same effect as "\(foo\):\end\1". I may diff --git a/vim/vim/bundle/matchit/plugin/matchit.vim b/vim/vim/bundle/matchit/plugin/matchit.vim index e41cda9..5e9df89 100644 --- a/vim/vim/bundle/matchit/plugin/matchit.vim +++ b/vim/vim/bundle/matchit/plugin/matchit.vim @@ -1,7 +1,9 @@ " matchit.vim: (global plugin) Extended "%" matching -" Last Change: Fri Jan 25 10:00 AM 2008 EST +" Last Change: 2017 Sep 15 " Maintainer: Benji Fisher PhD -" Version: 1.13.2, for Vim 6.3+ +" Version: 1.13.3, for Vim 6.3+ +" Fix from Fernando Torres included. +" Improvement from Ken Takata included. " URL: http://www.vim.org/script.php?script_id=39 " Documentation: @@ -43,6 +45,7 @@ endif let loaded_matchit = 1 let s:last_mps = "" let s:last_words = ":" +let s:patBR = "" let s:save_cpo = &cpo set cpo&vim @@ -86,12 +89,15 @@ let s:notslash = '\\\@\|#ifdef\>\|#else\>\|#elif\>\|#endif\>' let default = escape(&mps, '[$^.*~\\/?]') . (strlen(&mps) ? "," : "") . - \ '\/\*:\*\/,#if\%(def\)\=:#else\>:#elif\>:#endif\>' + \ '\/\*:\*\/,#\s*if\%(def\)\=:#\s*else\>:#\s*elif\>:#\s*endif\>' " s:all = pattern with all the keywords let match_words = match_words . (strlen(match_words) ? "," : "") . default + let s:last_words = match_words if match_words !~ s:notslash . '\\\d' let s:do_BR = 0 let s:pat = match_words @@ -147,6 +153,10 @@ function! s:Match_wrapper(word, forward, mode) range if exists("b:match_debug") let b:match_pat = s:pat endif + " Reconstruct the version with unresolved backrefs. + let s:patBR = substitute(match_words.',', + \ s:notslash.'\zs[,:]*,[,:]*', ',', 'g') + let s:patBR = substitute(s:patBR, s:notslash.'\zs:\{2,}', ':', 'g') endif " Second step: set the following local variables: @@ -191,14 +201,10 @@ function! s:Match_wrapper(word, forward, mode) range " group = colon-separated list of patterns, one of which matches " = ini:mid:fin or ini:fin " - " Reconstruct the version with unresolved backrefs. - let patBR = substitute(match_words.',', - \ s:notslash.'\zs[,:]*,[,:]*', ',', 'g') - let patBR = substitute(patBR, s:notslash.'\zs:\{2,}', ':', 'g') " Now, set group and groupBR to the matching group: 'if:endif' or " 'while:endwhile' or whatever. A bit of a kluge: s:Choose() returns " group . "," . groupBR, and we pick it apart. - let group = s:Choose(s:pat, matchline, ",", ":", prefix, suffix, patBR) + let group = s:Choose(s:pat, matchline, ",", ":", prefix, suffix, s:patBR) let i = matchend(group, s:notslash . ",") let groupBR = strpart(group, i) let group = strpart(group, 0, i-1) @@ -284,7 +290,9 @@ endfun " Restore options and do some special handling for Operator-pending mode. " The optional argument is the tail of the matching group. fun! s:CleanUp(options, mode, startline, startcol, ...) - execute "set" a:options + if strlen(a:options) + execute "set" a:options + endif " Open folds, if appropriate. if a:mode != "o" if &foldopen =~ "percent" @@ -303,7 +311,7 @@ fun! s:CleanUp(options, mode, startline, startcol, ...) let regexp = s:Wholematch(matchline, a:1, currcol-1) let endcol = matchend(matchline, regexp) if endcol > currcol " This is NOT off by one! - execute "normal!" . (endcol - currcol) . "l" + call cursor(0, endcol) endif endif " a:0 endif " a:mode != "o" && etc. @@ -357,7 +365,7 @@ fun! s:InsertRefs(groupBR, prefix, group, suffix, matchline) execute s:Ref(ini, d, "start", "len") let ini = strpart(ini, 0, start) . backref . strpart(ini, start+len) let tailBR = substitute(tailBR, s:notslash . '\zs\\' . d, - \ escape(backref, '\\'), 'g') + \ escape(backref, '\\&'), 'g') endif let d = d-1 endwhile @@ -636,8 +644,9 @@ fun! s:MultiMatch(spflag, mode) if !exists("b:match_words") || b:match_words == "" return "" end - let restore_options = (&ic ? "" : "no") . "ignorecase" - if exists("b:match_ignorecase") + let restore_options = "" + if exists("b:match_ignorecase") && b:match_ignorecase != &ic + let restore_options .= (&ic ? " " : " no") . "ignorecase" let &ignorecase = b:match_ignorecase endif let startline = line(".") @@ -649,7 +658,7 @@ fun! s:MultiMatch(spflag, mode) " s:all regexp based on s:pat and the default groups " This part is copied and slightly modified from s:Match_wrapper(). let default = escape(&mps, '[$^.*~\\/?]') . (strlen(&mps) ? "," : "") . - \ '\/\*:\*\/,#if\%(def\)\=:#else\>:#elif\>:#endif\>' + \ '\/\*:\*\/,#\s*if\%(def\)\=:#\s*else\>:#\s*elif\>:#\s*endif\>' " Allow b:match_words = "GetVimMatchWords()" . if b:match_words =~ ":" let match_words = b:match_words @@ -660,6 +669,7 @@ fun! s:MultiMatch(spflag, mode) \ exists("b:match_debug") let s:last_words = match_words let s:last_mps = &mps + let match_words = match_words . (strlen(match_words) ? "," : "") . default if match_words !~ s:notslash . '\\\d' let s:do_BR = 0 let s:pat = match_words @@ -667,8 +677,8 @@ fun! s:MultiMatch(spflag, mode) let s:do_BR = 1 let s:pat = s:ParseWords(match_words) endif - let s:all = '\%(' . substitute(s:pat . (strlen(s:pat)?",":"") . default, - \ '[,:]\+','\\|','g') . '\)' + let s:all = '\%(' . substitute(s:pat . (strlen(s:pat) ? "," : "") . default, + \ '[,:]\+', '\\|', 'g') . '\)' if exists("b:match_debug") let b:match_pat = s:pat endif @@ -694,9 +704,8 @@ fun! s:MultiMatch(spflag, mode) let skip = 's:comment\|string' endif let skip = s:ParseSkip(skip) - " let restore_cursor = line(".") . "G" . virtcol(".") . "|" - " normal! H - " let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor + " save v:count1 variable, might be reset from the restore_cursor command + let level = v:count1 let restore_cursor = virtcol(".") . "|" normal! g0 let restore_cursor = line(".") . "G" . virtcol(".") . "|zs" . restore_cursor @@ -716,7 +725,6 @@ fun! s:MultiMatch(spflag, mode) execute "if " . skip . "| let skip = '0' | endif" endif mark ' - let level = v:count1 while level if searchpair(openpat, '', closepat, a:spflag, skip) < 1 call s:CleanUp(restore_options, a:mode, startline, startcol) @@ -808,5 +816,6 @@ fun! s:ParseSkip(str) endfun let &cpo = s:save_cpo +unlet s:save_cpo " vim:sts=2:sw=2: -- 2.45.2