annotate runtime/indent/ocaml.vim @ 29560:14b139cbec49 v9.0.0121

patch 9.0.0121: cannot put virtual text after or below a line Commit: https://github.com/vim/vim/commit/b7963df98f9dbbb824713acad2f47c9989fcf8f3 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 31 17:12:43 2022 +0100 patch 9.0.0121: cannot put virtual text after or below a line Problem: Cannot put virtual text after or below a line. Solution: Add "text_align" and "text_wrap" arguments.
author Bram Moolenaar <Bram@vim.org>
date Sun, 31 Jul 2022 18:15:03 +0200
parents 15fa3923cc49
children 5c220cf30f1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
2 " Language: OCaml
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
3 " Maintainers: Jean-Francois Yuen <jfyuen@happycoders.org>
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
4 " Mike Leary <leary@nwlink.com>
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
5 " Markus Mottl <markus.mottl@gmail.com>
23466
15fa3923cc49 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
6 " URL: https://github.com/ocaml/vim-ocaml
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5055
diff changeset
7 " Last Change: 2017 Jun 13
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
8 " 2005 Jun 25 - Fixed multiple bugs due to 'else\nreturn ind' working
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
9 " 2005 May 09 - Added an option to not indent OCaml-indents specially (MM)
5055
c458ff35497e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3312
diff changeset
10 " 2013 June - commented textwidth (Marc Weber)
c458ff35497e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3312
diff changeset
11 "
c458ff35497e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3312
diff changeset
12 " Marc Weber's comment: This file may contain a lot of (very custom) stuff
c458ff35497e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3312
diff changeset
13 " which eventually should be moved somewhere else ..
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 if exists("b:did_indent")
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
17 finish
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 setlocal expandtab
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 setlocal indentexpr=GetOCamlIndent()
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
23 setlocal indentkeys+=0=and,0=class,0=constraint,0=done,0=else,0=end,0=exception,0=external,0=if,0=in,0=include,0=inherit,0=initializer,0=let,0=method,0=open,0=then,0=type,0=val,0=with,0;;,0>\],0\|\],0>},0\|,0},0\],0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 setlocal nolisp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 setlocal nosmartindent
5055
c458ff35497e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3312
diff changeset
26
c458ff35497e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3312
diff changeset
27 " At least Marc Weber and Markus Mottl do not like this:
c458ff35497e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3312
diff changeset
28 " setlocal textwidth=80
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 " Comment formatting
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
31 if !exists("no_ocaml_comments")
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
32 if (has("comments"))
23466
15fa3923cc49 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
33 setlocal comments=sr:(*\ ,mb:\ ,ex:*)
15fa3923cc49 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
34 setlocal comments^=sr:(**,mb:\ \ ,ex:*)
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
35 setlocal fo=cqort
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
36 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 if exists("*GetOCamlIndent")
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
41 finish
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 " Define some patterns:
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
45 let s:beflet = '^\s*\(initializer\|method\|try\)\|\(\<\(begin\|do\|else\|in\|then\|try\)\|->\|<-\|=\|;\|(\)\s*$'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 let s:letpat = '^\s*\(let\|type\|module\|class\|open\|exception\|val\|include\|external\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 let s:letlim = '\(\<\(sig\|struct\)\|;;\)\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 let s:lim = '^\s*\(exception\|external\|include\|let\|module\|open\|type\|val\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 let s:module = '\<\%(begin\|sig\|struct\|object\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 let s:obj = '^\s*\(constraint\|inherit\|initializer\|method\|val\)\>\|\<\(object\|object\s*(.*)\)\s*$'
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
51 let s:type = '^\s*\%(class\|let\|type\)\>.*='
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 " Skipping pattern, for comments
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
54 function! s:GetLineWithoutFullComment(lnum)
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
55 let lnum = prevnonblank(a:lnum - 1)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
56 let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
57 while lline =~ '^\s*$' && lnum > 0
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
58 let lnum = prevnonblank(lnum - 1)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
59 let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
60 endwhile
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
61 return lnum
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 " Indent for ';;' to match multiple 'let'
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
65 function! s:GetInd(lnum, pat, lim)
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
66 let llet = search(a:pat, 'bW')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
67 let old = indent(a:lnum)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
68 while llet > 0
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
69 let old = indent(llet)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
70 let nb = s:GetLineWithoutFullComment(llet)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
71 if getline(nb) =~ a:lim
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
72 return old
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
73 endif
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
74 let llet = search(a:pat, 'bW')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
75 endwhile
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
76 return old
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 " Indent pairs
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
80 function! s:FindPair(pstart, pmid, pend)
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
81 call search(a:pend, 'bW')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
82 return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 " Indent 'let'
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
86 function! s:FindLet(pstart, pmid, pend)
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
87 call search(a:pend, 'bW')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
88 return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment" || getline(".") =~ "^\\s*let\\>.*=.*\\<in\\s*$" || getline(prevnonblank(".") - 1) =~ s:beflet'))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
91 function! GetOCamlIndent()
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
92 " Find a non-commented line above the current line.
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
93 let lnum = s:GetLineWithoutFullComment(v:lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
95 " At the start of the file use zero indent.
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
96 if lnum == 0
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
97 return 0
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
98 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
100 let ind = indent(lnum)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
101 let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
103 " Return double 'shiftwidth' after lines matching:
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
104 if lline =~ '^\s*|.*->\s*$'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5055
diff changeset
105 return ind + 2 * shiftwidth()
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
106 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
108 let line = getline(v:lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
110 " Indent if current line begins with 'end':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
111 if line =~ '^\s*end\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
112 return s:FindPair(s:module, '','\<end\>')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
114 " Indent if current line begins with 'done' for 'do':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
115 elseif line =~ '^\s*done\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
116 return s:FindPair('\<do\>', '','\<done\>')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
118 " Indent if current line begins with '}' or '>}':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
119 elseif line =~ '^\s*\(\|>\)}'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
120 return s:FindPair('{', '','}')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
122 " Indent if current line begins with ']', '|]' or '>]':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
123 elseif line =~ '^\s*\(\||\|>\)\]'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
124 return s:FindPair('\[', '','\]')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
126 " Indent if current line begins with ')':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
127 elseif line =~ '^\s*)'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
128 return s:FindPair('(', '',')')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
130 " Indent if current line begins with 'let':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
131 elseif line =~ '^\s*let\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
132 if lline !~ s:lim . '\|' . s:letlim . '\|' . s:beflet
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
133 return s:FindLet(s:type, '','\<let\s*$')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
134 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
136 " Indent if current line begins with 'class' or 'type':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
137 elseif line =~ '^\s*\(class\|type\)\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
138 if lline !~ s:lim . '\|\<and\s*$\|' . s:letlim
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
139 return s:FindLet(s:type, '','\<\(class\|type\)\s*$')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
140 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
142 " Indent for pattern matching:
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
143 elseif line =~ '^\s*|'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
144 if lline !~ '^\s*\(|[^\]]\|\(match\|type\|with\)\>\)\|\<\(function\|parser\|private\|with\)\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
145 call search('|', 'bW')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
146 return indent(searchpair('^\s*\(match\|type\)\>\|\<\(function\|parser\|private\|with\)\s*$', '', '^\s*|', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment" || getline(".") !~ "^\\s*|.*->"'))
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
147 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
149 " Indent if current line begins with ';;':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
150 elseif line =~ '^\s*;;'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
151 if lline !~ ';;\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
152 return s:GetInd(v:lnum, s:letpat, s:letlim)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
153 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
155 " Indent if current line begins with 'in':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
156 elseif line =~ '^\s*in\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
157 if lline !~ '^\s*\(let\|and\)\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
158 return s:FindPair('\<let\>', '', '\<in\>')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
159 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
161 " Indent if current line begins with 'else':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
162 elseif line =~ '^\s*else\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
163 if lline !~ '^\s*\(if\|then\)\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
164 return s:FindPair('\<if\>', '', '\<else\>')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
165 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
167 " Indent if current line begins with 'then':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
168 elseif line =~ '^\s*then\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
169 if lline !~ '^\s*\(if\|else\)\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
170 return s:FindPair('\<if\>', '', '\<then\>')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
171 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
173 " Indent if current line begins with 'and':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
174 elseif line =~ '^\s*and\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
175 if lline !~ '^\s*\(and\|let\|type\)\>\|\<end\s*$'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5055
diff changeset
176 return ind - shiftwidth()
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
177 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
179 " Indent if current line begins with 'with':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
180 elseif line =~ '^\s*with\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
181 if lline !~ '^\s*\(match\|try\)\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
182 return s:FindPair('\<\%(match\|try\)\>', '','\<with\>')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
183 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
185 " Indent if current line begins with 'exception', 'external', 'include' or
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
186 " 'open':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
187 elseif line =~ '^\s*\(exception\|external\|include\|open\)\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
188 if lline !~ s:lim . '\|' . s:letlim
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
189 call search(line)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
190 return indent(search('^\s*\(\(exception\|external\|include\|open\|type\)\>\|val\>.*:\)', 'bW'))
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
191 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
193 " Indent if current line begins with 'val':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
194 elseif line =~ '^\s*val\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
195 if lline !~ '^\s*\(exception\|external\|include\|open\)\>\|' . s:obj . '\|' . s:letlim
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
196 return indent(search('^\s*\(\(exception\|include\|initializer\|method\|open\|type\|val\)\>\|external\>.*:\)', 'bW'))
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
197 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
199 " Indent if current line begins with 'constraint', 'inherit', 'initializer'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
200 " or 'method':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
201 elseif line =~ '^\s*\(constraint\|inherit\|initializer\|method\)\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
202 if lline !~ s:obj
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5055
diff changeset
203 return indent(search('\<\(object\|object\s*(.*)\)\s*$', 'bW')) + shiftwidth()
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
204 endif
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
205
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
206 endif
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
207
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
208 " Add a 'shiftwidth' after lines ending with:
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
209 if lline =~ '\(:\|=\|->\|<-\|(\|\[\|{\|{<\|\[|\|\[<\|\<\(begin\|do\|else\|fun\|function\|functor\|if\|initializer\|object\|parser\|private\|sig\|struct\|then\|try\)\|\<object\s*(.*)\)\s*$'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5055
diff changeset
210 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
212 " Back to normal indent after lines ending with ';;':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
213 elseif lline =~ ';;\s*$' && lline !~ '^\s*;;'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
214 let ind = s:GetInd(v:lnum, s:letpat, s:letlim)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
216 " Back to normal indent after lines ending with 'end':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
217 elseif lline =~ '\<end\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
218 let ind = s:FindPair(s:module, '','\<end\>')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
220 " Back to normal indent after lines ending with 'in':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
221 elseif lline =~ '\<in\s*$' && lline !~ '^\s*in\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
222 let ind = s:FindPair('\<let\>', '', '\<in\>')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
224 " Back to normal indent after lines ending with 'done':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
225 elseif lline =~ '\<done\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
226 let ind = s:FindPair('\<do\>', '','\<done\>')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
228 " Back to normal indent after lines ending with '}' or '>}':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
229 elseif lline =~ '\(\|>\)}\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
230 let ind = s:FindPair('{', '','}')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
232 " Back to normal indent after lines ending with ']', '|]' or '>]':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
233 elseif lline =~ '\(\||\|>\)\]\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
234 let ind = s:FindPair('\[', '','\]')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
236 " Back to normal indent after comments:
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
237 elseif lline =~ '\*)\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
238 call search('\*)', 'bW')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
239 let ind = indent(searchpair('(\*', '', '\*)', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"'))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
241 " Back to normal indent after lines ending with ')':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
242 elseif lline =~ ')\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
243 let ind = s:FindPair('(', '',')')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
245 " If this is a multiline comment then align '*':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
246 elseif lline =~ '^\s*(\*' && line =~ '^\s*\*'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
247 let ind = ind + 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
249 else
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
250 " Don't change indentation of this line
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
251 " for new lines (indent==0) use indentation of previous line
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
252
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
253 " This is for preventing removing indentation of these args:
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
254 " let f x =
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
255 " let y = x + 1 in
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
256 " Printf.printf
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
257 " "o" << here
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
258 " "oeuth" << don't touch indentation
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
259
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
260 let i = indent(v:lnum)
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
261 return i == 0 ? ind : i
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 1121
diff changeset
262
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
263 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
265 " Subtract a 'shiftwidth' after lines matching 'match ... with parser':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
266 if lline =~ '\<match\>.*\<with\>\s*\<parser\s*$'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5055
diff changeset
267 let ind = ind - shiftwidth()
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
268 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
270 return ind
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 " vim:sw=2