aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-11-22 18:58:20 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-11-22 18:58:20 +1300
commit63bc6cedaa90364f3e11ba9724491ddd7d2005cf (patch)
tree7090717fbc360a3dba32aec38d82a68333b53950
parentMerge branch 'release/v1.72.0' (diff)
parentBump VERSION (diff)
downloaddotfiles-63bc6cedaa90364f3e11ba9724491ddd7d2005cf.tar.gz
dotfiles-63bc6cedaa90364f3e11ba9724491ddd7d2005cf.zip
Merge branch 'release/v1.73.0'v1.73.0
* release/v1.73.0: Bump VERSION Make more of an effort with sudoedit(8) strips Add resolv.conf Vim filetype detection Add hostconf Vim filetype detection for hosts(5)
-rw-r--r--VERSION4
-rw-r--r--vim/filetype.vim60
2 files changed, 54 insertions, 10 deletions
diff --git a/VERSION b/VERSION
index 3e345d04..c68a6ccc 100644
--- a/VERSION
+++ b/VERSION
@@ -1,2 +1,2 @@
-tejr dotfiles v1.72.0
-Wed Nov 21 09:57:27 UTC 2018
+tejr dotfiles v1.73.0
+Thu Nov 22 05:58:20 UTC 2018
diff --git a/vim/filetype.vim b/vim/filetype.vim
index 541976f4..4f3839ef 100644
--- a/vim/filetype.vim
+++ b/vim/filetype.vim
@@ -42,6 +42,41 @@ function! s:StripRepeat()
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! s:SudoRepeat()
+
+ " Check we have the fnameescape() function
+ if !exists('*fnameescape')
+ return
+ endif
+
+ " Expand the match result
+ let l:fn = expand('<afile>')
+
+ " myfileXXQGS16A.conf: strip eight chars before final period
+ if l:fn =~# '/[^./]\+\w\{8}\.[^./]\+$'
+ let l:fr = expand('<afile>:r')
+ let l:fe = expand('<afile>:e')
+ let l:fn = strpart(l:fr, -8, strlen(l:fr)) . '.' . l:fe
+
+ " myfile.XXQGS16A: strip extension
+ elseif l:fn =~# '/[^./]\+\.\w\{8}$'
+ let l:fn = expand('<afile>:r')
+
+ " Unrecognised pattern; return, don't repeat
+ else
+ return
+ endif
+
+ " Re-run the group if there's anything left
+ if strlen(l:fn)
+ execute 'doautocmd filetypedetect BufRead ' . fnameescape(l:fn)
+ endif
+
+endfunction
+
" Check whether the first line was changed and looks like a shebang, and if
" so, re-run filetype detection
function! s:CheckShebang()
@@ -186,6 +221,10 @@ augroup filetypedetect
\ ?*.html
\,?*.htm
\ setfiletype html
+ " hosts(5) file
+ autocmd BufNewFile,BufRead
+ \ /etc/hosts
+ \ setfiletype hostconf
" inittab(5) files
autocmd BufNewFile,BufRead
\ inittab
@@ -320,6 +359,10 @@ augroup filetypedetect
\,?*.rem
\,?*.remind
\ setfiletype remind
+ " resolv.conf files
+ autocmd BufNewFile,BufRead
+ \ resolv.conf
+ \ setfiletype resolv
" robots.txt files
autocmd BufNewFile,BufRead
\ robots.txt
@@ -485,6 +528,15 @@ augroup filetypedetect
" Load any extra rules in ftdetect directories
runtime! ftdetect/*.vim
+ " Clumsy attempt at typing files in `sudo -e` if a filename hasn't already
+ " been found
+ autocmd BufNewFile,BufRead
+ \ /var/tmp/?*????????.*
+ \,/var/tmp/?*.????????
+ \ if !did_filetype()
+ \| call s:SudoRepeat()
+ \|endif
+
" Generic text, config, and log files, if no type assigned yet
autocmd BufNewFile,BufRead
\ ?*.text
@@ -505,14 +557,6 @@ augroup filetypedetect
\,?*.log
\ setfiletype messages
- " Clumsy attempt at typing files in `sudo -e` if a filename hasn't already
- " been found; strip temporary extension and re-run
- autocmd BufNewFile,BufRead
- \ /var/tmp/?*.????????
- \ if !did_filetype()
- \| call s:StripRepeat()
- \|endif
-
" If we still don't have a filetype, run the scripts.vim file that performs
" cleverer checks including looking at actual file contents--but only my
" custom one; don't load the system one at all.