diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2020-01-05 01:07:49 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2020-01-05 01:07:49 +1300 |
commit | 4fab9517f9bd115a6abbf49231bab66f05f81279 (patch) | |
tree | 0c6b7a7372f6e4b31f41e0892a7ad2ef74f06d4d /vim/autoload/filetype/repeat.vim | |
parent | Merge branch 'release/v8.9.0' (diff) | |
parent | Update PGP key (diff) | |
download | dotfiles-4fab9517f9bd115a6abbf49231bab66f05f81279.tar.gz dotfiles-4fab9517f9bd115a6abbf49231bab66f05f81279.zip |
Merge branch 'release/v8.10.0'v8.10.0
* release/v8.10.0:
Update PGP key
Rename filetype repeat commands
Fix case sensitivity of an operator for vim-vint
Diffstat (limited to 'vim/autoload/filetype/repeat.vim')
-rw-r--r-- | vim/autoload/filetype/repeat.vim | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/vim/autoload/filetype/repeat.vim b/vim/autoload/filetype/repeat.vim new file mode 100644 index 00000000..f681932b --- /dev/null +++ b/vim/autoload/filetype/repeat.vim @@ -0,0 +1,66 @@ +" Helper function to run the 'filetypedetect' group on a file with its +" extension stripped off +function! filetype#repeat#Strip() abort + + " Check we have the fnameescape() function + if !exists('*fnameescape') + return + endif + + " Expand the match result + let fn = expand('<afile>') + + " Strip leading and trailing #hashes# + if fn =~# '^#\+.*#\+$' + let fn = substitute(fn, '^#\+\(.\+\)#\+$', '\1', '') + + " Strip trailing tilde~ + elseif fn =~# '\~$' + let fn = substitute(fn, '\~$', '', '') + + " Strip generic .extension + else + let fn = expand('<afile>:r') + endif + + " Re-run the group if there's anything left + if strlen(fn) + execute 'doautocmd filetypedetect BufRead ' . fnameescape(fn) + endif + +endfunction + +" Helper function to run the 'filetypedetect' group on a file in a temporary +" sudoedit(8) directory, modifying it with an attempt to reverse the temporary +" filename change +function! filetype#repeat#Sudo() abort + + " Check we have the fnameescape() function + if !exists('*fnameescape') + return + endif + + " Expand the match result + let fn = expand('<afile>') + + " myfileXXQGS16A.conf: strip eight chars before final period + if fn =~# '/[^/]\+\w\{8}\.[^./]\+$' + let fr = expand('<afile>:r') + let fe = expand('<afile>:e') + let fn = strpart(fr, -8, strlen(fr)) . '.' . fe + + " myfile.XXQGS16A: strip extension + elseif fn =~# '/[^/]\+\.\w\{8}$' + let fn = expand('<afile>:r') + + " Unrecognised pattern; return, don't repeat + else + return + endif + + " Re-run the group if there's anything left + if strlen(fn) + execute 'doautocmd filetypedetect BufRead ' . fnameescape(fn) + endif + +endfunction |