Add vim indent
authorGiftpflanze <gifti@tools.wmflabs.org>
Tue, 23 Aug 2022 19:33:21 +0000 (19:33 +0000)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 23 Aug 2022 20:23:26 +0000 (13:23 -0700)
misc/vim/indent/factor.vim [new file with mode: 0644]

diff --git a/misc/vim/indent/factor.vim b/misc/vim/indent/factor.vim
new file mode 100644 (file)
index 0000000..0224e59
--- /dev/null
@@ -0,0 +1,36 @@
+" Vim indent file
+" Language:    Factor
+" Maintainer:  Giftpflanze <gifti@tools.wmflabs.org>
+" Last Change: 2022 August 23
+
+if exists("b:did_indent")
+       finish
+endif
+let b:did_indent = 1
+
+setlocal indentexpr=GetFactorIndent(v:lnum)
+
+let b:undo_indent = 'setlocal indentexpr<'
+
+if exists("*GetFactorIndent")
+       finish
+endif
+
+function! GetFactorIndent(lnum)
+       let cline = getline(a:lnum)
+       let pline = getline(a:lnum-1)
+       let pind = indent(a:lnum-1)
+       if pline =~ '^:'
+               return pind + shiftwidth()
+       endif
+       if pline =~ ';$'
+               return pind - shiftwidth()
+       endif
+       if pline =~ '[{[]$'
+               return pind + shiftwidth()
+       endif
+       if cline =~ '^\s*[\]}]'
+               return pind - shiftwidth()
+       endif
+       return pind
+endfunction