|
11 | 11 | let g:EasyMotion_loaded = 1
|
12 | 12 | " }}}
|
13 | 13 | " Default configuration {{{
|
14 |
| - if ! exists('g:EasyMotion_keys') " {{{ |
15 |
| - let g:EasyMotion_keys = '' |
16 |
| - let g:EasyMotion_keys .= 'abcdefghijklmnopqrstuvwxyz' |
17 |
| - let g:EasyMotion_keys .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
18 |
| - endif " }}} |
19 |
| - if ! exists('g:EasyMotion_target_hl') " {{{ |
20 |
| - let g:EasyMotion_target_hl = 'EasyMotionTarget' |
21 |
| - endif " }}} |
22 |
| - if ! exists('g:EasyMotion_shade_hl') " {{{ |
23 |
| - let g:EasyMotion_shade_hl = 'EasyMotionShade' |
24 |
| - endif " }}} |
25 |
| - if ! exists('g:EasyMotion_do_shade') " {{{ |
26 |
| - let g:EasyMotion_shade = 1 |
27 |
| - endif " }}} |
28 |
| - if ! exists('g:EasyMotion_do_mapping') " {{{ |
29 |
| - let g:EasyMotion_do_mapping = 1 |
30 |
| - endif " }}} |
31 |
| - " Create default highlighting {{{ |
32 |
| - if ! hlexists(g:EasyMotion_target_hl) " {{{ |
33 |
| - let hl = 'guibg=none guifg=#ff0000 gui=bold ' |
34 |
| - |
35 |
| - if &t_Co == 256 |
36 |
| - let hl .= 'ctermbg=none ctermfg=196 cterm=bold ' |
37 |
| - else |
38 |
| - let hl .= 'ctermbg=none ctermfg=red cterm=bold ' |
39 |
| - endif |
40 |
| - |
41 |
| - execute 'hi ' . g:EasyMotion_target_hl . ' ' . hl |
42 |
| - endif " }}} |
43 |
| - if ! hlexists(g:EasyMotion_shade_hl) " {{{ |
44 |
| - let hl = 'guibg=none guifg=#585858 gui=none ' |
| 14 | + function! s:InitOption(option, default) " {{{ |
| 15 | + if ! exists('g:EasyMotion_' . a:option) |
| 16 | + exec 'let g:EasyMotion_' . a:option . ' = ' . string(a:default) |
| 17 | + endif |
| 18 | + endfunction " }}} |
| 19 | + function! s:InitHL(group, gui, cterm256, cterm) " {{{ |
| 20 | + if ! hlexists(a:group) |
| 21 | + let guihl = printf('guibg=%s guifg=#%s gui=%s', a:gui[0], a:gui[1], a:gui[2]) |
| 22 | + let ctermhl = &t_Co == 256 |
| 23 | + \ ? printf('ctermbg=%s ctermfg=%s cterm=%s', a:cterm256[0], a:cterm256[1], a:cterm256[2]) |
| 24 | + \ : printf('ctermbg=%s ctermfg=%s cterm=%s', a:cterm[0], a:cterm[1], a:cterm[2]) |
| 25 | + |
| 26 | + execute printf('hi %s %s %s', a:group, guihl, ctermhl) |
| 27 | + endif |
| 28 | + endfunction " }}} |
45 | 29 |
|
46 |
| - if &t_Co == 256 |
47 |
| - let hl .= 'ctermbg=none ctermfg=240 cterm=none ' |
48 |
| - else |
49 |
| - let hl .= 'ctermbg=none ctermfg=darkgrey cterm=none ' |
50 |
| - endif |
| 30 | + call s:InitOption('keys', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') |
| 31 | + call s:InitOption('target_hl', 'EasyMotionTarget') |
| 32 | + call s:InitOption('shade_hl', 'EasyMotionShade') |
| 33 | + call s:InitOption('do_shade', 1) |
| 34 | + call s:InitOption('do_mapping', 1) |
51 | 35 |
|
52 |
| - execute 'hi ' . g:EasyMotion_shade_hl . ' ' . hl |
53 |
| - endif " }}} |
54 |
| - " }}} |
| 36 | + call s:InitHL(g:EasyMotion_target_hl, ['none', 'ff0000', 'bold'], ['none', '196', 'bold'], ['none', 'red', 'bold']) |
| 37 | + call s:InitHL(g:EasyMotion_shade_hl, ['none', '585858', 'none'], ['none', '240', 'none'], ['none', 'darkgrey', 'none']) |
55 | 38 | " }}}
|
56 | 39 | " Default key mapping {{{
|
57 | 40 | if g:EasyMotion_do_mapping
|
|
90 | 73 | let s:var_reset = {}
|
91 | 74 | " }}}
|
92 | 75 | " Motion functions {{{
|
93 |
| - " F key motions {{{ |
94 |
| - " Go to {char} to the right or the left |
95 |
| - function! EasyMotionF(visualmode, direction) |
96 |
| - call <SID>Prompt('Search for character') |
| 76 | + function! EasyMotionF(visualmode, direction) " {{{ |
| 77 | + let char = s:GetSearchChar(a:visualmode) |
97 | 78 |
|
98 |
| - let char = <SID>GetChar() |
99 |
| - |
100 |
| - " Check that we have an input char |
101 |
| - if empty(char) |
102 |
| - return |
103 |
| - endif |
104 |
| - |
105 |
| - let re = '\C' . escape(char, '.$^~') |
| 79 | + if empty(char) |
| 80 | + return |
| 81 | + endif |
106 | 82 |
|
107 |
| - call <SID>EasyMotion(re, a:direction, a:visualmode ? visualmode() : '') |
108 |
| - endfunction |
109 |
| - " }}} |
110 |
| - " T key motions {{{ |
111 |
| - " Go to {char} to the right (before) or the left (after) |
112 |
| - function! EasyMotionT(visualmode, direction) |
113 |
| - call <SID>Prompt('Search for character') |
| 83 | + let re = '\C' . escape(char, '.$^~') |
114 | 84 |
|
115 |
| - let char = <SID>GetChar() |
| 85 | + call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '') |
| 86 | + endfunction " }}} |
| 87 | + function! EasyMotionT(visualmode, direction) " {{{ |
| 88 | + let char = s:GetSearchChar(a:visualmode) |
116 | 89 |
|
117 |
| - " Check that we have an input char |
118 |
| - if empty(char) |
119 |
| - return |
120 |
| - endif |
| 90 | + if empty(char) |
| 91 | + return |
| 92 | + endif |
121 | 93 |
|
122 |
| - if a:direction == 1 |
123 |
| - let re = '\C' . escape(char, '.$^~') . '\zs.' |
124 |
| - else |
125 |
| - let re = '\C.' . escape(char, '.$^~') |
126 |
| - endif |
| 94 | + if a:direction == 1 |
| 95 | + let re = '\C' . escape(char, '.$^~') . '\zs.' |
| 96 | + else |
| 97 | + let re = '\C.' . escape(char, '.$^~') |
| 98 | + endif |
127 | 99 |
|
128 |
| - call <SID>EasyMotion(re, a:direction, a:visualmode ? visualmode() : '') |
129 |
| - endfunction |
130 |
| - " }}} |
131 |
| - " W key motions {{{ |
132 |
| - " Beginning of word forward |
133 |
| - function! EasyMotionW(visualmode) |
134 |
| - call <SID>EasyMotion('\<.', 0, a:visualmode ? visualmode() : '') |
135 |
| - endfunction |
136 |
| - " }}} |
137 |
| - " E key motions {{{ |
138 |
| - " End of word forward |
139 |
| - function! EasyMotionE(visualmode) |
140 |
| - call <SID>EasyMotion('.\>', 0, a:visualmode ? visualmode() : '') |
141 |
| - endfunction |
142 |
| - " }}} |
143 |
| - " B key motions {{{ |
144 |
| - " Beginning of word backward |
145 |
| - function! EasyMotionB(visualmode) |
146 |
| - call <SID>EasyMotion('\<.', 1, a:visualmode ? visualmode() : '') |
147 |
| - endfunction |
148 |
| - " }}} |
| 100 | + call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '') |
| 101 | + endfunction " }}} |
| 102 | + function! EasyMotionW(visualmode) " {{{ |
| 103 | + call s:EasyMotion('\<.', 0, a:visualmode ? visualmode() : '') |
| 104 | + endfunction " }}} |
| 105 | + function! EasyMotionE(visualmode) " {{{ |
| 106 | + call s:EasyMotion('.\>', 0, a:visualmode ? visualmode() : '') |
| 107 | + endfunction " }}} |
| 108 | + function! EasyMotionB(visualmode) " {{{ |
| 109 | + call s:EasyMotion('\<.', 1, a:visualmode ? visualmode() : '') |
| 110 | + endfunction " }}} |
149 | 111 | " }}}
|
150 | 112 | " Helper functions {{{
|
151 | 113 | function! s:Message(message) " {{{
|
|
188 | 150 | " Escape key pressed
|
189 | 151 | redraw
|
190 | 152 |
|
191 |
| - call <SID>Message('Cancelled') |
| 153 | + call s:Message('Cancelled') |
192 | 154 |
|
193 | 155 | return ''
|
194 | 156 | endif
|
195 | 157 |
|
196 | 158 | return nr2char(char)
|
197 | 159 | endfunction " }}}
|
| 160 | + function! s:GetSearchChar(visualmode) |
| 161 | + call s:Prompt('Search for character') |
| 162 | + |
| 163 | + let char = s:GetChar() |
| 164 | + |
| 165 | + " Check that we have an input char |
| 166 | + if empty(char) |
| 167 | + " Restore selection |
| 168 | + if ! empty(a:visualmode) |
| 169 | + silent exec 'normal! gv' |
| 170 | + endif |
| 171 | + |
| 172 | + return '' |
| 173 | + endif |
| 174 | + |
| 175 | + return char |
| 176 | + endfunction |
198 | 177 | " }}}
|
199 | 178 | " Core functions {{{
|
200 | 179 | function! s:PromptUser(groups) "{{{
|
|
243 | 222 | let target_hl_id = matchadd(g:EasyMotion_target_hl, join(hl_coords, '\|'), 1)
|
244 | 223 |
|
245 | 224 | " Set lines with markers
|
246 |
| - call <SID>SetLines(lines_items, 'marker') |
| 225 | + call s:SetLines(lines_items, 'marker') |
247 | 226 |
|
248 | 227 | redraw
|
249 | 228 |
|
250 | 229 | " Get target/group character
|
251 | 230 | if single_group
|
252 |
| - call <SID>Prompt('Target character') |
| 231 | + call s:Prompt('Target character') |
253 | 232 | else
|
254 |
| - call <SID>Prompt('Group character') |
| 233 | + call s:Prompt('Group character') |
255 | 234 | endif
|
256 | 235 |
|
257 |
| - let input_char = <SID>GetChar() |
| 236 | + let input_char = s:GetChar() |
258 | 237 |
|
259 | 238 | redraw
|
260 | 239 |
|
261 | 240 | " Restore original lines
|
262 |
| - call <SID>SetLines(lines_items, 'orig') |
| 241 | + call s:SetLines(lines_items, 'orig') |
263 | 242 |
|
264 | 243 | " Un-highlight code
|
265 | 244 | call matchdelete(target_hl_id)
|
|
290 | 269 |
|
291 | 270 | try
|
292 | 271 | " Reset properties
|
293 |
| - call <SID>VarReset('&scrolloff', 0) |
294 |
| - call <SID>VarReset('&modified', 0) |
295 |
| - call <SID>VarReset('&modifiable', 1) |
296 |
| - call <SID>VarReset('&readonly', 0) |
| 272 | + call s:VarReset('&scrolloff', 0) |
| 273 | + call s:VarReset('&modified', 0) |
| 274 | + call s:VarReset('&modifiable', 1) |
| 275 | + call s:VarReset('&readonly', 0) |
297 | 276 |
|
298 | 277 | " Find motion targets
|
299 | 278 | while 1
|
|
337 | 316 | " }}}
|
338 | 317 | " Too many groups; only display the first ones {{{
|
339 | 318 | if len(groups) > groups_len
|
340 |
| - call <SID>Message('Only displaying the first matches') |
| 319 | + call s:Message('Only displaying the first matches') |
341 | 320 |
|
342 | 321 | let groups = groups[0 : groups_len - 1]
|
343 | 322 | endif
|
344 | 323 | " }}}
|
345 | 324 |
|
346 | 325 | " Shade inactive source
|
347 |
| - if g:EasyMotion_shade |
| 326 | + if g:EasyMotion_do_shade |
348 | 327 | let shade_hl_pos = '\%' . orig_pos[0] . 'l\%'. orig_pos[1] .'c'
|
349 | 328 |
|
350 | 329 | if a:direction == 1
|
|
359 | 338 | endif
|
360 | 339 |
|
361 | 340 | " Prompt user for target group/character
|
362 |
| - let coords = <SID>PromptUser(groups) |
| 341 | + let coords = s:PromptUser(groups) |
363 | 342 |
|
364 | 343 | if ! empty(a:visualmode)
|
365 | 344 | " Store original marks
|
|
381 | 360 | call setpos('.', [0, coords[0], coords[1]])
|
382 | 361 | endif
|
383 | 362 |
|
384 |
| - call <SID>Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']') |
| 363 | + call s:Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']') |
385 | 364 | catch /.*/
|
386 | 365 | redraw
|
387 | 366 |
|
388 | 367 | " Show exception message
|
389 |
| - call <SID>Message(v:exception) |
| 368 | + call s:Message(v:exception) |
390 | 369 |
|
391 | 370 | " Restore cursor position/selection
|
392 | 371 | if ! empty(a:visualmode)
|
|
398 | 377 | redraw
|
399 | 378 |
|
400 | 379 | " Remove shading
|
401 |
| - if g:EasyMotion_shade && exists('shade_hl_id') |
| 380 | + if g:EasyMotion_do_shade && exists('shade_hl_id') |
402 | 381 | call matchdelete(shade_hl_id)
|
403 | 382 | endif
|
404 | 383 |
|
405 | 384 | " Restore properties
|
406 |
| - call <SID>VarReset('&scrolloff') |
407 |
| - call <SID>VarReset('&modified') |
408 |
| - call <SID>VarReset('&modifiable') |
409 |
| - call <SID>VarReset('&readonly') |
| 385 | + call s:VarReset('&scrolloff') |
| 386 | + call s:VarReset('&modified') |
| 387 | + call s:VarReset('&modifiable') |
| 388 | + call s:VarReset('&readonly') |
410 | 389 | endtry
|
411 | 390 | endfunction " }}}
|
412 | 391 | " }}}
|
0 commit comments