diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-08-26 18:01:12 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-08-26 18:01:12 +0100 |
commit | 7dd543246a4c21c4d5a4242a28076706f5abebd4 (patch) | |
tree | 65ba994a881d011a9b0b77b4ae883048b590138f /runtime/indent/context.vim | |
parent | 2ee347fbc0619179fefb9933e9bb1165463507b3 (diff) |
Update runtime files
Diffstat (limited to 'runtime/indent/context.vim')
-rw-r--r-- | runtime/indent/context.vim | 73 |
1 files changed, 51 insertions, 22 deletions
diff --git a/runtime/indent/context.vim b/runtime/indent/context.vim index 652479f7e2..762c5c16a1 100644 --- a/runtime/indent/context.vim +++ b/runtime/indent/context.vim @@ -1,36 +1,65 @@ -" ConTeXt indent file -" Language: ConTeXt typesetting engine -" Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com> -" Last Change: 2016 Oct 15 +vim9script -if exists("b:did_indent") - finish -endif +# Language: ConTeXt typesetting engine +# Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com> +# Former Maintainers: Nikolai Weibull <now@bitwi.se> +# Latest Revision: 2022 Aug 12 -if !get(b:, 'context_metapost', get(g:, 'context_metapost', 1)) +if exists("b:did_indent") finish endif -" Load MetaPost indentation script +# Load MetaPost indentation script (this will also set b:did_indent) runtime! indent/mp.vim -let s:keepcpo= &cpo -set cpo&vim +setlocal indentexpr=ConTeXtIndent() -setlocal indentexpr=GetConTeXtIndent() +b:undo_indent = "setl indentexpr<" -let b:undo_indent = "setl indentexpr<" +def PrevNotComment(l: number): number + var prevlnum = prevnonblank(l) -function! GetConTeXtIndent() - " Use MetaPost rules inside MetaPost graphic environments + 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 GetMetaPostIndent() + synIDattr(synstack(v:lnum, 1)[0], "name") ==# 'contextMPGraphic' + return g:MetaPostIndent() endif - return -1 -endfunc -let &cpo = s:keepcpo -unlet s:keepcpo + 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 +# vim: sw=2 fdm=marker |