vim-patch:bd76c89e31ac (#24630)

update matchit (vim/vim#12611)

bd76c89e31

Co-authored-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Christian Clason 2023-08-09 23:44:16 +02:00 committed by GitHub
parent f060f03304
commit 1cf942204f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 97 additions and 49 deletions

View File

@ -1,6 +1,6 @@
" matchit.vim: (global plugin) Extended "%" matching " matchit.vim: (global plugin) Extended "%" matching
" autload script of matchit plugin, see ../plugin/matchit.vim " autload script of matchit plugin, see ../plugin/matchit.vim
" Last Change: Jun 10, 2021 " Last Change: Jan 24, 2022
" Neovim does not support scriptversion " Neovim does not support scriptversion
if has("vimscript-4") if has("vimscript-4")
@ -42,6 +42,10 @@ function s:RestoreOptions()
let restore_options = " ve=" .. &ve .. restore_options let restore_options = " ve=" .. &ve .. restore_options
set ve= set ve=
endif endif
if &smartcase
let restore_options = " smartcase " .. restore_options
set nosmartcase
endif
return restore_options return restore_options
endfunction endfunction
@ -134,9 +138,6 @@ function matchit#Match_wrapper(word, forward, mode) range
let curcol = match(matchline, regexp) let curcol = match(matchline, regexp)
" If there is no match, give up. " If there is no match, give up.
if curcol == -1 if curcol == -1
" Make sure macros abort properly
"exe "norm! \<esc>"
call feedkeys("\e", 'tni')
return s:CleanUp(restore_options, a:mode, startpos) return s:CleanUp(restore_options, a:mode, startpos)
endif endif
let endcol = matchend(matchline, regexp) let endcol = matchend(matchline, regexp)
@ -756,15 +757,15 @@ endfun
fun! s:ParseSkip(str) fun! s:ParseSkip(str)
let skip = a:str let skip = a:str
if skip[1] == ":" if skip[1] == ":"
if skip[0] == "s" if skip[0] ==# "s"
let skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '" .. let skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '" ..
\ strpart(skip,2) .. "'" \ strpart(skip,2) .. "'"
elseif skip[0] == "S" elseif skip[0] ==# "S"
let skip = "synIDattr(synID(line('.'),col('.'),1),'name') !~? '" .. let skip = "synIDattr(synID(line('.'),col('.'),1),'name') !~? '" ..
\ strpart(skip,2) .. "'" \ strpart(skip,2) .. "'"
elseif skip[0] == "r" elseif skip[0] ==# "r"
let skip = "strpart(getline('.'),0,col('.'))=~'" .. strpart(skip,2) .. "'" let skip = "strpart(getline('.'),0,col('.'))=~'" .. strpart(skip,2) .. "'"
elseif skip[0] == "R" elseif skip[0] ==# "R"
let skip = "strpart(getline('.'),0,col('.'))!~'" .. strpart(skip,2) .. "'" let skip = "strpart(getline('.'),0,col('.'))!~'" .. strpart(skip,2) .. "'"
endif endif
endif endif

View File

@ -1,10 +1,10 @@
*matchit.txt* Extended "%" matching *matchit.txt* Extended "%" matching
For instructions on installing this file, type For instructions on installing this file, type
`:help matchit-install` `:help matchit-install`
inside Vim. inside Vim.
For Vim version 8.2. Last change: 2021 Dec 24 For Vim version 9.0. Last change: 2023 June 28
VIM REFERENCE MANUAL by Benji Fisher et al VIM REFERENCE MANUAL by Benji Fisher et al
@ -150,8 +150,7 @@ To use the matchit plugin add this line to your |vimrc|: >
The script should start working the next time you start Vim. The script should start working the next time you start Vim.
To use the matchit plugin after startup, you can use this command (note the To use the matchit plugin after Vim has started, execute this command: >
omitted '!'): >
packadd matchit packadd matchit
(Earlier versions of the script did nothing unless a |buffer-variable| named (Earlier versions of the script did nothing unless a |buffer-variable| named
@ -175,6 +174,22 @@ fail to skip matching groups in comments and strings. If the |filetype|
mechanism is turned off, the |b:match_words| variable will probably not be mechanism is turned off, the |b:match_words| variable will probably not be
defined automatically. defined automatically.
2.1 Temporarily disable the matchit plugin *matchit-disable* *:MatchDisable*
To temporarily reset the plugins, that are setup you can run the following
command: >
:MatchDisable
This will delete all the defined key mappings to the Vim default.
Now the "%" command will work like before loading the plugin |%|
2.2 Re-enable the matchit plugin *:MatchEnable*
To re-enable the plugin, after it was disabled, use the following command: >
:MatchEnable
This will resetup the key mappings.
============================================================================== ==============================================================================
3. Configuration *matchit-configure* 3. Configuration *matchit-configure*
@ -243,6 +258,9 @@ Examples:
comment character) you can > comment character) you can >
:let b:match_skip = 'r:\(^\|[^\\]\)\(\\\\\)*%' :let b:match_skip = 'r:\(^\|[^\\]\)\(\\\\\)*%'
< <
See the $VIMRUNTIME/ftplugin/vim.vim for an example that uses both
syntax and a regular expression.
============================================================================== ==============================================================================
4. Supporting a New Language *matchit-newlang* 4. Supporting a New Language *matchit-newlang*
*b:match_words* *b:match_words*

View File

@ -1,7 +1,7 @@
" matchit.vim: (global plugin) Extended "%" matching " matchit.vim: (global plugin) Extended "%" matching
" Maintainer: Christian Brabandt " Maintainer: Christian Brabandt
" Version: 1.18 " Version: 1.19
" Last Change: 2020 Dec 23 " Last Change: 2023, June 28th
" Repository: https://github.com/chrisbra/matchit " Repository: https://github.com/chrisbra/matchit
" Previous URL:http://www.vim.org/script.php?script_id=39 " Previous URL:http://www.vim.org/script.php?script_id=39
" Previous Maintainer: Benji Fisher PhD <benji@member.AMS.org> " Previous Maintainer: Benji Fisher PhD <benji@member.AMS.org>
@ -46,44 +46,65 @@ let g:loaded_matchit = 1
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim set cpo&vim
nnoremap <silent> <Plug>(MatchitNormalForward) :<C-U>call matchit#Match_wrapper('',1,'n')<CR> fun MatchEnable()
nnoremap <silent> <Plug>(MatchitNormalBackward) :<C-U>call matchit#Match_wrapper('',0,'n')<CR> nnoremap <silent> <Plug>(MatchitNormalForward) :<C-U>call matchit#Match_wrapper('',1,'n')<CR>
xnoremap <silent> <Plug>(MatchitVisualForward) :<C-U>call matchit#Match_wrapper('',1,'v')<CR> nnoremap <silent> <Plug>(MatchitNormalBackward) :<C-U>call matchit#Match_wrapper('',0,'n')<CR>
\:if col("''") != col("$") \| exe ":normal! m'" \| endif<cr>gv`` xnoremap <silent> <Plug>(MatchitVisualForward) :<C-U>call matchit#Match_wrapper('',1,'v')<CR>
xnoremap <silent> <Plug>(MatchitVisualBackward) :<C-U>call matchit#Match_wrapper('',0,'v')<CR>m'gv`` \:if col("''") != col("$") \| exe ":normal! m'" \| endif<cr>gv``
onoremap <silent> <Plug>(MatchitOperationForward) :<C-U>call matchit#Match_wrapper('',1,'o')<CR> xnoremap <silent> <Plug>(MatchitVisualBackward) :<C-U>call matchit#Match_wrapper('',0,'v')<CR>m'gv``
onoremap <silent> <Plug>(MatchitOperationBackward) :<C-U>call matchit#Match_wrapper('',0,'o')<CR> onoremap <silent> <Plug>(MatchitOperationForward) :<C-U>call matchit#Match_wrapper('',1,'o')<CR>
onoremap <silent> <Plug>(MatchitOperationBackward) :<C-U>call matchit#Match_wrapper('',0,'o')<CR>
" Analogues of [{ and ]} using matching patterns:
nnoremap <silent> <Plug>(MatchitNormalMultiBackward) :<C-U>call matchit#MultiMatch("bW", "n")<CR>
nnoremap <silent> <Plug>(MatchitNormalMultiForward) :<C-U>call matchit#MultiMatch("W", "n")<CR>
xnoremap <silent> <Plug>(MatchitVisualMultiBackward) :<C-U>call matchit#MultiMatch("bW", "n")<CR>m'gv``
xnoremap <silent> <Plug>(MatchitVisualMultiForward) :<C-U>call matchit#MultiMatch("W", "n")<CR>m'gv``
onoremap <silent> <Plug>(MatchitOperationMultiBackward) :<C-U>call matchit#MultiMatch("bW", "o")<CR>
onoremap <silent> <Plug>(MatchitOperationMultiForward) :<C-U>call matchit#MultiMatch("W", "o")<CR>
" text object:
xmap <silent> <Plug>(MatchitVisualTextObject) <Plug>(MatchitVisualMultiBackward)o<Plug>(MatchitVisualMultiForward)
if !exists("g:no_plugin_maps")
nmap <silent> % <Plug>(MatchitNormalForward)
nmap <silent> g% <Plug>(MatchitNormalBackward)
xmap <silent> % <Plug>(MatchitVisualForward)
xmap <silent> g% <Plug>(MatchitVisualBackward)
omap <silent> % <Plug>(MatchitOperationForward)
omap <silent> g% <Plug>(MatchitOperationBackward)
" Analogues of [{ and ]} using matching patterns: " Analogues of [{ and ]} using matching patterns:
nmap <silent> [% <Plug>(MatchitNormalMultiBackward) nnoremap <silent> <Plug>(MatchitNormalMultiBackward) :<C-U>call matchit#MultiMatch("bW", "n")<CR>
nmap <silent> ]% <Plug>(MatchitNormalMultiForward) nnoremap <silent> <Plug>(MatchitNormalMultiForward) :<C-U>call matchit#MultiMatch("W", "n")<CR>
xmap <silent> [% <Plug>(MatchitVisualMultiBackward) xnoremap <silent> <Plug>(MatchitVisualMultiBackward) :<C-U>call matchit#MultiMatch("bW", "n")<CR>m'gv``
xmap <silent> ]% <Plug>(MatchitVisualMultiForward) xnoremap <silent> <Plug>(MatchitVisualMultiForward) :<C-U>call matchit#MultiMatch("W", "n")<CR>m'gv``
omap <silent> [% <Plug>(MatchitOperationMultiBackward) onoremap <silent> <Plug>(MatchitOperationMultiBackward) :<C-U>call matchit#MultiMatch("bW", "o")<CR>
omap <silent> ]% <Plug>(MatchitOperationMultiForward) onoremap <silent> <Plug>(MatchitOperationMultiForward) :<C-U>call matchit#MultiMatch("W", "o")<CR>
" Text object " text object:
xmap a% <Plug>(MatchitVisualTextObject) xmap <silent> <Plug>(MatchitVisualTextObject) <Plug>(MatchitVisualMultiBackward)o<Plug>(MatchitVisualMultiForward)
endif
if !exists("g:no_plugin_maps")
nmap <silent> % <Plug>(MatchitNormalForward)
nmap <silent> g% <Plug>(MatchitNormalBackward)
xmap <silent> % <Plug>(MatchitVisualForward)
xmap <silent> g% <Plug>(MatchitVisualBackward)
omap <silent> % <Plug>(MatchitOperationForward)
omap <silent> g% <Plug>(MatchitOperationBackward)
" Analogues of [{ and ]} using matching patterns:
nmap <silent> [% <Plug>(MatchitNormalMultiBackward)
nmap <silent> ]% <Plug>(MatchitNormalMultiForward)
xmap <silent> [% <Plug>(MatchitVisualMultiBackward)
xmap <silent> ]% <Plug>(MatchitVisualMultiForward)
omap <silent> [% <Plug>(MatchitOperationMultiBackward)
omap <silent> ]% <Plug>(MatchitOperationMultiForward)
" Text object
xmap a% <Plug>(MatchitVisualTextObject)
endif
endfun
fun MatchDisable()
" remove all the setup keymappings
nunmap %
nunmap g%
xunmap %
xunmap g%
ounmap %
ounmap g%
nunmap [%
nunmap ]%
xunmap [%
xunmap ]%
ounmap [%
ounmap ]%
xunmap a%
endfun
" Call this function to turn on debugging information. Every time the main " Call this function to turn on debugging information. Every time the main
" script is run, buffer variables will be saved. These can be used directly " script is run, buffer variables will be saved. These can be used directly
@ -91,6 +112,14 @@ endif
if !exists(":MatchDebug") if !exists(":MatchDebug")
command! -nargs=0 MatchDebug call matchit#Match_debug() command! -nargs=0 MatchDebug call matchit#Match_debug()
endif endif
if !exists(":MatchDisable")
command! -nargs=0 MatchDisable :call MatchDisable()
endif
if !exists(":MatchEnable")
command! -nargs=0 MatchEnable :call MatchEnable()
endif
call MatchEnable()
let &cpo = s:save_cpo let &cpo = s:save_cpo
unlet s:save_cpo unlet s:save_cpo