]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - vim/vim/ftdetect/asciidoc_filetype.vim
Merge branch 'multimedia' again
[config/dotfiles.git] / vim / vim / ftdetect / asciidoc_filetype.vim
1 " Vim filetype detection file
2 " Language:     AsciiDoc
3 " Author:       Stuart Rackham <srackham@gmail.com>
4 " Last Change:  AsciiDoc 8.2.0
5 " URL:          http://www.methods.co.nz/asciidoc/
6 " Licence:      GPL (http://www.gnu.org)
7 " Remarks:      Vim 6 or greater
8
9 " COMMENT OUT ONE OF THE TWO FOLLOWING COMMANDS
10 " The first sets asciidoc syntax highlighting on all .txt files, the second
11 " only existing files *.txt that appear to be AsciiDoc files.
12
13 "au BufNewFile,BufRead *.txt,README,TODO,CHANGELOG,NOTES  setfiletype asciidoc
14 au BufRead *.txt,README,TODO,CHANGELOG,NOTES call s:FTasciidoc()
15
16 " This function checks for a valid AsciiDoc document title after first
17 " skipping any leading comments.
18 function! s:FTasciidoc()
19   let in_comment_block = 0
20   let n = 1
21   while n < 50
22     let line = getline(n)
23     let n = n + 1
24     if line =~ '^/\{4,}$'
25       if ! in_comment_block
26         let in_comment_block = 1
27       else
28         let in_comment_block = 0
29       endif
30       continue
31     endif
32     if in_comment_block
33       continue
34     endif
35     if line !~ '\(^//\)\|\(^\s*$\)'
36       break
37     endif
38   endwhile
39   if line !~ '.\{3,}'
40     return
41   endif
42   let len = len(line)
43   let line = getline(n)
44   if line !~ '[-=]\{3,}'
45     return
46   endif
47   if len < len(line) - 3 || len > len(line) + 3
48     return
49   endif
50   setfiletype asciidoc
51 endfunction
52
53 " vim: et sw=2 ts=2 sts=2: