robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonvim-patch:5ca8f22: runtime(idris2): include filetype,indent+syntax plugins for (L)Idris2 + ipkg096cb572af

master
4.4 KiB183 linesraw
1" Vim indent file
2" Language:            Idris 2
3" Maintainer:          Idris Hackers (https://github.com/edwinb/idris2-vim), Serhii Khoma <srghma@gmail.com>
4" Author:              raichoo <raichoo@googlemail.com>
5" Last Change:         2024 Nov 05
6" License:             Vim (see :h license)
7" Repository:          https://github.com/ShinKage/idris2-nvim
8"
9" indentation for idris (idris-lang.org)
10"
11" Based on haskell indentation by motemen <motemen@gmail.com>
12"
13" Indentation configuration variables:
14"
15" g:idris2_indent_if (default: 3)
16"   Controls indentation after 'if' statements
17"   Example:
18"     if condition
19"     >>>then expr
20"     >>>else expr
21"
22" g:idris2_indent_case (default: 5)
23"   Controls indentation of case expressions
24"   Example:
25"     case x of
26"     >>>>>Left y => ...
27"     >>>>>Right z => ...
28"
29" g:idris2_indent_let (default: 4)
30"   Controls indentation after 'let' bindings
31"   Example:
32"     let x = expr in
33"     >>>>body
34"
35" g:idris2_indent_rewrite (default: 8)
36"   Controls indentation after 'rewrite' expressions
37"   Example:
38"     rewrite proof in
39"     >>>>>>>>expr
40"
41" g:idris2_indent_where (default: 6)
42"   Controls indentation of 'where' blocks
43"   Example:
44"     function args
45"     >>>>>>where helper = expr
46"
47" g:idris2_indent_do (default: 3)
48"   Controls indentation in 'do' blocks
49"   Example:
50"     do x <- action
51"     >>>y <- action
52"
53" Example configuration in .vimrc:
54" let g:idris2_indent_if = 2
55
56if exists('b:did_indent')
57  finish
58endif
59
60setlocal indentexpr=GetIdrisIndent()
61setlocal indentkeys=!^F,o,O,}
62
63let b:did_indent = 1
64let b:undo_indent = "setlocal indentexpr< indentkeys<"
65
66" we want to use line continuations (\) BEGINNING
67let s:cpo_save = &cpo
68set cpo&vim
69
70" Define defaults for indent configuration
71let s:indent_defaults = {
72  \ 'idris2_indent_if': 3,
73  \ 'idris2_indent_case': 5,
74  \ 'idris2_indent_let': 4,
75  \ 'idris2_indent_rewrite': 8,
76  \ 'idris2_indent_where': 6,
77  \ 'idris2_indent_do': 3
78  \ }
79
80" we want to use line continuations (\) END
81let &cpo = s:cpo_save
82unlet s:cpo_save
83
84" Set up indent settings with user overrides
85for [key, default] in items(s:indent_defaults)
86  let varname = 'g:' . key
87  if !exists(varname)
88    execute 'let' varname '=' default
89  endif
90endfor
91
92if exists("*GetIdrisIndent")
93  finish
94endif
95
96function! GetIdrisIndent()
97  let prevline = getline(v:lnum - 1)
98
99  if prevline =~ '\s\+(\s*.\+\s\+:\s\+.\+\s*)\s\+->\s*$'
100    return match(prevline, '(')
101  elseif prevline =~ '\s\+{\s*.\+\s\+:\s\+.\+\s*}\s\+->\s*$'
102    return match(prevline, '{')
103  endif
104
105  if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$'
106    let s = match(prevline, '[:=]')
107    if s > 0
108      return s + 2
109    else
110      return match(prevline, '\S')
111    endif
112  endif
113
114  if prevline =~ '[{([][^})\]]\+$'
115    return match(prevline, '[{([]')
116  endif
117
118  if prevline =~ '\<let\>\s\+.\+\<in\>\s*$'
119    return match(prevline, '\<let\>') + g:idris2_indent_let
120  endif
121
122  if prevline =~ '\<rewrite\>\s\+.\+\<in\>\s*$'
123    return match(prevline, '\<rewrite\>') + g:idris2_indent_rewrite
124  endif
125
126  if prevline !~ '\<else\>'
127    let s = match(prevline, '\<if\>.*\&.*\zs\<then\>')
128    if s > 0
129      return s
130    endif
131
132    let s = match(prevline, '\<if\>')
133    if s > 0
134      return s + g:idris2_indent_if
135    endif
136  endif
137
138  if prevline =~ '\(\<where\>\|\<do\>\|=\|[{([]\)\s*$'
139    return match(prevline, '\S') + &shiftwidth
140  endif
141
142  if prevline =~ '\<where\>\s\+\S\+.*$'
143    return match(prevline, '\<where\>') + g:idris2_indent_where
144  endif
145
146  if prevline =~ '\<do\>\s\+\S\+.*$'
147    return match(prevline, '\<do\>') + g:idris2_indent_do
148  endif
149
150  if prevline =~ '^\s*\<\(co\)\?data\>\s\+[^=]\+\s\+=\s\+\S\+.*$'
151    return match(prevline, '=')
152  endif
153
154  if prevline =~ '\<with\>\s\+([^)]*)\s*$'
155    return match(prevline, '\S') + &shiftwidth
156  endif
157
158  if prevline =~ '\<case\>\s\+.\+\<of\>\s*$'
159    return match(prevline, '\<case\>') + g:idris2_indent_case
160  endif
161
162  if prevline =~ '^\s*\(\<namespace\>\|\<\(co\)\?data\>\)\s\+\S\+\s*$'
163    return match(prevline, '\(\<namespace\>\|\<\(co\)\?data\>\)') + &shiftwidth
164  endif
165
166  if prevline =~ '^\s*\(\<using\>\|\<parameters\>\)\s*([^(]*)\s*$'
167    return match(prevline, '\(\<using\>\|\<parameters\>\)') + &shiftwidth
168  endif
169
170  if prevline =~ '^\s*\<mutual\>\s*$'
171    return match(prevline, '\<mutual\>') + &shiftwidth
172  endif
173
174  let line = getline(v:lnum)
175
176  if (line =~ '^\s*}\s*' && prevline !~ '^\s*;')
177    return match(prevline, '\S') - &shiftwidth
178  endif
179
180  return match(prevline, '\S')
181endfunction
182
183" vim:et:sw=2:sts=2