xref: /vim-8.2.3635/runtime/syntax/lhaskell.vim (revision 0fa313a7)
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 Aug 31
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	set isk+=_
86    else
87	runtime! syntax/tex.vim
88	unlet b:current_syntax
89	" Tex.vim removes "_" from 'iskeyword', but we need it for Haskell.
90	setlocal isk+=_
91    endif
92endif
93
94" Literate Haskell is Haskell in between text, so at least read Haskell
95" highlighting
96if version < 600
97    syntax include @haskellTop <sfile>:p:h/haskell.vim
98else
99    syntax include @haskellTop syntax/haskell.vim
100endif
101
102syntax region lhsHaskellBirdTrack start="^>" end="\%(^[^>]\)\@=" contains=@haskellTop,lhsBirdTrack
103syntax region lhsHaskellBeginEndBlock start="^\\begin{code}\s*$" matchgroup=NONE end="\%(^\\end{code}.*$\)\@=" contains=@haskellTop,@beginCode
104
105syntax match lhsBirdTrack "^>" contained
106
107syntax match beginCodeBegin "^\\begin" nextgroup=beginCodeCode contained
108syntax region beginCodeCode  matchgroup=texDelimiter start="{" end="}"
109syntax cluster beginCode    contains=beginCodeBegin,beginCodeCode
110
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
114if version >= 508 || !exists("did_tex_syntax_inits")
115  if version < 508
116    let did_tex_syntax_inits = 1
117    command -nargs=+ HiLink hi link <args>
118  else
119    command -nargs=+ HiLink hi def link <args>
120  endif
121
122  HiLink lhsBirdTrack Comment
123
124  HiLink beginCodeBegin	      texCmdName
125  HiLink beginCodeCode	      texSection
126
127  delcommand HiLink
128endif
129
130" Restore cursor to original position, as it may have been disturbed
131" by the searches in our guessing code
132call cursor (s:oldline, s:oldcolumn)
133
134unlet s:oldline
135unlet s:oldcolumn
136
137let b:current_syntax = "lhaskell"
138
139" vim: ts=8
140