diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:09:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:09:20 +0000 |
commit | 029f72b1a93430b24b88eb3a72c6114d9f149737 (patch) | |
tree | 765d5c2041967f9c6fef195fe343d9234a030e90 /runtime/indent/context.vim | |
parent | Initial commit. (diff) | |
download | vim-029f72b1a93430b24b88eb3a72c6114d9f149737.tar.xz vim-029f72b1a93430b24b88eb3a72c6114d9f149737.zip |
Adding upstream version 2:9.1.0016.upstream/2%9.1.0016
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'runtime/indent/context.vim')
-rw-r--r-- | runtime/indent/context.vim | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/runtime/indent/context.vim b/runtime/indent/context.vim new file mode 100644 index 0000000..9656151 --- /dev/null +++ b/runtime/indent/context.vim @@ -0,0 +1,65 @@ +vim9script + +# Language: ConTeXt typesetting engine +# Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com> +# Former Maintainers: Nikolai Weibull <now@bitwi.se> +# Latest Revision: 2023 Dec 26 + +if exists("b:did_indent") + finish +endif + +# Load MetaPost indentation script (this will also set b:did_indent) +runtime! indent/mp.vim + +setlocal indentexpr=ConTeXtIndent() + +b:undo_indent = "setl indentexpr<" + +def PrevNotComment(l: number): number + var prevlnum = prevnonblank(l) + + while prevlnum > 0 && getline(prevlnum) =~# '^\s*%' + prevlnum = prevnonblank(prevlnum - 1) + endwhile + + return prevlnum +enddef + +def FindPair(pstart: string, pmid: string, pend: string): number + cursor(v:lnum, 1) + return indent(searchpair(pstart, pmid, pend, 'bWn', + 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"')) +enddef + +def ConTeXtIndent(): number + # Use MetaPost rules inside MetaPost graphic environments + if len(synstack(v:lnum, 1)) > 0 && + synIDattr(synstack(v:lnum, 1)[0], "name") ==# 'contextMPGraphic' + return g:MetaPostIndent() + endif + + const prevlnum = PrevNotComment(v:lnum - 1) + const prevind = indent(prevlnum) + const prevline = getline(prevlnum) + const currline = getline(v:lnum) + + # If the current line starts with ], match indentation. + if currline =~# '^\s*\]' + return FindPair('\[', '', '\]') + endif + + # If the current line starts with }, match indentation. + if currline =~# '^\s*}' + return FindPair('{', '', '}') + endif + + # If the previous line ends with [ or { (possibly followed by a comment) then indent. + if prevline =~# '[{[]\s*\%(%.*\)\=$' + return prevind + shiftwidth() + endif + + return -1 +enddef + +# vim: sw=2 fdm=marker |