blob: 077549a0c8b1d7d5b86f6832d76398573e4db8af [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" 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 <haskell-cafe@haskell.org>
6" Original Author: Arthur van Leeuwen <arthurvl@cs.uu.nl>
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007" Last Change: 2010 Apr 11
Bram Moolenaar5c736222010-01-06 20:54:52 +01008" Version: 1.04
Bram Moolenaar071d4272004-06-13 20:20:40 +00009"
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
Bram Moolenaar5c736222010-01-06 20:54:52 +010032" 2008 July 1: Removed % from guess list, as it totally breaks plain
33" text markup guessing
34" 2009 April 29: Fixed highlighting breakage in TeX mode,
35" thanks to Kalman Noel
Bram Moolenaar071d4272004-06-13 20:20:40 +000036"
37
38
39" For version 5.x: Clear all syntax items
40" For version 6.x: Quit when a syntax file was already loaded
41if version < 600
42 syntax clear
43elseif exists("b:current_syntax")
44 finish
45endif
46
47" First off, see if we can inherit a user preference for lhs_markup
48if !exists("b:lhs_markup")
49 if exists("lhs_markup")
50 if lhs_markup =~ '\<\%(tex\|none\)\>'
51 let b:lhs_markup = matchstr(lhs_markup,'\<\%(tex\|none\)\>')
52 else
53 echohl WarningMsg | echo "Unknown value of lhs_markup" | echohl None
54 let b:lhs_markup = "unknown"
55 endif
56 else
57 let b:lhs_markup = "unknown"
58 endif
59else
60 if b:lhs_markup !~ '\<\%(tex\|none\)\>'
61 let b:lhs_markup = "unknown"
62 endif
63endif
64
65" Remember where the cursor is, and go to upperleft
66let s:oldline=line(".")
67let s:oldcolumn=col(".")
68call cursor(1,1)
69
70" If no user preference, scan buffer for our guess of the markup to
71" highlight. We only differentiate between TeX and plain markup, where
72" plain is not highlighted. The heuristic for finding TeX markup is if
73" one of the following occurs anywhere in the file:
74" - \documentclass
75" - \begin{env} (for env != code)
76" - \part, \chapter, \section, \subsection, \subsubsection, etc
77if b:lhs_markup == "unknown"
Bram Moolenaar5c736222010-01-06 20:54:52 +010078 if search('\\documentclass\|\\begin{\(code}\)\@!\|\\\(sub\)*section\|\\chapter|\\part','W') != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000079 let b:lhs_markup = "tex"
80 else
81 let b:lhs_markup = "plain"
82 endif
83endif
84
Bram Moolenaar5c736222010-01-06 20:54:52 +010085" If user wants us to highlight TeX syntax or guess thinks it's TeX, read it.
Bram Moolenaar071d4272004-06-13 20:20:40 +000086if b:lhs_markup == "tex"
87 if version < 600
88 source <sfile>:p:h/tex.vim
Bram Moolenaard4755bb2004-09-02 19:12:26 +000089 set isk+=_
Bram Moolenaar071d4272004-06-13 20:20:40 +000090 else
91 runtime! syntax/tex.vim
92 unlet b:current_syntax
Bram Moolenaard4755bb2004-09-02 19:12:26 +000093 " Tex.vim removes "_" from 'iskeyword', but we need it for Haskell.
94 setlocal isk+=_
Bram Moolenaar071d4272004-06-13 20:20:40 +000095 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010096 syntax cluster lhsTeXContainer contains=tex.*Zone,texAbstract
97else
98 syntax cluster lhsTeXContainer contains=.*
Bram Moolenaar071d4272004-06-13 20:20:40 +000099endif
100
101" Literate Haskell is Haskell in between text, so at least read Haskell
102" highlighting
103if version < 600
104 syntax include @haskellTop <sfile>:p:h/haskell.vim
105else
106 syntax include @haskellTop syntax/haskell.vim
107endif
108
Bram Moolenaar5c736222010-01-06 20:54:52 +0100109syntax region lhsHaskellBirdTrack start="^>" end="\%(^[^>]\)\@=" contains=@haskellTop,lhsBirdTrack containedin=@lhsTeXContainer
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200110syntax region lhsHaskellBeginEndBlock start="^\\begin{code}\s*$" matchgroup=NONE end="\%(^\\end{code}.*$\)\@=" contains=@haskellTop,beginCodeBegin containedin=@lhsTeXContainer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000111
112syntax match lhsBirdTrack "^>" contained
113
114syntax match beginCodeBegin "^\\begin" nextgroup=beginCodeCode contained
115syntax region beginCodeCode matchgroup=texDelimiter start="{" end="}"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000116
117" Define the default highlighting.
118" For version 5.7 and earlier: only when not done already
119" For version 5.8 and later: only when an item doesn't have highlighting yet
120if version >= 508 || !exists("did_tex_syntax_inits")
121 if version < 508
122 let did_tex_syntax_inits = 1
123 command -nargs=+ HiLink hi link <args>
124 else
125 command -nargs=+ HiLink hi def link <args>
126 endif
127
128 HiLink lhsBirdTrack Comment
129
130 HiLink beginCodeBegin texCmdName
131 HiLink beginCodeCode texSection
132
133 delcommand HiLink
134endif
135
136" Restore cursor to original position, as it may have been disturbed
137" by the searches in our guessing code
138call cursor (s:oldline, s:oldcolumn)
139
140unlet s:oldline
141unlet s:oldcolumn
142
143let b:current_syntax = "lhaskell"
144
145" vim: ts=8