blob: 5974e28dc259afed268c29e82ee104dfe84bae28 [file] [log] [blame]
Luca Saccarola1da0e852024-02-14 22:25:41 +01001" Vim filetype plugin file
2" Original Author: Maxim Kim <habamax@gmail.com>
3" Language: asciidoc
4" Maintainer: Luca Saccarola <github.e41mv@aleeas.com>
5" Last Change: 2024 Jan 16
6
7if exists("b:did_ftplugin")
8 finish
9endif
10let b:did_ftplugin = 1
11
12if exists('b:undo_ftplugin')
13 let b:undo_ftplugin .= "|setl cms< com< fo< flp< inex< efm< cfu< fde< fdm<"
14else
15 let b:undo_ftplugin = "setl cms< com< fo< flp< inex< efm< cfu< fde< fdm<"
16endif
17
18" gf to open include::file.ext[] and link:file.ext[] files
19setlocal includeexpr=substitute(v:fname,'\\(link:\\\|include::\\)\\(.\\{-}\\)\\[.*','\\2','g')
20
21setlocal comments=
22setlocal commentstring=//\ %s
23
24setlocal formatoptions+=cqn
25setlocal formatlistpat=^\\s*[\\[({]\\?\\([0-9]\\+
26setlocal formatlistpat+=\\\|[a-zA-Z]\\)[\\]:.)}]\\s\\+
27setlocal formatlistpat+=\\\|^\\s*-\\s\\+
28setlocal formatlistpat+=\\\|^\\s*[*]\\+\\s\\+
29setlocal formatlistpat+=\\\|^\\s*[.]\\+\\s\\+
30
31function AsciidocFold()
32 let line = getline(v:lnum)
33
34 if (v:lnum == 1) && (line =~ '^----*$')
35 return ">1"
36 endif
37
38 let nested = get(g:, "asciidoc_foldnested", 1)
39
40 " Regular headers
41 let depth = match(line, '\(^=\+\)\@<=\( .*$\)\@=')
42
43 " Do not fold nested regular headers
44 if depth > 1 && !nested
45 let depth = 1
46 endif
47
48 if depth > 0
49 " fold all sections under title
50 if depth > 1 && !get(g:, "asciidoc_fold_under_title", 1)
51 let depth -= 1
52 endif
53 " check syntax, it should be asciidocTitle or asciidocH
54 let syncode = synstack(v:lnum, 1)
55 if len(syncode) > 0 && synIDattr(syncode[0], 'name') =~ 'asciidoc\%(H[1-6]\)\|Title'
56 return ">" . depth
57 endif
58 endif
59
60 return "="
61endfunction
62
63if has("folding") && get(g:, 'asciidoc_folding', 0)
64 setlocal foldexpr=AsciidocFold()
65 setlocal foldmethod=expr
66 let b:undo_ftplugin .= "|setl foldexpr< foldmethod< foldtext<"
67endif