From d2e2635fa5020ed12d570cdb691c0375238cb9f9 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 15:24:01 +1200 Subject: Clean up ad-hoc plugins These might end up packaged shortly. --- vim/autoload/spellfile_local.vim | 11 +++++++++++ vim/autoload/utc.vim | 4 ++++ vim/plugin/put_date.vim | 5 ----- vim/plugin/spellfile_local.vim | 25 +++++-------------------- vim/plugin/utc.vim | 25 ------------------------- 5 files changed, 20 insertions(+), 50 deletions(-) create mode 100644 vim/autoload/spellfile_local.vim create mode 100644 vim/autoload/utc.vim diff --git a/vim/autoload/spellfile_local.vim b/vim/autoload/spellfile_local.vim new file mode 100644 index 00000000..aafe64ef --- /dev/null +++ b/vim/autoload/spellfile_local.vim @@ -0,0 +1,11 @@ +function! spellfile_local#() abort + let spellfile = join([ + \ substitute(expand('%:p'), '[^0-9A-Za-z_.-]', '%', 'g'), + \ substitute(v:lang, '_.*', '', ''), + \ &encoding + \ ], '.') . '.add' + Establish $MYVIM/cache/spell/local + execute 'setlocal spellfile+=$MYVIM/cache/spell/local/'.spellfile + nnoremap zG 2zg + xnoremap zG 2zg +endfunction diff --git a/vim/autoload/utc.vim b/vim/autoload/utc.vim new file mode 100644 index 00000000..1a464342 --- /dev/null +++ b/vim/autoload/utc.vim @@ -0,0 +1,4 @@ +function! utc#(command) abort + let tz = expand('$TZ') + let $TZ = 'UTC' | execute a:command | let $TZ = tz +endfunction diff --git a/vim/plugin/put_date.vim b/vim/plugin/put_date.vim index 0828abe4..d911486e 100644 --- a/vim/plugin/put_date.vim +++ b/vim/plugin/put_date.vim @@ -2,10 +2,5 @@ if exists('loaded_put_date') finish endif let loaded_put_date = 1 - -" Define a :PutDate command that inserts a line into the buffer with an -" RFC-2822 date string, using the system strftime() implementation. Allow it -" to accept a range which defaults to the current line. -" command! -bar -range PutDate \ put =strftime('%a, %d %b %Y %T %z') diff --git a/vim/plugin/spellfile_local.vim b/vim/plugin/spellfile_local.vim index bb6421f2..b04b7573 100644 --- a/vim/plugin/spellfile_local.vim +++ b/vim/plugin/spellfile_local.vim @@ -3,32 +3,17 @@ if exists('loaded_spellfile_local') endif let loaded_spellfile_local = 1 -Establish $MYVIM/cache/spell - -let spellfile = join([ +let s:spellfile = join([ \ substitute(v:lang, '_.*', '', ''), \ &encoding \ ], '.') . '.add' -execute 'set spellfile=$MYVIM/cache/spell/'.spellfile - -Establish $MYVIM/cache/spell/local - -function! AddLocalSpellFile() abort - let spellfile = join([ - \ substitute(expand('%:p'), '[^0-9A-Za-z_.-]', '%', 'g'), - \ substitute(v:lang, '_.*', '', ''), - \ &encoding - \ ], '.') . '.add' - setlocal spellfile< - execute 'setlocal spellfile+=$MYVIM/cache/spell/local/'.spellfile - nnoremap zG 2zg - xnoremap zG 2zg -endfunction +Establish $MYVIM/cache/spell +execute 'set spellfile=$MYVIM/cache/spell/'.s:spellfile command! AddLocalSpellFile - \ call AddLocalSpellFile() + \ call spellfile_local#() augroup spellfile_local - autocmd BufRead * + autocmd BufNew,BufRead * \ AddLocalSpellFile augroup END diff --git a/vim/plugin/utc.vim b/vim/plugin/utc.vim index 8fb84890..e395ebd4 100644 --- a/vim/plugin/utc.vim +++ b/vim/plugin/utc.vim @@ -2,30 +2,5 @@ if exists('loaded_utc') finish endif let loaded_utc = 1 - -" Define a :UTC command wrapper, implemented with a script-local function of -" the same name. Use expand('$TZ') to ensure we're getting the value of the -" current timezone from the environment, and cache that in a local variable -" just long enough to manipulate the environment into using UTC for a command. -" -" While this is a tidy way to abstract the operation for the map, I don't like -" the function implementation much at all. It works OK in stable versions of -" Vim, but changing an environment variable just long enough to affect the -" outcome of a command as a side effect seems a bit gross. -" -" Worse, the whole thing presently seems to be broken in v8.1.1487; the -" timezone first chosen seems to 'stick' permanently, and the mapping each -" produce timestamps in that zone. I haven't worked out why this happens yet. -" Using the new getenv() and setenv() functions does not seem to fix it. It -" works fine in Debian GNU/Linux's packaged v8.0.x. - -function! s:UTC(command) abort - let tz = expand('$TZ') - let $TZ = 'UTC' | execute a:command | let $TZ = tz -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! -bar -complete=command -nargs=1 UTC \ call s:UTC() -- cgit v1.2.3