Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
context.vim66 linesDownload Raw Back to indent
1vim9script2 3# Language:           ConTeXt typesetting engine4# Maintainer:         Nicola Vitacolonna <nvitacolonna@gmail.com>5# Former Maintainers: Nikolai Weibull <now@bitwi.se>6# Latest Revision:    2026 Jan 107 8if exists("b:did_indent")9  finish10endif11 12# Load MetaPost indentation script (this will also set b:did_indent)13runtime! indent/mp.vim14 15setlocal indentexpr=ConTeXtIndent()16 17b:undo_indent = "setl indentexpr<"18 19def PrevNotComment(l: number): number20  var prevlnum = prevnonblank(l)21 22  while prevlnum > 0 && getline(prevlnum) =~# '^\s*%'23    prevlnum = prevnonblank(prevlnum - 1)24  endwhile25 26  return prevlnum27enddef28 29def FindPair(pstart: string, pmid: string, pend: string): number30  cursor(v:lnum, 1)31  return indent(searchpair(pstart, pmid, pend, 'bWn',32    'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'))33enddef34 35def ConTeXtIndent(): number36  # Use MetaPost rules inside MetaPost graphic environments37  if len(synstack(v:lnum, 1)) > 0 &&38    synIDattr(synstack(v:lnum, 1)[0], "name") ==# 'contextMPGraphic'39    return g:MetaPostIndent()40  endif41 42  var prevlnum = PrevNotComment(v:lnum - 1)43  var prevind  = indent(prevlnum)44  var prevline = getline(prevlnum)45  var currline = getline(v:lnum)46 47  # If the current line starts with ], match indentation.48  if currline =~# '^\s*\]'49    return FindPair('\[', '', '\]')50  endif51 52  # If the current line starts with }, match indentation.53  if currline =~# '^\s*}'54    return FindPair('{', '', '}')55  endif56 57  # If the previous line ends with [ or { (possibly followed by a comment) then indent.58  if prevline =~# '[{[]\s*\%(%.*\)\=$'59    return prevind + shiftwidth()60  endif61 62  return -163enddef64 65# vim: sw=2 fdm=marker66 
codekingpro/portable-devtools · Team Ai