Luca Saccarola | 1da0e85 | 2024-02-14 22:25:41 +0100 | [diff] [blame] | 1 | " 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 | |
| 7 | if exists("b:did_ftplugin") |
| 8 | finish |
| 9 | endif |
| 10 | let b:did_ftplugin = 1 |
| 11 | |
| 12 | if exists('b:undo_ftplugin') |
| 13 | let b:undo_ftplugin .= "|setl cms< com< fo< flp< inex< efm< cfu< fde< fdm<" |
| 14 | else |
| 15 | let b:undo_ftplugin = "setl cms< com< fo< flp< inex< efm< cfu< fde< fdm<" |
| 16 | endif |
| 17 | |
| 18 | " gf to open include::file.ext[] and link:file.ext[] files |
| 19 | setlocal includeexpr=substitute(v:fname,'\\(link:\\\|include::\\)\\(.\\{-}\\)\\[.*','\\2','g') |
| 20 | |
| 21 | setlocal comments= |
| 22 | setlocal commentstring=//\ %s |
| 23 | |
| 24 | setlocal formatoptions+=cqn |
| 25 | setlocal formatlistpat=^\\s*[\\[({]\\?\\([0-9]\\+ |
| 26 | setlocal formatlistpat+=\\\|[a-zA-Z]\\)[\\]:.)}]\\s\\+ |
| 27 | setlocal formatlistpat+=\\\|^\\s*-\\s\\+ |
| 28 | setlocal formatlistpat+=\\\|^\\s*[*]\\+\\s\\+ |
| 29 | setlocal formatlistpat+=\\\|^\\s*[.]\\+\\s\\+ |
| 30 | |
| 31 | function 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 "=" |
| 61 | endfunction |
| 62 | |
| 63 | if has("folding") && get(g:, 'asciidoc_folding', 0) |
| 64 | setlocal foldexpr=AsciidocFold() |
| 65 | setlocal foldmethod=expr |
| 66 | let b:undo_ftplugin .= "|setl foldexpr< foldmethod< foldtext<" |
| 67 | endif |