aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-05-30 20:49:01 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-05-30 20:49:01 +1200
commit16668b84818c21f6e00ef328a2ab79c25672eab8 (patch)
treed70a26d22ef17a6821fc628594aa3ea0ca42d8ea
parentMerge branch 'release/v0.5.0' into develop (diff)
downloadvim-cursorline-current-16668b84818c21f6e00ef328a2ab79c25672eab8.tar.gz
vim-cursorline-current-16668b84818c21f6e00ef328a2ab79c25672eab8.zip
Factor out functions into autoload
This isn't actually very helpful at the moment, because the autoload file gets included on VimEnter. I'm hoping that I can defer that in most circumstances.
-rw-r--r--autoload/cursorline_current.vim31
-rw-r--r--plugin/cursorline_current.vim42
2 files changed, 36 insertions, 37 deletions
diff --git a/autoload/cursorline_current.vim b/autoload/cursorline_current.vim
new file mode 100644
index 0000000..36bb210
--- /dev/null
+++ b/autoload/cursorline_current.vim
@@ -0,0 +1,31 @@
+" Suspend 'cursorline' when a window is inactive or inserting
+function! cursorline_current#Suspend() abort
+ let w:cursorline_current = &l:cursorline
+ let &l:cursorline = 0
+endfunction
+
+" Restore 'cursorline' when a window is active and non-insert
+function! cursorline_current#Restore() abort
+ let &l:cursorline = get(w:, 'cursorline_current', &g:cursorline)
+ let w:cursorline_current = &l:cursorline
+endfunction
+
+" Call cursorline_current#Suspend() on all windows besides the current one
+function! cursorline_current#Load() abort
+
+ " Cache current window index
+ let wcur = winnr()
+
+ " Iterate through all the windows and suspend all but the current one
+ for wnum in range(1, winnr('$'))
+ if wnum == wcur
+ continue
+ endif
+ execute wnum . 'wincmd w'
+ call cursorline_current#Suspend()
+ endfor
+
+ " Return to the window in which we started
+ execute wcur . 'wincmd w'
+
+endfunction
diff --git a/plugin/cursorline_current.vim b/plugin/cursorline_current.vim
index 9cdb25d..234450b 100644
--- a/plugin/cursorline_current.vim
+++ b/plugin/cursorline_current.vim
@@ -11,56 +11,24 @@ if exists('loaded_cursorline_current') || &compatible || v:version < 700
endif
let loaded_cursorline_current = 1
-" Suspend 'cursorline' when a window is inactive or inserting
-function! s:Suspend() abort
- let w:cursorline_current = &l:cursorline
- let &l:cursorline = 0
-endfunction
-
-" Restore 'cursorline' when a window is active and non-insert
-function! s:Restore() abort
- let &l:cursorline = get(w:, 'cursorline_current', &g:cursorline)
- let w:cursorline_current = &l:cursorline
-endfunction
-
-" Call s:Suspend() on all windows besides the current one
-function! s:Load() abort
-
- " Cache current window index
- let wcur = winnr()
-
- " Iterate through all the windows and suspend all but the current one
- for wnum in range(1, winnr('$'))
- if wnum == wcur
- continue
- endif
- execute wnum . 'wincmd w'
- call s:Suspend()
- endfor
-
- " Return to the window in which we started
- execute wcur . 'wincmd w'
-
-endfunction
-
" Set up hooks for toggling 'cursorline'
augroup cursorline_current
autocmd!
" Turn off 'cursorline' for other windows on load
- autocmd VimEnter * call s:Load()
+ autocmd VimEnter * call cursorline_current#Load()
" Turn off 'cursorline' when leaving a window or losing focus. We call the
" restore again on BufEnter to handle existent local buffer values for the
" option overwriting the window value (Vim bug?)
- autocmd WinLeave,FocusLost * call s:Suspend()
- autocmd BufEnter,WinEnter,FocusGained * call s:Restore()
+ autocmd WinLeave,FocusLost * call cursorline_current#Suspend()
+ autocmd BufEnter,WinEnter,FocusGained * call cursorline_current#Restore()
" Turn off 'cursorline' when in insert mode
" Check g:cursorline_current_insert, in case the user doesn't want it
if get(g:, 'cursorline_current_insert', 1)
- autocmd InsertEnter * call s:Suspend()
- autocmd InsertLeave * call s:Restore()
+ autocmd InsertEnter * call cursorline_current#Suspend()
+ autocmd InsertLeave * call cursorline_current#Restore()
endif
augroup END