1" Vim syntax file 2" Language: Haskell with literate comments, Bird style, 3" TeX style and plain text surrounding 4" \begin{code} \end{code} blocks 5" Maintainer: Haskell Cafe mailinglist <[email protected]> 6" Original Author: Arthur van Leeuwen <[email protected]> 7" Last Change: 2004 May 16 8" Version: 1.01 9" 10" Thanks to Ian Lynagh for thoughtful comments on initial versions and 11" for the inspiration for writing this in the first place. 12" 13" This style guesses as to the type of markup used in a literate haskell 14" file and will highlight (La)TeX markup if it finds any 15" This behaviour can be overridden, both glabally and locally using 16" the lhs_markup variable or b:lhs_markup variable respectively. 17" 18" lhs_markup must be set to either tex or none to indicate that 19" you always want (La)TeX highlighting or no highlighting 20" must not be set to let the highlighting be guessed 21" b:lhs_markup must be set to eiterh tex or none to indicate that 22" you want (La)TeX highlighting or no highlighting for 23" this particular buffer 24" must not be set to let the highlighting be guessed 25" 26" 27" 2004 February 18: New version, based on Ian Lynagh's TeX guessing 28" lhaskell.vim, cweb.vim, tex.vim, sh.vim and fortran.vim 29" 2004 February 20: Cleaned up the guessing and overriding a bit 30" 2004 February 23: Cleaned up syntax highlighting for \begin{code} and 31" \end{code}, added some clarification to the attributions 32" 33 34 35" For version 5.x: Clear all syntax items 36" For version 6.x: Quit when a syntax file was already loaded 37if version < 600 38 syntax clear 39elseif exists("b:current_syntax") 40 finish 41endif 42 43" First off, see if we can inherit a user preference for lhs_markup 44if !exists("b:lhs_markup") 45 if exists("lhs_markup") 46 if lhs_markup =~ '\<\%(tex\|none\)\>' 47 let b:lhs_markup = matchstr(lhs_markup,'\<\%(tex\|none\)\>') 48 else 49 echohl WarningMsg | echo "Unknown value of lhs_markup" | echohl None 50 let b:lhs_markup = "unknown" 51 endif 52 else 53 let b:lhs_markup = "unknown" 54 endif 55else 56 if b:lhs_markup !~ '\<\%(tex\|none\)\>' 57 let b:lhs_markup = "unknown" 58 endif 59endif 60 61" Remember where the cursor is, and go to upperleft 62let s:oldline=line(".") 63let s:oldcolumn=col(".") 64call cursor(1,1) 65 66" If no user preference, scan buffer for our guess of the markup to 67" highlight. We only differentiate between TeX and plain markup, where 68" plain is not highlighted. The heuristic for finding TeX markup is if 69" one of the following occurs anywhere in the file: 70" - \documentclass 71" - \begin{env} (for env != code) 72" - \part, \chapter, \section, \subsection, \subsubsection, etc 73if b:lhs_markup == "unknown" 74 if search('%\|\\documentclass\|\\begin{\(code}\)\@!\|\\\(sub\)*section\|\\chapter|\\part','W') != 0 75 let b:lhs_markup = "tex" 76 else 77 let b:lhs_markup = "plain" 78 endif 79endif 80 81" If user wants us to highlight TeX syntax, read it. 82if b:lhs_markup == "tex" 83 if version < 600 84 source <sfile>:p:h/tex.vim 85 else 86 runtime! syntax/tex.vim 87 unlet b:current_syntax 88 endif 89endif 90 91" Literate Haskell is Haskell in between text, so at least read Haskell 92" highlighting 93if version < 600 94 syntax include @haskellTop <sfile>:p:h/haskell.vim 95else 96 syntax include @haskellTop syntax/haskell.vim 97endif 98 99syntax region lhsHaskellBirdTrack start="^>" end="\%(^[^>]\)\@=" contains=@haskellTop,lhsBirdTrack 100syntax region lhsHaskellBeginEndBlock start="^\\begin{code}\s*$" matchgroup=NONE end="\%(^\\end{code}.*$\)\@=" contains=@haskellTop,@beginCode 101 102syntax match lhsBirdTrack "^>" contained 103 104syntax match beginCodeBegin "^\\begin" nextgroup=beginCodeCode contained 105syntax region beginCodeCode matchgroup=texDelimiter start="{" end="}" 106syntax cluster beginCode contains=beginCodeBegin,beginCodeCode 107 108" Define the default highlighting. 109" For version 5.7 and earlier: only when not done already 110" For version 5.8 and later: only when an item doesn't have highlighting yet 111if version >= 508 || !exists("did_tex_syntax_inits") 112 if version < 508 113 let did_tex_syntax_inits = 1 114 command -nargs=+ HiLink hi link <args> 115 else 116 command -nargs=+ HiLink hi def link <args> 117 endif 118 119 HiLink lhsBirdTrack Comment 120 121 HiLink beginCodeBegin texCmdName 122 HiLink beginCodeCode texSection 123 124 delcommand HiLink 125endif 126 127" Restore cursor to original position, as it may have been disturbed 128" by the searches in our guessing code 129call cursor (s:oldline, s:oldcolumn) 130 131unlet s:oldline 132unlet s:oldcolumn 133 134let b:current_syntax = "lhaskell" 135 136" vim: ts=8 137