From 810dc7d697474428ab10e15e80c4d1719b14051e Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 20 Dec 2019 01:17:25 +1300 Subject: uuu uuu(6df) --- .gitignore | 1 + Makefile | 1 + README.md | 1 + games/uuu.sed | 2 ++ man/man6/uuu.6df | 18 ++++++++++++++++++ 5 files changed, 23 insertions(+) create mode 100644 games/uuu.sed create mode 100644 man/man6/uuu.6df diff --git a/.gitignore b/.gitignore index 8dbb1aba..9b244d4d 100644 --- a/.gitignore +++ b/.gitignore @@ -171,6 +171,7 @@ /games/rot13 /games/squ /games/strik +/games/uuu /games/xyzzy /games/zs /git/gitconfig diff --git a/Makefile b/Makefile index 0b562f8e..58993c3a 100644 --- a/Makefile +++ b/Makefile @@ -265,6 +265,7 @@ GAMES = games/aaf \ games/pks \ games/rndn \ games/rot13 \ + games/uuu \ games/squ \ games/strik \ games/xyzzy \ diff --git a/README.md b/README.md index 074b08b1..774031a0 100644 --- a/README.md +++ b/README.md @@ -607,6 +607,7 @@ There's some silly stuff in `install-games`: * `rndn(6df)` implements an esoteric random number generation algorithm. * `strik(6df)` outputs s̶t̶r̶i̶k̶e̶d̶ ̶o̶u̶t̶ struck out text. * `rot13(6df)` rotates the Latin letters in its input. +* `uuu(6df)` uuuuu uuuu uu uuuuuu uuuuuuu u uuu uuuuu. * `xyzzy(6df)` teleports to a marked location on the filesystem. * `zs(6df)` prefixes "z" case-appropriately to every occurrence of "s" in the text on its standard input. diff --git a/games/uuu.sed b/games/uuu.sed new file mode 100644 index 00000000..ab8927be --- /dev/null +++ b/games/uuu.sed @@ -0,0 +1,2 @@ +# uuuuuu uu +s/[[:alpha:]]/u/g diff --git a/man/man6/uuu.6df b/man/man6/uuu.6df new file mode 100644 index 00000000..dd3fcc5a --- /dev/null +++ b/man/man6/uuu.6df @@ -0,0 +1,18 @@ +.TH UUU 6df "December 2019" "Manual page for uuu" +.SH NAME +.B uuu +\- uuuuu u uuuuuu uuuuu uuu uuuuu uuuuu +.SH USAGE +.B uuu +\< uuuu +.br +.B uuuuuuu +| uuu +.SH DESCRIPTION +.B uuu +uuuuuuuuu u uuuuuu uuuuu uuu uuuuu[1] uuuuu uuuuu, uuuuuuuuuu uu uuuu uuu uuuu +uuuu, uuu uuuuuu uu uu uuuuuu. +.SH SEE ALSO +[1]: +.SH AUTHOR +Tom Ryder -- cgit v1.2.3 From e43249fbdf9b4a8a28c53271e832676ed5ef1c1e Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 21 Dec 2019 12:56:40 +1300 Subject: Delete unused autoload function --- vim/autoload/path.vim | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 vim/autoload/path.vim diff --git a/vim/autoload/path.vim b/vim/autoload/path.vim deleted file mode 100644 index 83102138..00000000 --- a/vim/autoload/path.vim +++ /dev/null @@ -1,12 +0,0 @@ -function! path#Create(name, ...) abort - if a:0 > 2 - echoerr 'Too many arguments' - endif - if isdirectory(a:name) - return 1 - endif - let name = a:name - let path = 'p' - let prot = a:0 == 1 && a:1 ? 0700 : 0755 - return mkdir(name, path, prot) -endfunction -- cgit v1.2.3 From 8086fab1efd6cbd202ca6c02e0593d5e18ed0892 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 21 Dec 2019 13:01:19 +1300 Subject: Add a few comment lines --- vim/autoload/colorscheme.vim | 1 + vim/autoload/escape.vim | 5 +++++ vim/autoload/fortune.vim | 13 +++++++++++++ vim/autoload/gitcommit.vim | 1 + vim/autoload/has.vim | 18 ++++++++++++++++++ vim/autoload/markdown.vim | 2 ++ vim/autoload/plugin.vim | 3 +++ vim/autoload/reload.vim | 4 ++++ vim/autoload/unescape.vim | 2 ++ 9 files changed, 49 insertions(+) diff --git a/vim/autoload/colorscheme.vim b/vim/autoload/colorscheme.vim index db965d99..349ee374 100644 --- a/vim/autoload/colorscheme.vim +++ b/vim/autoload/colorscheme.vim @@ -9,6 +9,7 @@ function! colorscheme#UpdateCursorline(colors_name, list) abort " 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 diff --git a/vim/autoload/escape.vim b/vim/autoload/escape.vim index 0fdfba99..37ac3e8b 100644 --- a/vim/autoload/escape.vim +++ b/vim/autoload/escape.vim @@ -1,13 +1,18 @@ +" Escape text for use as an Ex command argument function! escape#Arg(arg) abort return exists('*fnameescape') \ ? fnameescape(a:arg) \ : escape(a:arg, "\n\r\t".' *?[{`$\%#''"|!<') endfunction +" Escape text for use as a list item function! escape#Item(item) abort return escape(a:item, ',') endfunction +" Escape wildcard characters in list items to prevent e.g. tilde or glob +" expansion in the resulting item +" function! escape#Wild(string) abort return escape(a:string, '\*?[{`''$~') endfunction diff --git a/vim/autoload/fortune.vim b/vim/autoload/fortune.vim index 6bbe6b3b..da6e2fa3 100644 --- a/vim/autoload/fortune.vim +++ b/vim/autoload/fortune.vim @@ -1,23 +1,32 @@ +" Declare paths to check for fortune files let s:paths = [ \ $HOME.'/.fortunes', \ $HOME.'/.local/share/games/fortunes', \] +" List of executables for which we need to check let s:executables = [ \ 'fortune', \ 'timeout', \] +" Entry point for plugin function! fortune#() abort + " Check we have all of the executables we need for executable in s:executables if !executable(executable) echoerr 'Missing executable "'.executable.'"' endif endfor + " Maximum length of fortunes is the width of the screen minus 1; characters + " wider than one column will break this + " let limit = &columns - 1 + " Some implementations of fortune(6) thrash the disk if they can't meet the + " length limit, so we need to rap this invocation in a timeout(1) call let command = [ \ 'timeout', \ '0.3s', @@ -27,6 +36,7 @@ function! fortune#() abort \ limit, \] + " Find a path for custom fortunes and add it on to the command if found for path in s:paths if isdirectory(path) call add(command, path) @@ -34,6 +44,8 @@ function! fortune#() abort endif endfor + " Run the command and condense any control or space character groups into + " just one space let fortune = substitute( \ system(join(command)), \ '[[:cntrl:][:space:]]\+', @@ -41,6 +53,7 @@ function! fortune#() abort \ 'g', \) + " Show the fortune message! echomsg fortune endfunction diff --git a/vim/autoload/gitcommit.vim b/vim/autoload/gitcommit.vim index 7aba1c5b..72d2b9ff 100644 --- a/vim/autoload/gitcommit.vim +++ b/vim/autoload/gitcommit.vim @@ -3,6 +3,7 @@ function! gitcommit#CursorColumn() abort " If we can find a line after the first that isn't a comment, we're " composing the message + " for num in range(1, line('$')) if num == 1 continue diff --git a/vim/autoload/has.vim b/vim/autoload/has.vim index 0100e913..c67420a5 100644 --- a/vim/autoload/has.vim +++ b/vim/autoload/has.vim @@ -1,7 +1,20 @@ +" Wrapper to backport the nicer has() syntax for simultaneous version and +" patch level checking that was introduced in v7.4.236 and fixed in v7.4.237. +" +" * +" * +" function! has#(feature) abort + + " If we're new enough, we can just run the native has() if has('patch-7.4.237') return has(a:feature) endif + + " Otherwise, we have to break down the pattern and do manual version and + " patch level checks; if it doesn't match the patch syntax, just return what + " the native has() does + " let feature = a:feature let pattern = 'patch-\(\d\+\)\.\(\d\+\)\.\(\d\+\)' let matchlist = matchlist(feature, pattern) @@ -9,8 +22,13 @@ function! has#(feature) abort return has(a:feature) endif let [major, minor, patch] = matchlist[1:3] + + " The v:version variable looks like e.g. 801 for v8.1 let l:version = major * 100 + minor + + " Compare the version numbers, and then the patch level if they're the same return v:version != l:version \ ? v:version > l:version \ : has('patch-'.patch) + endfunction diff --git a/vim/autoload/markdown.vim b/vim/autoload/markdown.vim index 8bac8045..6c8187a0 100644 --- a/vim/autoload/markdown.vim +++ b/vim/autoload/markdown.vim @@ -9,10 +9,12 @@ function! markdown#Heading(char) abort " Build underline string by repeating character by the string length of the " heading text + " let underline = repeat(a:char, strlen(heading)) " If the line after this one looks like it's already an underline, replace " it; otherwise, create a new underline + " if getline(pos[1] + 1) =~# '^[-=]\{2,}$' call setline(pos[1] + 1, underline) else diff --git a/vim/autoload/plugin.vim b/vim/autoload/plugin.vim index 68e3d54b..629a4367 100644 --- a/vim/autoload/plugin.vim +++ b/vim/autoload/plugin.vim @@ -1,3 +1,6 @@ +" Check whether plugins are enabled and a specific named plugin (excluding +" extension .vim) is available somewhere within 'runtimepath' +" function! plugin#Ready(name) abort return &loadplugins \ && globpath(&runtimepath, 'plugin/'.a:name.'.vim') !=# '' diff --git a/vim/autoload/reload.vim b/vim/autoload/reload.vim index 558f24d6..322c44d2 100644 --- a/vim/autoload/reload.vim +++ b/vim/autoload/reload.vim @@ -1,9 +1,13 @@ +" Re-run filetype detection, if it's run before function! reload#FileType() abort if exists('g:did_load_filetypes') doautocmd filetypedetect BufRead endif endfunction +" Re-read .vimrc file, reloading filetypes afterwards to avoid masking +" filetype plugin settings +" function! reload#Vimrc() abort noautocmd source $MYVIMRC call reload#FileType() diff --git a/vim/autoload/unescape.vim b/vim/autoload/unescape.vim index a809827d..d42403f8 100644 --- a/vim/autoload/unescape.vim +++ b/vim/autoload/unescape.vim @@ -1,3 +1,5 @@ +" Unescape a list item escaped with escape#Item(), by replacing all escaped +" commas with unescaped ones function! unescape#Item(key, val) abort return substitute(a:val, '\\,', ',', 'g') endfunction -- cgit v1.2.3 From 32b90713234575b54d6390e4647396dd51f09896 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 21 Dec 2019 13:01:32 +1300 Subject: Make a pattern stricter for #has() --- vim/autoload/has.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/autoload/has.vim b/vim/autoload/has.vim index c67420a5..162e4929 100644 --- a/vim/autoload/has.vim +++ b/vim/autoload/has.vim @@ -16,7 +16,7 @@ function! has#(feature) abort " the native has() does " let feature = a:feature - let pattern = 'patch-\(\d\+\)\.\(\d\+\)\.\(\d\+\)' + let pattern = '^patch-\(\d\+\)\.\(\d\+\)\.\(\d\+\)$' let matchlist = matchlist(feature, pattern) if empty(matchlist) return has(a:feature) -- cgit v1.2.3 From 91ef82841ce797aee6a06566f0edddc064656822 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 21 Dec 2019 14:29:07 +1300 Subject: Revert "Delete unused autoload function" This reverts commit e43249fbdf9b4a8a28c53271e832676ed5ef1c1e. --- vim/autoload/path.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 vim/autoload/path.vim diff --git a/vim/autoload/path.vim b/vim/autoload/path.vim new file mode 100644 index 00000000..83102138 --- /dev/null +++ b/vim/autoload/path.vim @@ -0,0 +1,12 @@ +function! path#Create(name, ...) abort + if a:0 > 2 + echoerr 'Too many arguments' + endif + if isdirectory(a:name) + return 1 + endif + let name = a:name + let path = 'p' + let prot = a:0 == 1 && a:1 ? 0700 : 0755 + return mkdir(name, path, prot) +endfunction -- cgit v1.2.3 From c785a20f302fb51075812fbbc394756f5db766db Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 21 Dec 2019 14:32:08 +1300 Subject: Simplify vim/bundle installation commands --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 58993c3a..5eedfacf 100644 --- a/Makefile +++ b/Makefile @@ -576,12 +576,12 @@ install-vim-autoload: cp -p -- vim/autoload/*.vim $(VIMDIR)/autoload install-vim-bundle: install-vim-config - find vim/bundle/*/* \ + cd vim/bundle && find */* \ -type d -exec sh -c \ - 'mkdir -p -- $(VIMDIR)/"$${1#vim/bundle/*/}"' _ {} \; - find vim/bundle/*/*/* \ + 'mkdir -p -- $(VIMDIR)/"$${1#*/}"' _ {} \; + cd vim/bundle && find */*/* \ -type f -exec sh -c \ - 'cp -p -- "$$1" $(VIMDIR)/"$${1#vim/bundle/*/}"' _ {} \; + 'cp -p -- "$$1" $(VIMDIR)/"$${1#*/}"' _ {} \; $(VIM) -e -u NONE -c 'helptags $(VIMDIR)/doc' -c quit install-vim-cache: -- cgit v1.2.3 From 1148b0042b17db0fd7555d156b83798aa1fe43f1 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 21 Dec 2019 14:34:05 +1300 Subject: Fix up capitalization patterns for indent autoload --- vim/after/indent/awk.vim | 2 +- vim/after/indent/css.vim | 2 +- vim/after/indent/html.vim | 2 +- vim/after/indent/javascript.vim | 2 +- vim/after/indent/mail.vim | 2 +- vim/after/indent/markdown.vim | 2 +- vim/after/indent/perl.vim | 2 +- vim/after/indent/php.vim | 2 +- vim/after/indent/sh.vim | 2 +- vim/after/indent/vim.vim | 2 +- vim/autoload/indent.vim | 10 +++++----- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/vim/after/indent/awk.vim b/vim/after/indent/awk.vim index 61f09a1e..bff1b904 100644 --- a/vim/after/indent/awk.vim +++ b/vim/after/indent/awk.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -call indent#spaces(4) +call indent#Spaces(4) diff --git a/vim/after/indent/css.vim b/vim/after/indent/css.vim index 61f09a1e..bff1b904 100644 --- a/vim/after/indent/css.vim +++ b/vim/after/indent/css.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -call indent#spaces(4) +call indent#Spaces(4) diff --git a/vim/after/indent/html.vim b/vim/after/indent/html.vim index c043f620..4cb4a678 100644 --- a/vim/after/indent/html.vim +++ b/vim/after/indent/html.vim @@ -1,5 +1,5 @@ " Use four spaces for indentation -call indent#spaces(4) +call indent#Spaces(4) " Clear away the flag we set to indent after paragraphs unlet html_indent_inctags diff --git a/vim/after/indent/javascript.vim b/vim/after/indent/javascript.vim index 61f09a1e..bff1b904 100644 --- a/vim/after/indent/javascript.vim +++ b/vim/after/indent/javascript.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -call indent#spaces(4) +call indent#Spaces(4) diff --git a/vim/after/indent/mail.vim b/vim/after/indent/mail.vim index 61f09a1e..bff1b904 100644 --- a/vim/after/indent/mail.vim +++ b/vim/after/indent/mail.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -call indent#spaces(4) +call indent#Spaces(4) diff --git a/vim/after/indent/markdown.vim b/vim/after/indent/markdown.vim index 61f09a1e..bff1b904 100644 --- a/vim/after/indent/markdown.vim +++ b/vim/after/indent/markdown.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -call indent#spaces(4) +call indent#Spaces(4) diff --git a/vim/after/indent/perl.vim b/vim/after/indent/perl.vim index 61f09a1e..bff1b904 100644 --- a/vim/after/indent/perl.vim +++ b/vim/after/indent/perl.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -call indent#spaces(4) +call indent#Spaces(4) diff --git a/vim/after/indent/php.vim b/vim/after/indent/php.vim index 61f09a1e..bff1b904 100644 --- a/vim/after/indent/php.vim +++ b/vim/after/indent/php.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -call indent#spaces(4) +call indent#Spaces(4) diff --git a/vim/after/indent/sh.vim b/vim/after/indent/sh.vim index 61f09a1e..bff1b904 100644 --- a/vim/after/indent/sh.vim +++ b/vim/after/indent/sh.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -call indent#spaces(4) +call indent#Spaces(4) diff --git a/vim/after/indent/vim.vim b/vim/after/indent/vim.vim index ce99f713..da34eb75 100644 --- a/vim/after/indent/vim.vim +++ b/vim/after/indent/vim.vim @@ -1,5 +1,5 @@ " Use two (not four!) spaces for indentation, per convention -call indent#spaces(2) +call indent#Spaces(2) " Remove inapplicable defaults from 'indentkeys'; we should only need to undo " this if the stock plugin didn't already arrange that (before v7.3.539) diff --git a/vim/autoload/indent.vim b/vim/autoload/indent.vim index 77403658..d597653f 100644 --- a/vim/autoload/indent.vim +++ b/vim/autoload/indent.vim @@ -1,5 +1,5 @@ " Set the current buffer to space indent -function! indent#spaces(...) abort +function! indent#Spaces(...) abort setlocal expandtab " If an argument was provided, use that for the number of spaces; otherwise, @@ -14,19 +14,19 @@ function! indent#spaces(...) abort \ ? -1 \ : &l:shiftwidth - call indent#undo() + call indent#Undo() endfunction " Set the current buffer to tab indent -function! indent#tabs() abort +function! indent#Tabs() abort setlocal noexpandtab setlocal shiftwidth< softtabstop< - call indent#undo() + 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 +function! indent#Undo() abort " Check and set a flag so that we only do this once per buffer if exists('b:undo_indent_type_set') -- cgit v1.2.3 From 3e400157a4049bd6409e775f1be814de6281e936 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 21 Dec 2019 14:37:41 +1300 Subject: Reshape autoloads into noun#Verb() pattern --- Makefile | 7 ++++++- vim/autoload/argument.vim | 6 ++++++ vim/autoload/escape.vim | 18 ------------------ vim/autoload/option.vim | 8 ++++++++ vim/autoload/option/item.vim | 11 +++++++++++ vim/autoload/split.vim | 12 ------------ vim/autoload/unescape.vim | 5 ----- vim/vimrc | 22 +++++++++++++--------- 8 files changed, 44 insertions(+), 45 deletions(-) create mode 100644 vim/autoload/argument.vim delete mode 100644 vim/autoload/escape.vim create mode 100644 vim/autoload/option.vim create mode 100644 vim/autoload/option/item.vim delete mode 100644 vim/autoload/split.vim delete mode 100644 vim/autoload/unescape.vim diff --git a/Makefile b/Makefile index 5eedfacf..8146f1cc 100644 --- a/Makefile +++ b/Makefile @@ -573,7 +573,12 @@ install-vim-after-syntax: install-vim-autoload: mkdir -p $(VIMDIR)/autoload - cp -p -- vim/autoload/*.vim $(VIMDIR)/autoload + cd vim && find autoload \ + -type d -exec sh -c \ + 'mkdir -p -- $(VIMDIR)/"$$1"' _ {} \; \ + -o \ + -type f -exec sh -c \ + 'cp -p -- "$$1" $(VIMDIR)/"$$1"' _ {} \; install-vim-bundle: install-vim-config cd vim/bundle && find */* \ diff --git a/vim/autoload/argument.vim b/vim/autoload/argument.vim new file mode 100644 index 00000000..9e381000 --- /dev/null +++ b/vim/autoload/argument.vim @@ -0,0 +1,6 @@ +function! argument#Escape(argument) abort + return exists('*fnameescape') + \ ? fnameescape(a:argument) + \ : escape(a:argument, "\n\r\t".' *?[{`$\%#''"|!<') +endfunction + diff --git a/vim/autoload/escape.vim b/vim/autoload/escape.vim deleted file mode 100644 index 37ac3e8b..00000000 --- a/vim/autoload/escape.vim +++ /dev/null @@ -1,18 +0,0 @@ -" Escape text for use as an Ex command argument -function! escape#Arg(arg) abort - return exists('*fnameescape') - \ ? fnameescape(a:arg) - \ : escape(a:arg, "\n\r\t".' *?[{`$\%#''"|!<') -endfunction - -" Escape text for use as a list item -function! escape#Item(item) abort - return escape(a:item, ',') -endfunction - -" Escape wildcard characters in list items to prevent e.g. tilde or glob -" expansion in the resulting item -" -function! escape#Wild(string) abort - return escape(a:string, '\*?[{`''$~') -endfunction diff --git a/vim/autoload/option.vim b/vim/autoload/option.vim new file mode 100644 index 00000000..d203dfe8 --- /dev/null +++ b/vim/autoload/option.vim @@ -0,0 +1,8 @@ +function! option#Split(expr, ...) abort + if a:0 > 1 + echoerr 'Too many arguments' + endif + let keepempty = a:0 ? a:1 : 0 + let parts = split(a:expr, '\\\@ 1 + echoerr 'Too many arguments' + endif + let item = a:item + let wild = a:0 ? a:1 : 0 + if wild + let item = substitute(item, '\\,', ',', 'g') + endif + return escape(item, ',') +endfunction diff --git a/vim/autoload/split.vim b/vim/autoload/split.vim deleted file mode 100644 index 44065094..00000000 --- a/vim/autoload/split.vim +++ /dev/null @@ -1,12 +0,0 @@ -if v:version < 702 || v:version == 702 && !has('patch-61') - runtime autoload/unescape.vim -endif - -function! split#Option(expr, ...) abort - if a:0 > 2 - echoerr 'Too many arguments' - endif - let keepempty = a:0 ? a:1 : 0 - let parts = split(a:expr, '\\\@ " -execute 'set viminfo+='.escape#Arg('n'.$MYVIM.'/viminfo') +execute 'set viminfo+='.argument#Escape('n'.$MYVIM.'/viminfo') CreatePath $MYVIM " Speaking of recorded data in viminfo files, the default Vim limit of a mere @@ -179,7 +179,7 @@ set history=10000 " 'backupfullname', 'swapfilefullname' would have been clearer. " set backup -execute 'set backupdir^='.escape#Arg(escape#Item( +execute 'set backupdir^='.argument#Escape(option#item#Escape( \ $MYVIM.'/backup'.(has#('patch-8.1.251') ? '//' : ''), \)) CreatePath! $MYVIM/backup @@ -218,7 +218,8 @@ endif " option has supported that hint for much longer than 'backupdir' has. We " apply path#Create() to attempt to create the path, if needed. " -execute 'set directory^='.escape#Arg(escape#Item($MYVIM.'/swap//')) +execute 'set directory^=' + \.argument#Escape(option#item#Escape($MYVIM.'/swap//')) CreatePath! $MYVIM/swap " Keep tracked undo history for files permanently, in a dedicated cache @@ -236,7 +237,8 @@ CreatePath! $MYVIM/swap " if has#('persistent_undo') set undofile - execute 'set undodir^='.escape#Arg(escape#Item($MYVIM.'/undo//')) + execute 'set undodir^=' + \.argument#Escape(option#item#Escape($MYVIM.'/undo//')) CreatePath! $MYVIM/undo endif @@ -354,8 +356,10 @@ set spellcapcheck=[.?!]\\%(\ \ \\\|[\\n\\r\\t]\\) set dictionary^=/usr/share/dict/words let s:ref = $MYVIM.'/ref' try - execute 'set dictionary^='.escape#Arg(escape#Item(s:ref.'/dictionary.txt')) - execute 'set thesaurus^='.escape#Arg(escape#Item(s:ref.'/thesaurus.txt')) + execute 'set dictionary^=' + \.argument#Escape(option#item#Escape(s:ref.'/dictionary.txt')) + execute 'set thesaurus^=' + \.argument#Escape(option#item#Escape(s:ref.'/thesaurus.txt')) catch /^Vim\%((\a\+)\)\=:E474:/ endtry -- cgit v1.2.3 From ec5357c4fd006ba4a1d01f8700b629092e459161 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 23 Dec 2019 19:40:40 +1300 Subject: Centralize default 'foldlevel' --- vim/after/ftplugin/c.vim | 5 ++--- vim/after/ftplugin/perl.vim | 5 ++--- vim/after/ftplugin/php.vim | 5 ++--- vim/after/ftplugin/sh.vim | 5 ++--- vim/after/ftplugin/vim.vim | 5 ++--- vim/after/ftplugin/zsh.vim | 3 +-- vim/ftplugin/awk.vim | 3 +-- vim/ftplugin/markdown.vim | 3 +-- vim/ftplugin/sed.vim | 3 +-- vim/vimrc | 5 +++++ 10 files changed, 19 insertions(+), 23 deletions(-) diff --git a/vim/after/ftplugin/c.vim b/vim/after/ftplugin/c.vim index f082ca18..ea220e65 100644 --- a/vim/after/ftplugin/c.vim +++ b/vim/after/ftplugin/c.vim @@ -6,10 +6,9 @@ let b:undo_ftplugin .= '|setlocal commentstring< define< include<' setlocal complete+=d let b:undo_ftplugin .= '|setlocal complete<' -" Fold based on indent level, but start with all folds open +" Fold based on indent level setlocal foldmethod=indent -setlocal foldlevel=99 -let b:undo_ftplugin .= '|setlocal foldmethod< foldlevel<' +let b:undo_ftplugin .= '|setlocal foldmethod<' " Include system headers on UNIX if has('unix') diff --git a/vim/after/ftplugin/perl.vim b/vim/after/ftplugin/perl.vim index 611af62c..9333e234 100644 --- a/vim/after/ftplugin/perl.vim +++ b/vim/after/ftplugin/perl.vim @@ -7,10 +7,9 @@ if executable('perltidy') let b:undo_ftplugin .= '|setlocal equalprg<' endif -" Fold based on indent level, but start with all folds open +" Fold based on indent level setlocal foldmethod=indent -setlocal foldlevel=99 -let b:undo_ftplugin .= '|setlocal foldmethod< foldlevel<' +let b:undo_ftplugin .= '|setlocal foldmethod<' " Add angle brackets to pairs of matched characters for q<...> setlocal matchpairs+=<:> diff --git a/vim/after/ftplugin/php.vim b/vim/after/ftplugin/php.vim index 20d8d42e..b747a14e 100644 --- a/vim/after/ftplugin/php.vim +++ b/vim/after/ftplugin/php.vim @@ -12,10 +12,9 @@ setlocal comments=s1:/*,m:*,ex:*/,://,:# setlocal formatoptions+=or let b:undo_ftplugin .= '|setlocal comments< formatoptions<' -" Fold based on indent level, but start with all folds open +" Fold based on indent level setlocal foldmethod=indent -setlocal foldlevel=99 -let b:undo_ftplugin .= '|setlocal foldmethod< foldlevel<' +let b:undo_ftplugin .= '|setlocal foldmethod<' " Use pman as 'keywordprg' setlocal keywordprg=pman diff --git a/vim/after/ftplugin/sh.vim b/vim/after/ftplugin/sh.vim index 39b8d0d6..2c68d83a 100644 --- a/vim/after/ftplugin/sh.vim +++ b/vim/after/ftplugin/sh.vim @@ -3,10 +3,9 @@ setlocal comments=:# setlocal formatoptions+=or let b:undo_ftplugin .= '|setlocal comments< formatoptions<' -" Fold based on indent level, but start with all folds open +" Fold based on indent level setlocal foldmethod=indent -setlocal foldlevel=99 -let b:undo_ftplugin .= '|setlocal foldmethod< foldlevel<' +let b:undo_ftplugin .= '|setlocal foldmethod<' " If subtype is Bash, set 'keywordprg' to han(1df) if exists('b:is_bash') diff --git a/vim/after/ftplugin/vim.vim b/vim/after/ftplugin/vim.vim index 481af0ec..01f971b9 100644 --- a/vim/after/ftplugin/vim.vim +++ b/vim/after/ftplugin/vim.vim @@ -9,10 +9,9 @@ endif let b:regex_escape_flavor = 'vim' let b:undo_ftplugin .= '|unlet b:regex_escape_flavor' -" Fold based on indent level, but start with all folds open +" Fold based on indent level setlocal foldmethod=indent -setlocal foldlevel=99 -let b:undo_ftplugin .= '|setlocal foldmethod< foldlevel<' +let b:undo_ftplugin .= '|setlocal foldmethod<' " Use :help as 'keywordprg' if not already set; this is the default since Vim " v8.1.1290 diff --git a/vim/after/ftplugin/zsh.vim b/vim/after/ftplugin/zsh.vim index 880c2c39..c361c859 100644 --- a/vim/after/ftplugin/zsh.vim +++ b/vim/after/ftplugin/zsh.vim @@ -5,5 +5,4 @@ let b:undo_ftplugin .= '|unlet b:current_compiler' " Fold based on indent level, but start with all folds open setlocal foldmethod=indent -setlocal foldlevel=99 -let b:undo_ftplugin .= '|setlocal foldmethod< foldlevel<' +let b:undo_ftplugin .= '|setlocal foldmethod<' diff --git a/vim/ftplugin/awk.vim b/vim/ftplugin/awk.vim index dbefa5cd..76637486 100644 --- a/vim/ftplugin/awk.vim +++ b/vim/ftplugin/awk.vim @@ -11,8 +11,7 @@ let b:undo_ftplugin = 'setlocal comments< formatoptions<' " Fold based on indent level, but start with all folds open setlocal foldmethod=indent -setlocal foldlevel=99 -let b:undo_ftplugin .= '|setlocal foldmethod< foldlevel<' +let b:undo_ftplugin .= '|setlocal foldmethod<' " Specify ERE flavor for regex_escape.vim let b:regex_escape_flavor = 'ere' diff --git a/vim/ftplugin/markdown.vim b/vim/ftplugin/markdown.vim index da2228b3..2b4087a5 100644 --- a/vim/ftplugin/markdown.vim +++ b/vim/ftplugin/markdown.vim @@ -42,8 +42,7 @@ endfunction let b:undo_ftplugin .= '|delfunction MarkdownFold' setlocal foldexpr=MarkdownFold() setlocal foldmethod=expr -setlocal foldlevel=99 -let b:undo_ftplugin .= '|setlocal foldexpr< foldmethod< foldlevel<' +let b:undo_ftplugin .= '|setlocal foldexpr< foldmethod<' " Spellcheck documents we're actually editing (not just viewing) if &modifiable && !&readonly diff --git a/vim/ftplugin/sed.vim b/vim/ftplugin/sed.vim index 35e705a4..04d86d7d 100644 --- a/vim/ftplugin/sed.vim +++ b/vim/ftplugin/sed.vim @@ -11,5 +11,4 @@ let b:undo_ftplugin = 'setlocal comments< formatoptions<' " Fold based on indent level, but start with all folds open setlocal foldmethod=indent -setlocal foldlevel=99 -let b:undo_ftplugin .= '|setlocal foldmethod< foldlevel<' +let b:undo_ftplugin .= '|setlocal foldmethod<' diff --git a/vim/vimrc b/vim/vimrc index 7daa54b6..601341f0 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -466,6 +466,11 @@ set confirm " set noesckeys +" Always start with 'foldlevel' set high enough to have all folds of any +" practical depth open by default. +" +set foldlevel=256 + " Automatic text wrapping options using flags in the 'formatoptions' option " begin here. I rely on the filetype plugins to set the ‘t’ and ‘c’ flags for " this option to configure whether text or comments should be wrapped, as -- cgit v1.2.3 From bb5cb79bd1736fc33f5959fafed207ca1dd0db6d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 28 Dec 2019 23:43:08 +1300 Subject: Fix and refactor HTML timestamp updating --- vim/autoload/html.vim | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/vim/autoload/html.vim b/vim/autoload/html.vim index 7ac4f9d3..72f29bb4 100644 --- a/vim/autoload/html.vim +++ b/vim/autoload/html.vim @@ -21,19 +21,48 @@ function! html#TidyBuffer() abort call winrestview(view) endfunction +let s:formats = { + \ 'human': '%a, %d %b %Y %T %Z', + \ 'machine': '%Y-%m-%dT%H:%M:%S.000Z', + \} + +function! s:Timestamp(time) abort + if exists('$TZ') + let tz = $TZ + endif + let $TZ = 'UTC' + let time = localtime() + let timestamp = {} + for key in keys(s:formats) + let timestamp[key] = strftime(s:formats[key], time) + endfor + if exists('tz') + let $TZ = tz + endif + return timestamp +endfunction + +let s:pattern = '\m\C' + \.'Last updated: ' + \.'' + " Update a timestamp function! html#TimestampUpdate() abort if !&modified return endif - let cv = winsaveview() - call cursor(1,1) - let li = search('\m\C^\s*Last updated: .\+$', 'n') - if li - let date = substitute(system('date -u'), '\n$', '', '') - let line = getline(li) - call setline(li, substitute(line, '\S.*', - \ 'Last updated: '.date.'', '')) + let lnum = search(s:pattern, 'nw') + if !lnum + return endif - call winrestview(cv) + let timestamp = s:Timestamp(localtime()) + let update = 'Last updated: ' + \.'' + let line = getline(lnum) + let line = substitute(line, s:pattern, update, '') + call setline(lnum, line) endfunction -- cgit v1.2.3 From 3c1b52b2667668f3bc1a0acb45b901fcd3bcf090 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 30 Dec 2019 17:21:06 +1300 Subject: Factor out HTML timestamp update into sep file --- vim/after/ftplugin/html.vim | 2 +- vim/autoload/html/timestamp.vim | 45 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 vim/autoload/html/timestamp.vim diff --git a/vim/after/ftplugin/html.vim b/vim/after/ftplugin/html.vim index 7866f31b..b4e55462 100644 --- a/vim/after/ftplugin/html.vim +++ b/vim/after/ftplugin/html.vim @@ -26,7 +26,7 @@ let b:undo_ftplugin .= '|nunmap =' augroup html_timestamp autocmd BufWritePre \ if exists('b:html_timestamp_check') - \| call html#TimestampUpdate() + \| call html#timestamp#Update() \|endif augroup END let b:undo_ftplugin .= '|execute ''autocmd! html_timestamp''' diff --git a/vim/autoload/html/timestamp.vim b/vim/autoload/html/timestamp.vim new file mode 100644 index 00000000..af9b0d44 --- /dev/null +++ b/vim/autoload/html/timestamp.vim @@ -0,0 +1,45 @@ +let s:formats = { + \ 'human': '%a, %d %b %Y %T %Z', + \ 'machine': '%Y-%m-%dT%H:%M:%S.000Z', + \} + +function! s:Timestamp(time) abort + if exists('$TZ') + let tz = $TZ + endif + let $TZ = 'UTC' + let time = localtime() + let timestamp = {} + for key in keys(s:formats) + let timestamp[key] = strftime(s:formats[key], time) + endfor + if exists('tz') + let $TZ = tz + endif + return timestamp +endfunction + +let s:pattern = '\m\C' + \.'Last updated: ' + \.'' + +" Update a timestamp +function! html#timestamp#Update() abort + if !&modified + return + endif + let lnum = search(s:pattern, 'nw') + if !lnum + return + endif + let timestamp = s:Timestamp(localtime()) + let update = 'Last updated: ' + \.'' + let line = getline(lnum) + let line = substitute(line, s:pattern, update, '') + call setline(lnum, line) +endfunction -- cgit v1.2.3 From 00782d5003c57936467dc5c945f8257562aeafa8 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 30 Dec 2019 17:37:24 +1300 Subject: Add some comments --- vim/autoload/html/timestamp.vim | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/vim/autoload/html/timestamp.vim b/vim/autoload/html/timestamp.vim index af9b0d44..871a800f 100644 --- a/vim/autoload/html/timestamp.vim +++ b/vim/autoload/html/timestamp.vim @@ -1,24 +1,39 @@ +" Keys and date formats for return value of s:Timestamp() let s:formats = { \ 'human': '%a, %d %b %Y %T %Z', \ 'machine': '%Y-%m-%dT%H:%M:%S.000Z', \} +" Get UTC timestamp string dictionary with layout in s:formats function! s:Timestamp(time) abort + + " Force UTC, recording previous timezone, if any if exists('$TZ') let tz = $TZ endif let $TZ = 'UTC' + + " Get current time let time = localtime() + + " Fill out timestamp dictionary let timestamp = {} for key in keys(s:formats) let timestamp[key] = strftime(s:formats[key], time) endfor + + " Clear UTC and restore previous timezone, if any + unlet $TZ if exists('tz') let $TZ = tz endif + + " Return filled-out timestamp dictionary return timestamp + endfunction +" Define pattern to match date timestamps; no Z̷͖̟̩͕̊̇̈ͬ̆̄Á̩̺͙̫͇͔̓͛ͭ̓̈́L̟͘G̤̣̳̊̌O̻̝̣̠͇̥̠͗ͤ͐͘ please let s:pattern = '\m\C' \.'Last updated: ' \.'