PageRenderTime 18ms CodeModel.GetById 2ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/extras/txt2tags.vim

http://txt2tags.googlecode.com/
Vim Script | 262 lines | 246 code | 16 blank | 0 comment | 10 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
 62
 63"FOLD: just uncomment the following line if you like to use Vim fold
 64"set foldmethod=syntax
 65
 66
 67" init
 68syn clear
 69syn sync minlines=500
 70syn case ignore
 71
 72"TODO see if user already has foldmethod defined, if so, set foldmethod=syntax
 73"TODO2 learn vim language :/
 74
 75syn cluster t2tComponents  contains=t2tNumber,t2tPercent,t2tMacro,t2tImg,t2tEmail,t2tUrl,t2tUrlMark,t2tUrlMarkImg,t2tUrlLocal
 76syn cluster t2tBeautifiers contains=t2tStrike,t2tUnderline,t2tItalic,t2tBold,t2tMonospace,t2tRaw
 77
 78""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 79"LIST:
 80syn match t2tList    '^ *[-+:]\s*$'
 81syn match t2tList    '^ *: '
 82syn match t2tList    '^ *[+-] [^ ]'me=e-1
 83
 84""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 85"TITLE:
 86syn match t2tTitleRef  contained '\[[a-z0-9_-]*\]\s*$'
 87syn match t2tTitleMark contained '^ *=\+'
 88syn match t2tTitleMark contained '=\+\s*$'
 89syn match t2tTitleMark contained '=\+\['me=e-1,he=e-1
 90syn match t2tTitle '^ *\(=\{1,5}\)[^=]\(\|.*[^=]\)\1\(\[[a-z0-9_-]*\]\)\=\s*$' contains=t2tTitleMark,t2tTitleRef
 91
 92syn match t2tNumTitleMark contained '^ *+\+'
 93syn match t2tNumTitleMark contained '+\+\s*$'
 94syn match t2tNumTitleMark contained '+\+\['me=e-1,he=e-1
 95syn match t2tNumTitle '^ *\(+\{1,5}\)[^+]\(\|.*[^+]\)\1\(\[[a-z0-9_-]*\]\)\=\s*$' contains=t2tNumTitleMark,t2tTitleRef
 96
 97""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 98"URL EMAIL:
 99"syn case match
