]> Git — Sourcephile - doclang.git/blob - vim/ftplugin/tct.vim
stack: add stack.yaml.lock
[doclang.git] / vim / ftplugin / tct.vim
1 " Language: Texte Convivial Technique (TCT)
2 " License: GNU General Public License, version 3 or later (at your option)
3 " Maintainer: Julien Moutinho <julm+hdoc@autogeree.net>
4 " URL: git://git.autogeree.net/hdoc
5 " Version: v2018-02-16
6 " Installation:
7 " Copy this file to ~/.vim/ftplugin/tct.vim
8 " then add this line to ~/.vimrc :
9 " autocmd BufNewFile,BufRead *.tct set filetype=tct
10 if exists("b:did_ftplugin")
11 finish
12 endif
13
14 let s:vim_tct_folding_indent = get(g:, "vim_tct_folding_indent", 0)
15 " NOTE: off by default, because quite slow
16
17 "setlocal comments=fb:*,fb:-,fb:+,n:> commentstring=>\ %s
18 setlocal formatoptions+=tcqln formatoptions-=ro
19 setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+\\\|^\\[^\\ze[^\\]]\\+\\]:
20
21 if exists('b:undo_ftplugin')
22 let b:undo_ftplugin .= "|setl cms< com< fo< flp<"
23 else
24 let b:undo_ftplugin = "setl cms< com< fo< flp<"
25 endif
26
27 function! s:sectionLevel(lnum)
28 let l = a:lnum
29 while l > 0
30 let l:lineCurr = getline(l)
31 let l:depth = match(l:lineCurr, '\(^#\+\)\@<=\( .*$\)\@=')
32 if l:depth > 0
33 return l:depth
34 endif
35 let l = l-1
36 endwhile
37 return 0
38 endfunction
39
40 function! TctFold()
41 let l:lineCurr = getline(v:lnum)
42
43 " Fold wrt. section level
44 let l:depth = match(l:lineCurr, '\(^#\+\)\@<=\( .*$\)\@=')
45 if l:depth > 0
46 return ">" . l:depth
47 endif
48
49 " Fold wrt. indent level
50 if s:vim_tct_folding_indent == 1
51 let spacesCurr = matchend(l:lineCurr,"^ *")
52 return s:sectionLevel(v:lnum) + spacesCurr
53 endif
54
55 " Keep previous fold level
56 return "="
57 endfunction
58
59 if has("folding")
60 setlocal foldexpr=TctFold()
61 setlocal foldmethod=expr
62 let b:undo_ftplugin .= " foldexpr< foldmethod<"
63 endif
64
65 " vim:set sw=2: