Merge branch 'release/1.0.3'

* release/1.0.3:
  Update version
  Wrap the main function in a try..catch..finally loop
  Create function for resetting/restoring variables
  Store and restore scrolloff value
This commit is contained in:
Kim Silkebækken 2011-03-28 17:51:14 +02:00
commit f2de1ee8fe
2 changed files with 115 additions and 117 deletions

View File

@ -1,4 +1,4 @@
*easymotion.txt* Version 1.0.2.1. Last change: 2011 Mar 28 *easymotion.txt* Version 1.0.3. Last change: 2011 Mar 28
______ __ ___ __ _ ______ __ ___ __ _

View File

@ -66,6 +66,8 @@
let s:key_to_index[i] = index let s:key_to_index[i] = index
let index += 1 let index += 1
endfor endfor
let s:var_reset = {}
" }}} " }}}
" Motion functions {{{ " Motion functions {{{
" F key motions {{{ " F key motions {{{
@ -124,6 +126,20 @@
echo a:message . ': ' echo a:message . ': '
echohl None echohl None
endfunction " }}} endfunction " }}}
function! s:VarReset(var, ...) " {{{
if a:0 == 0 && has_key(s:var_reset, a:var)
" Reset var to original value
call setbufvar(bufname(0), a:var, s:var_reset[a:var])
elseif a:0 == 1
let new_value = a:0 == 1 ? a:1 : ''
" Store original value
let s:var_reset[a:var] = getbufvar(bufname(0), a:var)
" Set new var value
call setbufvar(bufname(0), a:var, new_value)
endif
endfunction " }}}
" }}} " }}}
" Core functions {{{ " Core functions {{{
function! s:PromptUser(groups) "{{{ function! s:PromptUser(groups) "{{{
@ -167,11 +183,6 @@
let lines_items = items(lines) let lines_items = items(lines)
" }}} " }}}
" Store original buffer properties {{{
let modified = &modified
let modifiable = &modifiable
let readonly = &readonly
" }}}
let input_char = '' let input_char = ''
@ -179,16 +190,6 @@
" Highlight source " Highlight source
let target_hl_id = matchadd(g:EasyMotion_target_hl, join(hl_coords, '\|'), 1) let target_hl_id = matchadd(g:EasyMotion_target_hl, join(hl_coords, '\|'), 1)
" Make sure we can change the buffer {{{
if modifiable == 0
silent setl modifiable
endif
if readonly == 1
silent setl noreadonly
endif
" }}}
" Set lines with markers " Set lines with markers
for [line_num, line] in lines_items for [line_num, line] in lines_items
try try
@ -226,20 +227,6 @@
redraw redraw
" Restore original properties {{{
if modified == 0
silent setl nomodified
endif
if modifiable == 0
silent setl nomodifiable
endif
if readonly == 1
silent setl readonly
endif
" }}}
" Check if the input char is valid " Check if the input char is valid
if ! has_key(s:key_to_index, input_char) || s:key_to_index[input_char] >= targets_len if ! has_key(s:key_to_index, input_char) || s:key_to_index[input_char] >= targets_len
" Invalid input char " Invalid input char
@ -260,6 +247,13 @@
let targets = [] let targets = []
let visualmode = a:0 > 0 ? a:1 : '' let visualmode = a:0 > 0 ? a:1 : ''
try
" Reset properties
call <SID>VarReset('&scrolloff', 0)
call <SID>VarReset('&modified', 0)
call <SID>VarReset('&modifiable', 1)
call <SID>VarReset('&readonly', 0)
" Find motion targets " Find motion targets
while 1 while 1
let search_direction = (a:direction == 1 ? 'b' : '') let search_direction = (a:direction == 1 ? 'b' : '')
@ -284,14 +278,7 @@
let groups_len = len(s:index_to_key) let groups_len = len(s:index_to_key)
if targets_len == 0 if targets_len == 0
redraw throw 'No matches'
call <SID>Message('No matches')
" Restore cursor position
call setpos('.', [0, orig_pos[0], orig_pos[1]])
return
endif endif
" Restore cursor position " Restore cursor position
@ -339,17 +326,7 @@
endif endif
if len(coords) != 2 if len(coords) != 2
" Cancelled by user throw 'Cancelled'
call <SID>Message('Operation cancelled')
" Restore cursor position/selection
if ! empty(visualmode)
silent exec 'normal! `<' . visualmode . '`>'
else
call setpos('.', [0, orig_pos[0], orig_pos[1]])
endif
return
else else
if ! empty(visualmode) if ! empty(visualmode)
" Store original marks " Store original marks
@ -373,5 +350,26 @@
call <SID>Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']') call <SID>Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']')
endif endif
catch /.*/
redraw
" Show exception message
call <SID>Message(v:exception)
" Restore cursor position/selection
if ! empty(visualmode)
silent exec 'normal! `<' . visualmode . '`>'
else
call setpos('.', [0, orig_pos[0], orig_pos[1]])
endif
finally
redraw
" Restore properties
call <SID>VarReset('&scrolloff')
call <SID>VarReset('&modified')
call <SID>VarReset('&modifiable')
call <SID>VarReset('&readonly')
endtry
endfunction " }}} endfunction " }}}
" }}} " }}}