annotate runtime/pack/dist/opt/matchit/plugin/matchit.vim @ 9975:03fa8a51e9dc

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