comparison runtime/indent/context.vim @ 29885:f00c56ee8118

Update runtime files Commit: https://github.com/vim/vim/commit/7dd543246a4c21c4d5a4242a28076706f5abebd4 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Aug 26 18:01:12 2022 +0100 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Fri, 26 Aug 2022 19:15:05 +0200
parents 07d2b5a3b7cc
children d81556766132
comparison
equal deleted inserted replaced
29884:1eb91db19364 29885:f00c56ee8118
1 " ConTeXt indent file 1 vim9script
2 " Language: ConTeXt typesetting engine 2
3 " Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com> 3 # Language: ConTeXt typesetting engine
4 " Last Change: 2016 Oct 15 4 # Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
5 # Former Maintainers: Nikolai Weibull <now@bitwi.se>
6 # Latest Revision: 2022 Aug 12
5 7
6 if exists("b:did_indent") 8 if exists("b:did_indent")
7 finish 9 finish
8 endif 10 endif
9 11
10 if !get(b:, 'context_metapost', get(g:, 'context_metapost', 1)) 12 # Load MetaPost indentation script (this will also set b:did_indent)
11 finish
12 endif
13
14 " Load MetaPost indentation script
15 runtime! indent/mp.vim 13 runtime! indent/mp.vim
16 14
17 let s:keepcpo= &cpo 15 setlocal indentexpr=ConTeXtIndent()
18 set cpo&vim
19 16
20 setlocal indentexpr=GetConTeXtIndent() 17 b:undo_indent = "setl indentexpr<"
21 18
22 let b:undo_indent = "setl indentexpr<" 19 def PrevNotComment(l: number): number
20 var prevlnum = prevnonblank(l)
23 21
24 function! GetConTeXtIndent() 22 while prevlnum > 0 && getline(prevlnum) =~# '^\s*%'
25 " Use MetaPost rules inside MetaPost graphic environments 23 prevlnum = prevnonblank(prevlnum - 1)
24 endwhile
25
26 return prevlnum
27 enddef
28
29 def FindPair(pstart: string, pmid: string, pend: string): number
30 cursor(v:lnum, 1)
31 return indent(searchpair(pstart, pmid, pend, 'bWn',
32 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'))
33 enddef
34
35 def ConTeXtIndent(): number
36 # Use MetaPost rules inside MetaPost graphic environments
26 if len(synstack(v:lnum, 1)) > 0 && 37 if len(synstack(v:lnum, 1)) > 0 &&
27 \ synIDattr(synstack(v:lnum, 1)[0], "name") ==# 'contextMPGraphic' 38 synIDattr(synstack(v:lnum, 1)[0], "name") ==# 'contextMPGraphic'
28 return GetMetaPostIndent() 39 return g:MetaPostIndent()
29 endif 40 endif
41
42 const prevlnum = PrevNotComment(v:lnum - 1)
43 const prevind = indent(prevlnum)
44 const prevline = getline(prevlnum)
45 const currline = getline(v:lnum)
46
47 # If the current line starts with ], match indentation.
48 if currline =~# '^\s*\]'
49 return FindPair('\[', '', '\]')
50 endif
51
52 # If the current line starts with }, match indentation.
53 if currline =~# '^\s*}'
54 return FindPair('{', '', '}')
55 endif
56
57 # If the previous line ends with [ or { (possibly followed by a comment) then indent.
58 if prevline =~# '[{[]\s*\%(%.*\)\=$'
59 return prevind + shiftwidth()
60 endif
61
30 return -1 62 return -1
31 endfunc 63 enddef
32 64
33 let &cpo = s:keepcpo 65 # vim: sw=2 fdm=marker
34 unlet s:keepcpo
35
36 " vim:sw=2