annotate src/testdir/samples/matchparen.vim @ 33988:7c30841c60a0 v9.0.2180

patch 9.0.2180: POSIX function name in exarg causes issues Commit: https://github.com/vim/vim/commit/6fdb6280821a822768df5689a5d727e37d38306c Author: Zoltan Arpadffy <zoltan.arpadffy@gmail.com> Date: Tue Dec 19 20:53:07 2023 +0100 patch 9.0.2180: POSIX function name in exarg causes issues Problem: POSIX function name in exarg struct causes issues on OpenVMS Solution: Rename getline member in exarg struct to ea_getline, remove isinf() workaround for VMS There are compilers that do not treat well POSIX functions - like getline - usage in the structs. Older VMS compilers could digest this... but the newer OpenVMS compilers ( like VSI C x86-64 X7.4-843 (GEM 50XB9) ) cannot deal with these structs. This could be limited to getline() that is defined via getdelim() and might not affect all POSIX functions in general - but avoiding POSIX function names usage in the structs is a "safe side" practice without compromising the functionality or the code readability. The previous OpenVMS X86 port used a workaround limiting the compiler capabilities using __CRTL_VER_OVERRIDE=80400000 In order to make the OpenVMS port future proof, this pull request proposes a possible solution. closes: #13704 Signed-off-by: Zoltan Arpadffy <zoltan.arpadffy@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Tue, 19 Dec 2023 21:00:04 +0100
parents 58c9f11eae5b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33844
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Vim plugin for showing matching parens
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 " Maintainer: The Vim Project <https://github.com/vim/vim>
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 " Last Change: 2023 Oct 20
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 " Former Maintainer: Bram Moolenaar <Bram@vim.org>
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 " Exit quickly when:
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 " - this plugin was already loaded (or disabled)
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 " - when 'compatible' is set
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 if exists("g:loaded_matchparen") || &cp
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 finish
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 let g:loaded_matchparen = 1
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 if !exists("g:matchparen_timeout")
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 let g:matchparen_timeout = 300
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 if !exists("g:matchparen_insert_timeout")
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 let g:matchparen_insert_timeout = 60
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 let s:has_matchaddpos = exists('*matchaddpos')
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 augroup matchparen
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 " Replace all matchparen autocommands
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 autocmd! CursorMoved,CursorMovedI,WinEnter,BufWinEnter,WinScrolled * call s:Highlight_Matching_Pair()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 autocmd! WinLeave,BufLeave * call s:Remove_Matches()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 if exists('##TextChanged')
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 autocmd! TextChanged,TextChangedI * call s:Highlight_Matching_Pair()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 autocmd! TextChangedP * call s:Remove_Matches()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 augroup END
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 " Skip the rest if it was already done.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 if exists("*s:Highlight_Matching_Pair")
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 finish
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 let s:cpo_save = &cpo
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 set cpo-=C
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 " The function that is invoked (very often) to define a ":match" highlighting
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 " for any matching paren.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 func s:Highlight_Matching_Pair()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 if !exists("w:matchparen_ids")
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 let w:matchparen_ids = []
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 " Remove any previous match.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 call s:Remove_Matches()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 " Avoid that we remove the popup menu.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 " Return when there are no colors (looks like the cursor jumps).
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 if pumvisible() || (&t_Co < 8 && !has("gui_running"))
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 return
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 " Get the character under the cursor and check if it's in 'matchpairs'.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 let c_lnum = line('.')
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 let c_col = col('.')
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 let before = 0
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 let text = getline(c_lnum)
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 let matches = matchlist(text, '\(.\)\=\%'.c_col.'c\(.\=\)')
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 if empty(matches)
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 let [c_before, c] = ['', '']
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 else
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 let [c_before, c] = matches[1:2]
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 let plist = split(&matchpairs, '.\zs[:,]')
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 let i = index(plist, c)
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 if i < 0
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 " not found, in Insert mode try character before the cursor
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 if c_col > 1 && (mode() == 'i' || mode() == 'R')
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 let before = strlen(c_before)
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 let c = c_before
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 let i = index(plist, c)
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 if i < 0
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 " not found, nothing to do
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 return
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 " Figure out the arguments for searchpairpos().
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 if i % 2 == 0
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 let s_flags = 'nW'
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 let c2 = plist[i + 1]
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 else
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 let s_flags = 'nbW'
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 let c2 = c
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 let c = plist[i - 1]
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 if c == '['
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 let c = '\['
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 let c2 = '\]'
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 " Find the match. When it was just before the cursor move it there for a
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 " moment.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 if before > 0
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 let has_getcurpos = exists("*getcurpos")
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 if has_getcurpos
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 " getcurpos() is more efficient but doesn't exist before 7.4.313.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 let save_cursor = getcurpos()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 else
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 let save_cursor = winsaveview()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 call cursor(c_lnum, c_col - before)
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 if !has("syntax") || !exists("g:syntax_on")
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 let s_skip = "0"
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112 else
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 " Build an expression that detects whether the current cursor position is
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
114 " in certain syntax types (string, comment, etc.), for use as
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
115 " searchpairpos()'s skip argument.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
116 " We match "escape" for special items, such as lispEscapeSpecial, and
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
117 " match "symbol" for lispBarSymbol.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
118 let s_skip = 'synstack(".", col("."))'
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
119 \ . '->indexof({_, id -> synIDattr(id, "name") =~? '
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
120 \ . '"string\\|character\\|singlequote\\|escape\\|symbol\\|comment"}) >= 0'
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
121 " If executing the expression determines that the cursor is currently in
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
122 " one of the syntax types, then we want searchpairpos() to find the pair
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 " within those syntax types (i.e., not skip). Otherwise, the cursor is
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 " outside of the syntax types and s_skip should keep its value so we skip
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 " any matching pair inside the syntax types.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126 " Catch if this throws E363: pattern uses more memory than 'maxmempattern'.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
127 try
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
128 execute 'if ' . s_skip . ' | let s_skip = "0" | endif'
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
129 catch /^Vim\%((\a\+)\)\=:E363/
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
130 " We won't find anything, so skip searching, should keep Vim responsive.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
131 return
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
132 endtry
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
134
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 " Limit the search to lines visible in the window.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136 let stoplinebottom = line('w$')
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
137 let stoplinetop = line('w0')
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
138 if i % 2 == 0
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139 let stopline = stoplinebottom
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
140 else
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
141 let stopline = stoplinetop
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
142 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
143
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
144 " Limit the search time to 300 msec to avoid a hang on very long lines.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
145 " This fails when a timeout is not supported.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
146 if mode() == 'i' || mode() == 'R'
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147 let timeout = exists("b:matchparen_insert_timeout") ? b:matchparen_insert_timeout : g:matchparen_insert_timeout
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 else
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149 let timeout = exists("b:matchparen_timeout") ? b:matchparen_timeout : g:matchparen_timeout
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
150 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151 try
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
152 let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline, timeout)
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
153 catch /E118/
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
154 " Can't use the timeout, restrict the stopline a bit more to avoid taking
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
155 " a long time on closed folds and long lines.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156 " The "viewable" variables give a range in which we can scroll while
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157 " keeping the cursor at the same position.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158 " adjustedScrolloff accounts for very large numbers of scrolloff.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
159 let adjustedScrolloff = min([&scrolloff, (line('w$') - line('w0')) / 2])
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
160 let bottom_viewable = min([line('$'), c_lnum + &lines - adjustedScrolloff - 2])
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
161 let top_viewable = max([1, c_lnum-&lines+adjustedScrolloff + 2])
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
162 " one of these stoplines will be adjusted below, but the current values are
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
163 " minimal boundaries within the current window
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
164 if i % 2 == 0
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
165 if has("byte_offset") && has("syntax_items") && &smc > 0
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
166 let stopbyte = min([line2byte("$"), line2byte(".") + col(".") + &smc * 2])
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
167 let stopline = min([bottom_viewable, byte2line(stopbyte)])
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
168 else
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169 let stopline = min([bottom_viewable, c_lnum + 100])
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
170 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
171 let stoplinebottom = stopline
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
172 else
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
173 if has("byte_offset") && has("syntax_items") && &smc > 0
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
174 let stopbyte = max([1, line2byte(".") + col(".") - &smc * 2])
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
175 let stopline = max([top_viewable, byte2line(stopbyte)])
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
176 else
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
177 let stopline = max([top_viewable, c_lnum - 100])
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
178 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
179 let stoplinetop = stopline
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
180 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
181 let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline)
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
182 endtry
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
183
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
184 if before > 0
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
185 if has_getcurpos
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
186 call setpos('.', save_cursor)
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
187 else
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
188 call winrestview(save_cursor)
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
189 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
190 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
191
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
192 " If a match is found setup match highlighting.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
193 if m_lnum > 0 && m_lnum >= stoplinetop && m_lnum <= stoplinebottom
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
194 if s:has_matchaddpos
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
195 call add(w:matchparen_ids, matchaddpos('MatchParen', [[c_lnum, c_col - before], [m_lnum, m_col]], 10))
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
196 else
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
197 exe '3match MatchParen /\(\%' . c_lnum . 'l\%' . (c_col - before) .
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
198 \ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/'
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
199 call add(w:matchparen_ids, 3)
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
200 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
201 let w:paren_hl_on = 1
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
202 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
203 endfunction
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
204
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
205 func s:Remove_Matches()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
206 if exists('w:paren_hl_on') && w:paren_hl_on
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
207 while !empty(w:matchparen_ids)
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
208 silent! call remove(w:matchparen_ids, 0)->matchdelete()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
209 endwhile
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
210 let w:paren_hl_on = 0
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
211 endif
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
212 endfunc
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
213
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
214 " Define commands that will disable and enable the plugin.
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
215 command DoMatchParen call s:DoMatchParen()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
216 command NoMatchParen call s:NoMatchParen()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
217
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
218 func s:NoMatchParen()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
219 let w = winnr()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
220 noau windo silent! call matchdelete(3)
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
221 unlet! g:loaded_matchparen
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
222 exe "noau ". w . "wincmd w"
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
223 au! matchparen
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
224 endfunc
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
225
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
226 func s:DoMatchParen()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
227 runtime plugin/matchparen.vim
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
228 let w = winnr()
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
229 silent windo doau CursorMoved
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
230 exe "noau ". w . "wincmd w"
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
231 endfunc
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
232
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
233 let &cpo = s:cpo_save
58c9f11eae5b patch 9.0.2134: ml_get error when scrolling
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
234 unlet s:cpo_save