Handle scrolloff option when n-key motion

close #110
This commit is contained in:
haya14busa 2014-02-16 19:45:32 +09:00
parent 46606a9cc1
commit 215163c1b1
3 changed files with 45 additions and 39 deletions

View File

@ -3,7 +3,7 @@
" Author: Kim Silkebækken <kim.silkebaekken+vim@gmail.com> " Author: Kim Silkebækken <kim.silkebaekken+vim@gmail.com>
" haya14busa <hayabusa1419@gmail.com> " haya14busa <hayabusa1419@gmail.com>
" Source: https://github.com/Lokaltog/vim-easymotion " Source: https://github.com/Lokaltog/vim-easymotion
" Last Change: 16 Feb 2014. " Last Change: 21 Feb 2014.
"============================================================================= "=============================================================================
" Saving 'cpoptions' {{{ " Saving 'cpoptions' {{{
scriptencoding utf-8 scriptencoding utf-8
@ -325,44 +325,25 @@ function! s:Prompt(message) " {{{
echohl None echohl None
endfunction " }}} endfunction " }}}
" -- Save & Restore values --------------- " -- Save & Restore values ---------------
function! s:VarReset(var, ...) " {{{
if ! exists('s:var_reset')
let s:var_reset = {}
endif
if a:0 == 0 && has_key(s:var_reset, a:var)
" Reset var to original value
" setbufbar( or bufname): '' or '%' can be used for the current buffer
call setbufvar("", a:var, s:var_reset[a:var])
elseif a:0 == 1
" Save original value and set new var value
let new_value = a:0 == 1 ? a:1 : ''
" Store original value
let s:var_reset[a:var] = getbufvar("", a:var)
" Set new var value
call setbufvar("", a:var, new_value)
endif
endfunction " }}}
function! s:SaveValue() "{{{ function! s:SaveValue() "{{{
call s:VarReset('&scrolloff', 0) if ! s:current.is_search
call s:VarReset('&modified', 0) call EasyMotion#helper#VarReset('&scrolloff', 0)
call s:VarReset('&modifiable', 1) endif
call s:VarReset('&readonly', 0) call EasyMotion#helper#VarReset('&modified', 0)
call s:VarReset('&spell', 0) call EasyMotion#helper#VarReset('&modifiable', 1)
call s:VarReset('&virtualedit', '') call EasyMotion#helper#VarReset('&readonly', 0)
call s:VarReset('&foldmethod', 'manual') call EasyMotion#helper#VarReset('&spell', 0)
call EasyMotion#helper#VarReset('&virtualedit', '')
call EasyMotion#helper#VarReset('&foldmethod', 'manual')
endfunction "}}} endfunction "}}}
function! s:RestoreValue() "{{{ function! s:RestoreValue() "{{{
call s:VarReset('&scrolloff') call EasyMotion#helper#VarReset('&scrolloff')
call s:VarReset('&modified') call EasyMotion#helper#VarReset('&modified')
call s:VarReset('&modifiable') call EasyMotion#helper#VarReset('&modifiable')
call s:VarReset('&readonly') call EasyMotion#helper#VarReset('&readonly')
call s:VarReset('&spell') call EasyMotion#helper#VarReset('&spell')
call s:VarReset('&virtualedit') call EasyMotion#helper#VarReset('&virtualedit')
call s:VarReset('&foldmethod') call EasyMotion#helper#VarReset('&foldmethod')
endfunction "}}} endfunction "}}}
function! s:turn_off_hl_error() "{{{ function! s:turn_off_hl_error() "{{{
let s:error_hl = EasyMotion#highlight#capture('Error') let s:error_hl = EasyMotion#highlight#capture('Error')

View File

@ -2,7 +2,7 @@
" FILE: autoload/EasyMotion/command_line.vim " FILE: autoload/EasyMotion/command_line.vim
" AUTHOR: haya14busa " AUTHOR: haya14busa
" Reference: https://github.com/osyo-manga/vim-over " Reference: https://github.com/osyo-manga/vim-over
" Last Change: 09 Feb 2014. " Last Change: 16 Feb 2014.
" License: MIT license {{{ " License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining " Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the " a copy of this software and associated documentation files (the
@ -124,6 +124,7 @@ endfunction
function! s:search.on_enter(cmdline) "{{{ function! s:search.on_enter(cmdline) "{{{
if s:num_strokes == -1 if s:num_strokes == -1
call EasyMotion#highlight#delete_highlight() call EasyMotion#highlight#delete_highlight()
call EasyMotion#helper#VarReset('&scrolloff', 0)
if g:EasyMotion_do_shade if g:EasyMotion_do_shade
call EasyMotion#highlight#add_highlight('\_.*', call EasyMotion#highlight#add_highlight('\_.*',
\ g:EasyMotion_hl_group_shade) \ g:EasyMotion_hl_group_shade)
@ -133,7 +134,9 @@ function! s:search.on_enter(cmdline) "{{{
endif endif
endfunction "}}} endfunction "}}}
function! s:search.on_leave(cmdline) "{{{ function! s:search.on_leave(cmdline) "{{{
call EasyMotion#highlight#delete_highlight(g:EasyMotion_hl_inc_search) if s:num_strokes == -1
call EasyMotion#highlight#delete_highlight(g:EasyMotion_hl_inc_search)
endif
endfunction "}}} endfunction "}}}
function! s:search.on_char(cmdline) "{{{ function! s:search.on_char(cmdline) "{{{
if s:num_strokes == -1 if s:num_strokes == -1
@ -185,6 +188,7 @@ endfunction "}}}
" Helper: " Helper:
function! s:Cancell() " {{{ function! s:Cancell() " {{{
call EasyMotion#highlight#delete_highlight() call EasyMotion#highlight#delete_highlight()
call EasyMotion#helper#VarReset('&scrolloff')
keepjumps call setpos('.', s:save_orig_pos) keepjumps call setpos('.', s:save_orig_pos)
echo 'EasyMotion: Cancelled' echo 'EasyMotion: Cancelled'
return '' return ''

View File

@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" FILE: autoload/EasyMotion/helper.vim " FILE: autoload/EasyMotion/helper.vim
" AUTHOR: haya14busa " AUTHOR: haya14busa
" Last Change: 13 Feb 2014. " Last Change: 16 Feb 2014.
" License: MIT license {{{ " License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining " Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the " a copy of this software and associated documentation files (the
@ -98,6 +98,27 @@ function! EasyMotion#helper#silent_feedkeys(expr, name, ...) "{{{
call feedkeys(printf("\<Plug>(%s)", name)) call feedkeys(printf("\<Plug>(%s)", name))
endif endif
endfunction "}}} endfunction "}}}
function! EasyMotion#helper#VarReset(var, ...) "{{{
if ! exists('s:var_reset')
let s:var_reset = {}
endif
if a:0 == 0 && has_key(s:var_reset, a:var)
" Reset var to original value
" setbufbar( or bufname): '' or '%' can be used for the current buffer
call setbufvar("", a:var, s:var_reset[a:var])
elseif a:0 == 1
" Save original value and set new var value
let new_value = a:0 == 1 ? a:1 : ''
" Store original value
let s:var_reset[a:var] = getbufvar("", a:var)
" Set new var value
call setbufvar("", a:var, new_value)
endif
endfunction "}}}
" Migemo {{{ " Migemo {{{
function! EasyMotion#helper#load_migemo_dict() "{{{ function! EasyMotion#helper#load_migemo_dict() "{{{