From 48d0a7d0dd9e36208b245d00f7860bd322aa5f33 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 18 Dec 2019 20:56:53 +1300 Subject: Comment and clean up new Vim configuration --- vim/autoload/colorscheme.vim | 13 ++++++++++++- vim/autoload/indent.vim | 27 ++++++++++++++++++++------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/vim/autoload/colorscheme.vim b/vim/autoload/colorscheme.vim index 591550fd..db965d99 100644 --- a/vim/autoload/colorscheme.vim +++ b/vim/autoload/colorscheme.vim @@ -1,10 +1,21 @@ " Reset window-global value for 'cursorline' based on current colorscheme name function! colorscheme#UpdateCursorline(colors_name, list) abort + + " Record current tab and window number so we can jump back once we're done let l:tab = tabpagenr() let l:win = winnr() - tabdo windo let &g:cursorline = index(a:list, a:colors_name) >= 0 + + " Set the window-global value for 'cursorline' in each window of each tab; + " on if the current colorscheme is in the whitelist, and off otherwise; fire + " the WinEnter and WinLeave events so any other 'cursorline' related hooks + " can run too + let l:cursorline = index(a:list, a:colors_name) >= 0 + tabdo windo let &g:cursorline = l:cursorline \| silent doautocmd WinEnter,WinLeave + + " Move back to the tab and window the user started in execute l:tab . 'tabnext' execute l:win . 'wincmd w' \| silent doautocmd WinEnter + endfunction diff --git a/vim/autoload/indent.vim b/vim/autoload/indent.vim index 3e850c63..77403658 100644 --- a/vim/autoload/indent.vim +++ b/vim/autoload/indent.vim @@ -1,32 +1,45 @@ +" Set the current buffer to space indent function! indent#spaces(...) abort setlocal expandtab + + " If an argument was provided, use that for the number of spaces; otherwise, + " set 'shiftwidth' to 0, which then copies 'tabstop' let &l:shiftwidth = a:0 \ ? a:1 \ : 0 + + " If we have the patch that supports it, set 'softtabstop' to dynamically + " mirror the value of 'shiftwidth'; failing that, just copy it let &l:softtabstop = has#('patch-7.3.693') \ ? -1 \ : &l:shiftwidth + call indent#undo() endfunction +" Set the current buffer to tab indent function! indent#tabs() abort - setlocal noexpandtab shiftwidth< softtabstop< + setlocal noexpandtab + setlocal shiftwidth< softtabstop< call indent#undo() endfunction +" Add commands to b:undo_indent to clean up buffer-local indentation changes +" on a change of filetype function! indent#undo() abort - if exists('b:undo_indent_set') + + " Check and set a flag so that we only do this once per buffer + if exists('b:undo_indent_type_set') return endif - let l:undo = 'call indent#reset()' + let b:undo_indent_type_set = 1 + + " Either set or append relevant commands to b:undo_indent + let l:undo = 'setlocal expandtab< shiftwidth< softtabstop< tabstop<' if exists('b:undo_indent') let b:undo_indent .= '|'.l:undo else let b:undo_indent = l:undo endif - let b:undo_indent_set = 1 -endfunction -function! indent#reset() abort - setlocal expandtab< shiftwidth< softtabstop< tabstop< endfunction -- cgit v1.2.3