annotate runtime/indent/elm.vim @ 20905:802bf80bcfe4 v8.2.1004

patch 8.2.1004: line numbers below filler lines not always updated Commit: https://github.com/vim/vim/commit/511feec6f0a9e954f1d7353425fa51232b1a8e88 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jun 18 19:15:27 2020 +0200 patch 8.2.1004: line numbers below filler lines not always updated Problem: Line numbers below filler lines not always updated. Solution: Don't break out of the win_line() loop too early. (Christian Brabandt, closes #6294, closes #6138)
author Bram Moolenaar <Bram@vim.org>
date Thu, 18 Jun 2020 19:30:04 +0200
parents 661eb972cb22
children 9c221ad9634a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20753
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Elm indent plugin file
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 " Language: Elm
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 " Maintainer: Andreas Scharf <as@99n.de>
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 " Original Author: Joseph Hager <ajhager@gmail.com>
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 " Copyright: Joseph Hager <ajhager@gmail.com>
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 " License: BSD3
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 " Latest Revision: 2020-05-29
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 " Only load this indent file when no other was loaded.
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 if exists('b:did_indent')
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 finish
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 endif
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 let b:did_indent = 1
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 " Local defaults
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 setlocal expandtab
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 setlocal indentexpr=GetElmIndent()
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 setlocal indentkeys+=0=else,0=if,0=of,0=import,0=then,0=type,0\|,0},0\],0),=-},0=in
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 setlocal nolisp
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 setlocal nosmartindent
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 " Only define the function once.
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 if exists('*GetElmIndent')
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 finish
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 endif
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 " Indent pairs
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 function! s:FindPair(pstart, pmid, pend)
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 "call search(a:pend, 'bW')
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'))
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 endfunction
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 function! GetElmIndent()
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 let l:lnum = v:lnum - 1
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 " Ident 0 if the first line of the file:
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 if l:lnum == 0
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 return 0
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 endif
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 let l:ind = indent(l:lnum)
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 let l:lline = getline(l:lnum)
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 let l:line = getline(v:lnum)
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 " Indent if current line begins with '}':
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 if l:line =~? '^\s*}'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 return s:FindPair('{', '', '}')
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 " Indent if current line begins with 'else':
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 elseif l:line =~# '^\s*else\>'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 if l:lline !~# '^\s*\(if\|then\)\>'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 return s:FindPair('\<if\>', '', '\<else\>')
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 endif
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 " Indent if current line begins with 'then':
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 elseif l:line =~# '^\s*then\>'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 if l:lline !~# '^\s*\(if\|else\)\>'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 return s:FindPair('\<if\>', '', '\<then\>')
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 endif
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 " HACK: Indent lines in case with nearest case clause:
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 elseif l:line =~# '->' && l:line !~# ':' && l:line !~# '\\'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 return indent(search('^\s*case', 'bWn')) + &shiftwidth
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 " HACK: Don't change the indentation if the last line is a comment.
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 elseif l:lline =~# '^\s*--'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 return l:ind
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 " Align the end of block comments with the start
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 elseif l:line =~# '^\s*-}'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 return indent(search('{-', 'bWn'))
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 " Indent double shift after let with an empty rhs
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 elseif l:lline =~# '\<let\>.*\s=$'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 return l:ind + 4 + &shiftwidth
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 " Align 'in' with the parent let.
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 elseif l:line =~# '^\s*in\>'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 return indent(search('^\s*let', 'bWn'))
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 " Align bindings with the parent let.
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 elseif l:lline =~# '\<let\>'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 return l:ind + 4
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 " Align bindings with the parent in.
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 elseif l:lline =~# '^\s*in\>'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 return l:ind
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 endif
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 " Add a 'shiftwidth' after lines ending with:
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 if l:lline =~# '\(|\|=\|->\|<-\|(\|\[\|{\|\<\(of\|else\|if\|then\)\)\s*$'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 let l:ind = l:ind + &shiftwidth
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 " Add a 'shiftwidth' after lines starting with type ending with '=':
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 elseif l:lline =~# '^\s*type' && l:line =~# '^\s*='
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 let l:ind = l:ind + &shiftwidth
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 " Back to normal indent after comments:
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 elseif l:lline =~# '-}\s*$'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 call search('-}', 'bW')
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 let l:ind = indent(searchpair('{-', '', '-}', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"'))
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 " Ident some operators if there aren't any starting the last line.
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 elseif l:line =~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l:lline !~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l:lline !~# '^\s*$'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 let l:ind = l:ind + &shiftwidth
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 elseif l:lline ==# '' && getline(l:lnum - 1) !=# ''
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 let l:ind = indent(search('^\s*\S+', 'bWn'))
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 endif
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 return l:ind
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 endfunc