robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
fc1cdb8821
master
1" Vim indent file 2" Language: Hamster Script 3" Version: 2.0.6.1 4" Last Change: 2021 Oct 11 5" Maintainer: David Fishburn <dfishburn dot vim at gmail dot com> 6" Download: https://www.vim.org/scripts/script.php?script_id=1099 7" 8" 2.0.6.1 (Oct 2021) 9" Added b:undo_indent 10" Added cpo check 11" 12 13" Only load this indent file when no other was loaded. 14if exists ( "b:did_indent" ) 15finish 16endif 17let b: did_indent = 1 18 19setlocal indentkeys += =~if,=~else,=~endif,=~endfor,=~endwhile 20setlocal indentkeys += =~do,=~until,=~while,=~repeat,=~for,=~loop 21setlocal indentkeys += =~sub,=~endsub 22 23let b: undo_indent = "setl indentkeys<" 24 25" Define the appropriate indent function but only once 26setlocal indentexpr = HamGetFreeIndent () 27if exists ( "*HamGetFreeIndent" ) 28finish 29endif 30 31let s: keepcpo = & cpo 32set cpo & vim 33 34function HamGetIndent ( lnum ) 35let ind = indent ( a: lnum ) 36let prevline = getline ( a: lnum ) 37 38" Add a shiftwidth to statements following if, else, elseif, 39" case, select, default, do, until, while, for, start 40if prevline =~? '^\s*\<\(if\|else\%(if\)\?\|for\|repeat\|do\|while\|sub\)\>' 41let ind = ind + shiftwidth () 42endif 43 44" Subtract a shiftwidth from else, elseif, end(if|while|for), until 45let line = getline ( v: lnum ) 46if line =~? '^\s*\(else\|elseif\|loop\|until\|end\%(if\|while\|for\|sub\)\)\>' 47let ind = ind - shiftwidth () 48endif 49 50return ind 51endfunction 52 53function HamGetFreeIndent () 54" Find the previous non-blank line 55let lnum = prevnonblank ( v: lnum - 1 ) 56 57" Use zero indent at the top of the file 58if lnum == 0 59return 0 60endif 61 62let ind = HamGetIndent ( lnum ) 63return ind 64endfunction 65 66" Restore: 67let & cpo = s: keepcpo 68unlet s: keepcpo 69 70" vim:sw=2 tw=80