asciidoc.vim 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. if exists("b:did_ftplugin")
  7. finish
  8. endif
  9. let b:did_ftplugin = 1
  10. if exists('b:undo_ftplugin')
  11. let b:undo_ftplugin .= "|setl cms< com< fo< flp< inex< efm< cfu< fde< fdm<"
  12. else
  13. let b:undo_ftplugin = "setl cms< com< fo< flp< inex< efm< cfu< fde< fdm<"
  14. endif
  15. " gf to open include::file.ext[] and link:file.ext[] files
  16. setlocal includeexpr=substitute(v:fname,'\\(link:\\\|include::\\)\\(.\\{-}\\)\\[.*','\\2','g')
  17. setlocal comments=
  18. setlocal commentstring=//\ %s
  19. setlocal formatoptions+=cqn
  20. setlocal formatlistpat=^\\s*[\\[({]\\?\\([0-9]\\+
  21. setlocal formatlistpat+=\\\|[a-zA-Z]\\)[\\]:.)}]\\s\\+
  22. setlocal formatlistpat+=\\\|^\\s*-\\s\\+
  23. setlocal formatlistpat+=\\\|^\\s*[*]\\+\\s\\+
  24. setlocal formatlistpat+=\\\|^\\s*[.]\\+\\s\\+
  25. function AsciidocFold()
  26. let line = getline(v:lnum)
  27. if (v:lnum == 1) && (line =~ '^----*$')
  28. return ">1"
  29. endif
  30. let nested = get(g:, "asciidoc_foldnested", 1)
  31. " Regular headers
  32. let depth = match(line, '\(^=\+\)\@<=\( .*$\)\@=')
  33. " Do not fold nested regular headers
  34. if depth > 1 && !nested
  35. let depth = 1
  36. endif
  37. if depth > 0
  38. " fold all sections under title
  39. if depth > 1 && !get(g:, "asciidoc_fold_under_title", 1)
  40. let depth -= 1
  41. endif
  42. " check syntax, it should be asciidocTitle or asciidocH
  43. let syncode = synstack(v:lnum, 1)
  44. if len(syncode) > 0 && synIDattr(syncode[0], 'name') =~ 'asciidoc\%(H[1-6]\)\|Title'
  45. return ">" . depth
  46. endif
  47. endif
  48. return "="
  49. endfunction
  50. if has("folding") && get(g:, 'asciidoc_folding', 0)
  51. setlocal foldexpr=AsciidocFold()
  52. setlocal foldmethod=expr
  53. let b:undo_ftplugin .= "|setl foldexpr< foldmethod< foldtext<"
  54. endif