Have you tried 'lisp'
option? It produces
[foo [bar baz] [qux
[do a thing]
[more doing a thing]
[^ ()
; some stuff here
[foobar]]]]
[back to here]
on your example.
You can also construct your own indentexpr
. Very simple one will be
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
if exists('*shiftwidth')
let s:shiftwidth=function('shiftwidth')
else
function s:shiftwidth()
return &shiftwidth
endfunction
endif
function! YourLangIndent(lnum)
if a:lnum==1
return 0
endif
let line=getline(a:lnum-1)
return indent(prevnonblank(a:lnum-1))+s:shiftwidth()*(len(substitute(line, '[^[]', '', 'g'))-len(substitute(line, '[^]]', '', 'g')))
endfunction
setlocal indentexpr=YourLangIndent(v:lnum)
let b:undo_indent='setlocal indentexpr<'
. Its result:
[foo [bar baz] [qux
[do a thing]
[more doing a thing]
[^ ()
; some stuff here
[foobar]]]]
[back to here]
(for &sw
set to 4, half the amount of spaces for &sw
set to 2).