From 215163c1b1bc80655aee6543e236567ab9bc2b6b Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 16 Feb 2014 19:45:32 +0900 Subject: [PATCH] Handle scrolloff option when n-key motion close #110 --- autoload/EasyMotion.vim | 53 +++++++++------------------- autoload/EasyMotion/command_line.vim | 8 +++-- autoload/EasyMotion/helper.vim | 23 +++++++++++- 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/autoload/EasyMotion.vim b/autoload/EasyMotion.vim index 2998baa..6e60f2c 100644 --- a/autoload/EasyMotion.vim +++ b/autoload/EasyMotion.vim @@ -3,7 +3,7 @@ " Author: Kim Silkebækken " haya14busa " Source: https://github.com/Lokaltog/vim-easymotion -" Last Change: 16 Feb 2014. +" Last Change: 21 Feb 2014. "============================================================================= " Saving 'cpoptions' {{{ scriptencoding utf-8 @@ -325,44 +325,25 @@ function! s:Prompt(message) " {{{ echohl None endfunction " }}} " -- 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() "{{{ - call s:VarReset('&scrolloff', 0) - call s:VarReset('&modified', 0) - call s:VarReset('&modifiable', 1) - call s:VarReset('&readonly', 0) - call s:VarReset('&spell', 0) - call s:VarReset('&virtualedit', '') - call s:VarReset('&foldmethod', 'manual') + if ! s:current.is_search + call EasyMotion#helper#VarReset('&scrolloff', 0) + endif + call EasyMotion#helper#VarReset('&modified', 0) + call EasyMotion#helper#VarReset('&modifiable', 1) + call EasyMotion#helper#VarReset('&readonly', 0) + call EasyMotion#helper#VarReset('&spell', 0) + call EasyMotion#helper#VarReset('&virtualedit', '') + call EasyMotion#helper#VarReset('&foldmethod', 'manual') endfunction "}}} function! s:RestoreValue() "{{{ - call s:VarReset('&scrolloff') - call s:VarReset('&modified') - call s:VarReset('&modifiable') - call s:VarReset('&readonly') - call s:VarReset('&spell') - call s:VarReset('&virtualedit') - call s:VarReset('&foldmethod') + call EasyMotion#helper#VarReset('&scrolloff') + call EasyMotion#helper#VarReset('&modified') + call EasyMotion#helper#VarReset('&modifiable') + call EasyMotion#helper#VarReset('&readonly') + call EasyMotion#helper#VarReset('&spell') + call EasyMotion#helper#VarReset('&virtualedit') + call EasyMotion#helper#VarReset('&foldmethod') endfunction "}}} function! s:turn_off_hl_error() "{{{ let s:error_hl = EasyMotion#highlight#capture('Error') diff --git a/autoload/EasyMotion/command_line.vim b/autoload/EasyMotion/command_line.vim index ccdb02b..6960813 100644 --- a/autoload/EasyMotion/command_line.vim +++ b/autoload/EasyMotion/command_line.vim @@ -2,7 +2,7 @@ " FILE: autoload/EasyMotion/command_line.vim " AUTHOR: haya14busa " Reference: https://github.com/osyo-manga/vim-over -" Last Change: 09 Feb 2014. +" Last Change: 16 Feb 2014. " License: MIT license {{{ " Permission is hereby granted, free of charge, to any person obtaining " a copy of this software and associated documentation files (the @@ -124,6 +124,7 @@ endfunction function! s:search.on_enter(cmdline) "{{{ if s:num_strokes == -1 call EasyMotion#highlight#delete_highlight() + call EasyMotion#helper#VarReset('&scrolloff', 0) if g:EasyMotion_do_shade call EasyMotion#highlight#add_highlight('\_.*', \ g:EasyMotion_hl_group_shade) @@ -133,7 +134,9 @@ function! s:search.on_enter(cmdline) "{{{ endif endfunction "}}} 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 "}}} function! s:search.on_char(cmdline) "{{{ if s:num_strokes == -1 @@ -185,6 +188,7 @@ endfunction "}}} " Helper: function! s:Cancell() " {{{ call EasyMotion#highlight#delete_highlight() + call EasyMotion#helper#VarReset('&scrolloff') keepjumps call setpos('.', s:save_orig_pos) echo 'EasyMotion: Cancelled' return '' diff --git a/autoload/EasyMotion/helper.vim b/autoload/EasyMotion/helper.vim index df39b14..0516e38 100644 --- a/autoload/EasyMotion/helper.vim +++ b/autoload/EasyMotion/helper.vim @@ -1,7 +1,7 @@ "============================================================================= " FILE: autoload/EasyMotion/helper.vim " AUTHOR: haya14busa -" Last Change: 13 Feb 2014. +" Last Change: 16 Feb 2014. " License: MIT license {{{ " Permission is hereby granted, free of charge, to any person obtaining " a copy of this software and associated documentation files (the @@ -98,6 +98,27 @@ function! EasyMotion#helper#silent_feedkeys(expr, name, ...) "{{{ call feedkeys(printf("\(%s)", name)) endif 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 {{{ function! EasyMotion#helper#load_migemo_dict() "{{{