aboutsummaryrefslogtreecommitdiff
path: root/vim/vimrc
diff options
context:
space:
mode:
Diffstat (limited to 'vim/vimrc')
-rw-r--r--vim/vimrc154
1 files changed, 65 insertions, 89 deletions
diff --git a/vim/vimrc b/vim/vimrc
index ebd9de3d..6cde7036 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -2,7 +2,7 @@
" Tom Ryder (tejr)’s Literate Vimrc
" ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
"
-" Last updated: Thu, 14 May 2020 08:24:17 UTC
+" Last updated: Fri, 15 May 2020 13:24:13 UTC
"
" │ And I was lifted up in heart, and thought
" │ Of all my late-shown prowess in the lists,
@@ -113,9 +113,10 @@ endif
" first value from the 'runtimepath'. We'll use this later on in the file to
" comprehensively match expected paths for vimrc files.
"
-if &runtimepath !=# ''
- let $MYVIM = option#Split(&runtimepath)[0]
+if &runtimepath ==# ''
+ throw 'Empty ''runtimepath'''
endif
+let $MYVIM = option#Split(&runtimepath)[0]
" The next components of the runtime directory that we'll set up here will
" make use of the user’s configured XDG base directories:
@@ -130,9 +131,7 @@ endif
" We'll start by retrieving the list of valid paths for configuration from
" both the XDG_CONFIG_HOME and XDG_CONFIG_DIRS variables, or from their
-" defaults, using the autoloaded xdg#() function. We need to copy() it
-" because of Vim's implicit semantics for map() and reverse(), otherwise we'll
-" edit the values in-place. Man, my kingdom for Perl…
+" defaults, using autoloaded xdg# functions.
"
" We put XDG_CONFIG_HOME at the front of the list with insert(), provided it
" isn't empty, which is what the function returns when the configured path
@@ -147,39 +146,23 @@ endif
"
" Ours not to reason why…
"
-let s:xdgconfigpaths = copy(xdg#['config']['dirs'])
-if xdg#['config']['home'] !=# ''
- call insert(s:xdgconfigpaths, xdg#['config']['home'])
-endif
-if !empty(s:xdgconfigpaths)
+if xdg#ConfigHome() !=# '' || !empty(xdg#ConfigDirs())
execute 'set runtimepath^='.option#Escape(join(map(
- \ copy(s:xdgconfigpaths),
+ \ extend(
+ \ xdg#ConfigHome() !=# '' ? [xdg#ConfigHome()] : [],
+ \ xdg#ConfigDirs()
+ \),
\ 'option#item#Escape(v:val)'
\), ','))
-endif
-if !empty(s:xdgconfigpaths)
execute 'set runtimepath+='.option#Escape(join(map(
- \ reverse(copy(s:xdgconfigpaths)),
+ \ reverse(extend(
+ \ xdg#ConfigHome() !=# '' ? [xdg#ConfigHome()] : [],
+ \ xdg#ConfigDirs()
+ \)),
\ 'option#item#Escape(v:val.''/after'')'
\), ','))
endif
-unlet s:xdgconfigpaths
-" We need a command to reliably establish a full path, whether or not the
-" directories already exist. We create a wrapper for the autoloaded function
-" path#Create() with similar calling conventions to mkdir(), but with the ‘p’
-" value for the second parameter {prot} forced on. Calling it with a bang
-" like :CreatePath! creates a private directory (permissions 0700).
-"
-command! -bang -bar -complete=dir -nargs=1 CreatePath
- \ call path#Create(expand(<q-args>), <q-bang> ==# '!')
-
-" Now that we have a way to create directories if they don’t already exist,
-" let’s apply it for the first time to the user runtime directory. Note that
-" we aren’t checking whether this actually succeeded. We do want errors
-" raised if there were problems with the creation, but we’ll barrel on ahead
-" regardless after warning the user about our failure.
-"
" Using a logical but non-default location for viminfo has the nice benefit of
" preventing command and search history from getting clobbered when something
" runs Vim without using this vimrc, because such an instance will safely
@@ -190,9 +173,12 @@ command! -bang -bar -complete=dir -nargs=1 CreatePath
" v8.1.716 introduced a way to set this with an option named 'viminfofile',
" but I don't see a reason to use that.
"
-if xdg#['cache']['home'] !=# '' && path#Create(xdg#['cache']['home'])
+if xdg#CacheHome() !=# ''
+ if !isdirectory(xdg#CacheHome())
+ call mkdir(xdg#CacheHome(), 'p', 0700)
+ endif
execute 'set viminfo+='.option#Escape(
- \ 'n'.xdg#['cache']['home'].'/viminfo'
+ \ 'n'.xdg#CacheHome().'/viminfo'
\)
endif
@@ -239,14 +225,13 @@ set history=10000
" 'backupfullname', 'swapfilefullname' would have been clearer.
"
set backup
-if xdg#['cache']['home'] !=# ''
- let s:backupdir = xdg#['cache']['home'].'/backup'
- if path#Create(s:backupdir)
- execute 'set backupdir^='.option#Escape(option#item#Escape(
- \ s:backupdir.(has#('patch-8.1.251') ? '//' : ''),
- \))
+if xdg#CacheHome() !=# ''
+ if !isdirectory(xdg#CacheHome().'/backup')
+ call mkdir(xdg#CacheHome().'/backup', 'p', 0700)
endif
- unlet s:backupdir
+ execute 'set backupdir^='.option#Escape(option#item#Escape(
+ \ xdg#CacheHome().'/backup'.(has#('patch-8.1.251') ? '//' : '')
+ \))
endif
" Files in certain directories on Unix-compatible filesystems should not be
@@ -280,17 +265,15 @@ endif
" default of writing them to the same directory as the buffer file. Add two
" trailing slashes to the path to prompt Vim to use the full escaped path in
" its name, in order to avoid filename collisions, since the 'directory'
-" option has supported that hint for much longer than 'backupdir' has. We
-" apply path#Create() to attempt to create the path, if needed.
-"
-if xdg#['cache']['home'] !=# ''
- let s:directory = xdg#['cache']['home'].'/swap'
- if path#Create(s:directory)
- execute 'set directory^='.option#Escape(option#item#Escape(
- \ s:directory.'//'
- \))
+" option has supported that hint for much longer than 'backupdir' has.
+"
+if xdg#CacheHome() !=# ''
+ if !isdirectory(xdg#CacheHome().'/swap')
+ call mkdir(xdg#CacheHome().'/swap', 'p', 0700)
endif
- unlet s:directory
+ execute 'set directory^='.option#Escape(option#item#Escape(
+ \ xdg#CacheHome().'/swap//'
+ \))
endif
" Keep tracked undo history for files permanently, in a dedicated cache
@@ -298,25 +281,21 @@ endif
" Vim invocations.
"
" The 'undodir' option has the same structure as 'backupdir' and 'directory';
-" if we have a user runtime directory, create a sub-subdirectory within it
-" dedicated to the undo files cache. Note also the trailing double-slash as
-" a signal to Vim to use the full path of the original file in its undo file
-" cache’s name.
+" if we have a user cache directory, create a subdirectory within it dedicated
+" to the undo files cache. Note also the trailing double-slash as a signal to
+" Vim to use the full path of the original file in its undo file cache’s name.
"
" Support for these persistent undo file caches was not released until v7.3.0,
" so we need to check for the feature’s presence before we enable it.
"
-if has#('persistent_undo')
+if xdg#CacheHome() !=# '' && has#('persistent_undo')
set undofile
- if xdg#['cache']['home'] !=# ''
- let s:undodir = xdg#['cache']['home'].'/undo'
- if path#Create(s:undodir)
- execute 'set undodir^='.option#Escape(option#item#Escape(
- \ s:undodir.'//'
- \))
- endif
- unlet s:undodir
+ if !isdirectory(xdg#CacheHome().'/undo')
+ call mkdir(xdg#CacheHome().'/undo', 'p', 0700)
endif
+ execute 'set undodir^='.option#Escape(option#item#Escape(
+ \ xdg#CacheHome().'/undo//'
+ \))
endif
" Set up a directory for files generated by :mkview. To date, I think I have
@@ -324,13 +303,13 @@ endif
" directories of this type. This isn't a comma-separated list like the others
" ('backupdir', 'directory', 'spell', 'undodir')
"
-if has#('mksession') && xdg#['cache']['home']
- let s:viewdir = xdg#['cache']['home'].'/view'
- if path#Create(s:viewdir)
- execute 'set viewdir='
- \.option#Escape(option#item#Escape(s:viewdir))
+if xdg#CacheHome() !=# '' && has#('mksession')
+ if !isdirectory(xdg#CacheHome().'/view')
+ call mkdir(xdg#CacheHome().'/view', 'p', 0700)
endif
- unlet s:viewdir
+ execute 'set viewdir='.option#Escape(option#item#Escape(
+ \ xdg#CacheHome().'/view'
+ \))
endif
" Now that we have a bit more confidence in our runtime environment, set up
@@ -450,24 +429,22 @@ set spellcapcheck=[.?!]\\%(\ \ \\\|[\\n\\r\\t]\\)
" 'isfname'; the blacklist is hard-coded.
"
set dictionary^=/usr/share/dict/words
-let s:refdirs = copy(xdg#['data']['dirs'])
-if xdg#['data']['home'] !=# ''
- call insert(s:refdirs, xdg#['data']['home'])
-endif
-if !empty(s:refdirs)
- try
- execute 'set dictionary^='.option#Escape(join(map(
- \ copy(s:refdirs),
- \ 'option#item#Escape(v:val.''/dictionary.txt'')'
- \), ','))
- execute 'set thesaurus^='.option#Escape(join(map(
- \ copy(s:refdirs),
- \ 'option#item#Escape(v:val.''/thesaurus.txt'')'
- \), ','))
- catch /^Vim\%((\a\+)\)\=:E474:/
- endtry
+if xdg#DataHome() !=# '' || !empty(xdg#DataDirs())
+ execute 'set dictionary^='.option#Escape(join(map(
+ \ extend(
+ \ xdg#DataHome() !=# '' ? [xdg#DataHome()] : [],
+ \ xdg#DataDirs()
+ \),
+ \ 'option#item#Escape(v:val.''/dictionary.txt'')'
+ \), ','))
+ execute 'set thesaurus^='.option#Escape(join(map(
+ \ reverse(extend(
+ \ xdg#DataHome() !=# '' ? [xdg#DataHome()] : [],
+ \ xdg#DataDirs()
+ \)),
+ \ 'option#item#Escape(v:val.''/thesaurus.txt'')'
+ \), ','))
endif
-unlet s:refdirs
" Next, we’ll modernize a little in adjusting some options with old
" language-specific defaults.
@@ -1381,8 +1358,7 @@ nnoremap <Leader>D
\ :PutDate!<CR>
" This group contains mappings that are to do with file and path management
-" relative to the current buffer. The Leader,P mapping that creates
-" directory hierarchies uses the :CreatePath command created earlier.
+" relative to the current buffer.
"" Leader,g shows the current file’s fully expanded path
nnoremap <Leader>g
@@ -1392,7 +1368,7 @@ nnoremap <Leader>G
\ :<C-U>cd %:h<Bar>pwd<CR>
"" Leader,P creates the path to the current file if it doesn’t exist
nnoremap <Leader>P
- \ :<C-U>CreatePath %:h<CR>
+ \ :<C-U>call mkdir(expand('%:h'), 'p')<CR>
" This group contains mappings that show information about Vim’s internals:
" marks, registers, variables, and the like.