100syn match t2tEmail '\<[A-Za-z0-9_.-]\+@\([A-Za-z0-9_-]\+\.\)\+[A-Za-z]\{2,4}\>\(?[A-Za-z0-9%&=+.,@*_-]\+\)\='
101syn 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%._-]\+\)\='
102syn match t2tUrlLocal contained ' \([A-Za-z0-9%._/~,-]\+\|[A-Za-z0-9%._/~,-]*#[A-Za-z0-9%._-]\+\)\]'ms=s+1,me=e-1
103syn match t2tUrlMark '\[[^]]\+ [^] ]\+\]' contains=t2tUrlLabel,t2tUrl,t2tEmail,t2tUrlLocal
104syn match t2tUrlMarkImg '\[\[[[:alnum:]_,.+%$#@!?+~/-]\+\.\(png\|jpe\=g\|gif\|eps\|bmp\)\( \+"[^"]*"\)\{0,1\}\] [^] ]\+\]' contains=t2tUrl,t2tEmail,t2tUrlLocal,t2tImg
105syn match t2tUrlLabel contained '\[[^]]\+ 'ms=s+1,me=e-1
106
107""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
108"FONT BEAUTIFIERS:
109syn match   t2tBold       '\*\*\S\(\|.\{-}\S\)\*\*\+'hs=s+2,he=e-2
110syn match   t2tItalic       '//\S\(\|.\{-}\S\)//\+'hs=s+2,he=e-2
111syn match   t2tUnderline    '__\S\(\|.\{-}\S\)__\+'hs=s+2,he=e-2
112syn match   t2tStrike       '--\S\(\|.\{-}\S\)--\+'hs=s+2,he=e-2
113syn match   t2tMonospace    '``\S\(\|.\{-}\S\)``\+'hs=s+2,he=e-2
114syn match   t2tRaw          '""\S\(\|.\{-}\S\)""\+'hs=s+2,he=e-2
115syn match   t2tTagged       "''\S\(\|.\{-}\S\)''\+"hs=s+2,he=e-2
116syn match   t2tVerb1Line     '^``` .*$'hs=s+3
117syn match   t2tRaw1Line      '^""" .*$'hs=s+3
118syn match   t2tTagged1Line   "^''' .*$"hs=s+3
119syn region  t2tVerbArea     start='^```\s*$'hs=s+3 end='^```\s*$'he=e-3
120syn region  t2tRawArea      start='^"""\s*$'hs=s+3 end='^"""\s*$'he=e-3
121syn region  t2tTaggedArea   start="^'''\s*$"hs=s+3 end="^'''\s*$"he=e-3
122syn match   t2tComment '^%.*$' contains=t2tTodo,t2tFoldMark,t2tIncluded
123syn region  t2tCommentArea  start="^%%%\s*$" end="^%%%\s*$"
124
125"Experimental
126syn region  t2tTableArea  start="^|||\s*$" end="^|||\s*$" contains=t2tTableTab,t2tComment
127syn match   t2tTableTab '\t' contained
128"hi t2tTableTab    term=reverse     cterm=reverse     gui=reverse
129"hi link t2tTableArea  Statement
130set list listchars=tab:??
131
132
133""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
134"TABLE:
135syn match   t2tTableAlign contained ' \+$'
136syn match   t2tTableMark  contained '^ *[^ ]\+'
137syn match   t2tTableBar   contained ' |\+ '     contains=t2tBlank
138syn match   t2tTableBar   contained '|\+\s*$'   contains=t2tBlank
139syn match   t2tTableTit   contained '^ *||.*' contains=t2tTableMark,t2tTableBar,t2tTableAlign
140syn match   t2tTable             '^ *||\= .*' contains=t2tTableMark,t2tTableBar,t2tTableTit,@t2tBeautifiers,@t2tComponents,t2tTableAlign
141
142""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
143"MISC:
144syn keyword t2tTodo    TODO FIXME XXX contained
145syn match   t2tNumber  '\<\d\+\([,.]\d\+\)\{,1}\>'
146syn match   t2tPercent '\<\d\+\([,.]\d\+\)\{,1}%'
147syn match   t2tBlank   '\s\+$'
148syn match   t2tQuote   '^\t\+'
149syn match   t2tBar     '^\s*[_=-]\{20,}\s*$' contains=t2tQuote
150syn match   t2tImg     '\[[[:alnum:]_,.+%$#@!?+~/-]\+\.\(png\|jpe\=g\|gif\|eps\|bmp\)\( \+"[^"]*"\)\{0,1\}\]'
151
152""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
153"MACROS AND COMMANDS:
154"syn match   t2tMacro    '%%[a-z]\+'
155syn match   t2tMacro    '%%\(date\|mtime\|infile\|outfile\)\>\(([^)]*)\)\='
156syn match   t2tMacro    '^ *%%toc\s*$'
157syn match   t2tIncluded '^%INCLUDED([a-z2]\+)'ms=s+1 contained 
158syn match   t2tIncluded '^%--\{10,} Area Delimiter:'ms=s+1 contained 
159syn 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
160
161""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
162"FOLD:
163syn match  t2tFoldMark '\({{{\|}}}\)$'
164syn region t2tUserFold keepend transparent fold start='^%.\+{{{$' end='^%.*}}}$'
165syn region t2tTitleFold    transparent fold start='^ *=[^=].*[^=]=\(\[[a-z0-9_-]*\]\)\=\s*$' end='\n\n\n\n'
166syn region t2tNumtitleFold transparent fold start='^ *+[^+].*[^+]+\(\[[a-z0-9_-]*\]\)\=\s*$' end='\n\n\n\n'
167"heavy-folding-users: uncomment the following to fold *every* subtitle area
168"syn region t2tTitleFoldDeep transparent fold start='^ *\(=\{2,5}\)[^=].*[^=]\1$' end='\n\n\n\n'
169"syn region t2tNumtitleFoldDeep transparent fold start='^ *\(+\{2,5}\)[^+].*[^+]\1$' end='\n\n\n\n'
170
171""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
172"HEADERS AND CONFIG:
173"Headers are the first 3 lines
174"Config are special comments right after the headers
175"Config Area ends on a no-comment and no-blank line
176syn keyword t2tTargets    contained txt xhtml html sgml tex lout mgp man
177syn keyword t2tTargets    contained moin pm6 wiki gwiki doku dbk creole
178syn keyword t2tTargets    contained pmw adoc art
179syn match t2tConfigString contained +"[^"]*"\|'[^']*'+
180syn match t2tConfigValue  contained ':.*'ms=s+1 contains=t2tConfigString
181syn match t2tConfigKey    contained '^%![^:]\+:' contains=t2tTargets
182syn 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
183syn match t2tConfigLine   contained "^%!\s*target\s*:\s*\S.*" contains=t2tConfigKey,t2tTargets
184syn match t2tConfigLine   contained "^%!\s*guicolors\s*:\s*\(\S\+\s\+\)\{3}\S\+\s*$" contains=t2tConfigKey,t2tTargets
185
186syn match  t2tHeaderArea  contained '\%^.*\n.*\n.*$' contains=t2tMacro
187syn 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
188syn 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
189
190
191syn 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
192syn region t2tTopAreaNoHead start='\%^\s*$'  end='^[^%]'me=e-1 end='^%!include[^c]'me=e-10 end='%%\(date\|mtim\|infi\|outf\)'me=e-6 contains=t2tConfigAreaNoHeader
193
194""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
195"
196" color groups
197hi default link t2t_Link       PreProc
198hi default link t2t_Component  Statement
199hi default link t2t_Delim      Identifier
200hi default link t2t_Verb       Type
201hi default link t2t_Raw        String
202hi default link t2t_Tagged     Special
203"
204" color definitions (specific)
205hi default t2tBar         term=bold        cterm=bold        gui=bold
206hi default t2tBold        term=bold        cterm=bold        gui=bold
207hi default t2tItalic      term=italic      cterm=italic      gui=italic
208hi default t2tStrike      term=italic      cterm=italic      gui=italic
209hi default t2tUnderline   term=underline   cterm=underline   gui=underline
210hi default t2tQuote       term=reverse     cterm=reverse     gui=reverse
211hi default t2tTableAlign  term=reverse     cterm=reverse     gui=reverse
212if &background == "light"
213    hi default t2tComment     ctermfg=brown    guifg=brown
214else
215    hi default t2tComment     ctermfg=brown    guifg=bisque
216endif
217hi default link t2tCommentArea t2tComment 
218"
219" color definitions (using Vim defaults)
220hi default link t2tTitle         Error
221hi default link t2tNumTitle      Error
222" comment the following line to avoid having trailing whitespaces in red
223hi default link t2tBlank         Error
224hi default link t2tNumber        Number
225hi default link t2tPercent       Number
226hi default link t2tFoldMark      Special
227hi default link t2tTodo          Todo
228hi default link t2tCommand       Special
229hi default      t2tIncluded      cterm=bold
230hi default link t2tTargets       Type
231hi default link t2tConfigKey     Special
232hi default link t2tConfigValue   NONE
233hi default link t2tConfigString  String
234hi default link t2tHeaderArea    t2t_Raw
235hi default link t2tUrlMark       t2t_Delim
236hi default link t2tUrlMarkImg    t2t_Delim
237hi default link t2tUrlLabel      t2t_Delim
238hi default link t2tTableTit      t2t_Delim
239hi default link t2tTableMark     t2t_Delim
240hi default link t2tTableBar      t2t_Delim
241hi default link t2tEmail         t2t_Link
242hi default link t2tUrl           t2t_Link
243hi default link t2tUrlLocal      t2t_Link
244hi default link t2tTitleRef      t2t_Link
245hi default link t2tMacro         t2t_Component
246hi default link t2tImg           t2t_Component
247hi default link t2tList          t2t_Component
248hi default link t2tMacro         t2t_Component
249hi default link t2tTitleMark     NONE
250hi default link t2tVerbArea      t2t_Verb
251hi default link t2tVerb1Line     t2t_Verb
252hi default link t2tMonospace     t2t_Verb
253hi default link t2tRaw           t2t_Raw
254hi default link t2tRaw1Line      t2t_Raw
255hi default link t2tRawArea       t2t_Raw
256hi default link t2tTagged        t2t_Tagged
257hi default link t2tTagged1Line   t2t_Tagged
258hi default link t2tTaggedArea    t2t_Tagged
259
260"
261let b:current_syntax = 'txt2tags'
262" vim:tw=0:et