X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=vim%2Fvim%2Fftdetect%2Fasciidoc_filetype.vim;fp=vim%2Fvim%2Fftdetect%2Fasciidoc_filetype.vim;h=9a936e08d3a21733d9e43eaf18ed194df89f7d38;hb=58f1d82fd556e0aec9c69b41c7f0faf8fe6369b6;hp=0000000000000000000000000000000000000000;hpb=b0086513fce699422e101d079820316b1a7a438d;p=config%2Fdotfiles.git diff --git a/vim/vim/ftdetect/asciidoc_filetype.vim b/vim/vim/ftdetect/asciidoc_filetype.vim new file mode 100644 index 0000000..9a936e0 --- /dev/null +++ b/vim/vim/ftdetect/asciidoc_filetype.vim @@ -0,0 +1,53 @@ +" Vim filetype detection file +" Language: AsciiDoc +" Author: Stuart Rackham +" Last Change: AsciiDoc 8.2.0 +" URL: http://www.methods.co.nz/asciidoc/ +" Licence: GPL (http://www.gnu.org) +" Remarks: Vim 6 or greater + +" COMMENT OUT ONE OF THE TWO FOLLOWING COMMANDS +" The first sets asciidoc syntax highlighting on all .txt files, the second +" only existing files *.txt that appear to be AsciiDoc files. + +"au BufNewFile,BufRead *.txt,README,TODO,CHANGELOG,NOTES setfiletype asciidoc +au BufRead *.txt,README,TODO,CHANGELOG,NOTES call s:FTasciidoc() + +" This function checks for a valid AsciiDoc document title after first +" skipping any leading comments. +function! s:FTasciidoc() + let in_comment_block = 0 + let n = 1 + while n < 50 + let line = getline(n) + let n = n + 1 + if line =~ '^/\{4,}$' + if ! in_comment_block + let in_comment_block = 1 + else + let in_comment_block = 0 + endif + continue + endif + if in_comment_block + continue + endif + if line !~ '\(^//\)\|\(^\s*$\)' + break + endif + endwhile + if line !~ '.\{3,}' + return + endif + let len = len(line) + let line = getline(n) + if line !~ '[-=]\{3,}' + return + endif + if len < len(line) - 3 || len > len(line) + 3 + return + endif + setfiletype asciidoc +endfunction + +" vim: et sw=2 ts=2 sts=2: