| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " Vim syntax file | 
					
						
							|  |  |  | " Language:		Haskell with literate comments, Bird style, | 
					
						
							|  |  |  | "			TeX style and plain text surrounding | 
					
						
							|  |  |  | "			\begin{code} \end{code} blocks | 
					
						
							|  |  |  | " Maintainer:		Haskell Cafe mailinglist <haskell-cafe@haskell.org> | 
					
						
							|  |  |  | " Original Author:	Arthur van Leeuwen <arthurvl@cs.uu.nl> | 
					
						
							| 
									
										
										
										
											2010-05-14 23:24:24 +02:00
										 |  |  | " Last Change:		2010 Apr 11 | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  | " Version:		1.04 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " | 
					
						
							|  |  |  | " Thanks to Ian Lynagh for thoughtful comments on initial versions and | 
					
						
							|  |  |  | " for the inspiration for writing this in the first place. | 
					
						
							|  |  |  | " | 
					
						
							|  |  |  | " This style guesses as to the type of markup used in a literate haskell | 
					
						
							|  |  |  | " file and will highlight (La)TeX markup if it finds any | 
					
						
							|  |  |  | " This behaviour can be overridden, both glabally and locally using | 
					
						
							|  |  |  | " the lhs_markup variable or b:lhs_markup variable respectively. | 
					
						
							|  |  |  | " | 
					
						
							|  |  |  | " lhs_markup	    must be set to either  tex	or  none  to indicate that | 
					
						
							|  |  |  | "		    you always want (La)TeX highlighting or no highlighting | 
					
						
							|  |  |  | "		    must not be set to let the highlighting be guessed | 
					
						
							|  |  |  | " b:lhs_markup	    must be set to eiterh  tex	or  none  to indicate that | 
					
						
							|  |  |  | "		    you want (La)TeX highlighting or no highlighting for | 
					
						
							|  |  |  | "		    this particular buffer | 
					
						
							|  |  |  | "		    must not be set to let the highlighting be guessed | 
					
						
							|  |  |  | " | 
					
						
							|  |  |  | " | 
					
						
							|  |  |  | " 2004 February 18: New version, based on Ian Lynagh's TeX guessing | 
					
						
							|  |  |  | "		    lhaskell.vim, cweb.vim, tex.vim, sh.vim and fortran.vim | 
					
						
							|  |  |  | " 2004 February 20: Cleaned up the guessing and overriding a bit | 
					
						
							|  |  |  | " 2004 February 23: Cleaned up syntax highlighting for \begin{code} and | 
					
						
							|  |  |  | "		    \end{code}, added some clarification to the attributions | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  | " 2008 July 1:      Removed % from guess list, as it totally breaks plain | 
					
						
							|  |  |  | "                   text markup guessing | 
					
						
							|  |  |  | " 2009 April 29:    Fixed highlighting breakage in TeX mode,  | 
					
						
							|  |  |  | "                   thanks to Kalman Noel | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  | " quit when a syntax file was already loaded | 
					
						
							|  |  |  | if exists("b:current_syntax") | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |   finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " First off, see if we can inherit a user preference for lhs_markup | 
					
						
							|  |  |  | if !exists("b:lhs_markup") | 
					
						
							|  |  |  |     if exists("lhs_markup") | 
					
						
							|  |  |  | 	if lhs_markup =~ '\<\%(tex\|none\)\>' | 
					
						
							|  |  |  | 	    let b:lhs_markup = matchstr(lhs_markup,'\<\%(tex\|none\)\>') | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	    echohl WarningMsg | echo "Unknown value of lhs_markup" | echohl None | 
					
						
							|  |  |  | 	    let b:lhs_markup = "unknown" | 
					
						
							|  |  |  | 	endif | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  | 	let b:lhs_markup = "unknown" | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |     if b:lhs_markup !~ '\<\%(tex\|none\)\>' | 
					
						
							|  |  |  | 	let b:lhs_markup = "unknown" | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Remember where the cursor is, and go to upperleft | 
					
						
							|  |  |  | let s:oldline=line(".") | 
					
						
							|  |  |  | let s:oldcolumn=col(".") | 
					
						
							|  |  |  | call cursor(1,1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " If no user preference, scan buffer for our guess of the markup to | 
					
						
							|  |  |  | " highlight. We only differentiate between TeX and plain markup, where | 
					
						
							|  |  |  | " plain is not highlighted. The heuristic for finding TeX markup is if | 
					
						
							|  |  |  | " one of the following occurs anywhere in the file: | 
					
						
							|  |  |  | "   - \documentclass | 
					
						
							|  |  |  | "   - \begin{env}       (for env != code) | 
					
						
							|  |  |  | "   - \part, \chapter, \section, \subsection, \subsubsection, etc | 
					
						
							|  |  |  | if b:lhs_markup == "unknown" | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  |     if search('\\documentclass\|\\begin{\(code}\)\@!\|\\\(sub\)*section\|\\chapter|\\part','W') != 0 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	let b:lhs_markup = "tex" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  | 	let b:lhs_markup = "plain" | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  | " If user wants us to highlight TeX syntax or guess thinks it's TeX, read it. | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | if b:lhs_markup == "tex" | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  |     runtime! syntax/tex.vim | 
					
						
							|  |  |  |     unlet b:current_syntax | 
					
						
							|  |  |  |     " Tex.vim removes "_" from 'iskeyword', but we need it for Haskell. | 
					
						
							|  |  |  |     setlocal isk+=_ | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  |     syntax cluster lhsTeXContainer contains=tex.*Zone,texAbstract | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |     syntax cluster lhsTeXContainer contains=.* | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Literate Haskell is Haskell in between text, so at least read Haskell | 
					
						
							|  |  |  | " highlighting | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  | syntax include @haskellTop syntax/haskell.vim | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  | syntax region lhsHaskellBirdTrack start="^>" end="\%(^[^>]\)\@=" contains=@haskellTop,lhsBirdTrack containedin=@lhsTeXContainer | 
					
						
							| 
									
										
										
										
											2010-05-14 23:24:24 +02:00
										 |  |  | syntax region lhsHaskellBeginEndBlock start="^\\begin{code}\s*$" matchgroup=NONE end="\%(^\\end{code}.*$\)\@=" contains=@haskellTop,beginCodeBegin containedin=@lhsTeXContainer | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | syntax match lhsBirdTrack "^>" contained | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | syntax match beginCodeBegin "^\\begin" nextgroup=beginCodeCode contained | 
					
						
							|  |  |  | syntax region beginCodeCode  matchgroup=texDelimiter start="{" end="}" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Define the default highlighting. | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  | " Only when an item doesn't have highlighting yet | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-31 22:22:10 +02:00
										 |  |  | hi def link lhsBirdTrack Comment | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-31 22:22:10 +02:00
										 |  |  | hi def link beginCodeBegin	      texCmdName | 
					
						
							|  |  |  | hi def link beginCodeCode	      texSection | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | " Restore cursor to original position, as it may have been disturbed | 
					
						
							|  |  |  | " by the searches in our guessing code | 
					
						
							|  |  |  | call cursor (s:oldline, s:oldcolumn) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | unlet s:oldline | 
					
						
							|  |  |  | unlet s:oldcolumn | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let b:current_syntax = "lhaskell" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " vim: ts=8 |