annotate runtime/pack/dist/opt/matchit/autoload/matchit.vim @ 27459:5825405e4e2c

Update runtime files Commit: https://github.com/vim/vim/commit/f10911e5db16f1fe6ab519c5d091ad0c1df0d063 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 29 22:20:48 2022 +0000 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Sat, 29 Jan 2022 23:30:04 +0100
parents f0d7cb510ce3
children ea044451c98f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " matchit.vim: (global plugin) Extended "%" matching
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 " autload script of matchit plugin, see ../plugin/matchit.vim
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
3 " Last Change: Jun 10, 2021
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
4
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
5 " Neovim does not support scriptversion
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
6 if has("vimscript-4")
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
7 scriptversion 4
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
8 endif
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 let s:last_mps = ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 let s:last_words = ":"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 let s:patBR = ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 let s:save_cpo = &cpo
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 set cpo&vim
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 " Auto-complete mappings: (not yet "ready for prime time")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 " TODO Read :help write-plugin for the "right" way to let the user
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 " specify a key binding.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 " let g:match_auto = '<C-]>'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 " let g:match_autoCR = '<C-CR>'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 " if exists("g:match_auto")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 " execute "inoremap " . g:match_auto . ' x<Esc>"=<SID>Autocomplete()<CR>Pls'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 " endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 " if exists("g:match_autoCR")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 " execute "inoremap " . g:match_autoCR . ' <CR><C-R>=<SID>Autocomplete()<CR>'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 " endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 " if exists("g:match_gthhoh")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 " execute "inoremap " . g:match_gthhoh . ' <C-O>:call <SID>Gthhoh()<CR>'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 " endif " gthhoh = "Get the heck out of here!"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 let s:notslash = '\\\@1<!\%(\\\\\)*'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 function s:RestoreOptions()
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 " In s:CleanUp(), :execute "set" restore_options .
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 let restore_options = ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 if get(b:, 'match_ignorecase', &ic) != &ic
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
38 let restore_options ..= (&ic ? " " : " no") .. "ignorecase"
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 let &ignorecase = b:match_ignorecase
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 if &ve != ''
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
42 let restore_options = " ve=" .. &ve .. restore_options
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 set ve=
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 return restore_options
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 endfunction
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 function matchit#Match_wrapper(word, forward, mode) range
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 let restore_options = s:RestoreOptions()
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
50 " In s:CleanUp(), we may need to check whether the cursor moved forward.
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
51 let startpos = [line("."), col(".")]
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
52 " if a count has been applied, use the default [count]% mode (see :h N%)
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
53 if v:count
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
54 exe "normal! " .. v:count .. "%"
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
55 return s:CleanUp(restore_options, a:mode, startpos)
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
56 end
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
57 if a:mode =~# "v" && mode(1) =~# 'ni'
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
58 exe "norm! gv"
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 elseif a:mode == "o" && mode(1) !~# '[vV]'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 exe "norm! v"
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
61 " If this function was called from Visual mode, make sure that the cursor
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
62 " is at the correct end of the Visual range:
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
63 elseif a:mode == "v"
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
64 execute "normal! gv\<Esc>"
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
65 let startpos = [line("."), col(".")]
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 " First step: if not already done, set the script variables
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 " s:do_BR flag for whether there are backrefs
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 " s:pat parsed version of b:match_words
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 " s:all regexp based on s:pat and the default groups
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 if !exists("b:match_words") || b:match_words == ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 let match_words = ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 elseif b:match_words =~ ":"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 let match_words = b:match_words
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 else
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 " Allow b:match_words = "GetVimMatchWords()" .
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 execute "let match_words =" b:match_words
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 " Thanks to Preben "Peppe" Guldberg and Bram Moolenaar for this suggestion!
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 if (match_words != s:last_words) || (&mps != s:last_mps)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 \ || exists("b:match_debug")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 let s:last_mps = &mps
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 " quote the special chars in 'matchpairs', replace [,:] with \| and then
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 " append the builtin pairs (/*, */, #if, #ifdef, #ifndef, #else, #elif,
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 " #endif)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
87 let default = escape(&mps, '[$^.*~\\/?]') .. (strlen(&mps) ? "," : "") ..
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 \ '\/\*:\*\/,#\s*if\%(n\=def\)\=:#\s*else\>:#\s*elif\>:#\s*endif\>'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 " s:all = pattern with all the keywords
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
90 let match_words = match_words .. (strlen(match_words) ? "," : "") .. default
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 let s:last_words = match_words
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
92 if match_words !~ s:notslash .. '\\\d'
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 let s:do_BR = 0
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 let s:pat = match_words
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 else
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 let s:do_BR = 1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 let s:pat = s:ParseWords(match_words)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 endif
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
99 let s:all = substitute(s:pat, s:notslash .. '\zs[,:]\+', '\\|', 'g')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 " Just in case there are too many '\(...)' groups inside the pattern, make
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 " sure to use \%(...) groups, so that error E872 can be avoided
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 let s:all = substitute(s:all, '\\(', '\\%(', 'g')
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
103 let s:all = '\%(' .. s:all .. '\)'
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 if exists("b:match_debug")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 let b:match_pat = s:pat
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 " Reconstruct the version with unresolved backrefs.
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
108 let s:patBR = substitute(match_words .. ',',
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
109 \ s:notslash .. '\zs[,:]*,[,:]*', ',', 'g')
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
110 let s:patBR = substitute(s:patBR, s:notslash .. '\zs:\{2,}', ':', 'g')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 " Second step: set the following local variables:
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 " matchline = line on which the cursor started
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 " curcol = number of characters before match
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 " prefix = regexp for start of line to start of match
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 " suffix = regexp for end of match to end of line
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 " Require match to end on or after the cursor and prefer it to
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 " start on or before the cursor.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 let matchline = getline(startpos[0])
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 if a:word != ''
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 " word given
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 if a:word !~ s:all
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 echohl WarningMsg|echo 'Missing rule for word:"'.a:word.'"'|echohl NONE
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 return s:CleanUp(restore_options, a:mode, startpos)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 let matchline = a:word
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 let curcol = 0
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 let prefix = '^\%('
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 let suffix = '\)$'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 " Now the case when "word" is not given
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 else " Find the match that ends on or after the cursor and set curcol.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 let regexp = s:Wholematch(matchline, s:all, startpos[1]-1)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 let curcol = match(matchline, regexp)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 " If there is no match, give up.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 if curcol == -1
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
137 " Make sure macros abort properly
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
138 "exe "norm! \<esc>"
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
139 call feedkeys("\e", 'tni')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 return s:CleanUp(restore_options, a:mode, startpos)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 let endcol = matchend(matchline, regexp)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 let suf = strlen(matchline) - endcol
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
144 let prefix = (curcol ? '^.*\%' .. (curcol + 1) .. 'c\%(' : '^\%(')
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
145 let suffix = (suf ? '\)\%' .. (endcol + 1) .. 'c.*$' : '\)$')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 if exists("b:match_debug")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 let b:match_match = matchstr(matchline, regexp)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 let b:match_col = curcol+1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 " Third step: Find the group and single word that match, and the original
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 " (backref) versions of these. Then, resolve the backrefs.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 " Set the following local variable:
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 " group = colon-separated list of patterns, one of which matches
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 " = ini:mid:fin or ini:fin
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 "
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 " Now, set group and groupBR to the matching group: 'if:endif' or
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 " 'while:endwhile' or whatever. A bit of a kluge: s:Choose() returns
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 " group . "," . groupBR, and we pick it apart.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 let group = s:Choose(s:pat, matchline, ",", ":", prefix, suffix, s:patBR)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
162 let i = matchend(group, s:notslash .. ",")
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 let groupBR = strpart(group, i)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 let group = strpart(group, 0, i-1)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 " Now, matchline =~ prefix . substitute(group,':','\|','g') . suffix
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 if s:do_BR " Do the hard part: resolve those backrefs!
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 let group = s:InsertRefs(groupBR, prefix, group, suffix, matchline)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 if exists("b:match_debug")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 let b:match_wholeBR = groupBR
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
171 let i = matchend(groupBR, s:notslash .. ":")
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 let b:match_iniBR = strpart(groupBR, 0, i-1)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 " Fourth step: Set the arguments for searchpair().
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
176 let i = matchend(group, s:notslash .. ":")
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
177 let j = matchend(group, '.*' .. s:notslash .. ":")
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 let ini = strpart(group, 0, i-1)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
179 let mid = substitute(strpart(group, i,j-i-1), s:notslash .. '\zs:', '\\|', 'g')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 let fin = strpart(group, j)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 "Un-escape the remaining , and : characters.
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
182 let ini = substitute(ini, s:notslash .. '\zs\\\(:\|,\)', '\1', 'g')
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
183 let mid = substitute(mid, s:notslash .. '\zs\\\(:\|,\)', '\1', 'g')
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
184 let fin = substitute(fin, s:notslash .. '\zs\\\(:\|,\)', '\1', 'g')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 " searchpair() requires that these patterns avoid \(\) groups.
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
186 let ini = substitute(ini, s:notslash .. '\zs\\(', '\\%(', 'g')
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
187 let mid = substitute(mid, s:notslash .. '\zs\\(', '\\%(', 'g')
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
188 let fin = substitute(fin, s:notslash .. '\zs\\(', '\\%(', 'g')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 " Set mid. This is optimized for readability, not micro-efficiency!
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
190 if a:forward && matchline =~ prefix .. fin .. suffix
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
191 \ || !a:forward && matchline =~ prefix .. ini .. suffix
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 let mid = ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 " Set flag. This is optimized for readability, not micro-efficiency!
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
195 if a:forward && matchline =~ prefix .. fin .. suffix
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
196 \ || !a:forward && matchline !~ prefix .. ini .. suffix
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 let flag = "bW"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 else
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 let flag = "W"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 " Set skip.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 if exists("b:match_skip")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 let skip = b:match_skip
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 elseif exists("b:match_comment") " backwards compatibility and testing!
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
205 let skip = "r:" .. b:match_comment
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 else
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 let skip = 's:comment\|string'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 let skip = s:ParseSkip(skip)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 if exists("b:match_debug")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 let b:match_ini = ini
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
212 let b:match_tail = (strlen(mid) ? mid .. '\|' : '') .. fin
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 " Fifth step: actually start moving the cursor and call searchpair().
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 " Later, :execute restore_cursor to get to the original screen.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 let view = winsaveview()
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 call cursor(0, curcol + 1)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 if skip =~ 'synID' && !(has("syntax") && exists("g:syntax_on"))
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 let skip = "0"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 else
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
222 execute "if " .. skip .. "| let skip = '0' | endif"
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 let sp_return = searchpair(ini, mid, fin, flag, skip)
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15735
diff changeset
225 if &selection isnot# 'inclusive' && a:mode == 'v'
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15735
diff changeset
226 " move cursor one pos to the right, because selection is not inclusive
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
227 " add virtualedit=onemore, to make it work even when the match ends the
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
228 " line
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15735
diff changeset
229 if !(col('.') < col('$')-1)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
230 let eolmark=1 " flag to set a mark on eol (since we cannot move there)
18456
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15735
diff changeset
231 endif
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15735
diff changeset
232 norm! l
6d11fc4aa683 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 15735
diff changeset
233 endif
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
234 let final_position = "call cursor(" .. line(".") .. "," .. col(".") .. ")"
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 " Restore cursor position and original screen.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 call winrestview(view)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 normal! m'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 if sp_return > 0
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 execute final_position
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 endif
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
241 if exists('eolmark') && eolmark
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
242 call setpos("''", [0, line('.'), col('$'), 0]) " set mark on the eol
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
243 endif
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
244 return s:CleanUp(restore_options, a:mode, startpos, mid .. '\|' .. fin)
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 endfun
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 " Restore options and do some special handling for Operator-pending mode.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 " The optional argument is the tail of the matching group.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 fun! s:CleanUp(options, mode, startpos, ...)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 if strlen(a:options)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 execute "set" a:options
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 " Open folds, if appropriate.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 if a:mode != "o"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 if &foldopen =~ "percent"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 normal! zv
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 " In Operator-pending mode, we want to include the whole match
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 " (for example, d%).
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 " This is only a problem if we end up moving in the forward direction.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 elseif (a:startpos[0] < line(".")) ||
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 \ (a:startpos[0] == line(".") && a:startpos[1] < col("."))
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 if a:0
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 " Check whether the match is a single character. If not, move to the
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 " end of the match.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 let matchline = getline(".")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 let currcol = col(".")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 let regexp = s:Wholematch(matchline, a:1, currcol-1)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 let endcol = matchend(matchline, regexp)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 if endcol > currcol " This is NOT off by one!
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 call cursor(0, endcol)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 endif " a:0
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 endif " a:mode != "o" && etc.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 return 0
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 endfun
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 " Example (simplified HTML patterns): if
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 " a:groupBR = '<\(\k\+\)>:</\1>'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 " a:prefix = '^.\{3}\('
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 " a:group = '<\(\k\+\)>:</\(\k\+\)>'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 " a:suffix = '\).\{2}$'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 " a:matchline = "123<tag>12" or "123</tag>12"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 " then extract "tag" from a:matchline and return "<tag>:</tag>" .
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 fun! s:InsertRefs(groupBR, prefix, group, suffix, matchline)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
286 if a:matchline !~ a:prefix ..
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
287 \ substitute(a:group, s:notslash .. '\zs:', '\\|', 'g') .. a:suffix
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 return a:group
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 endif
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
290 let i = matchend(a:groupBR, s:notslash .. ':')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 let ini = strpart(a:groupBR, 0, i-1)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 let tailBR = strpart(a:groupBR, i)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 let word = s:Choose(a:group, a:matchline, ":", "", a:prefix, a:suffix,
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 \ a:groupBR)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
295 let i = matchend(word, s:notslash .. ":")
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 let wordBR = strpart(word, i)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 let word = strpart(word, 0, i-1)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 " Now, a:matchline =~ a:prefix . word . a:suffix
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 if wordBR != ini
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 let table = s:Resolve(ini, wordBR, "table")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 else
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 let table = ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 let d = 0
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 while d < 10
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
305 if tailBR =~ s:notslash .. '\\' .. d
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
306 let table = table .. d
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 else
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
308 let table = table .. "-"
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 let d = d + 1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 endwhile
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 let d = 9
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 while d
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 if table[d] != "-"
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
316 let backref = substitute(a:matchline, a:prefix .. word .. a:suffix,
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
317 \ '\' .. table[d], "")
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 " Are there any other characters that should be escaped?
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 let backref = escape(backref, '*,:')
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 execute s:Ref(ini, d, "start", "len")
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
321 let ini = strpart(ini, 0, start) .. backref .. strpart(ini, start+len)
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
322 let tailBR = substitute(tailBR, s:notslash .. '\zs\\' .. d,
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 \ escape(backref, '\\&'), 'g')
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 let d = d-1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 endwhile
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 if exists("b:match_debug")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 if s:do_BR
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 let b:match_table = table
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 let b:match_word = word
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 else
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 let b:match_table = ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 let b:match_word = ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 endif
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
336 return ini .. ":" .. tailBR
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 endfun
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 " Input a comma-separated list of groups with backrefs, such as
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 " a:groups = '\(foo\):end\1,\(bar\):end\1'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 " and return a comma-separated list of groups with backrefs replaced:
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 " return '\(foo\):end\(foo\),\(bar\):end\(bar\)'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 fun! s:ParseWords(groups)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
344 let groups = substitute(a:groups .. ",", s:notslash .. '\zs[,:]*,[,:]*', ',', 'g')
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
345 let groups = substitute(groups, s:notslash .. '\zs:\{2,}', ':', 'g')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 let parsed = ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 while groups =~ '[^,:]'
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
348 let i = matchend(groups, s:notslash .. ':')
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
349 let j = matchend(groups, s:notslash .. ',')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 let ini = strpart(groups, 0, i-1)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
351 let tail = strpart(groups, i, j-i-1) .. ":"
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 let groups = strpart(groups, j)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
353 let parsed = parsed .. ini
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
354 let i = matchend(tail, s:notslash .. ':')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 while i != -1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 " In 'if:else:endif', ini='if' and word='else' and then word='endif'.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 let word = strpart(tail, 0, i-1)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 let tail = strpart(tail, i)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
359 let i = matchend(tail, s:notslash .. ':')
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
360 let parsed = parsed .. ":" .. s:Resolve(ini, word, "word")
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 endwhile " Now, tail has been used up.
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
362 let parsed = parsed .. ","
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 endwhile " groups =~ '[^,:]'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 let parsed = substitute(parsed, ',$', '', '')
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 return parsed
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 endfun
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 " TODO I think this can be simplified and/or made more efficient.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 " TODO What should I do if a:start is out of range?
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 " Return a regexp that matches all of a:string, such that
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 " matchstr(a:string, regexp) represents the match for a:pat that starts
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 " as close to a:start as possible, before being preferred to after, and
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 " ends after a:start .
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 " Usage:
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 " let regexp = s:Wholematch(getline("."), 'foo\|bar', col(".")-1)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 " let i = match(getline("."), regexp)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 " let j = matchend(getline("."), regexp)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 " let match = matchstr(getline("."), regexp)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 fun! s:Wholematch(string, pat, start)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
380 let group = '\%(' .. a:pat .. '\)'
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
381 let prefix = (a:start ? '\(^.*\%<' .. (a:start + 2) .. 'c\)\zs' : '^')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 let len = strlen(a:string)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
383 let suffix = (a:start+1 < len ? '\(\%>' .. (a:start+1) .. 'c.*$\)\@=' : '$')
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
384 if a:string !~ prefix .. group .. suffix
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 let prefix = ''
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 endif
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
387 return prefix .. group .. suffix
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 endfun
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 " No extra arguments: s:Ref(string, d) will
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 " find the d'th occurrence of '\(' and return it, along with everything up
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 " to and including the matching '\)'.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 " One argument: s:Ref(string, d, "start") returns the index of the start
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 " of the d'th '\(' and any other argument returns the length of the group.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 " Two arguments: s:Ref(string, d, "foo", "bar") returns a string to be
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 " executed, having the effect of
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 " :let foo = s:Ref(string, d, "start")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 " :let bar = s:Ref(string, d, "len")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 fun! s:Ref(string, d, ...)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 let len = strlen(a:string)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 if a:d == 0
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 let start = 0
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 else
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 let cnt = a:d
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 let match = a:string
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 while cnt
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 let cnt = cnt - 1
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
408 let index = matchend(match, s:notslash .. '\\(')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 if index == -1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 return ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 let match = strpart(match, index)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 endwhile
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 let start = len - strlen(match)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 if a:0 == 1 && a:1 == "start"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 return start - 2
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 let cnt = 1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 while cnt
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
420 let index = matchend(match, s:notslash .. '\\(\|\\)') - 1
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 if index == -2
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 return ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 " Increment if an open, decrement if a ')':
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 let cnt = cnt + (match[index]=="(" ? 1 : -1) " ')'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 let match = strpart(match, index+1)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 endwhile
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 let start = start - 2
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 let len = len - start - strlen(match)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 if a:0 == 1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 return len
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 elseif a:0 == 2
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
434 return "let " .. a:1 .. "=" .. start .. "| let " .. a:2 .. "=" .. len
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 else
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 return strpart(a:string, start, len)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 endfun
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 " Count the number of disjoint copies of pattern in string.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 " If the pattern is a literal string and contains no '0' or '1' characters
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 " then s:Count(string, pattern, '0', '1') should be faster than
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 " s:Count(string, pattern).
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 fun! s:Count(string, pattern, ...)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 let pat = escape(a:pattern, '\\')
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 if a:0 > 1
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
447 let foo = substitute(a:string, '[^' .. a:pattern .. ']', "a:1", "g")
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 let foo = substitute(a:string, pat, a:2, "g")
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
449 let foo = substitute(foo, '[^' .. a:2 .. ']', "", "g")
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 return strlen(foo)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 let result = 0
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 let foo = a:string
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 let index = matchend(foo, pat)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 while index != -1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 let result = result + 1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 let foo = strpart(foo, index)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 let index = matchend(foo, pat)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 endwhile
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 return result
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 endfun
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 " s:Resolve('\(a\)\(b\)', '\(c\)\2\1\1\2') should return table.word, where
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 " word = '\(c\)\(b\)\(a\)\3\2' and table = '-32-------'. That is, the first
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 " '\1' in target is replaced by '\(a\)' in word, table[1] = 3, and this
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 " indicates that all other instances of '\1' in target are to be replaced
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 " by '\3'. The hard part is dealing with nesting...
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 " Note that ":" is an illegal character for source and target,
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 " unless it is preceded by "\".
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 fun! s:Resolve(source, target, output)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 let word = a:target
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
472 let i = matchend(word, s:notslash .. '\\\d') - 1
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 let table = "----------"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 while i != -2 " There are back references to be replaced.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 let d = word[i]
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 let backref = s:Ref(a:source, d)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 " The idea is to replace '\d' with backref. Before we do this,
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 " replace any \(\) groups in backref with :1, :2, ... if they
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 " correspond to the first, second, ... group already inserted
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 " into backref. Later, replace :1 with \1 and so on. The group
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 " number w+b within backref corresponds to the group number
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 " s within a:source.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 " w = number of '\(' in word before the current one
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 let w = s:Count(
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 \ substitute(strpart(word, 0, i-1), '\\\\', '', 'g'), '\(', '1')
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 let b = 1 " number of the current '\(' in backref
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 let s = d " number of the current '\(' in a:source
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 while b <= s:Count(substitute(backref, '\\\\', '', 'g'), '\(', '1')
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 \ && s < 10
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 if table[s] == "-"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 if w + b < 10
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 " let table[s] = w + b
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
493 let table = strpart(table, 0, s) .. (w+b) .. strpart(table, s+1)
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 let b = b + 1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 let s = s + 1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 else
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 execute s:Ref(backref, b, "start", "len")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 let ref = strpart(backref, start, len)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
500 let backref = strpart(backref, 0, start) .. ":" .. table[s]
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
501 \ .. strpart(backref, start+len)
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 let s = s + s:Count(substitute(ref, '\\\\', '', 'g'), '\(', '1')
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 endwhile
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
505 let word = strpart(word, 0, i-1) .. backref .. strpart(word, i+1)
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
506 let i = matchend(word, s:notslash .. '\\\d') - 1
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 endwhile
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
508 let word = substitute(word, s:notslash .. '\zs:', '\\', 'g')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 if a:output == "table"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 return table
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 elseif a:output == "word"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 return word
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 else
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
514 return table .. word
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 endfun
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 " Assume a:comma = ",". Then the format for a:patterns and a:1 is
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 " a:patterns = "<pat1>,<pat2>,..."
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 " a:1 = "<alt1>,<alt2>,..."
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 " If <patn> is the first pattern that matches a:string then return <patn>
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 " if no optional arguments are given; return <patn>,<altn> if a:1 is given.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 fun! s:Choose(patterns, string, comma, branch, prefix, suffix, ...)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
524 let tail = (a:patterns =~ a:comma .. "$" ? a:patterns : a:patterns .. a:comma)
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
525 let i = matchend(tail, s:notslash .. a:comma)
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 if a:0
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
527 let alttail = (a:1 =~ a:comma .. "$" ? a:1 : a:1 .. a:comma)
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
528 let j = matchend(alttail, s:notslash .. a:comma)
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 let current = strpart(tail, 0, i-1)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 if a:branch == ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 let currpat = current
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 else
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
534 let currpat = substitute(current, s:notslash .. a:branch, '\\|', 'g')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 endif
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
536 while a:string !~ a:prefix .. currpat .. a:suffix
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 let tail = strpart(tail, i)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
538 let i = matchend(tail, s:notslash .. a:comma)
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 if i == -1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 return -1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 let current = strpart(tail, 0, i-1)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 if a:branch == ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 let currpat = current
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 else
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
546 let currpat = substitute(current, s:notslash .. a:branch, '\\|', 'g')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 if a:0
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 let alttail = strpart(alttail, j)
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
550 let j = matchend(alttail, s:notslash .. a:comma)
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 endwhile
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 if a:0
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
554 let current = current .. a:comma .. strpart(alttail, 0, j-1)
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 return current
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 endfun
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 fun! matchit#Match_debug()
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 let b:match_debug = 1 " Save debugging information.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 " pat = all of b:match_words with backrefs parsed
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 amenu &Matchit.&pat :echo b:match_pat<CR>
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 " match = bit of text that is recognized as a match
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 amenu &Matchit.&match :echo b:match_match<CR>
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 " curcol = cursor column of the start of the matching text
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 amenu &Matchit.&curcol :echo b:match_col<CR>
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 " wholeBR = matching group, original version
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 amenu &Matchit.wh&oleBR :echo b:match_wholeBR<CR>
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 " iniBR = 'if' piece, original version
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 amenu &Matchit.ini&BR :echo b:match_iniBR<CR>
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 " ini = 'if' piece, with all backrefs resolved from match
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 amenu &Matchit.&ini :echo b:match_ini<CR>
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 " tail = 'else\|endif' piece, with all backrefs resolved from match
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 amenu &Matchit.&tail :echo b:match_tail<CR>
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 " fin = 'endif' piece, with all backrefs resolved from match
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 amenu &Matchit.&word :echo b:match_word<CR>
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 " '\'.d in ini refers to the same thing as '\'.table[d] in word.
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
578 amenu &Matchit.t&able :echo '0:' .. b:match_table .. ':9'<CR>
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 endfun
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 " Jump to the nearest unmatched "(" or "if" or "<tag>" if a:spflag == "bW"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 " or the nearest unmatched "</tag>" or "endif" or ")" if a:spflag == "W".
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 " Return a "mark" for the original position, so that
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 " let m = MultiMatch("bW", "n") ... call winrestview(m)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 " will return to the original position. If there is a problem, do not
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 " move the cursor and return {}, unless a count is given, in which case
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 " go up or down as many levels as possible and again return {}.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 " TODO This relies on the same patterns as % matching. It might be a good
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 " idea to give it its own matching patterns.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 fun! matchit#MultiMatch(spflag, mode)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 let restore_options = s:RestoreOptions()
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 let startpos = [line("."), col(".")]
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 " save v:count1 variable, might be reset from the restore_cursor command
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 let level = v:count1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 if a:mode == "o" && mode(1) !~# '[vV]'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 exe "norm! v"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 " First step: if not already done, set the script variables
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 " s:do_BR flag for whether there are backrefs
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 " s:pat parsed version of b:match_words
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 " s:all regexp based on s:pat and the default groups
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 " This part is copied and slightly modified from matchit#Match_wrapper().
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 if !exists("b:match_words") || b:match_words == ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 let match_words = ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 " Allow b:match_words = "GetVimMatchWords()" .
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 elseif b:match_words =~ ":"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 let match_words = b:match_words
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 else
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 execute "let match_words =" b:match_words
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 if (match_words != s:last_words) || (&mps != s:last_mps) ||
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 \ exists("b:match_debug")
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
614 let default = escape(&mps, '[$^.*~\\/?]') .. (strlen(&mps) ? "," : "") ..
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 \ '\/\*:\*\/,#\s*if\%(n\=def\)\=:#\s*else\>:#\s*elif\>:#\s*endif\>'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 let s:last_mps = &mps
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
617 let match_words = match_words .. (strlen(match_words) ? "," : "") .. default
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 let s:last_words = match_words
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
619 if match_words !~ s:notslash .. '\\\d'
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 let s:do_BR = 0
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 let s:pat = match_words
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 else
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 let s:do_BR = 1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 let s:pat = s:ParseWords(match_words)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 endif
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
626 let s:all = '\%(' .. substitute(s:pat, '[,:]\+', '\\|', 'g') .. '\)'
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 if exists("b:match_debug")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 let b:match_pat = s:pat
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 " Reconstruct the version with unresolved backrefs.
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
631 let s:patBR = substitute(match_words .. ',',
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
632 \ s:notslash .. '\zs[,:]*,[,:]*', ',', 'g')
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
633 let s:patBR = substitute(s:patBR, s:notslash .. '\zs:\{2,}', ':', 'g')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 " Second step: figure out the patterns for searchpair()
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 " and save the screen, cursor position, and 'ignorecase'.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 " - TODO: A lot of this is copied from matchit#Match_wrapper().
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 " - maybe even more functionality should be split off
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 " - into separate functions!
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
641 let openlist = split(s:pat .. ',', s:notslash .. '\zs:.\{-}' .. s:notslash .. ',')
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
642 let midclolist = split(',' .. s:pat, s:notslash .. '\zs,.\{-}' .. s:notslash .. ':')
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
643 call map(midclolist, {-> split(v:val, s:notslash .. ':')})
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 let closelist = []
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 let middlelist = []
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 call map(midclolist, {i,v -> [extend(closelist, v[-1 : -1]),
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 \ extend(middlelist, v[0 : -2])]})
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
648 call map(openlist, {i,v -> v =~# s:notslash .. '\\|' ? '\%(' .. v .. '\)' : v})
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
649 call map(middlelist, {i,v -> v =~# s:notslash .. '\\|' ? '\%(' .. v .. '\)' : v})
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
650 call map(closelist, {i,v -> v =~# s:notslash .. '\\|' ? '\%(' .. v .. '\)' : v})
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 let open = join(openlist, ',')
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 let middle = join(middlelist, ',')
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 let close = join(closelist, ',')
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 if exists("b:match_skip")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 let skip = b:match_skip
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 elseif exists("b:match_comment") " backwards compatibility and testing!
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
657 let skip = "r:" .. b:match_comment
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 else
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 let skip = 's:comment\|string'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 let skip = s:ParseSkip(skip)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 let view = winsaveview()
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 " Third step: call searchpair().
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 " Replace '\('--but not '\\('--with '\%(' and ',' with '\|'.
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
666 let openpat = substitute(open, '\%(' .. s:notslash .. '\)\@<=\\(', '\\%(', 'g')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 let openpat = substitute(openpat, ',', '\\|', 'g')
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
668 let closepat = substitute(close, '\%(' .. s:notslash .. '\)\@<=\\(', '\\%(', 'g')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 let closepat = substitute(closepat, ',', '\\|', 'g')
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
670 let middlepat = substitute(middle, '\%(' .. s:notslash .. '\)\@<=\\(', '\\%(', 'g')
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 let middlepat = substitute(middlepat, ',', '\\|', 'g')
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 if skip =~ 'synID' && !(has("syntax") && exists("g:syntax_on"))
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 let skip = '0'
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 else
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 try
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
677 execute "if " .. skip .. "| let skip = '0' | endif"
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 catch /^Vim\%((\a\+)\)\=:E363/
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 " We won't find anything, so skip searching, should keep Vim responsive.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 return {}
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 endtry
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 mark '
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 while level
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 if searchpair(openpat, middlepat, closepat, a:spflag, skip) < 1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 call s:CleanUp(restore_options, a:mode, startpos)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 return {}
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 let level = level - 1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 endwhile
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 " Restore options and return a string to restore the original position.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 call s:CleanUp(restore_options, a:mode, startpos)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 return view
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 endfun
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 " Search backwards for "if" or "while" or "<tag>" or ...
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 " and return "endif" or "endwhile" or "</tag>" or ... .
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 " For now, this uses b:match_words and the same script variables
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 " as matchit#Match_wrapper() . Later, it may get its own patterns,
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 " either from a buffer variable or passed as arguments.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 " fun! s:Autocomplete()
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 " echo "autocomplete not yet implemented :-("
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 " if !exists("b:match_words") || b:match_words == ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 " return ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 " end
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 " let startpos = matchit#MultiMatch("bW")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 "
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 " if startpos == ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 " return ""
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 " endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 " " - TODO: figure out whether 'if' or '<tag>' matched, and construct
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 " " - the appropriate closing.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 " let matchline = getline(".")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 " let curcol = col(".") - 1
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 " " - TODO: Change the s:all argument if there is a new set of match pats.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 " let regexp = s:Wholematch(matchline, s:all, curcol)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 " let suf = strlen(matchline) - matchend(matchline, regexp)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 " let prefix = (curcol ? '^.\{' . curcol . '}\%(' : '^\%(')
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 " let suffix = (suf ? '\).\{' . suf . '}$' : '\)$')
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 " " Reconstruct the version with unresolved backrefs.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 " let patBR = substitute(b:match_words.',', '[,:]*,[,:]*', ',', 'g')
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 " let patBR = substitute(patBR, ':\{2,}', ':', "g")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 " " Now, set group and groupBR to the matching group: 'if:endif' or
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 " " 'while:endwhile' or whatever.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 " let group = s:Choose(s:pat, matchline, ",", ":", prefix, suffix, patBR)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 " let i = matchend(group, s:notslash . ",")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 " let groupBR = strpart(group, i)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 " let group = strpart(group, 0, i-1)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 " " Now, matchline =~ prefix . substitute(group,':','\|','g') . suffix
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 " if s:do_BR
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 " let group = s:InsertRefs(groupBR, prefix, group, suffix, matchline)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 " endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 " " let g:group = group
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 "
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 " " - TODO: Construct the closing from group.
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 " let fake = "end" . expand("<cword>")
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 " execute startpos
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 " return fake
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 " endfun
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 " Close all open structures. "Get the heck out of here!"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 " fun! s:Gthhoh()
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 " let close = s:Autocomplete()
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 " while strlen(close)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 " put=close
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 " let close = s:Autocomplete()
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 " endwhile
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 " endfun
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 " Parse special strings as typical skip arguments for searchpair():
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 " s:foo becomes (current syntax item) =~ foo
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 " S:foo becomes (current syntax item) !~ foo
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 " r:foo becomes (line before cursor) =~ foo
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 " R:foo becomes (line before cursor) !~ foo
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 fun! s:ParseSkip(str)
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 let skip = a:str
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 if skip[1] == ":"
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 if skip[0] == "s"
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
760 let skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '" ..
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
761 \ strpart(skip,2) .. "'"
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 elseif skip[0] == "S"
26708
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
763 let skip = "synIDattr(synID(line('.'),col('.'),1),'name') !~? '" ..
f0d7cb510ce3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 19574
diff changeset
764 \ strpart(skip,2) .. "'"
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 elseif skip[0] == "r"
27459
5825405e4e2c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 26708
diff changeset
766 let skip = "strpart(getline('.'),0,col('.'))=~'" .. strpart(skip,2) .. "'"
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 elseif skip[0] == "R"
27459
5825405e4e2c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 26708
diff changeset
768 let skip = "strpart(getline('.'),0,col('.'))!~'" .. strpart(skip,2) .. "'"
15735
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 endif
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 return skip
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 endfun
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 let &cpo = s:save_cpo
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 unlet s:save_cpo
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776
5688ec97294b Add missing matchit file.
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 " vim:sts=2:sw=2:et: