annotate runtime/indent/ocaml.vim @ 34028:bcf1429cb1fc v9.0.2188

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