blob: 7ff09e7b3b523826e85d1f6201bbc104d3a44359 [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 Moolenaarc236c162008-07-13 17:41:49 +00007" Last Change: 2008 Jul 01
8" Version: 1.02
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 Moolenaarc236c162008-07-13 17:41:49 +000032" 2008 July 1: Removed % from guess list, as it totally breaks plain
33" text markup guessing
Bram Moolenaar071d4272004-06-13 20:20:40 +000034"
35
36
37" For version 5.x: Clear all syntax items
38" For version 6.x: Quit when a syntax file was already loaded
39if version < 600
40 syntax clear
41elseif exists("b:current_syntax")
42 finish
43endif
44
45" First off, see if we can inherit a user preference for lhs_markup
46if !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\)\>')
50 else
51 echohl WarningMsg | echo "Unknown value of lhs_markup" | echohl None
52 let b:lhs_markup = "unknown"
53 endif
54 else
55 let b:lhs_markup = "unknown"
56 endif
57else
58 if b:lhs_markup !~ '\<\%(tex\|none\)\>'
59 let b:lhs_markup = "unknown"
60 endif
61endif
62
63" Remember where the cursor is, and go to upperleft
64let s:oldline=line(".")
65let s:oldcolumn=col(".")
66call cursor(1,1)
67
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:
72" - \documentclass
73" - \begin{env} (for env != code)
74" - \part, \chapter, \section, \subsection, \subsubsection, etc
75if b:lhs_markup == "unknown"
Bram Moolenaarc236c162008-07-13 17:41:49 +000076 if search('\\documentclass\|\\begin{\(code}\)\@!\|\\\(sub \)*section\|\\chapter|\\part','W') != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000077 let b:lhs_markup = "tex"
78 else
79 let b:lhs_markup = "plain"
80 endif
81endif
82
Bram Moolenaarc236c162008-07-13 17:41:49 +000083" If user wants us to highlight TeX syntax or guess thinks it's TeX, read it.
Bram Moolenaar071d4272004-06-13 20:20:40 +000084if b:lhs_markup == "tex"
85 if version < 600
86 source <sfile>:p:h/tex.vim
Bram Moolenaard4755bb2004-09-02 19:12:26 +000087 set isk+=_
Bram Moolenaar071d4272004-06-13 20:20:40 +000088 else
89 runtime! syntax/tex.vim
90 unlet b:current_syntax
Bram Moolenaard4755bb2004-09-02 19:12:26 +000091 " Tex.vim removes "_" from 'iskeyword', but we need it for Haskell.
92 setlocal isk+=_
Bram Moolenaar071d4272004-06-13 20:20:40 +000093 endif
94endif
95
96" Literate Haskell is Haskell in between text, so at least read Haskell
97" highlighting
98if version < 600
99 syntax include @haskellTop <sfile>:p:h/haskell.vim
100else
101 syntax include @haskellTop syntax/haskell.vim
102endif
103
104syntax region lhsHaskellBirdTrack start="^>" end="\%(^[^>]\)\@=" contains=@haskellTop,lhsBirdTrack
105syntax region lhsHaskellBeginEndBlock start="^\\begin{code}\s*$" matchgroup=NONE end="\%(^\\end{code}.*$\)\@=" contains=@haskellTop,@beginCode
106
107syntax match lhsBirdTrack "^>" contained
108
109syntax match beginCodeBegin "^\\begin" nextgroup=beginCodeCode contained
110syntax region beginCodeCode matchgroup=texDelimiter start="{" end="}"
111syntax cluster beginCode contains=beginCodeBegin,beginCodeCode
112
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
116if version >= 508 || !exists("did_tex_syntax_inits")
117 if version < 508
118 let did_tex_syntax_inits = 1
119 command -nargs=+ HiLink hi link <args>
120 else
121 command -nargs=+ HiLink hi def link <args>
122 endif
123
124 HiLink lhsBirdTrack Comment
125
126 HiLink beginCodeBegin texCmdName
127 HiLink beginCodeCode texSection
128
129 delcommand HiLink
130endif
131
132" Restore cursor to original position, as it may have been disturbed
133" by the searches in our guessing code
134call cursor (s:oldline, s:oldcolumn)
135
136unlet s:oldline
137unlet s:oldcolumn
138
139let b:current_syntax = "lhaskell"
140
141" vim: ts=8