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: 2008 Jul 01
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
32 " 2008 July 1: Removed % from guess list, as it totally breaks plain
33 " text markup guessing
37 " For version 5.x: Clear all syntax items
38 " For version 6.x: Quit when a syntax file was already loaded
41 elseif exists("b:current_syntax")
45 " First off, see if we can inherit a user preference for lhs_markup
46 if !exists("b:lhs_markup")
47 if exists("lhs_markup")
48 if lhs_markup =~ '\<\%(tex\|none\)\>'
49 let b:lhs_markup = matchstr(lhs_markup,'\<\%(tex\|none\)\>')
51 echohl WarningMsg | echo "Unknown value of lhs_markup" | echohl None
52 let b:lhs_markup = "unknown"
55 let b:lhs_markup = "unknown"
58 if b:lhs_markup !~ '\<\%(tex\|none\)\>'
59 let b:lhs_markup = "unknown"
63 " Remember where the cursor is, and go to upperleft
64 let s:oldline=line(".")
65 let s:oldcolumn=col(".")
68 " If no user preference, scan buffer for our guess of the markup to
69 " highlight. We only differentiate between TeX and plain markup, where
70 " plain is not highlighted. The heuristic for finding TeX markup is if
71 " one of the following occurs anywhere in the file:
73 " - \begin{env} (for env != code)
74 " - \part, \chapter, \section, \subsection, \subsubsection, etc
75 if b:lhs_markup == "unknown"
76 if search('\\documentclass\|\\begin{\(code}\)\@!\|\\\(sub \)*section\|\\chapter|\\part','W') != 0
77 let b:lhs_markup = "tex"
79 let b:lhs_markup = "plain"
83 " If user wants us to highlight TeX syntax or guess thinks it's TeX, read it.
84 if b:lhs_markup == "tex"
86 source <sfile>:p:h/tex.vim
89 runtime! syntax/tex.vim
90 unlet b:current_syntax
91 " Tex.vim removes "_" from 'iskeyword', but we need it for Haskell.
96 " Literate Haskell is Haskell in between text, so at least read Haskell
99 syntax include @haskellTop <sfile>:p:h/haskell.vim
101 syntax include @haskellTop syntax/haskell.vim
104 syntax region lhsHaskellBirdTrack start="^>" end="\%(^[^>]\)\@=" contains=@haskellTop,lhsBirdTrack
105 syntax region lhsHaskellBeginEndBlock start="^\\begin{code}\s*$" matchgroup=NONE end="\%(^\\end{code}.*$\)\@=" contains=@haskellTop,@beginCode
107 syntax match lhsBirdTrack "^>" contained
109 syntax match beginCodeBegin "^\\begin" nextgroup=beginCodeCode contained
110 syntax region beginCodeCode matchgroup=texDelimiter start="{" end="}"
111 syntax cluster beginCode contains=beginCodeBegin,beginCodeCode
113 " Define the default highlighting.
114 " For version 5.7 and earlier: only when not done already
115 " For version 5.8 and later: only when an item doesn't have highlighting yet
116 if version >= 508 || !exists("did_tex_syntax_inits")
118 let did_tex_syntax_inits = 1
119 command -nargs=+ HiLink hi link <args>
121 command -nargs=+ HiLink hi def link <args>
124 HiLink lhsBirdTrack Comment
126 HiLink beginCodeBegin texCmdName
127 HiLink beginCodeCode texSection
132 " Restore cursor to original position, as it may have been disturbed
133 " by the searches in our guessing code
134 call cursor (s:oldline, s:oldcolumn)
139 let b:current_syntax = "lhaskell"