]> gitweb.factorcode.org Git - factor.git/commitdiff
[misc] vim: Hygenic text width highlights
authorDusk <me@bb010g.com>
Fri, 29 May 2020 23:47:22 +0000 (16:47 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 7 Jun 2020 00:10:18 +0000 (00:10 +0000)
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
misc/vim/ftdetect/factor.vim
misc/vim/ftplugin/factor-docs.vim [new file with mode: 0644]
misc/vim/ftplugin/factor.vim

index 08fa521ed5929617dd413c6816ecf04c1a4571ef..312f2cfff5e85150d0d81a78d7531048ffcf47ab 100644 (file)
@@ -1,2 +1,3 @@
 *.factor text eol=lf
 *.html text eol=lf
+misc/vim/ftplugin/factor.vim linguist-generated
index eb9c0deda6dc4789da839aa4153f693321dfe1b6..733cc5ba277628131c9f7ccfcc95821a2bc2dc47 100644 (file)
@@ -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 (file)
index 0000000..cf2611d
--- /dev/null
@@ -0,0 +1,10 @@
+" Vim filetype plugin file\r
+" Language: Factor (documentation)\r
+" Maintainer: Tim Allen <screwtape@froup.com>\r
+" Last Change: 2020 May 29\r
+\r
+" Documentation lines can be any length of characters.\r
+setlocal textwidth=0\r
+augroup factorTextWidth\r
+    au!\r
+augroup END\r
index bb34b3a60d769014094c75d34690e682b6fb686d..002330b4b08fe69f784c7bcfd28f9e1e2f4f76d1 100644 (file)
@@ -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 <buffer> 2match Error /\%>64v.\+/
+    au BufLeave <buffer> 2match none
+augroup END
 
 " Teach Vim what comments look like.
 setlocal comments+=b:!,b:#!