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 <haskell-cafe@haskell.org>
6 " Original Author: Arthur van Leeuwen <arthurvl@cs.uu.nl>
7 " Last Change: 2004 Aug 31
10 " Thanks to Ian Lynagh for thoughtful comments on initial versions and
11 " for the inspiration for writing this in the first place.
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.
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
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
35 " For version 5.x: Clear all syntax items
36 " For version 6.x: Quit when a syntax file was already loaded
39 elseif exists("b:current_syntax")
43 " First off, see if we can inherit a user preference for lhs_markup
44 if !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\)\>')
49 echohl WarningMsg | echo "Unknown value of lhs_markup" | echohl None
50 let b:lhs_markup = "unknown"
53 let b:lhs_markup = "unknown"
56 if b:lhs_markup !~ '\<\%(tex\|none\)\>'
57 let b:lhs_markup = "unknown"
61 " Remember where the cursor is, and go to upperleft
62 let s:oldline=line(".")
63 let s:oldcolumn=col(".")
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:
71 " - \begin{env} (for env != code)
72 " - \part, \chapter, \section, \subsection, \subsubsection, etc
73 if b:lhs_markup == "unknown"
74 if search('%\|\\documentclass\|\\begin{\(code}\)\@!\|\\\(sub\)*section\|\\chapter|\\part','W') != 0
75 let b:lhs_markup = "tex"
77 let b:lhs_markup = "plain"
81 " If user wants us to highlight TeX syntax, read it.
82 if b:lhs_markup == "tex"
84 source <sfile>:p:h/tex.vim
87 runtime! syntax/tex.vim
88 unlet b:current_syntax
89 " Tex.vim removes "_" from 'iskeyword', but we need it for Haskell.
94 " Literate Haskell is Haskell in between text, so at least read Haskell
97 syntax include @haskellTop <sfile>:p:h/haskell.vim
99 syntax include @haskellTop syntax/haskell.vim
102 syntax region lhsHaskellBirdTrack start="^>" end="\%(^[^>]\)\@=" contains=@haskellTop,lhsBirdTrack
103 syntax region lhsHaskellBeginEndBlock start="^\\begin{code}\s*$" matchgroup=NONE end="\%(^\\end{code}.*$\)\@=" contains=@haskellTop,@beginCode
105 syntax match lhsBirdTrack "^>" contained
107 syntax match beginCodeBegin "^\\begin" nextgroup=beginCodeCode contained
108 syntax region beginCodeCode matchgroup=texDelimiter start="{" end="}"
109 syntax cluster beginCode contains=beginCodeBegin,beginCodeCode
111 " Define the default highlighting.
112 " For version 5.7 and earlier: only when not done already
113 " For version 5.8 and later: only when an item doesn't have highlighting yet
114 if version >= 508 || !exists("did_tex_syntax_inits")
116 let did_tex_syntax_inits = 1
117 command -nargs=+ HiLink hi link <args>
119 command -nargs=+ HiLink hi def link <args>
122 HiLink lhsBirdTrack Comment
124 HiLink beginCodeBegin texCmdName
125 HiLink beginCodeCode texSection
130 " Restore cursor to original position, as it may have been disturbed
131 " by the searches in our guessing code
132 call cursor (s:oldline, s:oldcolumn)
137 let b:current_syntax = "lhaskell"