comparison runtime/plugin/matchparen.vim @ 1556:1c597397f006 v7.1.269

updated for version 7.1-269
author vimboss
date Sun, 09 Mar 2008 15:45:53 +0000
parents 29c09fa57168
children 7bc41231fbc7
comparison
equal deleted inserted replaced
1555:71db8539b8c4 1556:1c597397f006
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: 2008 Jan 06 3 " Last Change: 2008 Feb 27
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.
32 3match none 32 3match none
33 let w:paren_hl_on = 0 33 let w:paren_hl_on = 0
34 endif 34 endif
35 35
36 " Avoid that we remove the popup menu. 36 " Avoid that we remove the popup menu.
37 if pumvisible() 37 " Return when there are no colors (looks like the cursor jumps).
38 if pumvisible() || (&t_Co < 8 && !has("gui_running"))
38 return 39 return
39 endif 40 endif
40 41
41 " Get the character under the cursor and check if it's in 'matchpairs'. 42 " Get the character under the cursor and check if it's in 'matchpairs'.
42 let c_lnum = line('.') 43 let c_lnum = line('.')
58 return 59 return
59 endif 60 endif
60 endif 61 endif
61 62
62 " Figure out the arguments for searchpairpos(). 63 " Figure out the arguments for searchpairpos().
63 " Restrict the search to visible lines with "stopline".
64 " And avoid searching very far (e.g., for closed folds and long lines)
65 " The "viewable" variables give a range in which we can scroll while keeping
66 " the cursor at the same position
67 " adjustedScrolloff accounts for very large numbers of scrolloff
68 let adjustedScrolloff = min([&scrolloff, (line('w$') - line('w0')) / 2])
69 let bottom_viewable = min([line('$'), c_lnum + &lines - adjustedScrolloff - 2])
70 let top_viewable = max([1, c_lnum-&lines+adjustedScrolloff + 2])
71 " one of these stoplines will be adjusted below, but the current values are
72 " minimal boundaries within the current window
73 let stoplinebottom = line('w$')
74 let stoplinetop = line('w0')
75 if i % 2 == 0 64 if i % 2 == 0
76 let s_flags = 'nW' 65 let s_flags = 'nW'
77 let c2 = plist[i + 1] 66 let c2 = plist[i + 1]
78 if has("byte_offset") && has("syntax_items") && &smc > 0
79 let stopbyte = min([line2byte("$"), line2byte(".") + col(".") + &smc * 2])
80 let stopline = min([bottom_viewable, byte2line(stopbyte)])
81 else
82 let stopline = min([bottom_viewable, c_lnum + 100])
83 endif
84 let stoplinebottom = stopline
85 else 67 else
86 let s_flags = 'nbW' 68 let s_flags = 'nbW'
87 let c2 = c 69 let c2 = c
88 let c = plist[i - 1] 70 let c = plist[i - 1]
89 if has("byte_offset") && has("syntax_items") && &smc > 0
90 let stopbyte = max([1, line2byte(".") + col(".") - &smc * 2])
91 let stopline = max([top_viewable, byte2line(stopbyte)])
92 else
93 let stopline = max([top_viewable, c_lnum - 100])
94 endif
95 let stoplinetop = stopline
96 endif 71 endif
97 if c == '[' 72 if c == '['
98 let c = '\[' 73 let c = '\['
99 let c2 = '\]' 74 let c2 = '\]'
100 endif 75 endif
109 " When not in a string or comment ignore matches inside them. 84 " When not in a string or comment ignore matches inside them.
110 let s_skip ='synIDattr(synID(line("."), col("."), 0), "name") ' . 85 let s_skip ='synIDattr(synID(line("."), col("."), 0), "name") ' .
111 \ '=~? "string\\|character\\|singlequote\\|comment"' 86 \ '=~? "string\\|character\\|singlequote\\|comment"'
112 execute 'if' s_skip '| let s_skip = 0 | endif' 87 execute 'if' s_skip '| let s_skip = 0 | endif'
113 88
89 " Limit the search to lines visible in the window.
90 let stoplinebottom = line('w$')
91 let stoplinetop = line('w0')
92 if i % 2 == 0
93 let stopline = stoplinebottom
94 else
95 let stopline = stoplinetop
96 endif
97
114 try 98 try
115 " Limit the search time to 500 msec to avoid a hang on very long lines. 99 " Limit the search time to 300 msec to avoid a hang on very long lines.
116 let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline, 500) 100 " This fails when a timeout is not supported.
101 let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline, 300)
117 catch /E118/ 102 catch /E118/
103 " Can't use the timeout, restrict the stopline a bit more to avoid taking
104 " a long time on closed folds and long lines.
105 " The "viewable" variables give a range in which we can scroll while
106 " keeping the cursor at the same position.
107 " adjustedScrolloff accounts for very large numbers of scrolloff.
108 let adjustedScrolloff = min([&scrolloff, (line('w$') - line('w0')) / 2])
109 let bottom_viewable = min([line('$'), c_lnum + &lines - adjustedScrolloff - 2])
110 let top_viewable = max([1, c_lnum-&lines+adjustedScrolloff + 2])
111 " one of these stoplines will be adjusted below, but the current values are
112 " minimal boundaries within the current window
113 if i % 2 == 0
114 if has("byte_offset") && has("syntax_items") && &smc > 0
115 let stopbyte = min([line2byte("$"), line2byte(".") + col(".") + &smc * 2])
116 let stopline = min([bottom_viewable, byte2line(stopbyte)])
117 else
118 let stopline = min([bottom_viewable, c_lnum + 100])
119 endif
120 let stoplinebottom = stopline
121 else
122 if has("byte_offset") && has("syntax_items") && &smc > 0
123 let stopbyte = max([1, line2byte(".") + col(".") - &smc * 2])
124 let stopline = max([top_viewable, byte2line(stopbyte)])
125 else
126 let stopline = max([top_viewable, c_lnum - 100])
127 endif
128 let stoplinetop = stopline
129 endif
118 let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline) 130 let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline)
119 endtry 131 endtry
120 132
121 if before > 0 133 if before > 0
122 call winrestview(save_cursor) 134 call winrestview(save_cursor)