aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload
diff options
context:
space:
mode:
Diffstat (limited to 'vim/autoload')
-rw-r--r--vim/autoload/put_date.vim19
-rw-r--r--vim/autoload/select_old_files.vim16
-rw-r--r--vim/autoload/spellfile_local.vim79
-rw-r--r--vim/autoload/utc.vim4
4 files changed, 102 insertions, 16 deletions
diff --git a/vim/autoload/put_date.vim b/vim/autoload/put_date.vim
new file mode 100644
index 00000000..c9f52c12
--- /dev/null
+++ b/vim/autoload/put_date.vim
@@ -0,0 +1,19 @@
+let s:rfc_2822 = '%a, %d %b %Y %T %z'
+
+function! put_date#(line, utc, format) abort
+ let line = a:line
+ let utc = a:utc
+ let format = strlen(a:format)
+ \ ? substitute(a:format, '\a', '%&', 'g')
+ \ : s:rfc_2822
+ if utc
+ if exists('$TZ')
+ let tz = $TZ
+ endif
+ let $TZ = 'UTC'
+ endif
+ execute line.'put =strftime(format)'
+ if exists('tz')
+ let $TZ = tz
+ endif
+endfunction
diff --git a/vim/autoload/select_old_files.vim b/vim/autoload/select_old_files.vim
index 518b98d4..aceff110 100644
--- a/vim/autoload/select_old_files.vim
+++ b/vim/autoload/select_old_files.vim
@@ -1,7 +1,17 @@
-function! select_old_files#() abort
+function! select_old_files#(...) abort
+ if a:0
+ if a:1 =~# '^\d\+$'
+ let limit = a:1
+ else
+ echoerr 'Invalid count'
+ endif
+ elseif exists('g:select_old_files_limit')
+ let limit = g:select_old_files_limit
+ else
+ let limit = &lines - 2
+ endif
let oldfiles = v:oldfiles
- let limit = get(g:, 'select_old_files_limit', &lines - 1)
- let v:oldfiles = v:oldfiles[:limit-2]
+ let v:oldfiles = v:oldfiles[:limit - 1]
browse oldfiles
let v:oldfiles = oldfiles
endfunction
diff --git a/vim/autoload/spellfile_local.vim b/vim/autoload/spellfile_local.vim
index aafe64ef..081b2970 100644
--- a/vim/autoload/spellfile_local.vim
+++ b/vim/autoload/spellfile_local.vim
@@ -1,11 +1,72 @@
+function! s:SplitOption(string) abort
+ return map(
+ \ split(a:string, '\\\@<!,[, ]*')
+ \,"substitute(v:val, '\\\\,', '', 'g')"
+ \)
+endfunction
+
+function! s:JoinOption(list) abort
+ return join(map(
+ \ a:list
+ \,"substitute(v:val, '\\\\\\@<!,', '\\\\,', 'g')"
+ \), ',')
+endfunction
+
+function! s:Establish(path) abort
+ return isdirectory(a:path)
+ \ || exists('*mkdir') && mkdir(a:path, 'p', 0700)
+endfunction
+
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 <buffer> zG 2zg
- xnoremap <buffer> zG 2zg
+
+ set spellfile<
+
+ let spelllangs = s:SplitOption(&spelllang)
+ if !len(spelllangs) || &spelllang[0] ==# ''
+ echoerr 'Blank ''spelllang'''
+ endif
+ let spelllang = substitute(spelllangs[0], '_.*', '', '')
+
+ if !len(&encoding)
+ echoerr 'Blank ''encoding'''
+ endif
+
+ let spellfiles = s:SplitOption(&spellfile)
+ if len(spellfiles) != 1 || spellfiles[0] ==# ''
+ return
+ endif
+
+ let spelldir = fnamemodify(spellfiles[0], ':h')
+ if spelldir ==# ''
+ echoerr 'Blank directory'
+ endif
+
+ try
+ let path = substitute(expand('%:p'), '/', '%', 'g')
+ if path ==# ''
+ echoerr 'Blank path'
+ endif
+ call s:Establish(spelldir.'/path')
+ call add(spellfiles, spelldir.'/path/'.join([
+ \ path
+ \,spelllang
+ \,&encoding
+ \,'add'
+ \], '.'))
+
+ if &filetype ==# ''
+ echoerr 'Blank filetype'
+ endif
+ call s:Establish(spelldir.'/filetype')
+ call add(spellfiles, spelldir.'/filetype/'.join([
+ \ &filetype
+ \,spelllang
+ \,&encoding
+ \,'add'
+ \], '.'))
+ catch
+ endtry
+
+ let &l:spellfile = s:JoinOption(spellfiles)
+
endfunction
diff --git a/vim/autoload/utc.vim b/vim/autoload/utc.vim
deleted file mode 100644
index 1a464342..00000000
--- a/vim/autoload/utc.vim
+++ /dev/null
@@ -1,4 +0,0 @@
-function! utc#(command) abort
- let tz = expand('$TZ')
- let $TZ = 'UTC' | execute a:command | let $TZ = tz
-endfunction