diff options
author | Luca Saccarola <github.e41mv@aleeas.com> | 2024-02-14 22:25:41 +0100 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2024-02-14 22:26:43 +0100 |
commit | 1da0e85816718a1d45ca60b3581c62df4e352c91 (patch) | |
tree | 47d3f2b098c247fb70c703600b5bf1ca89b677f5 | |
parent | cf1d65e060e32ba8a0ba99fc299dc192fe4aa961 (diff) |
runtime(asciidoc): include basic ftplugin
closes: #13873
Signed-off-by: Luca Saccarola <github.e41mv@aleeas.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
-rw-r--r-- | runtime/doc/filetype.txt | 14 | ||||
-rw-r--r-- | runtime/doc/tags | 1 | ||||
-rw-r--r-- | runtime/ftplugin/asciidoc.vim | 67 |
3 files changed, 81 insertions, 1 deletions
diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt index 4876e3d754..b56a3d3fa7 100644 --- a/runtime/doc/filetype.txt +++ b/runtime/doc/filetype.txt @@ -1,4 +1,4 @@ -*filetype.txt* For Vim version 9.1. Last change: 2024 Jan 04 +*filetype.txt* For Vim version 9.1. Last change: 2024 Feb 14 VIM REFERENCE MANUAL by Bram Moolenaar @@ -564,6 +564,18 @@ under it. If not found, a new entry and item is prepended to the beginning of the Changelog. +ASCIIDOC *ft-asciidoc-plugin* + +To enable |folding| use this: > + let g:asciidoc_folding = 1 + +To disable nesting of folded headers use this: > + let g:asciidoc_foldnested = 0 + +To disable folding everything under the title use this: > + let asciidoc_fold_under_title = 0 + + FORTRAN *ft-fortran-plugin* Options: diff --git a/runtime/doc/tags b/runtime/doc/tags index d5ccb99da0..e457180d29 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -7191,6 +7191,7 @@ ft-ada-syntax ft_ada.txt /*ft-ada-syntax* ft-ada-variables ft_ada.txt /*ft-ada-variables* ft-ant-syntax syntax.txt /*ft-ant-syntax* ft-apache-syntax syntax.txt /*ft-apache-syntax* +ft-asciidoc-plugin filetype.txt /*ft-asciidoc-plugin* ft-asm-syntax syntax.txt /*ft-asm-syntax* ft-asm68k-syntax syntax.txt /*ft-asm68k-syntax* ft-asmh8300-syntax syntax.txt /*ft-asmh8300-syntax* diff --git a/runtime/ftplugin/asciidoc.vim b/runtime/ftplugin/asciidoc.vim new file mode 100644 index 0000000000..5974e28dc2 --- /dev/null +++ b/runtime/ftplugin/asciidoc.vim @@ -0,0 +1,67 @@ +" Vim filetype plugin file +" Original Author: Maxim Kim <habamax@gmail.com> +" Language: asciidoc +" Maintainer: Luca Saccarola <github.e41mv@aleeas.com> +" Last Change: 2024 Jan 16 + +if exists("b:did_ftplugin") + finish +endif +let b:did_ftplugin = 1 + +if exists('b:undo_ftplugin') + let b:undo_ftplugin .= "|setl cms< com< fo< flp< inex< efm< cfu< fde< fdm<" +else + let b:undo_ftplugin = "setl cms< com< fo< flp< inex< efm< cfu< fde< fdm<" +endif + +" gf to open include::file.ext[] and link:file.ext[] files +setlocal includeexpr=substitute(v:fname,'\\(link:\\\|include::\\)\\(.\\{-}\\)\\[.*','\\2','g') + +setlocal comments= +setlocal commentstring=//\ %s + +setlocal formatoptions+=cqn +setlocal formatlistpat=^\\s*[\\[({]\\?\\([0-9]\\+ +setlocal formatlistpat+=\\\|[a-zA-Z]\\)[\\]:.)}]\\s\\+ +setlocal formatlistpat+=\\\|^\\s*-\\s\\+ +setlocal formatlistpat+=\\\|^\\s*[*]\\+\\s\\+ +setlocal formatlistpat+=\\\|^\\s*[.]\\+\\s\\+ + +function AsciidocFold() + let line = getline(v:lnum) + + if (v:lnum == 1) && (line =~ '^----*$') + return ">1" + endif + + let nested = get(g:, "asciidoc_foldnested", 1) + + " Regular headers + let depth = match(line, '\(^=\+\)\@<=\( .*$\)\@=') + + " Do not fold nested regular headers + if depth > 1 && !nested + let depth = 1 + endif + + if depth > 0 + " fold all sections under title + if depth > 1 && !get(g:, "asciidoc_fold_under_title", 1) + let depth -= 1 + endif + " check syntax, it should be asciidocTitle or asciidocH + let syncode = synstack(v:lnum, 1) + if len(syncode) > 0 && synIDattr(syncode[0], 'name') =~ 'asciidoc\%(H[1-6]\)\|Title' + return ">" . depth + endif + endif + + return "=" +endfunction + +if has("folding") && get(g:, 'asciidoc_folding', 0) + setlocal foldexpr=AsciidocFold() + setlocal foldmethod=expr + let b:undo_ftplugin .= "|setl foldexpr< foldmethod< foldtext<" +endif |