From 03ce9988ddbea0ab4f055ac035d80dea449012aa Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 10 Jun 2019 22:22:59 +1200 Subject: Refactor and simplify, remove autoload Drop support for local values for 'cursorline'. I think I'm getting better at this. --- autoload/cursorline_current.vim | 17 ----------------- doc/cursorline_current.txt | 7 ++----- plugin/cursorline_current.vim | 31 +++++++------------------------ 3 files changed, 9 insertions(+), 46 deletions(-) delete mode 100644 autoload/cursorline_current.vim diff --git a/autoload/cursorline_current.vim b/autoload/cursorline_current.vim deleted file mode 100644 index 648d633..0000000 --- a/autoload/cursorline_current.vim +++ /dev/null @@ -1,17 +0,0 @@ -" Suspend 'cursorline' when a window is inactive or inserting -function! cursorline_current#Suspend() abort - let w:cursorline = &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', &g:cursorline) -endfunction - -" Call cursorline_current#Suspend() on all windows besides the current one -function! cursorline_current#Load() abort - let wcur = winnr() - windo if winnr() != wcur | call cursorline_current#Suspend() | endif - execute wcur . 'wincmd w' -endfunction diff --git a/doc/cursorline_current.txt b/doc/cursorline_current.txt index be3e78d..a3d67a5 100644 --- a/doc/cursorline_current.txt +++ b/doc/cursorline_current.txt @@ -1,14 +1,11 @@ -*cursorline_current.txt* For Vim version 7.0 Last change: 2019 May 25 +*cursorline_current.txt* For Vim version 7.0 Last change: 2019 Jun 10 DESCRIPTION *cursorline_current* This plugin tweaks the behaviour of the 'cursorline' option to enable it only in the current window, when not in insert mode, and (if supported) when Vim has focus. It essentially makes 'cursorline' follow the cursor in normal mode -as much as possible. - -It uses the global value of 'cursorline' as its default, and should also -correctly handle local values for windows. +as much as possible. It uses the global value of 'cursorline' as its default. REQUIREMENTS *cursorline_current-requirements* diff --git a/plugin/cursorline_current.vim b/plugin/cursorline_current.vim index ed590b8..f7298b3 100644 --- a/plugin/cursorline_current.vim +++ b/plugin/cursorline_current.vim @@ -1,33 +1,16 @@ -" -" cursorline_current: If 'cursorline' is globally on, only enable it for the -" current window, and only when not in insert mode. Essentially, make -" 'cursorline' follow the actual normal-mode cursor as much as possible. -" -" Author: Tom Ryder -" License: Same as Vim itself -" if exists('loaded_cursorline_current') || &compatible || v:version < 700 finish endif let loaded_cursorline_current = 1 -" Set up hooks augroup cursorline_current autocmd! - - " Toggle local 'cursorline' state to follow window focus - autocmd InsertLeave,WinEnter,FocusGained * - \ call cursorline_current#Restore() - autocmd InsertEnter,WinLeave,FocusLost * - \ call cursorline_current#Suspend() - - " If Vim opens with more than one window, set them up correctly + autocmd BufEnter,FocusGained,InsertLeave,WinEnter * + \ let &l:cursorline = &g:cursorline + autocmd BufLeave,FocusGained,InsertEnter,WinLeave * + \ let &l:cursorline = 0 autocmd VimEnter * - \ if winnr('$') > 1 | call cursorline_current#Load() | endif - - " Restore the window setting on re-entering a window onto an existing - " buffer, if there is more than one buffer - autocmd BufEnter * - \ if winnr('$') > 1 | call cursorline_current#Restore() | endif - + \ windo doautocmd WinLeave + autocmd VimEnter * + \ 1 windo doautocmd WinEnter augroup END -- cgit v1.2.3