comparison runtime/plugin/matchparen.vim @ 819:23f82b5d2814 v7.0c10

updated for version 7.0c10
author vimboss
date Wed, 05 Apr 2006 20:41:53 +0000
parents 1f929f3ca806
children 0fe7765dcb8e
comparison
equal deleted inserted replaced
818:1f929f3ca806 819:23f82b5d2814
1 " Vim plugin for showing matching parens 1 " Vim plugin for showing matching parens
2 " Maintainer: Bram Moolenaar <Bram@vim.org> 2 " Maintainer: Bram Moolenaar <Bram@vim.org>
3 " Last Change: 2006 Mar 29 3 " Last Change: 2006 Apr 04
4 4
5 " Exit quickly when: 5 " Exit quickly when:
6 " - this plugin was already loaded (or disabled) 6 " - this plugin was already loaded (or disabled)
7 " - when 'compatible' is set 7 " - when 'compatible' is set
8 " - the "CursorMoved" autocmd event is not availble. 8 " - the "CursorMoved" autocmd event is not availble.
14 augroup matchparen 14 augroup matchparen
15 " Replace all matchparen autocommands 15 " Replace all matchparen autocommands
16 autocmd! CursorMoved,CursorMovedI * call s:Highlight_Matching_Pair() 16 autocmd! CursorMoved,CursorMovedI * call s:Highlight_Matching_Pair()
17 augroup END 17 augroup END
18 18
19 let s:paren_hl_on = 0
20
21 " Skip the rest if it was already done. 19 " Skip the rest if it was already done.
22 if exists("*s:Highlight_Matching_Pair") 20 if exists("*s:Highlight_Matching_Pair")
23 finish 21 finish
24 endif 22 endif
25 23
28 26
29 " The function that is invoked (very often) to define a ":match" highlighting 27 " The function that is invoked (very often) to define a ":match" highlighting
30 " for any matching paren. 28 " for any matching paren.
31 function! s:Highlight_Matching_Pair() 29 function! s:Highlight_Matching_Pair()
32 " Remove any previous match. 30 " Remove any previous match.
33 if s:paren_hl_on 31 if exists('w:paren_hl_on') && w:paren_hl_on
34 3match none 32 3match none
35 let s:paren_hl_on = 0 33 let w:paren_hl_on = 0
36 endif 34 endif
37 35
38 " Avoid that we remove the popup menu. 36 " Avoid that we remove the popup menu.
39 if pumvisible() 37 if pumvisible()
40 return 38 return
61 endif 59 endif
62 endif 60 endif
63 61
64 " Figure out the arguments for searchpairpos(). 62 " Figure out the arguments for searchpairpos().
65 " Restrict the search to visible lines with "stopline". 63 " Restrict the search to visible lines with "stopline".
66 " And avoid searching very far (e.g., for closed folds) 64 " And avoid searching very far (e.g., for closed folds and long lines)
67 if i % 2 == 0 65 if i % 2 == 0
68 let s_flags = 'nW' 66 let s_flags = 'nW'
69 let c2 = plist[i + 1] 67 let c2 = plist[i + 1]
70 let stopline = line('w$') 68 if has("byte_offset") && has("syntax_items") && &smc > 0
71 if stopline > c_lnum + 100 69 let stopbyte = min([line2byte("$"), line2byte(".") + col(".") + &smc * 2])
72 let stopline = c_lnu + 100 70 let stopline = min([line('w$'), byte2line(stopbyte)])
71 else
72 let stopline = min([line('w$'), c_lnum + 100])
73 endif 73 endif
74 else 74 else
75 let s_flags = 'nbW' 75 let s_flags = 'nbW'
76 let c2 = c 76 let c2 = c
77 let c = plist[i - 1] 77 let c = plist[i - 1]
78 let stopline = line('w0') 78 if has("byte_offset") && has("syntax_items") && &smc > 0
79 if stopline < c_lnum - 100 79 let stopbyte = max([1, line2byte(".") + col(".") - &smc * 2])
80 let stopline = c_lnu - 100 80 let stopline = max([line('w0'), byte2line(stopbyte)])
81 else
82 let stopline = max([line('w0'), c_lnum - 100])
81 endif 83 endif
82 endif 84 endif
83 if c == '[' 85 if c == '['
84 let c = '\[' 86 let c = '\['
85 let c2 = '\]' 87 let c2 = '\]'
86 endif 88 endif
87 89
88 " When not in a string or comment ignore matches inside them. 90 " When not in a string or comment ignore matches inside them.
89 let s_skip ='synIDattr(synID(c_lnum, c_col - before, 0), "name") ' . 91 let s_skip ='synIDattr(synID(line("."), col(".") - before, 0), "name") ' .
90 \ '=~? "string\\|comment"' 92 \ '=~? "string\\|comment"'
91 execute 'if' s_skip '| let s_skip = 0 | endif' 93 execute 'if' s_skip '| let s_skip = 0 | endif'
92 94
93 " Find the match. When it was just before the cursor move it there for a 95 " Find the match. When it was just before the cursor move it there for a
94 " moment. 96 " moment.
103 105
104 " If a match is found setup match highlighting. 106 " If a match is found setup match highlighting.
105 if m_lnum > 0 && m_lnum >= line('w0') && m_lnum <= line('w$') 107 if m_lnum > 0 && m_lnum >= line('w0') && m_lnum <= line('w$')
106 exe '3match MatchParen /\(\%' . c_lnum . 'l\%' . (c_col - before) . 108 exe '3match MatchParen /\(\%' . c_lnum . 'l\%' . (c_col - before) .
107 \ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/' 109 \ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/'
108 let s:paren_hl_on = 1 110 let w:paren_hl_on = 1
109 endif 111 endif
110 endfunction 112 endfunction
111 113
112 " Define commands that will disable and enable the plugin. 114 " Define commands that will disable and enable the plugin.
113 command! NoMatchParen 3match none | unlet! g:loaded_matchparen | au! matchparen 115 command! NoMatchParen 3match none | unlet! g:loaded_matchparen | au! matchparen