robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa9fd08034
master
1" Language: HCL 2" Maintainer: Gregory Anders 3" Last Change: 2024-09-03 4" Based on: https://github.com/hashivim/vim-terraform 5" License: ISC 6" 7" Copyright (c) 2014-2016 Mark Cornick <mark@markcornick.com> 8" 9" Permission to use, copy, modify, and/or distribute this software for any purpose 10" with or without fee is hereby granted, provided that the above copyright notice 11" and this permission notice appear in all copies. 12" 13" THE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 14" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 15" FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 16" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 17" OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 18" TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 19" THIS SOFTWARE. 20 21function ! hcl#indentexpr ( lnum ) 22" Beginning of the file should have no indent 23if a: lnum == 0 24return 0 25endif 26 27" Usual case is to continue at the same indent as the previous non-blank line. 28let prevlnum = prevnonblank ( a: lnum - 1 ) 29let thisindent = indent ( prevlnum ) 30 31" If that previous line is a non-comment ending in [ { (, increase the 32" indent level. 33let prevline = getline ( prevlnum ) 34if prevline !~# '^\s*\(#\|//\)' && prevline =~# '[\[{\(]\s*$' 35let thisindent += & shiftwidth 36endif 37 38" If the current line ends a block, decrease the indent level. 39let thisline = getline ( a: lnum ) 40if thisline =~# '^\s*[\)}\]]' 41let thisindent -= & shiftwidth 42endif 43 44" If the previous line starts a block comment /*, increase by one 45if prevline =~# '/\*' 46let thisindent += 1 47endif 48 49" If the previous line ends a block comment */, decrease by one 50if prevline =~# '\*/' 51let thisindent -= 1 52endif 53 54return thisindent 55endfunction