From 89813d2eef781fc19a76f1ed59e5019c68432a65 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 11:04:25 +1200 Subject: Check correct scope for filetype load guard var Oh god, I spent way too long figuring this out... --- vim/vimrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index 8aa53791..6e607523 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -143,7 +143,7 @@ filetype plugin indent on " they've been loaded. " function! s:FileTypeReload() abort - if exists('did_load_filetypes') + if exists('g:did_load_filetypes') doautocmd filetypedetect BufRead endif endfunction -- cgit v1.2.3 From 168862706a6b2670c52a5f3d8f8ce84605d5fdcb Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 11:30:08 +1200 Subject: Completely refactor vimrc/filetype reloading --- vim/vimrc | 103 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 48 insertions(+), 55 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 6e607523..981c8f00 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -132,68 +132,61 @@ endif " filetype plugin indent on -" If this file or the vimrc stub that calls it is sourced, whether because of -" the above hook, or the R mapping prescribed later in this file, add -" a hook that re-runs filetype detection and thereby ftplugin loading. This -" is chiefly so that any global options set in this file don't trample over -" needed buffer-local settings. +" There are a couple of contexts in which it's useful to reload filetypes for +" the current buffer, quietly doing nothing if filetypes aren't enabled. +" We'll set up a script-local function to do this, just to be tidy, which is +" abstracted behind a simple user command of the same name. " -" We'll abstract this away a bit behind a new user command named -" FileTypeReload, which just re-runs BufRead events for filetype detection if -" they've been loaded. -" -function! s:FileTypeReload() abort +function! s:ReloadFileType() abort if exists('g:did_load_filetypes') doautocmd filetypedetect BufRead endif endfunction +command! ReloadFileType + \ call s:ReloadFileType() -" The command accepts no arguments, and has no range. It just calls the -" function; that's all. It's also used by the F mapping defined later -" in this file. +" We'll also define a :ReloadVimrc command. This may seem like overkill at +" first; surely just :source $MYVIMRC is good enough? +" +" We're defining the command because of an edge case: if the vimrc stub or +" main file is re-sourced, the global settings for options like 'expandtab' +" and 'shiftwidth' may trample over different buffer-local settings that were +" specified by filetype and indent plugins. To handle this, we'll define the +" command to run :ReloadFileType after the vimrc file is sourced. +" +" We can't put these two commands in a script-local function in the vimrc, in +" order to be tidy like we did for :ReloadFileType above, because Vim would +" get upset that we're trying to redefine a function as it executes! " -command! FileTypeReload - \ call s:FileTypeReload() +" Just to be on the safe side, we also suppress any further ##SourceCmd hooks +" from running the :source command with a :noautocmd wrapper. This is +" a defensive measure to avoid infinite recursion. +" +command! ReloadVimrc + \ noautocmd source $MYVIMRC | ReloadFileType -" Create a 'vimrc' automatic command hook group, if it doesn't already exist; -" this group should only be used for command hooks related to this vimrc -" itself. +" Reset and define a group of automatic command hooks specific to matters +" related to reloading the vimrc itself. " augroup vimrc - - " Clear away any automatic command hooks already defined within it if it - " does. This way, we don't end up collecting multiple copies of the hooks - " configured in the rest of this file if it's reloaded. - " autocmd! - " Now we'll use that new :FileTypeReload command as part of an automatic - " command hook that runs whenever this vimrc is sourced. + " Reload the vimrc each time the stub vimrc or this vimrc are saved. This + " often makes errors in the file immediately apparent, and saves restarting + " Vim or running the :source command manually, which I almost always want to + " do, anyway. " - " If there's stuff in any of the filetype plugins that doesn't cope well - " with being reloaded, and just assumes a single BufRead event, it might be - " necessary to rewrite those parts to be idempotent, or to add load guards - " around them so that they only run once. - " - " Note that the SourceCmd event wasn't added until Vim 7.0.187, so we need - " to check it exists first. + autocmd BufWritePost $MYVIMRC,$MYVIM/vimrc + \ ReloadVimrc + + " If Vim is new enough (v7.0.187) to support the ##SourceCmd event for + " automatic command hooks, we'll also apply that to catch invocations of + " :source of either the stub or main vimrc, and translate that into sourcing + " the stub vimrc and reloading the filetype using our new command. " if exists('##SourceCmd') autocmd SourceCmd $MYVIMRC,$MYVIM/vimrc - \ source | FileTypeReload - endif - - " If this file or the vimrc stub that calls it is written to by Vim, we'd like - " to reload the stub vimrc and thereby the main vimrc, so that our changes - " apply immediately in the current editing session. This often makes broken - " changes immediately apparent. We can lean on the SourceCmd hook we just - " established to do this; in fact, we'll only establish this hook if we can do - " so, because otherwise filetype plugins won't reload, and options like - " 'shiftwidth' might be set incorrectly. - " - if exists('#vimrc#SourceCmd') - autocmd BufWritePost $MYVIMRC,$MYVIM/vimrc - \ doautocmd vimrc SourceCmd + \ ReloadVimrc endif augroup END @@ -1293,12 +1286,12 @@ nnoremap L xmap L Lgv " These mappings are for managing filetypes. The first one uses the -" :FileTypeReload command that was defined much earlier in this file.for -" a vimrc reload hook. +" :ReloadFileType command that was defined much earlier in this file for +" application in the vimrc reload command. -"" Leader,F reloads filetype plugins +"" Leader,F reloads filetype settings nnoremap F - \ :FileTypeReload + \ :ReloadFileType "" Leader,t shows current filetype nnoremap t \ :setlocal filetype? @@ -1458,14 +1451,14 @@ nmap * (RegexEscape) xmap * (RegexEscape) " And last, but definitely not least, I'm required by Vim fanatic law to -" include a mapping that reloads my whole configuration. Doing this triggers -" the #vimrc#SourceCmd hooks defined much earlier in the file so that -" filetypes get reloaded afterwards, so I don't need to follow R with -" a F. +" include a mapping that reloads my whole configuration. This uses the +" command wrapper defined much earlier in the file, so that filetypes also get +" reloaded afterwards, meaning I don't need to follow R with +" a F to fix up broken global settings. "" Leader,R reloads ~/.vimrc nnoremap R - \ :source $MYVIMRC + \ :ReloadVimrc " I'll close this file with a few abbreviations. Perhaps of everything in " here, I'm least confident that these should be in here, but they've proven -- cgit v1.2.3 From b58548c3e64bd397fd916be14c1aadcb4695eca0 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 11:41:00 +1200 Subject: Arrange for :PutDate maps to accept line numbers --- vim/vimrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 981c8f00..7b57f9a7 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -1304,10 +1304,10 @@ nnoremap T "" Leader,d inserts the local date (RFC 2822) nnoremap d - \ :PutDate + \ :PutDate "" Leader,D inserts the UTC date (RFC 2822) nnoremap D - \ :UTC PutDate + \ :UTC PutDate " This group contains mappings that are to do with file and path management " relative to the current buffer. -- cgit v1.2.3 From 7b11d9459f78f8dfb740d64fa7892021852d10bc Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 11:41:19 +1200 Subject: Mention the sources of a few mapping commands --- vim/vimrc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 7b57f9a7..e0baed6c 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -1310,7 +1310,8 @@ nnoremap D \ :UTC PutDate " This group contains mappings that are to do with file and path management -" relative to the current buffer. +" relative to the current buffer. The Leader,P mapping that creates +" directory hierarchies uses the :Establish command created earlier. "" Leader,g shows the current file's fully expanded path nnoremap g @@ -1372,7 +1373,16 @@ nnoremap E nnoremap j \ :buffers:buffer -" Filtering and batch operations to clean up buffer text +" This ground defines mappings for filtering and batch operations to clean up +" buffer text. All of these mappings use commands from my custom plugins: +" +" strip_trailing_whitespace.vim: +" :StripTrailingWhitespace +" squeeze_repeat_blanks.vim: +" :SqueezeRepeatBlanks +" keep_position.vim +" :KeepPosition +" "" Leader,x strips trailing whitespace via a custom plugin nnoremap x -- cgit v1.2.3 From 448423e4f8237f7ed3bace88327f1a6422584b04 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 11:50:21 +1200 Subject: Allow -bar in custom commands --- vim/plugin/put_date.vim | 2 +- vim/plugin/utc.vim | 2 +- vim/vimrc | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vim/plugin/put_date.vim b/vim/plugin/put_date.vim index 29cf886e..0828abe4 100644 --- a/vim/plugin/put_date.vim +++ b/vim/plugin/put_date.vim @@ -7,5 +7,5 @@ let loaded_put_date = 1 " RFC-2822 date string, using the system strftime() implementation. Allow it " to accept a range which defaults to the current line. " -command! -range PutDate +command! -bar -range PutDate \ put =strftime('%a, %d %b %Y %T %z') diff --git a/vim/plugin/utc.vim b/vim/plugin/utc.vim index 39eebad8..8fb84890 100644 --- a/vim/plugin/utc.vim +++ b/vim/plugin/utc.vim @@ -27,5 +27,5 @@ endfunction " The :UTC command itself completes another command name, and accepts one " required argument, which it passes in quoted form to the helper function. " -command! -complete=command -nargs=1 UTC +command! -bar -complete=command -nargs=1 UTC \ call s:UTC() diff --git a/vim/vimrc b/vim/vimrc index e0baed6c..94af80f6 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -142,7 +142,7 @@ function! s:ReloadFileType() abort doautocmd filetypedetect BufRead endif endfunction -command! ReloadFileType +command! -bar ReloadFileType \ call s:ReloadFileType() " We'll also define a :ReloadVimrc command. This may seem like overkill at @@ -162,7 +162,7 @@ command! ReloadFileType " from running the :source command with a :noautocmd wrapper. This is " a defensive measure to avoid infinite recursion. " -command! ReloadVimrc +command! -bar ReloadVimrc \ noautocmd source $MYVIMRC | ReloadFileType " Reset and define a group of automatic command hooks specific to matters @@ -222,7 +222,7 @@ endfunction " names as candidates, and specify that there must be only one argument, which " we'll provide as a quoted parameter to the function. " -command! -complete=dir -nargs=1 Establish +command! -bar -complete=dir -nargs=1 Establish \ call s:Establish() " Now that we have a clean means to create directories if they don't already -- cgit v1.2.3 From 5c7c970352a4c41d5e31cf199b44ed1ecbc7e557 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 11:57:39 +1200 Subject: Update vim-keep-position to v0.3.0 --- vim/bundle/keep_position | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/bundle/keep_position b/vim/bundle/keep_position index 2bb4902d..93c879e9 160000 --- a/vim/bundle/keep_position +++ b/vim/bundle/keep_position @@ -1 +1 @@ -Subproject commit 2bb4902d546efc814150134f3900b7860bac9b84 +Subproject commit 93c879e99f4324366057c308e548be5d262447bb -- cgit v1.2.3 From da78d984b0174565a576ab3e52c6cf179df7456d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 11:58:20 +1200 Subject: Update vim-squeeze-repeat-plans to v0.6.0 --- vim/bundle/squeeze_repeat_blanks | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/bundle/squeeze_repeat_blanks b/vim/bundle/squeeze_repeat_blanks index 448470c7..8c849183 160000 --- a/vim/bundle/squeeze_repeat_blanks +++ b/vim/bundle/squeeze_repeat_blanks @@ -1 +1 @@ -Subproject commit 448470c75df7d3f2a5513cb68fe43e703faaf23b +Subproject commit 8c849183f8723086e6b61a0644292bdb1ad99c1b -- cgit v1.2.3 From 2a93582aa719239ed84035fa14a0137b592e4af2 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 11:58:44 +1200 Subject: Update vim-strip-trailing-whitespace to v3.2.0 --- vim/bundle/strip_trailing_whitespace | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/bundle/strip_trailing_whitespace b/vim/bundle/strip_trailing_whitespace index 4ae00d5a..90e60095 160000 --- a/vim/bundle/strip_trailing_whitespace +++ b/vim/bundle/strip_trailing_whitespace @@ -1 +1 @@ -Subproject commit 4ae00d5a5cf92aed3cab774f72df8fcd6d141b94 +Subproject commit 90e60095bcfcfeb60bea60ba7f51bbfac3bf4691 -- cgit v1.2.3 From 5cfa482d9d0780d8d1c08c05f1233e5cd2dfce62 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 11:59:09 +1200 Subject: Update vim-toggle-flags plugin to v3.1.0 --- vim/bundle/toggle_flags | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/bundle/toggle_flags b/vim/bundle/toggle_flags index 4d4883b5..95aa2b83 160000 --- a/vim/bundle/toggle_flags +++ b/vim/bundle/toggle_flags @@ -1 +1 @@ -Subproject commit 4d4883b58ccfff2d3ee6d5c871ddaf623e2eff3c +Subproject commit 95aa2b83543456ae100c697adb79a57b9aeccb10 -- cgit v1.2.3 From 7393d83f915e2ea2adb2f6e1ba4d07d4a55847ea Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 11:59:54 +1200 Subject: Bump VERSION --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 909b9eae..4e1c6b4b 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v5.37.0 -Mon Jun 10 22:45:19 UTC 2019 +tejr dotfiles v5.38.0 +Mon Jun 10 23:59:54 UTC 2019 -- cgit v1.2.3