vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

asciidoc.vim (2010B)


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