Skip to content

Commit 2f4a591

Browse files
committed
Merge branch 'release/1.0.5'
* release/1.0.5: Bump version Restore visual selection when cancelling F/T motions Create function for setting default highlighting Fix variable name issue Create function for initializing options Use s: instead of <SID>
2 parents 6b8de70 + 7d80932 commit 2f4a591

File tree

2 files changed

+89
-110
lines changed

2 files changed

+89
-110
lines changed

doc/easymotion.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*easymotion.txt* Version 1.0.4.1. Last change: 2011 Mar 28
1+
*easymotion.txt* Version 1.0.5. Last change: 2011 Mar 28
22

33

44
______ __ ___ __ _

plugin/EasyMotion.vim

Lines changed: 88 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,30 @@
1111
let g:EasyMotion_loaded = 1
1212
" }}}
1313
" 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 " }}}
4529

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)
5135

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'])
5538
" }}}
5639
" Default key mapping {{{
5740
if g:EasyMotion_do_mapping
@@ -90,62 +73,41 @@
9073
let s:var_reset = {}
9174
" }}}
9275
" 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)
9778

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
10682

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, '.$^~')
11484

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)
11689

117-
" Check that we have an input char
118-
if empty(char)
119-
return
120-
endif
90+
if empty(char)
91+
return
92+
endif
12193

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
12799

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 " }}}
149111
" }}}
150112
" Helper functions {{{
151113
function! s:Message(message) " {{{
@@ -188,13 +150,30 @@
188150
" Escape key pressed
189151
redraw
190152

191-
call <SID>Message('Cancelled')
153+
call s:Message('Cancelled')
192154

193155
return ''
194156
endif
195157

196158
return nr2char(char)
197159
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
198177
" }}}
199178
" Core functions {{{
200179
function! s:PromptUser(groups) "{{{
@@ -243,23 +222,23 @@
243222
let target_hl_id = matchadd(g:EasyMotion_target_hl, join(hl_coords, '\|'), 1)
244223

245224
" Set lines with markers
246-
call <SID>SetLines(lines_items, 'marker')
225+
call s:SetLines(lines_items, 'marker')
247226

248227
redraw
249228

250229
" Get target/group character
251230
if single_group
252-
call <SID>Prompt('Target character')
231+
call s:Prompt('Target character')
253232
else
254-
call <SID>Prompt('Group character')
233+
call s:Prompt('Group character')
255234
endif
256235

257-
let input_char = <SID>GetChar()
236+
let input_char = s:GetChar()
258237

259238
redraw
260239

261240
" Restore original lines
262-
call <SID>SetLines(lines_items, 'orig')
241+
call s:SetLines(lines_items, 'orig')
263242

264243
" Un-highlight code
265244
call matchdelete(target_hl_id)
@@ -290,10 +269,10 @@
290269

291270
try
292271
" 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)
297276

298277
" Find motion targets
299278
while 1
@@ -337,14 +316,14 @@
337316
" }}}
338317
" Too many groups; only display the first ones {{{
339318
if len(groups) > groups_len
340-
call <SID>Message('Only displaying the first matches')
319+
call s:Message('Only displaying the first matches')
341320

342321
let groups = groups[0 : groups_len - 1]
343322
endif
344323
" }}}
345324

346325
" Shade inactive source
347-
if g:EasyMotion_shade
326+
if g:EasyMotion_do_shade
348327
let shade_hl_pos = '\%' . orig_pos[0] . 'l\%'. orig_pos[1] .'c'
349328

350329
if a:direction == 1
@@ -359,7 +338,7 @@
359338
endif
360339

361340
" Prompt user for target group/character
362-
let coords = <SID>PromptUser(groups)
341+
let coords = s:PromptUser(groups)
363342

364343
if ! empty(a:visualmode)
365344
" Store original marks
@@ -381,12 +360,12 @@
381360
call setpos('.', [0, coords[0], coords[1]])
382361
endif
383362

384-
call <SID>Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']')
363+
call s:Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']')
385364
catch /.*/
386365
redraw
387366

388367
" Show exception message
389-
call <SID>Message(v:exception)
368+
call s:Message(v:exception)
390369

391370
" Restore cursor position/selection
392371
if ! empty(a:visualmode)
@@ -398,15 +377,15 @@
398377
redraw
399378

400379
" Remove shading
401-
if g:EasyMotion_shade && exists('shade_hl_id')
380+
if g:EasyMotion_do_shade && exists('shade_hl_id')
402381
call matchdelete(shade_hl_id)
403382
endif
404383

405384
" 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')
410389
endtry
411390
endfunction " }}}
412391
" }}}

0 commit comments

Comments
 (0)