From 624bd993b589d84265e66654faf05bcb3c160f43 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 22:00:17 +1200 Subject: Factor out all my autoloaded functions I've changed my mind again; I want this file to be self-contained. --- vim/autoload/vimrc.vim | 82 -------------------------------------------------- vim/vimrc | 53 ++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 104 deletions(-) delete mode 100644 vim/autoload/vimrc.vim diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim deleted file mode 100644 index b3a28062..00000000 --- a/vim/autoload/vimrc.vim +++ /dev/null @@ -1,82 +0,0 @@ -" Utility functions for use in .vim/vimrc only - -" Expand the first path in an option string, check if it exists, and attempt -" to create it if it doesn't. Strip double-trailing-slash hints. -function! vimrc#Ensure(string) abort - - " Get first part of the option string - let part = vimrc#SplitOption(a:string)[0] - - " Remove any trailing slashes; neither expand() nor mkdir() seems bothered, - " at least on Unix, but let's be tidy anyway - let part = substitute(part, '/\+$', '', '') - - " Expand the directory name to replace tildes with the home directory, but - " it still may not necessarily be an absolute path - let dirname = expand(part) - - " Return either the confirmed presence of the directory, or failing that, - " the result of an attempt to create it - return isdirectory(dirname) - \ || mkdir(dirname, 'p') - -endfunction - -" Check that we have a plugin available, and will be loading it -function! vimrc#PluginReady(filename) abort - - " Return whether the given filename with a .vim extension is present in - " a subdirectory named 'plugin', and that the 'loadplugins' option is on, - " implying that Vim will at least attempt to load it - let path = 'plugin/'.a:filename.'.vim' - return globpath(&runtimepath, path) !=# '' - \ && &loadplugins - -endfunction - -" Split a comma-separated option string into its constituent parts -function! vimrc#SplitOption(string) abort - - " A separator can be defined as: a comma that is not preceded by - " a backslash, and which is followed by any number of spaces and/or further - " commas. No, I don't have to deal with escaped backslashes; read the - " source of copy_option_part() in vim/src/misc2.c to see why. - let pattern - \ = '\\\@ running - \ || v:version == running && has(patch) - -endfunction diff --git a/vim/vimrc b/vim/vimrc index a5633921..8ef77a69 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -36,12 +36,17 @@ " " We'll use the first path specified in 'runtimepath', rather like Vim itself " does for spelling database files in the absence of a setting for -" 'spellfile'. Splitting the values of an option like 'runtimepath' correctly -" is a bit more complicated than it seems; we defer that to an autoloaded -" utility function for clarity. +" 'spellfile'. +" +" Splitting the values of an option like 'runtimepath' correctly +" is a bit more complicated than it seems. A separator can be defined as: +" a comma that is not preceded by a backslash, and which is followed by any +" number of spaces and/or further commas. No, I don't have to deal with +" escaped backslashes; read the source of copy_option_part() in +" vim/src/misc2.c to see why. " if !exists('$MYVIM') && &runtimepath !=# '' - let $MYVIM = vimrc#SplitOption(&runtimepath)[0] + let $MYVIM = split(&runtimepath, '\\\@ 730 || v:version == 730 && has('patch693') + set softtabstop=-1 +else + let &softtabstop = &shiftwidth +endif " Relax traditional vi's harsh standards over what regions of the buffer can " be removed with backspace in insert mode. While this admittedly allows bad @@ -120,6 +129,9 @@ set backup " inserting, which prompts Vim to incorporate the full escaped path in the " backup filename, avoiding collisions. " +" Create the first path in the 'backupdir' list, the one we just added, if it +" doesn't already exist. It isn't created automatically, which is by design. +" " As a historical note, other similar directory path list options supported " this trailing slashes hint for a long time before 'backupdir' caught up to " them. The 'directory' option for swapfiles has supported it at least as far @@ -135,16 +147,12 @@ set backup " It's all so awkward. Surely options named something like 'backupfullpath', " 'swapfilefullpath', and 'undofullpath' would have been clearer. " -if vimrc#Version('8.1.251') +if has('patch-8.1.251') set backupdir^=$MYVIM/cache/backup// else set backupdir^=$MYVIM/cache/backup endif - -" Create the first path in the 'backupdir' list, the one we just added, if it -" doesn't already exist. It isn't created automatically, which is by design. -" -call vimrc#Ensure(&backupdir) +call mkdir($MYVIM.'/cache/backup', 'p') " Files in certain directories on Unix-compatible filesystems should not be " backed up for reasons of privacy, or an intentional ephemerality, or both. @@ -245,13 +253,11 @@ set dictionary^=/usr/share/dict/words " trailing slashes to the path to prompt Vim to use the full escaped path in " its name, in order to avoid filename collisions. " -set directory^=$MYVIM/cache/swap - -" Create the first path in the 'directory' swapfile path list, the one we just -" added, if it doesn't already exist. It isn't created automatically, which -" is by design. +" Create the first directory after adding it, if it doesn't already exist. It +" isn't created automatically, by design. " -call vimrc#Ensure(&directory) +set directory^=$MYVIM/cache/swap// +call mkdir($MYVIM.'/cache/swap', 'p') " On Unix, I keep LANG defined in my environment, and it's almost always set " to a multibyte (UTF-8) locale. This informs Vim's choice of internal @@ -329,7 +335,7 @@ set formatoptions+=1 " availability of option flags directly, we instead do a version number check " before attempting to add the flag. " -if vimrc#Version('7.3.541') +if v:version > 730 || v:version == 730 && has('patch541') set formatoptions+=j endif @@ -351,7 +357,7 @@ endif " " " -if vimrc#Version('8.1.728') +if has('patch-8.1.728') set formatoptions+=p endif @@ -452,7 +458,7 @@ endif if has('persistent_undo') " v7.2.438 set undofile set undodir^=$MYVIM/cache/undo// - call vimrc#Ensure(&undodir) + call mkdir($MYVIM.'/cache/undo', 'p') endif " Keep the viminfo file in the home Vim directory, mostly to stop history @@ -462,6 +468,7 @@ if exists('+viminfofile') " Use new option method if we can (v8.1.716) else " Resort to clunkier method with 'viminfo' option flag set viminfo+=n$MYVIM/cache/viminfo endif +call mkdir($MYVIM.'/cache', 'p') " Let me move beyond buffer text in visual block mode set virtualedit+=block @@ -502,7 +509,8 @@ catch endtry " Space bar scrolls down a page, :next at buffer's end if plugin available -if vimrc#PluginReady('scroll_next') +if globpath(&runtimepath, 'plugin/scroll_next.vim') + \ && &loadplugins nmap (ScrollNext) else nnoremap @@ -510,7 +518,8 @@ endif " Remap insert Ctrl-C to undo the escaped insert operation, but don't break " the key if the plugin isn't there -if vimrc#PluginReady('insert_cancel') +if globpath(&runtimepath, 'plugin/insert_cancel.vim') + \ && &loadplugins imap (InsertCancel) endif -- cgit v1.2.3