diff options
Diffstat (limited to 'mnv/runtime/autoload/hcl.mnv')
| -rw-r--r-- | mnv/runtime/autoload/hcl.mnv | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/mnv/runtime/autoload/hcl.mnv b/mnv/runtime/autoload/hcl.mnv new file mode 100644 index 0000000000..85b150ab96 --- /dev/null +++ b/mnv/runtime/autoload/hcl.mnv @@ -0,0 +1,55 @@ +" Language: HCL +" Maintainer: Gregory Anders +" Last Change: 2024-09-03 +" Based on: https://github.com/hashimnv/mnv-terraform +" License: ISC +" +" Copyright (c) 2014-2016 Mark Cornick <mark@markcornick.com> +" +" Permission to use, copy, modify, and/or distribute this software for any purpose +" with or without fee is hereby granted, provided that the above copyright notice +" and this permission notice appear in all copies. +" +" THE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +" FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +" OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +" TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +" THIS SOFTWARE. + +function! hcl#indentexpr(lnum) + " Beginning of the file should have no indent + if a:lnum == 0 + return 0 + endif + + " Usual case is to continue at the same indent as the previous non-blank line. + let prevlnum = prevnonblank(a:lnum-1) + let thisindent = indent(prevlnum) + + " If that previous line is a non-comment ending in [ { (, increase the + " indent level. + let prevline = getline(prevlnum) + if prevline !~# '^\s*\(#\|//\)' && prevline =~# '[\[{\(]\s*$' + let thisindent += &shiftwidth + endif + + " If the current line ends a block, decrease the indent level. + let thisline = getline(a:lnum) + if thisline =~# '^\s*[\)}\]]' + let thisindent -= &shiftwidth + endif + + " If the previous line starts a block comment /*, increase by one + if prevline =~# '/\*' + let thisindent += 1 + endif + + " If the previous line ends a block comment */, decrease by one + if prevline =~# '\*/' + let thisindent -= 1 + endif + + return thisindent +endfunction |
