forked from aniani/vim
patch 9.1.1203: matchparen keeps cursor on case label in sh filetype
Problem: matchparen keeps cursor on case label in sh filetype (@categorical, after 9.1.1187). Solution: Use :defer so that cursor is always restored, remove checks for older Vims, finish early if Vim does not support :defer fixes: #16887 closes: #16888 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
2329bd427a
commit
47071c6076
@@ -1,12 +1,14 @@
|
|||||||
" Vim plugin for showing matching parens
|
" Vim plugin for showing matching parens
|
||||||
" Maintainer: The Vim Project <https://github.com/vim/vim>
|
" Maintainer: The Vim Project <https://github.com/vim/vim>
|
||||||
" Last Change: 2025 Mar 08
|
" Last Change: 2025 Mar 14
|
||||||
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
|
" Former Maintainer: Bram Moolenaar <Bram@vim.org>
|
||||||
|
|
||||||
" Exit quickly when:
|
" Exit quickly when:
|
||||||
" - this plugin was already loaded (or disabled)
|
" - this plugin was already loaded (or disabled)
|
||||||
" - when 'compatible' is set
|
" - when 'compatible' is set
|
||||||
if exists("g:loaded_matchparen") || &cp
|
" - Vim has no support for :defer
|
||||||
|
if exists("g:loaded_matchparen") || &cp ||
|
||||||
|
\ exists(":defer") != 2
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let g:loaded_matchparen = 1
|
let g:loaded_matchparen = 1
|
||||||
@@ -21,17 +23,13 @@ if !exists("g:matchparen_disable_cursor_hl")
|
|||||||
let g:matchparen_disable_cursor_hl = 0
|
let g:matchparen_disable_cursor_hl = 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let s:has_matchaddpos = exists('*matchaddpos')
|
|
||||||
|
|
||||||
augroup matchparen
|
augroup matchparen
|
||||||
" Replace all matchparen autocommands
|
" Replace all matchparen autocommands
|
||||||
autocmd! CursorMoved,CursorMovedI,WinEnter,WinScrolled * call s:Highlight_Matching_Pair()
|
autocmd! CursorMoved,CursorMovedI,WinEnter,WinScrolled * call s:Highlight_Matching_Pair()
|
||||||
autocmd! BufWinEnter * autocmd SafeState * ++once call s:Highlight_Matching_Pair()
|
autocmd! BufWinEnter * autocmd SafeState * ++once call s:Highlight_Matching_Pair()
|
||||||
autocmd! WinLeave,BufLeave * call s:Remove_Matches()
|
autocmd! WinLeave,BufLeave * call s:Remove_Matches()
|
||||||
if exists('##TextChanged')
|
|
||||||
autocmd! TextChanged,TextChangedI * call s:Highlight_Matching_Pair()
|
autocmd! TextChanged,TextChangedI * call s:Highlight_Matching_Pair()
|
||||||
autocmd! TextChangedP * call s:Remove_Matches()
|
autocmd! TextChangedP * call s:Remove_Matches()
|
||||||
endif
|
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
" Skip the rest if it was already done.
|
" Skip the rest if it was already done.
|
||||||
@@ -97,14 +95,9 @@ func s:Highlight_Matching_Pair()
|
|||||||
" Find the match. When it was just before the cursor move it there for a
|
" Find the match. When it was just before the cursor move it there for a
|
||||||
" moment.
|
" moment.
|
||||||
if before > 0
|
if before > 0
|
||||||
let has_getcurpos = exists("*getcurpos")
|
|
||||||
if has_getcurpos
|
|
||||||
" getcurpos() is more efficient but doesn't exist before 7.4.313.
|
|
||||||
let save_cursor = getcurpos()
|
let save_cursor = getcurpos()
|
||||||
else
|
|
||||||
let save_cursor = winsaveview()
|
|
||||||
endif
|
|
||||||
call cursor(c_lnum, c_col - before)
|
call cursor(c_lnum, c_col - before)
|
||||||
|
defer setpos('.', save_cursor)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !has("syntax") || !exists("g:syntax_on")
|
if !has("syntax") || !exists("g:syntax_on")
|
||||||
@@ -192,31 +185,13 @@ func s:Highlight_Matching_Pair()
|
|||||||
let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline)
|
let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline)
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
if before > 0
|
|
||||||
if has_getcurpos
|
|
||||||
call setpos('.', save_cursor)
|
|
||||||
else
|
|
||||||
call winrestview(save_cursor)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
" If a match is found setup match highlighting.
|
" If a match is found setup match highlighting.
|
||||||
if m_lnum > 0 && m_lnum >= stoplinetop && m_lnum <= stoplinebottom
|
if m_lnum > 0 && m_lnum >= stoplinetop && m_lnum <= stoplinebottom
|
||||||
if s:has_matchaddpos
|
|
||||||
if !g:matchparen_disable_cursor_hl
|
if !g:matchparen_disable_cursor_hl
|
||||||
call add(w:matchparen_ids, matchaddpos('MatchParen', [[c_lnum, c_col - before], [m_lnum, m_col]], 10))
|
call add(w:matchparen_ids, matchaddpos('MatchParen', [[c_lnum, c_col - before], [m_lnum, m_col]], 10))
|
||||||
else
|
else
|
||||||
call add(w:matchparen_ids, matchaddpos('MatchParen', [[m_lnum, m_col]], 10))
|
call add(w:matchparen_ids, matchaddpos('MatchParen', [[m_lnum, m_col]], 10))
|
||||||
endif
|
endif
|
||||||
else
|
|
||||||
if !g:matchparen_disable_cursor_hl
|
|
||||||
exe '3match MatchParen /\(\%' . c_lnum . 'l\%' . (c_col - before) .
|
|
||||||
\ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/'
|
|
||||||
else
|
|
||||||
exe '3match MatchParen /\(\%' . m_lnum . 'l\%' . m_col . 'c\)/'
|
|
||||||
endif
|
|
||||||
call add(w:matchparen_ids, 3)
|
|
||||||
endif
|
|
||||||
let w:paren_hl_on = 1
|
let w:paren_hl_on = 1
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
10
src/testdir/dumps/Test_matchparen_sh_case_2.dump
Normal file
10
src/testdir/dumps/Test_matchparen_sh_case_2.dump
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
|#+0#0000e05#ffffff0|!|/|b|i|n|/|s|h| +0#0000000&@65
|
||||||
|
|S+0#00e0e07&|U|S|U|W|U|_|P|R|I|N|T|(|)| |(| +0#0000000&@58
|
||||||
|
@2|c+0#af5f00255&|a|s|e| +0#0000000&|"+0#af5f00255&|$+0#e000e06&|{|L|E|V|E|L|}|"+0#af5f00255&| +0#0000000&|i+0#af5f00255&|n| +0#0000000&@54
|
||||||
|
@4|"+0#af5f00255&|$+0#e000e06&|S|U|S|U|W|U|_|S|H|_|N|O|T|I|C|E|"+0#af5f00255&|)| +0#0000000&|f|o@1|b|a|r> @43
|
||||||
|
@4|$+0#e000e06&|{|S|U|S|U|W|U|_|S|}| +0#0000000&|&+0#af5f00255&@1| +0#0000000&|r+0#af5f00255&|e|t|u|r|n| +0#0000000&|1+0#e000002&| +0#0000000&@47
|
||||||
|
@2|;+0#af5f00255&@1| +0#0000000&@70
|
||||||
|
@4|"+0#af5f00255&|$+0#e000e06&|S|U|S|U|W|U|_|S|H|_|D|E|B|U|G|"+0#af5f00255&|)| +0#0000000&@51
|
||||||
|
@4|(+0#e000e06&|!+0#af5f00255&| +0#0000000&|$+0#e000e06&|{|S|U|S|U|W|U|_|V|E|R|B|O|S|E|}|)| +0#0000000&|&+0#af5f00255&@1| +0#0000000&|r+0#af5f00255&|e|t|u|r|n| +0#0000000&|1+0#e000002&| +0#0000000&@37
|
||||||
|
@2|;+0#af5f00255&@1| +0#0000000&@70
|
||||||
|
|-+2&&@1| |I|N|S|E|R|T| |-@1| +0&&@44|4|,|3|2| @9|T|o|p|
|
@@ -168,6 +168,12 @@ func Test_matchparen_ignore_sh_case()
|
|||||||
|
|
||||||
let buf = RunVimInTerminal('-S '.filename, #{rows: 10})
|
let buf = RunVimInTerminal('-S '.filename, #{rows: 10})
|
||||||
call VerifyScreenDump(buf, 'Test_matchparen_sh_case_1', {})
|
call VerifyScreenDump(buf, 'Test_matchparen_sh_case_1', {})
|
||||||
|
" Send keys one by one so that CursorMoved is triggered.
|
||||||
|
for c in 'A foobar'
|
||||||
|
call term_sendkeys(buf, c)
|
||||||
|
call term_wait(buf)
|
||||||
|
endfor
|
||||||
|
call VerifyScreenDump(buf, 'Test_matchparen_sh_case_2', {})
|
||||||
call StopVimInTerminal(buf)
|
call StopVimInTerminal(buf)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -704,6 +704,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1203,
|
||||||
/**/
|
/**/
|
||||||
1202,
|
1202,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user