From 710b54869abb5077e7feb348b9d31fead79649e9 Mon Sep 17 00:00:00 2001 From: Dusk Date: Fri, 29 May 2020 16:47:22 -0700 Subject: [PATCH] [misc] vim: Hygenic text width highlights This lets Factor's overly long line highlighting avoid bleeding over into documentation source buffers, or buffers of other non-Factor file types entirely. Also, by taking `:2match` instead of `:match`, clobbering of most user matches (or vice versa) can be avoided. Unfortunately, the highlighting effects all windows in a multi-buffer split setup, but since we can't reasonably make this a `:syntax match` group, it'll have to do. (And this behavior isn't new.) --- .gitattributes | 1 + misc/vim/ftdetect/factor.vim | 4 +++- misc/vim/ftplugin/factor-docs.vim | 10 ++++++++++ misc/vim/ftplugin/factor.vim | 15 +++++++-------- 4 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 misc/vim/ftplugin/factor-docs.vim diff --git a/.gitattributes b/.gitattributes index 08fa521ed5..312f2cfff5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,3 @@ *.factor text eol=lf *.html text eol=lf +misc/vim/ftplugin/factor.vim linguist-generated diff --git a/misc/vim/ftdetect/factor.vim b/misc/vim/ftdetect/factor.vim index eb9c0deda6..733cc5ba27 100644 --- a/misc/vim/ftdetect/factor.vim +++ b/misc/vim/ftdetect/factor.vim @@ -1 +1,3 @@ -autocmd BufRead,BufNewFile *.factor,{,.}factor*-rc set filetype=factor +" autocmd BufRead,BufNewFile *.factor setf factor " upstreamed +autocmd BufRead,BufNewFile {,.}factor*-rc setf factor +autocmd BufRead,BufNewFile *-docs.factor set ft=factor.factor-docs diff --git a/misc/vim/ftplugin/factor-docs.vim b/misc/vim/ftplugin/factor-docs.vim new file mode 100644 index 0000000000..cf2611d998 --- /dev/null +++ b/misc/vim/ftplugin/factor-docs.vim @@ -0,0 +1,10 @@ +" Vim filetype plugin file +" Language: Factor (documentation) +" Maintainer: Tim Allen +" Last Change: 2020 May 29 + +" Documentation lines can be any length of characters. +setlocal textwidth=0 +augroup factorTextWidth + au! +augroup END diff --git a/misc/vim/ftplugin/factor.vim b/misc/vim/ftplugin/factor.vim index bb34b3a60d..002330b4b0 100644 --- a/misc/vim/ftplugin/factor.vim +++ b/misc/vim/ftplugin/factor.vim @@ -15,14 +15,13 @@ let b:did_ftplugin = 1 " Tabs are not allowed in Factor source files; use four spaces instead. setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4 -" Try to limit lines to 64 characters, except for documentation, which can be -" any length. -if expand("%:t") !~ "-docs\.factor$" - setlocal textwidth=64 - - " Mark anything in column 64 or beyond as a syntax error. - match Error /\%>63v.\+/ -endif +" Try to limit lines to 64 characters. +setlocal textwidth=64 +augroup factorTextWidth + au! + au BufEnter 2match Error /\%>64v.\+/ + au BufLeave 2match none +augroup END " Teach Vim what comments look like. setlocal comments+=b:!,b:#! -- 2.34.1