├── README.md ├── after ├── ftplugin │ └── idris.vim └── syntax │ └── idris.vim ├── doc └── idris-vim.txt ├── ftdetect ├── idris.vim └── lidris.vim ├── ftplugin └── idris.vim ├── indent └── idris.vim ├── syntax ├── idris.vim └── lidris.vim └── syntax_checkers └── idris └── idris.vim /README.md: -------------------------------------------------------------------------------- 1 | Idris mode for vim 2 | ================== 3 | 4 | This is an [Idris][] mode for vim which features syntax highlighting, indentation 5 | and optional syntax checking via [Syntastic][]. If you need a REPL I recommend using 6 | [Vimshell][]. 7 | 8 | ![Screenshot](http://raichoo.github.io/images/vim.png) 9 | 10 | ## Installation 11 | 12 | I recommend using [Pathogen][] for installation. Simply clone 13 | this repo into your `~/.vim/bundle` directory and you are ready to go. 14 | 15 | cd ~/.vim/bundle 16 | git clone https://github.com/idris-hackers/idris-vim.git 17 | 18 | ### Manual Installation 19 | 20 | Copy content into your `~/.vim` directory. 21 | 22 | Be sure that the following lines are in your 23 | `.vimrc` 24 | 25 | 26 | syntax on 27 | filetype on 28 | filetype plugin indent on 29 | 30 | ## Features 31 | 32 | Apart from syntax highlighting, indentation, and unicode character concealing, 33 | idris-vim offers some neat interactive editing features. For more information on 34 | how to use it, read this blog article by Edwin Brady on [Interactive Idris editing with vim][]. 35 | 36 | ## Interactive Editing Commands 37 | 38 | [Idris][] mode for vim offers interactive editing capabilities, the following 39 | commands are supported. 40 | 41 | `r` reload file 42 | 43 | `t` show type 44 | 45 | `d` Create an initial clause for a type declaration. 46 | 47 | `b` Same as \d but for an initial typeclass method impl. 48 | 49 | `md` Same as \d but for a proof clause 50 | 51 | `c` case split 52 | 53 | `mc` make case 54 | 55 | `w` add with clause 56 | 57 | `e` evaluate expression 58 | 59 | `l` make lemma 60 | 61 | `m` add missing clause 62 | 63 | `f` refine item 64 | 65 | `o` obvious proof search 66 | 67 | `p` proof search 68 | 69 | `i` open idris response window 70 | 71 | `h` show documentation 72 | 73 | ## Configuration 74 | 75 | ### Indentation 76 | 77 | To configure indentation in `idris-vim` you can use the following variables: 78 | 79 | * `let g:idris_indent_if = 3` 80 | 81 | if bool 82 | >>>then ... 83 | >>>else ... 84 | 85 | * `let g:idris_indent_case = 5` 86 | 87 | case xs of 88 | >>>>>[] => ... 89 | >>>>>(y::ys) => ... 90 | 91 | * `let g:idris_indent_let = 4` 92 | 93 | let x = 0 in 94 | >>>>x 95 | 96 | * `let g:idris_indent_where = 6` 97 | 98 | where f : Int -> Int 99 | >>>>>>f x = x 100 | 101 | * `let g:idris_indent_do = 3` 102 | 103 | do x <- a 104 | >>>y <- b 105 | 106 | * `let g:idris_indent_rewrite = 8` 107 | 108 | rewrite prf in expr 109 | >>>>>>>>x 110 | 111 | ### Concealing 112 | 113 | Concealing with unicode characters is off by default, but `let g:idris_conceal = 1` turns it on. 114 | 115 | ### Tab Characters 116 | 117 | If you simply must use tab characters, and would prefer that the ftplugin not set expandtab add `let g:idris_allow_tabchar = 1`. 118 | 119 | 120 | [Idris]: http://www.idris-lang.org 121 | [Syntastic]: https://github.com/scrooloose/syntastic 122 | [Vimshell]: https://github.com/Shougo/vimshell.vim 123 | [Pathogen]: https://github.com/tpope/vim-pathogen 124 | [Interactive Idris editing with vim]: http://edwinb.wordpress.com/2013/10/28/interactive-idris-editing-with-vim/ 125 | 126 | -------------------------------------------------------------------------------- /after/ftplugin/idris.vim: -------------------------------------------------------------------------------- 1 | setlocal iskeyword+=' 2 | -------------------------------------------------------------------------------- /after/syntax/idris.vim: -------------------------------------------------------------------------------- 1 | " This script allows for unicode concealing of certain characters 2 | " For instance -> goes to → 3 | " 4 | " It needs vim >= 7.3, set nocompatible, set enc=utf-8 5 | " 6 | " If you want to turn this on, let g:idris_conceal = 1 7 | 8 | if !exists('g:idris_conceal') || !has('conceal') || &enc != 'utf-8' 9 | finish 10 | endif 11 | 12 | " vim: set fenc=utf-8: 13 | syntax match idrNiceOperator "\\\ze[[:alpha:][:space:]_([]" conceal cchar=λ 14 | syntax match idrNiceOperator "<-" conceal cchar=← 15 | syntax match idrNiceOperator "->" conceal cchar=→ 16 | syntax match idrNiceOperator "\" conceal cchar=∑ 17 | syntax match idrNiceOperator "\" conceal cchar=∏ 18 | syntax match idrNiceOperator "\" conceal cchar=√ 19 | syntax match idrNiceOperator "\" conceal cchar=π 20 | syntax match idrNiceOperator "==" conceal cchar=≡ 21 | syntax match idrNiceOperator "\/=" conceal cchar=≠ 22 | 23 | 24 | let s:extraConceal = 1 25 | 26 | let s:doubleArrow = 1 27 | " Set this to 0 to use the more technically correct arrow from bar 28 | 29 | " Some windows font don't support some of the characters, 30 | " so if they are the main font, we don't load them :) 31 | if has("win32") 32 | let s:incompleteFont = [ 'Consolas' 33 | \ , 'Lucida Console' 34 | \ , 'Courier New' 35 | \ ] 36 | let s:mainfont = substitute( &guifont, '^\([^:,]\+\).*', '\1', '') 37 | for s:fontName in s:incompleteFont 38 | if s:mainfont ==? s:fontName 39 | let s:extraConceal = 0 40 | break 41 | endif 42 | endfor 43 | endif 44 | 45 | if s:extraConceal 46 | syntax match idrNiceOperator "Void" conceal cchar=⊥ 47 | 48 | " Match greater than and lower than w/o messing with Kleisli composition 49 | syntax match idrNiceOperator "<=\ze[^<]" conceal cchar=≤ 50 | syntax match idrNiceOperator ">=\ze[^>]" conceal cchar=≥ 51 | 52 | if s:doubleArrow 53 | syntax match idrNiceOperator "=>" conceal cchar=⇒ 54 | else 55 | syntax match idrNiceOperator "=>" conceal cchar=↦ 56 | endif 57 | 58 | syntax match idrNiceOperator "=\zs<<" conceal cchar=« 59 | 60 | syntax match idrNiceOperator "++" conceal cchar=⧺ 61 | syntax match idrNiceOperator "::" conceal cchar=∷ 62 | syntax match idrNiceOperator "-<" conceal cchar=↢ 63 | syntax match idrNiceOperator ">-" conceal cchar=↣ 64 | syntax match idrNiceOperator "-<<" conceal cchar=⤛ 65 | syntax match idrNiceOperator ">>-" conceal cchar=⤜ 66 | 67 | " Only replace the dot, avoid taking spaces around. 68 | syntax match idrNiceOperator /\s\.\s/ms=s+1,me=e-1 conceal cchar=∘ 69 | syntax match idrNiceOperator "\.\." conceal cchar=‥ 70 | 71 | syntax match idrNiceOperator "`elem`" conceal cchar=∈ 72 | syntax match idrNiceOperator "`notElem`" conceal cchar=∉ 73 | endif 74 | 75 | hi link idrNiceOperator Operator 76 | hi! link Conceal Operator 77 | setlocal conceallevel=2 78 | 79 | -------------------------------------------------------------------------------- /doc/idris-vim.txt: -------------------------------------------------------------------------------- 1 | *idris-vim.txt* Last change 2014 April 24 2 | =============================================================================== 3 | =============================================================================== 4 | @@@@ @@@@@@@@ @@@@@@@@ @@@@ @@@@@@ @@ @@ @@@@ @@ @@ 5 | @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@@ @@@ 6 | @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@@@ @@@@ 7 | @@ @@ @@ @@@@@@@@ @@ @@@@@@ @@@@@@@ @@ @@ @@ @@ @@@ @@ 8 | @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ 9 | @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ 10 | @@@@ @@@@@@@@ @@ @@ @@@@ @@@@@@ @@@ @@@@ @@ @@ 11 | =============================================================================== 12 | CONTENTS *idris-vim-contents* 13 | 14 | 1. Features: |idris-vim-features| 15 | 2. Requirements: |idris-vim-requirements| 16 | 3. Functions: |idris-vim-functions| 17 | 4. Troubleshooting |idris-vim-troubleshooting| 18 | 5. Examples: |idris-vim-examples| 19 | 6. Information: |idris-vim-information| 20 | 21 | =============================================================================== 22 | FEATURES *idris-vim-features* 23 | 24 | * Syntax Highlighting 25 | * Indentation 26 | * Unicode Concealing 27 | * Syntax Checking (via Syntastic(https://github.com/scrooloose/syntastic)) 28 | * Interactive Editing via the REPL 29 | 30 | =============================================================================== 31 | REQUIREMENTS *idris-vim-requirements* 32 | 33 | * Idris (http://www.idris-lang.org/) 34 | 35 | OPTIONAL: 36 | 37 | * Syntastic(https://github.com/scrooloose/syntastic) for syntax checking 38 | * Vimshell(https://github.com/Shougo/vimshell.vim) for a REPL 39 | 40 | =============================================================================== 41 | FUNCTIONS *idris-vim-functions* 42 | 43 | All of the functions in idris-vim are essentially just calls back to the REPL, 44 | so documentation for each of them is also available there. 45 | 46 | IdrisDocumentation *IdrisDocumentation* 47 | Shows internal documentation of the primitive under the cursor. 48 | 49 | Mapped to '_h' by default. 50 | 51 | IdrisResponseWin *IdrisResponseWin* 52 | This opens an idris response window in a new pane. 53 | 54 | Mapped to '_i' by default. 55 | 56 | IdrisShowType *IdrisShowType* 57 | This shows the type of the name under the cursor (or, if the cursor happens 58 | to be over a metavariable, a bit more information about its context). 59 | 60 | Mapped to '_t' by default. 61 | 62 | IdrisReload *IdrisReload* 63 | This reloads the file and type-checks the file in the current buffer. 64 | 65 | Mapped to '_r' by default. 66 | 67 | IdrisEval *IdrisEval* 68 | This prompts for an expression and then evaluates it in the REPL, then 69 | returns the result. 70 | 71 | Mapped to '_e' by default. 72 | 73 | IdrisCaseSplit *IdrisCaseSplit* 74 | When the cursor is over a variable in a pattern match clause or case 75 | expression, this splits the variable into all well-typed patterns. 76 | 77 | Mapped to '_c' by default 78 | 79 | IdrisAddClause *IdrisAddClause* 80 | When the cursor is at a type declaration this creates a new clause for that 81 | signature. 82 | 83 | By default mapped to '_d' for an ordinary top-level definition, 84 | '_b' for a typeclass instance definition, and 85 | '_md' to add a pattern-matching proof clause. 86 | 87 | IdrisAddMissing: *IdrisAddMissing* 88 | When the cursor is over a function, this adds all clauses necessary to make 89 | that function cover all inputs. This also eliminates clauses which would 90 | lead to unification errors from appearing. 91 | 92 | Mapped to '_m' by default 93 | 94 | IdrisRefine: *IdrisRefine* 95 | Refines the item the cursor is over (applies the name and fills in any 96 | arguments which can be filled in via unification) 97 | 98 | Mapped to '_f' by default 99 | 100 | IdrisProofSearch: *IdrisProofSearch* 101 | This attempts to find a value for the metavariable it was called on by 102 | looking at the rest of the code. It can also be called with hints, which 103 | are functions that can apply to help solve for the metavariable. 104 | 105 | Mapped to '_o' without hints and 'p' with hints by 106 | default 107 | 108 | IdrisMakeWith: *IdrisMakeWith* 109 | When the cursor is over a pattern clause and this is called, it creates a 110 | new with clause. 111 | 112 | Mapped to '_w' by default 113 | 114 | IdrisMakeLemma: *IdrisMakeLemma* 115 | When the cursor is over a metavariable and this is called, it creates a new 116 | top-level definition to solve the metavariable. 117 | 118 | Mapped to '_l' by default 119 | 120 | =============================================================================== 121 | TROUBLESHOOTING *idris-vim-troubleshooting* 122 | 123 | If this isn't working for you, make sure that: 124 | 125 | * There is an Idris REPL running 126 | * For syntax checking, you have syntastic installed 127 | * The plugins mappings exists and don't conflict with anything else installed 128 | (You can use ':map' to check. There should be mappings similar to 129 | '\h * :call IdrisShowDoc()'.) 130 | * Vim recognizes you're in an idris file (you can use ':verb set ft' to check) 131 | 132 | If none of this works, check to issue tracker on github and if nothing is 133 | there create an issue with a detailed description of the problem. 134 | 135 | =============================================================================== 136 | EXAMPLES *idris-vim-examples* 137 | 138 | Some excellent tutorials/examples for interactive editing using the above 139 | functions can be found at: 140 | http://edwinb.wordpress.com/2013/10/28/interactive-idris-editing-with-vim/ 141 | and 142 | http://www.scribd.com/doc/214031954/60/Interactive-Editing-in-Vim 143 | 144 | =============================================================================== 145 | INFORMATION *idris-vim-information* 146 | 147 | Author: edwinb 148 | Repo: https://github.com/idris-hackers/idris-vim 149 | 150 | Documentation by japesinator 151 | 152 | =============================================================================== 153 | =============================================================================== 154 | " vim:ft=help:et:ts=2:sw=2:sts=2:norl: 155 | -------------------------------------------------------------------------------- /ftdetect/idris.vim: -------------------------------------------------------------------------------- 1 | au BufNewFile,BufRead *.idr setf idris 2 | au BufNewFile,BufRead idris-response setf idris 3 | -------------------------------------------------------------------------------- /ftdetect/lidris.vim: -------------------------------------------------------------------------------- 1 | au BufNewFile,BufRead *.lidr setf lidris 2 | -------------------------------------------------------------------------------- /ftplugin/idris.vim: -------------------------------------------------------------------------------- 1 | if bufname('%') == "idris-response" 2 | finish 3 | endif 4 | 5 | if exists("b:did_ftplugin") 6 | finish 7 | endif 8 | 9 | setlocal shiftwidth=2 10 | setlocal tabstop=2 11 | if !exists("g:idris_allow_tabchar") || g:idris_allow_tabchar == 0 12 | setlocal expandtab 13 | endif 14 | setlocal comments=s1:{-,mb:-,ex:-},:\|\|\|,:-- 15 | setlocal commentstring=--%s 16 | setlocal iskeyword+=? 17 | setlocal wildignore+=*.ibc 18 | 19 | let idris_response = 0 20 | let b:did_ftplugin = 1 21 | 22 | " Text near cursor position that needs to be passed to a command. 23 | " Refinment of `expand()` to accomodate differences between 24 | " a (n)vim word and what Idris requires. 25 | function! s:currentQueryObject() 26 | let word = expand("") 27 | if word =~ '^?' 28 | " Cut off '?' that introduces a hole identifier. 29 | let word = strpart(word, 1) 30 | endif 31 | return word 32 | endfunction 33 | 34 | function! s:IdrisCommand(...) 35 | let idriscmd = shellescape(join(a:000)) 36 | return system("idris --client " . idriscmd) 37 | endfunction 38 | 39 | function! IdrisDocFold(lineNum) 40 | let line = getline(a:lineNum) 41 | 42 | if line =~ "^\s*|||" 43 | return "1" 44 | endif 45 | 46 | return "0" 47 | endfunction 48 | 49 | function! IdrisFold(lineNum) 50 | return IdrisDocFold(a:lineNum) 51 | endfunction 52 | 53 | setlocal foldmethod=expr 54 | setlocal foldexpr=IdrisFold(v:lnum) 55 | 56 | function! IdrisResponseWin() 57 | if (!bufexists("idris-response")) 58 | botright 10split 59 | badd idris-response 60 | b idris-response 61 | let g:idris_respwin = "active" 62 | set buftype=nofile 63 | wincmd k 64 | elseif (bufexists("idris-response") && g:idris_respwin == "hidden") 65 | botright 10split 66 | b idris-response 67 | let g:idris_respwin = "active" 68 | wincmd k 69 | endif 70 | endfunction 71 | 72 | function! IdrisHideResponseWin() 73 | let g:idris_respwin = "hidden" 74 | endfunction 75 | 76 | function! IdrisShowResponseWin() 77 | let g:idris_respwin = "active" 78 | endfunction 79 | 80 | function! IWrite(str) 81 | if (bufexists("idris-response")) 82 | let save_cursor = getcurpos() 83 | b idris-response 84 | %delete 85 | let resp = split(a:str, '\n') 86 | call append(1, resp) 87 | b # 88 | call setpos('.', save_cursor) 89 | else 90 | echo a:str 91 | endif 92 | endfunction 93 | 94 | function! IdrisReload(q) 95 | w 96 | let file = expand("%:p") 97 | let tc = s:IdrisCommand(":l", file) 98 | if (! (tc is "")) 99 | call IWrite(tc) 100 | else 101 | if (a:q==0) 102 | echo "Successfully reloaded " . file 103 | call IWrite("") 104 | endif 105 | endif 106 | return tc 107 | endfunction 108 | 109 | function! IdrisReloadToLine(cline) 110 | return IdrisReload(1) 111 | "w 112 | "let file = expand("%:p") 113 | "let tc = s:IdrisCommand(":lto", a:cline, file) 114 | "if (! (tc is "")) 115 | " call IWrite(tc) 116 | "endif 117 | "return tc 118 | endfunction 119 | 120 | function! IdrisShowType() 121 | w 122 | let word = s:currentQueryObject() 123 | let cline = line(".") 124 | let tc = IdrisReloadToLine(cline) 125 | if (! (tc is "")) 126 | echo tc 127 | else 128 | let ty = s:IdrisCommand(":t", word) 129 | call IWrite(ty) 130 | endif 131 | return tc 132 | endfunction 133 | 134 | function! IdrisShowDoc() 135 | w 136 | let word = expand("") 137 | let ty = s:IdrisCommand(":doc", word) 138 | call IWrite(ty) 139 | endfunction 140 | 141 | function! IdrisProofSearch(hint) 142 | let view = winsaveview() 143 | w 144 | let cline = line(".") 145 | let word = s:currentQueryObject() 146 | let tc = IdrisReload(1) 147 | 148 | if (a:hint==0) 149 | let hints = "" 150 | else 151 | let hints = input ("Hints: ") 152 | endif 153 | 154 | if (tc is "") 155 | let result = s:IdrisCommand(":ps!", cline, word, hints) 156 | if (! (result is "")) 157 | call IWrite(result) 158 | else 159 | e 160 | call winrestview(view) 161 | endif 162 | endif 163 | endfunction 164 | 165 | function! IdrisMakeLemma() 166 | let view = winsaveview() 167 | w 168 | let cline = line(".") 169 | let word = s:currentQueryObject() 170 | let tc = IdrisReload(1) 171 | 172 | if (tc is "") 173 | let result = s:IdrisCommand(":ml!", cline, word) 174 | if (! (result is "")) 175 | call IWrite(result) 176 | else 177 | e 178 | call winrestview(view) 179 | call search(word, "b") 180 | endif 181 | endif 182 | endfunction 183 | 184 | function! IdrisRefine() 185 | let view = winsaveview() 186 | w 187 | let cline = line(".") 188 | let word = expand("") 189 | let tc = IdrisReload(1) 190 | 191 | let name = input ("Name: ") 192 | 193 | if (tc is "") 194 | let result = s:IdrisCommand(":ref!", cline, word, name) 195 | if (! (result is "")) 196 | call IWrite(result) 197 | else 198 | e 199 | call winrestview(view) 200 | endif 201 | endif 202 | endfunction 203 | 204 | function! IdrisAddMissing() 205 | let view = winsaveview() 206 | w 207 | let cline = line(".") 208 | let word = expand("") 209 | let tc = IdrisReload(1) 210 | 211 | if (tc is "") 212 | let result = s:IdrisCommand(":am!", cline, word) 213 | if (! (result is "")) 214 | call IWrite(result) 215 | else 216 | e 217 | call winrestview(view) 218 | endif 219 | endif 220 | endfunction 221 | 222 | function! IdrisCaseSplit() 223 | let view = winsaveview() 224 | let cline = line(".") 225 | let word = expand("") 226 | let tc = IdrisReloadToLine(cline) 227 | 228 | if (tc is "") 229 | let result = s:IdrisCommand(":cs!", cline, word) 230 | if (! (result is "")) 231 | call IWrite(result) 232 | else 233 | e 234 | call winrestview(view) 235 | endif 236 | endif 237 | endfunction 238 | 239 | function! IdrisMakeWith() 240 | let view = winsaveview() 241 | w 242 | let cline = line(".") 243 | let word = s:currentQueryObject() 244 | let tc = IdrisReload(1) 245 | 246 | if (tc is "") 247 | let result = s:IdrisCommand(":mw!", cline, word) 248 | if (! (result is "")) 249 | call IWrite(result) 250 | else 251 | e 252 | call winrestview(view) 253 | call search("_") 254 | endif 255 | endif 256 | endfunction 257 | 258 | function! IdrisMakeCase() 259 | let view = winsaveview() 260 | w 261 | let cline = line(".") 262 | let word = s:currentQueryObject() 263 | let tc = IdrisReload(1) 264 | 265 | if (tc is "") 266 | let result = s:IdrisCommand(":mc!", cline, word) 267 | if (! (result is "")) 268 | call IWrite(result) 269 | else 270 | e 271 | call winrestview(view) 272 | call search("_") 273 | endif 274 | endif 275 | endfunction 276 | 277 | function! IdrisAddClause(proof) 278 | let view = winsaveview() 279 | w 280 | let cline = line(".") 281 | let word = expand("") 282 | let tc = IdrisReloadToLine(cline) 283 | 284 | if (tc is "") 285 | if (a:proof==0) 286 | let fn = ":ac!" 287 | else 288 | let fn = ":apc!" 289 | endif 290 | 291 | let result = s:IdrisCommand(fn, cline, word) 292 | if (! (result is "")) 293 | call IWrite(result) 294 | else 295 | e 296 | call winrestview(view) 297 | call search(word) 298 | 299 | endif 300 | endif 301 | endfunction 302 | 303 | function! IdrisEval() 304 | w 305 | let tc = IdrisReload(1) 306 | if (tc is "") 307 | let expr = input ("Expression: ") 308 | let result = s:IdrisCommand(expr) 309 | call IWrite(" = " . result) 310 | endif 311 | endfunction 312 | 313 | nnoremap t :call IdrisShowType() 314 | nnoremap r :call IdrisReload(0) 315 | nnoremap c :call IdrisCaseSplit() 316 | nnoremap d 0:call search(":")b:call IdrisAddClause(0)w 317 | nnoremap b 0:call IdrisAddClause(0) 318 | nnoremap m :call IdrisAddMissing() 319 | nnoremap md 0:call search(":")b:call IdrisAddClause(1)w 320 | nnoremap f :call IdrisRefine() 321 | nnoremap o :call IdrisProofSearch(0) 322 | nnoremap p :call IdrisProofSearch(1) 323 | nnoremap l :call IdrisMakeLemma() 324 | nnoremap e :call IdrisEval() 325 | nnoremap w 0:call IdrisMakeWith() 326 | nnoremap mc :call IdrisMakeCase() 327 | nnoremap i 0:call IdrisResponseWin() 328 | nnoremap h :call IdrisShowDoc() 329 | 330 | menu Idris.Reload r 331 | menu Idris.Show\ Type t 332 | menu Idris.Evaluate e 333 | menu Idris.-SEP0- : 334 | menu Idris.Add\ Clause d 335 | menu Idris.Add\ with w 336 | menu Idris.Case\ Split c 337 | menu Idris.Add\ missing\ cases m 338 | menu Idris.Proof\ Search o 339 | menu Idris.Proof\ Search\ with\ hints p 340 | 341 | au BufHidden idris-response call IdrisHideResponseWin() 342 | au BufEnter idris-response call IdrisShowResponseWin() 343 | -------------------------------------------------------------------------------- /indent/idris.vim: -------------------------------------------------------------------------------- 1 | " indentation for idris (idris-lang.org) 2 | " 3 | " Based on haskell indentation by motemen 4 | " 5 | " author: raichoo (raichoo@googlemail.com) 6 | " 7 | " Modify g:idris_indent_if and g:idris_indent_case to 8 | " change indentation for `if'(default 3) and `case'(default 5). 9 | " Example (in .vimrc): 10 | " > let g:idris_indent_if = 2 11 | 12 | if exists('b:did_indent') 13 | finish 14 | endif 15 | 16 | let b:did_indent = 1 17 | 18 | if !exists('g:idris_indent_if') 19 | " if bool 20 | " >>>then ... 21 | " >>>else ... 22 | let g:idris_indent_if = 3 23 | endif 24 | 25 | if !exists('g:idris_indent_case') 26 | " case xs of 27 | " >>>>>[] => ... 28 | " >>>>>(y::ys) => ... 29 | let g:idris_indent_case = 5 30 | endif 31 | 32 | if !exists('g:idris_indent_let') 33 | " let x : Nat = O in 34 | " >>>>x 35 | let g:idris_indent_let = 4 36 | endif 37 | 38 | if !exists('g:idris_indent_rewrite') 39 | " rewrite prf in expr 40 | " >>>>>>>>x 41 | let g:idris_indent_rewrite = 8 42 | endif 43 | 44 | if !exists('g:idris_indent_where') 45 | " where f : Nat -> Nat 46 | " >>>>>>f x = x 47 | let g:idris_indent_where = 6 48 | endif 49 | 50 | if !exists('g:idris_indent_do') 51 | " do x <- a 52 | " >>>y <- b 53 | let g:idris_indent_do = 3 54 | endif 55 | 56 | setlocal indentexpr=GetIdrisIndent() 57 | setlocal indentkeys=!^F,o,O,} 58 | 59 | function! GetIdrisIndent() 60 | let prevline = getline(v:lnum - 1) 61 | 62 | if prevline =~ '\s\+(\s*.\+\s\+:\s\+.\+\s*)\s\+->\s*$' 63 | return match(prevline, '(') 64 | elseif prevline =~ '\s\+{\s*.\+\s\+:\s\+.\+\s*}\s\+->\s*$' 65 | return match(prevline, '{') 66 | endif 67 | 68 | if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$' 69 | let s = match(prevline, '[:=]') 70 | if s > 0 71 | return s + 2 72 | else 73 | return match(prevline, '\S') 74 | endif 75 | endif 76 | 77 | if prevline =~ '[{([][^})\]]\+$' 78 | return match(prevline, '[{([]') 79 | endif 80 | 81 | if prevline =~ '\\s\+.\+\\s*$' 82 | return match(prevline, '\') + g:idris_indent_let 83 | endif 84 | 85 | if prevline =~ '\\s\+.\+\\s*$' 86 | return match(prevline, '\') + g:idris_indent_rewrite 87 | endif 88 | 89 | if prevline !~ '\' 90 | let s = match(prevline, '\.*\&.*\zs\') 91 | if s > 0 92 | return s 93 | endif 94 | 95 | let s = match(prevline, '\') 96 | if s > 0 97 | return s + g:idris_indent_if 98 | endif 99 | endif 100 | 101 | if prevline =~ '\(\\|\\|=\|[{([]\)\s*$' 102 | return match(prevline, '\S') + &shiftwidth 103 | endif 104 | 105 | if prevline =~ '\\s\+\S\+.*$' 106 | return match(prevline, '\') + g:idris_indent_where 107 | endif 108 | 109 | if prevline =~ '\\s\+\S\+.*$' 110 | return match(prevline, '\') + g:idris_indent_do 111 | endif 112 | 113 | if prevline =~ '^\s*\<\(co\)\?data\>\s\+[^=]\+\s\+=\s\+\S\+.*$' 114 | return match(prevline, '=') 115 | endif 116 | 117 | if prevline =~ '\\s\+([^)]*)\s*$' 118 | return match(prevline, '\S') + &shiftwidth 119 | endif 120 | 121 | if prevline =~ '\\s\+.\+\\s*$' 122 | return match(prevline, '\') + g:idris_indent_case 123 | endif 124 | 125 | if prevline =~ '^\s*\(\\|\<\(co\)\?data\>\)\s\+\S\+\s*$' 126 | return match(prevline, '\(\\|\<\(co\)\?data\>\)') + &shiftwidth 127 | endif 128 | 129 | if prevline =~ '^\s*\(\\|\\)\s*([^(]*)\s*$' 130 | return match(prevline, '\(\\|\\)') + &shiftwidth 131 | endif 132 | 133 | if prevline =~ '^\s*\\s*$' 134 | return match(prevline, '\') + &shiftwidth 135 | endif 136 | 137 | let line = getline(v:lnum) 138 | 139 | if (line =~ '^\s*}\s*' && prevline !~ '^\s*;') 140 | return match(prevline, '\S') - &shiftwidth 141 | endif 142 | 143 | return match(prevline, '\S') 144 | endfunction 145 | -------------------------------------------------------------------------------- /syntax/idris.vim: -------------------------------------------------------------------------------- 1 | " syntax highlighting for idris (idris-lang.org) 2 | " 3 | " Heavily modified version of the haskell syntax 4 | " highlighter to support idris. 5 | " 6 | " author: raichoo (raichoo@googlemail.com) 7 | 8 | if exists("b:current_syntax") 9 | finish 10 | endif 11 | 12 | syn match idrisTypeDecl "[a-zA-Z][a-zA-z0-9_']*\s\+:\s\+" 13 | \ contains=idrisIdentifier,idrisOperators 14 | syn region idrisParens matchgroup=idrisDelimiter start="(" end=")" contains=TOP,idrisTypeDecl 15 | syn region idrisBrackets matchgroup=idrisDelimiter start="\[" end="]" contains=TOP,idrisTypeDecl 16 | syn region idrisBlock matchgroup=idrisDelimiter start="{" end="}" contains=TOP,idrisTypeDecl 17 | syn keyword idrisModule module namespace 18 | syn keyword idrisImport import 19 | syn keyword idrisRefl refl 20 | syn keyword idrisDeprecated class instance 21 | syn keyword idrisStructure codata data record dsl interface implementation 22 | syn keyword idrisWhere where 23 | syn keyword idrisVisibility public abstract private export 24 | syn keyword idrisBlock parameters mutual postulate using 25 | syn keyword idrisTotality total partial covering 26 | syn keyword idrisImplicit implicit 27 | syn keyword idrisAnnotation auto impossible static constructor 28 | syn keyword idrisStatement do case of rewrite with proof 29 | syn keyword idrisLet let in 30 | syn match idrisSyntax "\(pattern \+\|term \+\)\?syntax" 31 | syn keyword idrisConditional if then else 32 | syn match idrisTactic contained "\<\(intros\?\|rewrite\|exact\|refine\|trivial\|let\|focus\|try\|compute\|solve\|attack\|reflect\|fill\|applyTactic\)\>" 33 | syn match idrisNumber "\<[0-9]\+\>\|\<0[xX][0-9a-fA-F]\+\>\|\<0[oO][0-7]\+\>" 34 | syn match idrisFloat "\<[0-9]\+\.[0-9]\+\([eE][-+]\=[0-9]\+\)\=\>" 35 | syn match idrisDelimiter "[,;]" 36 | syn keyword idrisInfix prefix infix infixl infixr 37 | syn match idrisOperators "\([-!#$%&\*\+./<=>\?@\\^|~:]\|\<_\>\)" 38 | syn match idrisType "\<[A-Z][a-zA-Z0-9_']*\>" 39 | syn keyword idrisTodo TODO FIXME XXX HACK contained 40 | syn match idrisLineComment "---*\([^-!#$%&\*\+./<=>\?@\\^|~].*\)\?$" contains=idrisTodo,@Spell 41 | syn match idrisDocComment "|||\([^-!#$%&\*\+./<=>\?@\\^|~].*\)\?$" contains=idrisTodo,@Spell 42 | syn match idrisMetaVar "?[a-z][A-Za-z0-9_']*" 43 | syn match idrisLink "%\(lib\|link\|include\)" 44 | syn match idrisDirective "%\(access\|assert_total\|default\|elim\|error_reverse\|hide\|name\|reflection\|error_handlers\|language\|flag\|dynamic\|provide\|inline\|used\|no_implicit\|hint\|extern\|unqualified\|error_handler\)" 45 | syn keyword idrisDSL lambda variable index_first index_next 46 | syn match idrisChar "'[^'\\]'\|'\\.'\|'\\u[0-9a-fA-F]\{4}'" 47 | syn match idrisBacktick "`[A-Za-z][A-Za-z0-9_']*`" 48 | syn region idrisString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell 49 | syn region idrisBlockComment start="{-" end="-}" contains=idrisBlockComment,idrisTodo,@Spell 50 | syn region idrisProofBlock start="\(default\s\+\)\?\(proof\|tactics\) *{" end="}" contains=idrisTactic 51 | syn match idrisIdentifier "[a-zA-Z][a-zA-z0-9_']*" contained 52 | 53 | highlight def link idrisDeprecated Error 54 | highlight def link idrisIdentifier Identifier 55 | highlight def link idrisImport Structure 56 | highlight def link idrisModule Structure 57 | highlight def link idrisStructure Structure 58 | highlight def link idrisStatement Statement 59 | highlight def link idrisDSL Statement 60 | highlight def link idrisBlock Statement 61 | highlight def link idrisAnnotation Statement 62 | highlight def link idrisWhere Structure 63 | highlight def link idrisLet Structure 64 | highlight def link idrisTotality Statement 65 | highlight def link idrisImplicit Statement 66 | highlight def link idrisSyntax Statement 67 | highlight def link idrisVisibility Statement 68 | highlight def link idrisConditional Conditional 69 | highlight def link idrisProofBlock Macro 70 | highlight def link idrisRefl Macro 71 | highlight def link idrisTactic Identifier 72 | highlight def link idrisLink Statement 73 | highlight def link idrisDirective Statement 74 | highlight def link idrisNumber Number 75 | highlight def link idrisFloat Float 76 | highlight def link idrisDelimiter Delimiter 77 | highlight def link idrisInfix PreProc 78 | highlight def link idrisOperators Operator 79 | highlight def link idrisType Include 80 | highlight def link idrisDocComment Comment 81 | highlight def link idrisLineComment Comment 82 | highlight def link idrisBlockComment Comment 83 | highlight def link idrisTodo Todo 84 | highlight def link idrisMetaVar Macro 85 | highlight def link idrisString String 86 | highlight def link idrisChar String 87 | highlight def link idrisBacktick Operator 88 | 89 | let b:current_syntax = "idris" 90 | -------------------------------------------------------------------------------- /syntax/lidris.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: Literate Idris 3 | " Maintainer: Idris Hackers (https://github.com/idris-hackers/idris-vim) 4 | " Last Change: 2014 Mar 4 5 | " Version: 0.1 6 | " 7 | " This is just a minimal adaption of the Literate Haskell syntax file. 8 | 9 | 10 | " Read Idris highlighting. 11 | if version < 600 12 | syntax include @idrisTop :p:h/idris.vim 13 | else 14 | syntax include @idrisTop syntax/idris.vim 15 | endif 16 | 17 | " Recognize blocks of Bird tracks, highlight as Idris. 18 | syntax region lidrisBirdTrackBlock start="^>" end="\%(^[^>]\)\@=" contains=@idrisTop,lidrisBirdTrack 19 | syntax match lidrisBirdTrack "^>" contained 20 | hi def link lidrisBirdTrack Comment 21 | 22 | let b:current_syntax = "lidris" 23 | -------------------------------------------------------------------------------- /syntax_checkers/idris/idris.vim: -------------------------------------------------------------------------------- 1 | "============================================================================ 2 | "File: idris.vim 3 | "Description: Syntax checking plugin for syntastic.vim 4 | "Maintainer: raichoo 5 | "License: This program is free software. It comes without any warranty, 6 | " to the extent permitted by applicable law. You can redistribute 7 | " it and/or modify it under the terms of the Do What The Fuck You 8 | " Want To Public License, Version 2, as published by Sam Hocevar. 9 | " See http://sam.zoy.org/wtfpl/COPYING for more details. 10 | " 11 | "============================================================================ 12 | 13 | if exists("g:loaded_syntastic_idris_idris_checker") 14 | finish 15 | endif 16 | let g:loaded_syntastic_idris_idris_checker=1 17 | 18 | function! SyntaxCheckers_idris_idris_IsAvailable() 19 | return executable("idris") 20 | endfunction 21 | 22 | if !exists("g:syntastic_idris_options") 23 | let g:syntastic_idris_options = " " 24 | endif 25 | 26 | function! SyntaxCheckers_idris_idris_GetLocList() dict 27 | let makeprg = self.makeprgBuild({ 28 | \ 'exe': 'idris', 29 | \ 'args': "--client ':l". g:syntastic_idris_options, 30 | \ 'post_args': "'", 31 | \ 'filetype': 'idris', 32 | \ 'subchecker': 'idris' }) 33 | 34 | let errorformat = 35 | \ '"%f" (line %l\, column %c\):,' . 36 | \ 'user error (%f\:%l\:%m\),' . 37 | \ '%E%f:%l:%c: error: %m,' . 38 | \ '%E%f:%l:%c-%*[0-9]: error: %m,' . 39 | \ '%W%f:%l:%c: warning: %m,' . 40 | \ '%W%f:%l:%c-%*[0-9]: warning: %m,' . 41 | \ '%E%f:%l:%c:%m,' . 42 | \ '%E%f:%l:%c-%*[0-9]:%m,' . 43 | \ '%C%m,' . 44 | \ '%m' 45 | 46 | return SyntasticMake({ 47 | \ 'makeprg': makeprg, 48 | \ 'errorformat': errorformat, 49 | \ 'postprocess': ['compressWhitespace'] }) 50 | endfunction 51 | 52 | call g:SyntasticRegistry.CreateAndRegisterChecker({ 53 | \ 'filetype': 'idris', 54 | \ 'name': 'idris'}) 55 | --------------------------------------------------------------------------------