annotate runtime/indent/elm.vim @ 30207:7147c6059e80 v9.0.0439

patch 9.0.0439: cursor wrong if inserting before line with virtual text above Commit: https://github.com/vim/vim/commit/88b79cb7d47e2e1fee1baf4016c50b861e6b21c4 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 10 22:32:14 2022 +0100 patch 9.0.0439: cursor wrong if inserting before line with virtual text above Problem: Cursor wrong if inserting before line with virtual text above. Solution: Add the width of the "above" virtual text to the cursor position. (issue #11084)
author Bram Moolenaar <Bram@vim.org>
date Sat, 10 Sep 2022 23:45:02 +0200
parents 9c221ad9634a
children
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
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 20753
diff changeset
7 " Latest Revision: 2021-09-29
20753
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
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 20753
diff changeset
22 let b:undo_indent = "setl et< inde< indk< lisp< si<"
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 20753
diff changeset
23
20753
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 " Only define the function once.
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 if exists('*GetElmIndent')
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 finish
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 endif
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 " Indent pairs
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 function! s:FindPair(pstart, pmid, pend)
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 "call search(a:pend, 'bW')
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 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
33 endfunction
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 function! GetElmIndent()
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 let l:lnum = v:lnum - 1
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 " Ident 0 if the first line of the file:
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 if l:lnum == 0
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 return 0
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 endif
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 let l:ind = indent(l:lnum)
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 let l:lline = getline(l:lnum)
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 let l:line = getline(v:lnum)
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 " Indent if current line begins with '}':
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 if l:line =~? '^\s*}'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 return s:FindPair('{', '', '}')
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 " Indent if current line begins with 'else':
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 elseif l:line =~# '^\s*else\>'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 if l:lline !~# '^\s*\(if\|then\)\>'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 return s:FindPair('\<if\>', '', '\<else\>')
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 endif
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 " Indent if current line begins with 'then':
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 elseif l:line =~# '^\s*then\>'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 if l:lline !~# '^\s*\(if\|else\)\>'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 return s:FindPair('\<if\>', '', '\<then\>')
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 endif
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 " HACK: Indent lines in case with nearest case clause:
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 elseif l:line =~# '->' && l:line !~# ':' && l:line !~# '\\'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 return indent(search('^\s*case', 'bWn')) + &shiftwidth
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 " 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
68 elseif l:lline =~# '^\s*--'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 return l:ind
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 " Align the end of block comments with the start
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 elseif l:line =~# '^\s*-}'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 return indent(search('{-', 'bWn'))
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 " Indent double shift after let with an empty rhs
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 elseif l:lline =~# '\<let\>.*\s=$'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 return l:ind + 4 + &shiftwidth
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 " Align 'in' with the parent let.
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 elseif l:line =~# '^\s*in\>'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 return indent(search('^\s*let', 'bWn'))
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 " Align bindings with the parent let.
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 elseif l:lline =~# '\<let\>'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 return l:ind + 4
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 " Align bindings with the parent in.
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 elseif l:lline =~# '^\s*in\>'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 return l:ind
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 endif
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 " Add a 'shiftwidth' after lines ending with:
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 if l:lline =~# '\(|\|=\|->\|<-\|(\|\[\|{\|\<\(of\|else\|if\|then\)\)\s*$'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 let l:ind = l:ind + &shiftwidth
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 " Add a 'shiftwidth' after lines starting with type ending with '=':
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 elseif l:lline =~# '^\s*type' && l:line =~# '^\s*='
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 let l:ind = l:ind + &shiftwidth
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 " Back to normal indent after comments:
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 elseif l:lline =~# '-}\s*$'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 call search('-}', 'bW')
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 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
105
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 " Ident some operators if there aren't any starting the last line.
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 elseif l:line =~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l:lline !~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l:lline !~# '^\s*$'
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 let l:ind = l:ind + &shiftwidth
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 elseif l:lline ==# '' && getline(l:lnum - 1) !=# ''
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 let l:ind = indent(search('^\s*\S+', 'bWn'))
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 endif
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 return l:ind
661eb972cb22 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 endfunc