annotate runtime/indent/mp.vim @ 35209:c7799d9fd100 default tip

runtime(dart): add basic dart ftplugin file Commit: https://github.com/vim/vim/commit/4d7892bfb1dbcc8ba19d9c60c63b3d11b758553f Author: Riley Bruins <ribru17@hotmail.com> Date: Sun May 19 09:31:46 2024 +0200 runtime(dart): add basic dart ftplugin file fixes https://github.com/vim/vim/issues/14793 closes https://github.com/vim/vim/issues/14802 Signed-off-by: Riley Bruins <ribru17@hotmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 19 May 2024 09:45:03 +0200
parents f00c56ee8118
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
1 vim9script
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
2
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
3 # MetaPost indent file
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
4 # Language: MetaPost
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
5 # Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
6 # Former Maintainers: Eugene Minkovskii <emin@mccme.ru>
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
7 # Latest Revision: 2022 Aug 12
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
13 b:did_indent = 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
15 setlocal indentexpr=g:MetaPostIndent()
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
16 setlocal indentkeys+==end,=else,=fi,=fill,0),0]
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
17 setlocal nolisp
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
18 setlocal nosmartindent
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
19
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
20 b:undo_indent = "setl indentexpr< indentkeys< lisp< smartindent<"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
22 # Regexps {{{
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
23 # Expressions starting indented blocks
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
24 const MP_OPEN_TAG = [
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
25 '\<if\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
26 '\<else\%[if]\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
27 '\<for\%(\|ever\|suffixes\)\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
28 '\<begingroup\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
29 '\<\%(\|var\|primary\|secondary\|tertiary\)def\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
30 '^\s*\<begin\%(fig\|graph\|glyph\|char\|logochar\)\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
31 '[([{]',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
32 ]->extend(get(g:, "mp_open_tag", []))->join('\|')
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
33
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
34 # Expressions ending indented blocks
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
35 const MP_CLOSE_TAG = [
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
36 '\<fi\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
37 '\<else\%[if]\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
38 '\<end\%(\|for\|group\|def\|fig\|char\|glyph\|graph\)\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
39 '[)\]}]'
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
40 ]->extend(get(g:, "mp_close_tag", []))->join('\|')
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
41
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
42 # Statements that may span multiple lines and are ended by a semicolon. To
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
43 # keep this list short, statements that are unlikely to be very long or are
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
44 # not very common (e.g., keywords like `interim` or `showtoken`) are not
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
45 # included.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
46 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
47 # The regex for assignments and equations (the last branch) is tricky, because
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
48 # it must not match things like `for i :=`, `if a=b`, `def...=`, etc... It is
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
49 # not perfect, but it works reasonably well.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
50 const MP_STATEMENT = [
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
51 '\<\%(\|un\|cut\)draw\%(dot\)\=\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
52 '\<\%(\|un\)fill\%[draw]\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
53 '\<draw\%(dbl\)\=arrow\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
54 '\<clip\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
55 '\<addto\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
56 '\<save\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
57 '\<setbounds\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
58 '\<message\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
59 '\<errmessage\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
60 '\<errhelp\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
61 '\<fontmapline\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
62 '\<pickup\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
63 '\<show\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
64 '\<special\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
65 '\<write\>',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
66 '\%(^\|;\)\%([^;=]*\%(' .. MP_OPEN_TAG .. '\)\)\@!.\{-}:\==',
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
67 ]->join('\|')
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
68
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
69 # A line ends with zero or more spaces, possibly followed by a comment.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
70 const EOL = '\s*\%($\|%\)'
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
71 # }}}
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
72
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
73 # Auxiliary functions {{{
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
74 # Returns true if (0-based) position immediately preceding `pos` in `line` is
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
75 # inside a string or a comment; returns false otherwise.
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
76
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
77 # This is the function that is called more often when indenting, so it is
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
78 # critical that it is efficient. The method we use is significantly faster
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
79 # than using syntax attributes, and more general (it does not require
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
80 # syntax_items). It is also faster than using a single regex matching an even
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
81 # number of quotes. It helps that MetaPost strings cannot span more than one
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
82 # line and cannot contain escaped quotes.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
83 def IsCommentOrString(line: string, pos: number): bool
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
84 var in_string = 0
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
85 var q = stridx(line, '"')
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
86 var c = stridx(line, '%')
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
87
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
88 while q >= 0 && q < pos
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
89 if c >= 0 && c < q
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
90 if in_string # Find next percent symbol
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
91 c = stridx(line, '%', q + 1)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
92 else # Inside comment
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
93 return true
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
94 endif
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
95 endif
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
96 in_string = 1 - in_string
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
97 q = stridx(line, '"', q + 1) # Find next quote
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 endwhile
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
99
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
100 return in_string || (c >= 0 && c <= pos)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
101 enddef
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
103 # Find the first non-comment non-blank line before the given line.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
104 def PrevNonBlankNonComment(lnum: number): number
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
105 var nr = prevnonblank(lnum - 1)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
106 while getline(nr) =~# '^\s*%'
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
107 nr = prevnonblank(nr - 1)
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
108 endwhile
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
109 return nr
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
110 enddef
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
111
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
112 # Returns true if the last tag appearing in the line is an open tag; returns
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
113 # false otherwise.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
114 def LastTagIsOpen(line: string): bool
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
115 var o = LastValidMatchEnd(line, MP_OPEN_TAG, 0)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
116 if o == - 1
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
117 return false
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
118 endif
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
119 return LastValidMatchEnd(line, MP_CLOSE_TAG, o) < 0
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
120 enddef
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
121
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
122 # A simple, efficient and quite effective heuristics is used to test whether
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
123 # a line should cause the next line to be indented: count the "opening tags"
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
124 # (if, for, def, ...) in the line, count the "closing tags" (endif, endfor,
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
125 # ...) in the line, and compute the difference. We call the result the
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
126 # "weight" of the line. If the weight is positive, then the next line should
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
127 # most likely be indented. Note that `else` and `elseif` are both opening and
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
128 # closing tags, so they "cancel out" in almost all cases, the only exception
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
129 # being a leading `else[if]`, which is counted as an opening tag, but not as
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
130 # a closing tag (so that, for instance, a line containing a single `else:`
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
131 # will have weight equal to one, not zero). We do not treat a trailing
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
132 # `else[if]` in any special way, because lines ending with an open tag are
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
133 # dealt with separately before this function is called (see MetaPostIndent()).
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
134 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
135 # Example:
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
136 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
137 # forsuffixes $=a,b: if x.$ = y.$ : draw else: fill fi
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
138 # % This line will be indented because |{forsuffixes,if,else}| > |{else,fi}| (3 > 2)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
139 # endfor
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
140 def Weight(line: string): number
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
141 var o = 0
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
142 var i = ValidMatchEnd(line, MP_OPEN_TAG, 0)
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
143 while i > 0
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
144 o += 1
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
145 i = ValidMatchEnd(line, MP_OPEN_TAG, i)
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
146 endwhile
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
147 var c = 0
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
148 i = matchend(line, '^\s*\<else\%[if]\>') # Skip a leading else[if]
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
149 i = ValidMatchEnd(line, MP_CLOSE_TAG, i)
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
150 while i > 0
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
151 c += 1
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
152 i = ValidMatchEnd(line, MP_CLOSE_TAG, i)
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
153 endwhile
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
154 return o - c
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
155 enddef
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
156
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
157 # Similar to matchend(), but skips strings and comments.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
158 # line: a String
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
159 def ValidMatchEnd(line: string, pat: string, start: number): number
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
160 var i = matchend(line, pat, start)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
161 while i > 0 && IsCommentOrString(line, i)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
162 i = matchend(line, pat, i)
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
163 endwhile
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
164 return i
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
165 enddef
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
166
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
167 # Like s:ValidMatchEnd(), but returns the end position of the last (i.e.,
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
168 # rightmost) match.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
169 def LastValidMatchEnd(line: string, pat: string, start: number): number
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
170 var last_found = -1
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
171 var i = matchend(line, pat, start)
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
172 while i > 0
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
173 if !IsCommentOrString(line, i)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
174 last_found = i
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
175 endif
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
176 i = matchend(line, pat, i)
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
177 endwhile
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
178 return last_found
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
179 enddef
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
181 def DecreaseIndentOnClosingTag(curr_indent: number): number
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
182 var cur_text = getline(v:lnum)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
183 if cur_text =~# '^\s*\%(' .. MP_CLOSE_TAG .. '\)'
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
184 return max([curr_indent - shiftwidth(), 0])
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
185 endif
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
186 return curr_indent
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
187 enddef
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
188 # }}}
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
189
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
190 # Main function {{{
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
191 def g:MetaPostIndent(): number
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
192 # Do not touch indentation inside verbatimtex/btex.. etex blocks.
10261
bdd7fc1a38c0 commit https://github.com/vim/vim/commit/dc08328821a2c11e33dfb1980332e4923ec64fca
Christian Brabandt <cb@256bit.org>
parents: 10244
diff changeset
193 if synIDattr(synID(v:lnum, 1, 1), "name") =~# '^mpTeXinsert$\|^tex\|^Delimiter'
bdd7fc1a38c0 commit https://github.com/vim/vim/commit/dc08328821a2c11e33dfb1980332e4923ec64fca
Christian Brabandt <cb@256bit.org>
parents: 10244
diff changeset
194 return -1
bdd7fc1a38c0 commit https://github.com/vim/vim/commit/dc08328821a2c11e33dfb1980332e4923ec64fca
Christian Brabandt <cb@256bit.org>
parents: 10244
diff changeset
195 endif
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
196
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
197 # At the start of a MetaPost block inside ConTeXt, do not touch indentation
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
198 if synIDattr(synID(prevnonblank(v:lnum - 1), 1, 1), "name") == "contextBlockDelim"
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
199 return -1
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
200 endif
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
201
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
202 var lnum = PrevNonBlankNonComment(v:lnum)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
203
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
204 # At the start of the file use zero indent.
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
205 if lnum == 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 endif
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
208
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
209 var prev_text = getline(lnum)
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
210
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
211 # Every rule of indentation in MetaPost is very subjective. We might get
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
212 # creative, but things get murky very soon (there are too many corner
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
213 # cases). So, we provide a means for the user to decide what to do when this
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
214 # script doesn't get it. We use a simple idea: use '%>', '%<', '%=', and
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
215 # '%!', to explicitly control indentation. The '<' and '>' symbols may be
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
216 # repeated many times (e.g., '%>>' will cause the next line to be indented
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
217 # twice).
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
218 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
219 # User-defined overrides take precedence over anything else.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
220 var j = match(prev_text, '%[<>=!]')
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
221 if j > 0
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
222 var i = strlen(matchstr(prev_text, '%>\+', j)) - 1
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
223 if i > 0
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
224 return indent(lnum) + i * shiftwidth()
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
225 endif
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
226
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
227 i = strlen(matchstr(prev_text, '%<\+', j)) - 1
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
228 if i > 0
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
229 return max([indent(lnum) - i * shiftwidth(), 0])
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
230 endif
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
231
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
232 if match(prev_text, '%=', j) > -1
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
233 return indent(lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 endif
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
235
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
236 if match(prev_text, '%!', j) > -1
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
237 return -1
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
238 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 endif
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
240
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
241 # If the reference line ends with an open tag, indent.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
242 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
243 # Example:
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
244 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
245 # if c:
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
246 # 0
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
247 # else:
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
248 # 1
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
249 # fi if c2: % Note that this line has weight equal to zero.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
250 # ... % This line will be indented
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
251 if LastTagIsOpen(prev_text)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
252 return DecreaseIndentOnClosingTag(indent(lnum) + shiftwidth())
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
253 endif
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
254
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
255 # Lines with a positive weight are unbalanced and should likely be indented.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
256 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
257 # Example:
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
258 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
259 # def f = enddef for i = 1 upto 5: if x[i] > 0: 1 else: 2 fi
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
260 # ... % This line will be indented (because of the unterminated `for`)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
261 if Weight(prev_text) > 0
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
262 return DecreaseIndentOnClosingTag(indent(lnum) + shiftwidth())
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 endif
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
264
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
265 # Unterminated statements cause indentation to kick in.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
266 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
267 # Example:
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
268 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
269 # draw unitsquare
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
270 # withcolor black; % This line is indented because of `draw`.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
271 # x := a + b + c
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
272 # + d + e; % This line is indented because of `:=`.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
273 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
274 var i = LastValidMatchEnd(prev_text, MP_STATEMENT, 0)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
275 if i >= 0 # Does the line contain a statement?
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
276 if ValidMatchEnd(prev_text, ';', i) < 0 # Is the statement unterminated?
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
277 return indent(lnum) + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 else
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
279 return DecreaseIndentOnClosingTag(indent(lnum))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
283 # Deal with the special case of a statement spanning multiple lines. If the
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
284 # current reference line L ends with a semicolon, search backwards for
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
285 # another semicolon or a statement keyword. If the latter is found first,
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
286 # its line is used as the reference line for indenting the current line
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
287 # instead of L.
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
288 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
289 # Example:
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
290 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
291 # if cond:
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
292 # draw if a: z0 else: z1 fi
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
293 # shifted S
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
294 # scaled T; % L
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
295 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
296 # for i = 1 upto 3: % <-- Current line: this gets the same indent as `draw ...`
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
297 #
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
298 # NOTE: we get here only if L does not contain a statement (among those
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
299 # listed in g:MP_STATEMENT).
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
300 if ValidMatchEnd(prev_text, ';' .. EOL, 0) >= 0 # L ends with a semicolon
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
301 var stm_lnum = PrevNonBlankNonComment(lnum)
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
302 while stm_lnum > 0
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
303 prev_text = getline(stm_lnum)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
304 var sc_pos = LastValidMatchEnd(prev_text, ';', 0)
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
305 var stm_pos = ValidMatchEnd(prev_text, MP_STATEMENT, sc_pos)
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
306 if stm_pos > sc_pos
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
307 lnum = stm_lnum
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
308 break
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
309 elseif sc_pos > stm_pos
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
310 break
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
311 endif
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
312 stm_lnum = PrevNonBlankNonComment(stm_lnum)
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
313 endwhile
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
314 endif
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 3526
diff changeset
315
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
316 return DecreaseIndentOnClosingTag(indent(lnum))
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
317 enddef
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
318 # }}}
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319
29885
f00c56ee8118 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
320 # vim: sw=2 fdm=marker