/extras/txt2tags.vim

http://txt2tags.googlecode.com/ · Vim Script · 262 lines · 135 code · 23 blank · 104 comment · 2 complexity · 323df74833c82faf71b0193d09eefe52 MD5 · raw file

  1. " Vim syntax file
  2. " Filename: txt2tags.vim
  3. " Language: marked text for conversion by txt2tags
  4. " Maintainer: Aurelio Jargas
  5. " Last change: 2010-10-22 - Added new targets for v2.6
  6. "
  7. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  8. " INFO:
  9. "
  10. " - This is the txt2tags VIM syntax file.
  11. " - It's a syntax file just like those for programming languages as C
  12. " or Python, so you know it's handy.
  13. " - Here are registered all the structures for txt2tags marks.
  14. " - When composing your text file, the marks will be highlighted,
  15. " helping you to quickly make error-free txt2tags files.
  16. "
  17. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  18. " FOLD:
  19. "
  20. " - There are some folding rules on the syntax also
  21. " - To use fold just uncomment the line of foldmethod below
  22. " - Or set the fold use directly on the t2t file, adding this last line:
  23. "
  24. " % vim: foldmethod=syntax
  25. "
  26. " - There are two kinds of fold:
  27. "
  28. " Automatic fold:
  29. " - The fold starts at any top level title
  30. " - The fold ends with 3 consecutive blank lines
  31. "
  32. " User defined fold:
  33. " - The fold starts by the "% label {{{" comment
  34. " - The fold ends with the "% }}}" comment
  35. "
  36. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  37. " INSTALL: (as user)
  38. "
  39. " - Copy this file to the ~/.vim/syntax/ dir (create it if necessary)
  40. "
  41. " - Put in your .vimrc the following line:
  42. " au BufNewFile,BufRead *.t2t set ft=txt2tags
  43. "
  44. " If you use other extension for txt2tags files, change the '*.t2t'
  45. "
  46. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  47. " INSTALL: (as superuser)
  48. "
  49. " If you have access to the system configuration, edit the
  50. " /usr/share/vim/vim*/filetype.vim file, adding the following
  51. " lines after the 'Z-Shell script' entry (near the end):
  52. "
  53. " " txt2tags file
  54. " au BufNewFile,BufRead *.t2t setf txt2tags
  55. "
  56. " And copy this file (txt2tags.vim) to the Vim syntax dir:
  57. "
  58. " /usr/share/vim/vim*/syntax/
  59. "
  60. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  61. "FOLD: just uncomment the following line if you like to use Vim fold
  62. "set foldmethod=syntax
  63. " init
  64. syn clear
  65. syn sync minlines=500
  66. syn case ignore
  67. "TODO see if user already has foldmethod defined, if so, set foldmethod=syntax
  68. "TODO2 learn vim language :/
  69. syn cluster t2tComponents contains=t2tNumber,t2tPercent,t2tMacro,t2tImg,t2tEmail,t2tUrl,t2tUrlMark,t2tUrlMarkImg,t2tUrlLocal
  70. syn cluster t2tBeautifiers contains=t2tStrike,t2tUnderline,t2tItalic,t2tBold,t2tMonospace,t2tRaw
  71. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  72. "LIST:
  73. syn match t2tList '^ *[-+:]\s*$'
  74. syn match t2tList '^ *: '
  75. syn match t2tList '^ *[+-] [^ ]'me=e-1
  76. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  77. "TITLE:
  78. syn match t2tTitleRef contained '\[[a-z0-9_-]*\]\s*$'
  79. syn match t2tTitleMark contained '^ *=\+'
  80. syn match t2tTitleMark contained '=\+\s*$'
  81. syn match t2tTitleMark contained '=\+\['me=e-1,he=e-1
  82. syn match t2tTitle '^ *\(=\{1,5}\)[^=]\(\|.*[^=]\)\1\(\[[a-z0-9_-]*\]\)\=\s*$' contains=t2tTitleMark,t2tTitleRef
  83. syn match t2tNumTitleMark contained '^ *+\+'
  84. syn match t2tNumTitleMark contained '+\+\s*$'
  85. syn match t2tNumTitleMark contained '+\+\['me=e-1,he=e-1
  86. syn match t2tNumTitle '^ *\(+\{1,5}\)[^+]\(\|.*[^+]\)\1\(\[[a-z0-9_-]*\]\)\=\s*$' contains=t2tNumTitleMark,t2tTitleRef
  87. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  88. "URL EMAIL:
  89. "syn case match
  90. syn match t2tEmail '\<[A-Za-z0-9_.-]\+@\([A-Za-z0-9_-]\+\.\)\+[A-Za-z]\{2,4}\>\(?[A-Za-z0-9%&=+.,@*_-]\+\)\='
  91. syn match t2tUrl '\<\(\(https\=\|ftp\|news\|telnet\|gopher\|wais\)://\([A-Za-z0-9._-]\+\(:[^ @]*\)\=@\)\=\|\(www[23]\=\.\|ftp\.\)\)[A-Za-z0-9%._/~:,=$@&-]\+\>/*\(?[A-Za-z0-9/%&=+;.,@*_-]\+\)\=\(#[A-Za-z0-9%._-]\+\)\='
  92. syn match t2tUrlLocal contained ' \([A-Za-z0-9%._/~,-]\+\|[A-Za-z0-9%._/~,-]*#[A-Za-z0-9%._-]\+\)\]'ms=s+1,me=e-1
  93. syn match t2tUrlMark '\[[^]]\+ [^] ]\+\]' contains=t2tUrlLabel,t2tUrl,t2tEmail,t2tUrlLocal
  94. syn match t2tUrlMarkImg '\[\[[[:alnum:]_,.+%$#@!?+~/-]\+\.\(png\|jpe\=g\|gif\|eps\|bmp\)\( \+"[^"]*"\)\{0,1\}\] [^] ]\+\]' contains=t2tUrl,t2tEmail,t2tUrlLocal,t2tImg
  95. syn match t2tUrlLabel contained '\[[^]]\+ 'ms=s+1,me=e-1
  96. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  97. "FONT BEAUTIFIERS:
  98. syn match t2tBold '\*\*\S\(\|.\{-}\S\)\*\*\+'hs=s+2,he=e-2
  99. syn match t2tItalic '//\S\(\|.\{-}\S\)//\+'hs=s+2,he=e-2
  100. syn match t2tUnderline '__\S\(\|.\{-}\S\)__\+'hs=s+2,he=e-2
  101. syn match t2tStrike '--\S\(\|.\{-}\S\)--\+'hs=s+2,he=e-2
  102. syn match t2tMonospace '``\S\(\|.\{-}\S\)``\+'hs=s+2,he=e-2
  103. syn match t2tRaw '""\S\(\|.\{-}\S\)""\+'hs=s+2,he=e-2
  104. syn match t2tTagged "''\S\(\|.\{-}\S\)''\+"hs=s+2,he=e-2
  105. syn match t2tVerb1Line '^``` .*$'hs=s+3
  106. syn match t2tRaw1Line '^""" .*$'hs=s+3
  107. syn match t2tTagged1Line "^''' .*$"hs=s+3
  108. syn region t2tVerbArea start='^```\s*$'hs=s+3 end='^```\s*$'he=e-3
  109. syn region t2tRawArea start='^"""\s*$'hs=s+3 end='^"""\s*$'he=e-3
  110. syn region t2tTaggedArea start="^'''\s*$"hs=s+3 end="^'''\s*$"he=e-3
  111. syn match t2tComment '^%.*$' contains=t2tTodo,t2tFoldMark,t2tIncluded
  112. syn region t2tCommentArea start="^%%%\s*$" end="^%%%\s*$"
  113. "Experimental
  114. syn region t2tTableArea start="^|||\s*$" end="^|||\s*$" contains=t2tTableTab,t2tComment
  115. syn match t2tTableTab '\t' contained
  116. "hi t2tTableTab term=reverse cterm=reverse gui=reverse
  117. "hi link t2tTableArea Statement
  118. set list listchars=tab:??
  119. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  120. "TABLE:
  121. syn match t2tTableAlign contained ' \+$'
  122. syn match t2tTableMark contained '^ *[^ ]\+'
  123. syn match t2tTableBar contained ' |\+ ' contains=t2tBlank
  124. syn match t2tTableBar contained '|\+\s*$' contains=t2tBlank
  125. syn match t2tTableTit contained '^ *||.*' contains=t2tTableMark,t2tTableBar,t2tTableAlign
  126. syn match t2tTable '^ *||\= .*' contains=t2tTableMark,t2tTableBar,t2tTableTit,@t2tBeautifiers,@t2tComponents,t2tTableAlign
  127. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  128. "MISC:
  129. syn keyword t2tTodo TODO FIXME XXX contained
  130. syn match t2tNumber '\<\d\+\([,.]\d\+\)\{,1}\>'
  131. syn match t2tPercent '\<\d\+\([,.]\d\+\)\{,1}%'
  132. syn match t2tBlank '\s\+$'
  133. syn match t2tQuote '^\t\+'
  134. syn match t2tBar '^\s*[_=-]\{20,}\s*$' contains=t2tQuote
  135. syn match t2tImg '\[[[:alnum:]_,.+%$#@!?+~/-]\+\.\(png\|jpe\=g\|gif\|eps\|bmp\)\( \+"[^"]*"\)\{0,1\}\]'
  136. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  137. "MACROS AND COMMANDS:
  138. "syn match t2tMacro '%%[a-z]\+'
  139. syn match t2tMacro '%%\(date\|mtime\|infile\|outfile\)\>\(([^)]*)\)\='
  140. syn match t2tMacro '^ *%%toc\s*$'
  141. syn match t2tIncluded '^%INCLUDED([a-z2]\+)'ms=s+1 contained
  142. syn match t2tIncluded '^%--\{10,} Area Delimiter:'ms=s+1 contained
  143. syn match t2tCommand "^%!\s*include\s*\((\(\|txt\|html\|xhtml\|sgml\|lout\|tex\|mgp\|man\|moin\|pm6\|wiki\|gwiki\|doku\))\)\=\s*:\s*\S"me=e-1 contains=t2tTargets
  144. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  145. "FOLD:
  146. syn match t2tFoldMark '\({{{\|}}}\)$'
  147. syn region t2tUserFold keepend transparent fold start='^%.\+{{{$' end='^%.*}}}$'
  148. syn region t2tTitleFold transparent fold start='^ *=[^=].*[^=]=\(\[[a-z0-9_-]*\]\)\=\s*$' end='\n\n\n\n'
  149. syn region t2tNumtitleFold transparent fold start='^ *+[^+].*[^+]+\(\[[a-z0-9_-]*\]\)\=\s*$' end='\n\n\n\n'
  150. "heavy-folding-users: uncomment the following to fold *every* subtitle area
  151. "syn region t2tTitleFoldDeep transparent fold start='^ *\(=\{2,5}\)[^=].*[^=]\1$' end='\n\n\n\n'
  152. "syn region t2tNumtitleFoldDeep transparent fold start='^ *\(+\{2,5}\)[^+].*[^+]\1$' end='\n\n\n\n'
  153. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  154. "HEADERS AND CONFIG:
  155. "Headers are the first 3 lines
  156. "Config are special comments right after the headers
  157. "Config Area ends on a no-comment and no-blank line
  158. syn keyword t2tTargets contained txt xhtml html sgml tex lout mgp man
  159. syn keyword t2tTargets contained moin pm6 wiki gwiki doku dbk creole
  160. syn keyword t2tTargets contained pmw adoc art
  161. syn match t2tConfigString contained +"[^"]*"\|'[^']*'+
  162. syn match t2tConfigValue contained ':.*'ms=s+1 contains=t2tConfigString
  163. syn match t2tConfigKey contained '^%![^:]\+:' contains=t2tTargets
  164. syn match t2tConfigLine contained "^%!\s*\(encoding\|style\|preproc\|postproc\|includeconf\|options\)\s*\((\s*\(\|txt\|html\|xhtml\|sgml\|tex\|lout\|mgp\|man\|moin\|pm6\|wiki\|gwiki\|doku\|dbk\|creole\|pmw\|adoc\|art\)\s*)\)\=\s*:\s*\S.*" contains=t2tConfigKey,t2tConfigValue,t2tConfigString
  165. syn match t2tConfigLine contained "^%!\s*target\s*:\s*\S.*" contains=t2tConfigKey,t2tTargets
  166. syn match t2tConfigLine contained "^%!\s*guicolors\s*:\s*\(\S\+\s\+\)\{3}\S\+\s*$" contains=t2tConfigKey,t2tTargets
  167. syn match t2tHeaderArea contained '\%^.*\n.*\n.*$' contains=t2tMacro
  168. syn region t2tConfigArea contained start='\%4l' end='^\%>3l[^%]'me=e-1 end='^\%>3l%!include[^c]'me=e-10 end='%%\(date\|mtim\|infi\|outf\)'me=e-6 contains=t2tComment,t2tConfigLine,t2tConfig1
  169. syn region t2tConfigAreaNoHeader contained start='\%2l' end='^\%>1l[^%]'me=e-1 end='^\%>1l%!include[^c]'me=e-10 end='%%\(date\|mtim\|infi\|outf\)'me=e-6 contains=t2tComment,t2tConfigLine,t2tConfig1
  170. syn region t2tTopArea start='\%^\s*\S' end='^[^%]'me=e-1 end='^%!include[^c]'me=e-10 end='%%\(date\|mtim\|infi\|outf\)'me=e-6 contains=t2tHeaderArea,t2tConfigArea
  171. syn region t2tTopAreaNoHead start='\%^\s*$' end='^[^%]'me=e-1 end='^%!include[^c]'me=e-10 end='%%\(date\|mtim\|infi\|outf\)'me=e-6 contains=t2tConfigAreaNoHeader
  172. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  173. "
  174. " color groups
  175. hi default link t2t_Link PreProc
  176. hi default link t2t_Component Statement
  177. hi default link t2t_Delim Identifier
  178. hi default link t2t_Verb Type
  179. hi default link t2t_Raw String
  180. hi default link t2t_Tagged Special
  181. "
  182. " color definitions (specific)
  183. hi default t2tBar term=bold cterm=bold gui=bold
  184. hi default t2tBold term=bold cterm=bold gui=bold
  185. hi default t2tItalic term=italic cterm=italic gui=italic
  186. hi default t2tStrike term=italic cterm=italic gui=italic
  187. hi default t2tUnderline term=underline cterm=underline gui=underline
  188. hi default t2tQuote term=reverse cterm=reverse gui=reverse
  189. hi default t2tTableAlign term=reverse cterm=reverse gui=reverse
  190. if &background == "light"
  191. hi default t2tComment ctermfg=brown guifg=brown
  192. else
  193. hi default t2tComment ctermfg=brown guifg=bisque
  194. endif
  195. hi default link t2tCommentArea t2tComment
  196. "
  197. " color definitions (using Vim defaults)
  198. hi default link t2tTitle Error
  199. hi default link t2tNumTitle Error
  200. " comment the following line to avoid having trailing whitespaces in red
  201. hi default link t2tBlank Error
  202. hi default link t2tNumber Number
  203. hi default link t2tPercent Number
  204. hi default link t2tFoldMark Special
  205. hi default link t2tTodo Todo
  206. hi default link t2tCommand Special
  207. hi default t2tIncluded cterm=bold
  208. hi default link t2tTargets Type
  209. hi default link t2tConfigKey Special
  210. hi default link t2tConfigValue NONE
  211. hi default link t2tConfigString String
  212. hi default link t2tHeaderArea t2t_Raw
  213. hi default link t2tUrlMark t2t_Delim
  214. hi default link t2tUrlMarkImg t2t_Delim
  215. hi default link t2tUrlLabel t2t_Delim
  216. hi default link t2tTableTit t2t_Delim
  217. hi default link t2tTableMark t2t_Delim
  218. hi default link t2tTableBar t2t_Delim
  219. hi default link t2tEmail t2t_Link
  220. hi default link t2tUrl t2t_Link
  221. hi default link t2tUrlLocal t2t_Link
  222. hi default link t2tTitleRef t2t_Link
  223. hi default link t2tMacro t2t_Component
  224. hi default link t2tImg t2t_Component
  225. hi default link t2tList t2t_Component
  226. hi default link t2tMacro t2t_Component
  227. hi default link t2tTitleMark NONE
  228. hi default link t2tVerbArea t2t_Verb
  229. hi default link t2tVerb1Line t2t_Verb
  230. hi default link t2tMonospace t2t_Verb
  231. hi default link t2tRaw t2t_Raw
  232. hi default link t2tRaw1Line t2t_Raw
  233. hi default link t2tRawArea t2t_Raw
  234. hi default link t2tTagged t2t_Tagged
  235. hi default link t2tTagged1Line t2t_Tagged
  236. hi default link t2tTaggedArea t2t_Tagged
  237. "
  238. let b:current_syntax = 'txt2tags'
  239. " vim:tw=0:et