Skip to content

Commit 5ca8f22

Browse files
Serhii Khomaclason
authored andcommitted
runtime(idris2): include filetype,indent+syntax plugins for (L)Idris2 + ipkg
closes: #15993 Co-authored-by: Christian Clason <ch.clason+github@icloud.com> Signed-off-by: Serhii Khoma <srghma@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent f18987c commit 5ca8f22

10 files changed

Lines changed: 463 additions & 3 deletions

File tree

runtime/doc/filetype.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*filetype.txt* For Vim version 9.1. Last change: 2024 Nov 09
1+
*filetype.txt* For Vim version 9.1. Last change: 2024 Nov 12
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -667,6 +667,19 @@ HARE *ft-hare*
667667
Since the text for this plugin is rather long it has been put in a separate
668668
file: |ft_hare.txt|.
669669

670+
IDRIS2 *ft-idris2-plugin*
671+
672+
By default the following options are set: >
673+
674+
setlocal shiftwidth=2 tabstop=2 expandtab
675+
setlocal comments=s1:{-,mb:-,ex:-},:\|\|\|,:--
676+
setlocal commentstring=--\ %s
677+
setlocal wildignore+=*.ibc
678+
679+
To use tabs instead of spaces for indentation, set the following variable
680+
in your vimrc: >
681+
682+
let g:idris2#allow_tabchar = 1
670683
671684
JAVA *ft-java-plugin*
672685

runtime/doc/indent.txt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*indent.txt* For Vim version 9.1. Last change: 2024 Oct 05
1+
*indent.txt* For Vim version 9.1. Last change: 2024 Nov 12
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -813,6 +813,38 @@ Detail:
813813
: GetCSSIndent() else
814814
<!-- --> : -1
815815

816+
IDRIS2 *ft-idris2-indent*
817+
818+
Idris 2 indentation can be configured with several variables that control the
819+
indentation level for different language constructs:
820+
821+
The "g:idris2_indent_if" variable controls the indentation of `then` and `else`
822+
blocks after `if` statements. Defaults to 3.
823+
824+
The "g:idris2_indent_case" variable controls the indentation of patterns in
825+
`case` expressions. Defaults to 5.
826+
827+
The "g:idris2_indent_let" variable controls the indentation after `let`
828+
bindings. Defaults to 4.
829+
830+
The "g:idris2_indent_rewrite" variable controls the indentation after `rewrite`
831+
expressions. Defaults to 8.
832+
833+
The "g:idris2_indent_where" variable controls the indentation of `where`
834+
blocks. Defaults to 6.
835+
836+
The "g:idris2_indent_do" variable controls the indentation in `do` blocks.
837+
Defaults to 3.
838+
839+
Example configuration: >
840+
841+
let g:idris2_indent_if = 2
842+
let g:idris2_indent_case = 4
843+
let g:idris2_indent_let = 4
844+
let g:idris2_indent_rewrite = 8
845+
let g:idris2_indent_where = 6
846+
let g:idris2_indent_do = 3
847+
<
816848

817849
MATLAB *ft-matlab-indent* *matlab-indent* *matlab-indenting*
818850

runtime/doc/tags

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7333,6 +7333,8 @@ ft-html-omni insert.txt /*ft-html-omni*
73337333
ft-html-syntax syntax.txt /*ft-html-syntax*
73347334
ft-htmlos-syntax syntax.txt /*ft-htmlos-syntax*
73357335
ft-ia64-syntax syntax.txt /*ft-ia64-syntax*
7336+
ft-idris2-indent indent.txt /*ft-idris2-indent*
7337+
ft-idris2-plugin filetype.txt /*ft-idris2-plugin*
73367338
ft-inform-syntax syntax.txt /*ft-inform-syntax*
73377339
ft-java-plugin filetype.txt /*ft-java-plugin*
73387340
ft-java-syntax syntax.txt /*ft-java-syntax*

runtime/filetype.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ au BufRead,BufNewFile usw2kagt.log\c,usw2kagt.*.log\c,*.usw2kagt.log\c setf usw2
11561156
" Ipfilter
11571157
au BufNewFile,BufRead ipf.conf,ipf6.conf,ipf.rules setf ipfilter
11581158

1159-
" Ipkg
1159+
" Ipkg for Idris 2 language
11601160
au BufNewFile,BufRead *.ipkg setf ipkg
11611161

11621162
" Informix 4GL (source - canonical, include file, I4GL+M4 preproc.)

runtime/ftplugin/idris2.vim

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
" Vim ftplugin file
2+
" Language: Idris 2
3+
" Last Change: 2024 Nov 05
4+
" Maintainer: Idris Hackers (https://github.com/edwinb/idris2-vim), Serhii Khoma <srghma@gmail.com>
5+
" License: Vim (see :h license)
6+
" Repository: https://github.com/ShinKage/idris2-nvim
7+
"
8+
" Based on ftplugin/idris2.vim from https://github.com/edwinb/idris2-vim
9+
10+
if exists("b:did_ftplugin")
11+
finish
12+
endif
13+
14+
setlocal shiftwidth=2
15+
setlocal tabstop=2
16+
17+
" Set g:idris2#allow_tabchar = 1 to use tabs instead of spaces
18+
if exists('g:idris2#allow_tabchar') && g:idris2#allow_tabchar != 0
19+
setlocal noexpandtab
20+
else
21+
setlocal expandtab
22+
endif
23+
24+
setlocal comments=s1:{-,mb:-,ex:-},:\|\|\|,:--
25+
setlocal commentstring=--\ %s
26+
27+
" makes ? a part of a word, e.g. for named holes `vzipWith f [] [] = ?vzipWith_rhs_3`, uncomment if want to reenable
28+
" setlocal iskeyword+=?
29+
30+
setlocal wildignore+=*.ibc
31+
32+
let b:undo_ftplugin = "setlocal shiftwidth< tabstop< expandtab< comments< commentstring< iskeyword< wildignore<"
33+
34+
let b:did_ftplugin = 1

runtime/ftplugin/ipkg.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
" Vim ftplugin file
2+
" Language: Ipkg
3+
" Maintainer: Idris Hackers (https://github.com/edwinb/idris2-vim), Serhii Khoma <srghma@gmail.com>
4+
" Last Change: 2024 Nov 05
5+
" Author: ShinKage
6+
" License: Vim (see :h license)
7+
" Repository: https://github.com/ShinKage/idris2-nvim
8+
9+
if exists("b:did_ftplugin")
10+
finish
11+
endif
12+
13+
setlocal comments=:--
14+
setlocal commentstring=--\ %s
15+
setlocal wildignore+=*.ibc
16+
17+
let b:undo_ftplugin = "setlocal shiftwidth< tabstop< expandtab< comments< commentstring< iskeyword< wildignore<"
18+
19+
let b:did_ftplugin = 1

runtime/indent/idris2.vim

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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+
56+
if exists('b:did_indent')
57+
finish
58+
endif
59+
60+
setlocal indentexpr=GetIdrisIndent()
61+
setlocal indentkeys=!^F,o,O,}
62+
63+
let b:did_indent = 1
64+
let b:undo_indent = "setlocal indentexpr< indentkeys<"
65+
66+
" we want to use line continuations (\) BEGINNING
67+
let s:cpo_save = &cpo
68+
set cpo&vim
69+
70+
" Define defaults for indent configuration
71+
let 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
81+
let &cpo = s:cpo_save
82+
unlet s:cpo_save
83+
84+
" Set up indent settings with user overrides
85+
for [key, default] in items(s:indent_defaults)
86+
let varname = 'g:' . key
87+
if !exists(varname)
88+
execute 'let' varname '=' default
89+
endif
90+
endfor
91+
92+
if exists("*GetIdrisIndent")
93+
finish
94+
endif
95+
96+
function! 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')
181+
endfunction
182+
183+
" vim:et:sw=2:sts=2

0 commit comments

Comments
 (0)