This repository has been archived by the owner on Sep 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
haskellFold.vim
63 lines (54 loc) · 1.73 KB
/
haskellFold.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
" =============================================================================
" Descriptions: Provide a function providing folding information for haskell
" files.
" Maintainer: Vincent B (twinside@gmail.com)
" Warning: Assume the presence of type signatures on top of your functions to
" work well.
" Usage: drop in ~/vimfiles/plugin or ~/.vim/plugin
" Version: 1.0
" Changelog: - 1.0 : initial version
" =============================================================================
if exists("g:__HASKELLFOLD_VIM__")
finish
endif
let g:__HASKELLFOLD_VIM__ = 1
" Top level bigdefs
fun! s:HaskellFoldMaster( line ) "{{{
return a:line =~ '^data\s'
\ || a:line =~ '^type\s'
\ || a:line =~ '^newdata\s'
\ || a:line =~ '^class\s'
\ || a:line =~ '^instance\s'
\ || a:line =~ '^[^:]\+\s*::'
endfunction "}}}
" Top Level one line shooters.
fun! s:HaskellSnipGlobal(line) "{{{
return a:line =~ '^module'
\ || a:line =~ '^import'
\ || a:line =~ '^infix[lr]\s'
endfunction "}}}
" The real folding function
fun! HaskellFold( lineNum ) "{{{
let line = getline( a:lineNum )
" Beginning of comment
if line =~ '^\s*--'
return 2
endif
if s:HaskellSnipGlobal( line )
return 0
endif
if line =~ '^\s*$'
let nextline = getline(a:lineNum + 1)
if s:HaskellFoldMaster( nextline ) > 0 || s:HaskellSnipGlobal( nextline ) > 0
\ || nextline =~ "^--"
return 0
else
return -1
endif
endif
return 1
endfunction "}}}
augroup HaskellFold
au BufNewFile,BufRead,BufCreate *.hs setlocal foldexpr=HaskellFold(v:lnum)
au BufNewFile,BufRead,BufCreate *.hs setlocal foldmethod=expr
augroup END