robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:57352b2: runtime: mention subscription only ml, fix typo in maintainer email (#37222)db210dd2a4

master
4.9 KiB135 linesraw
1" Vim syntax file
2" Language:		Haskell with literate comments, Bird style,
3"			Markdown style, TeX style and plain text surrounding
4"			\begin{code} \end{code} blocks
5" Maintainer:		Haskell Cafe mailinglist <haskell-cafe@haskell.org>
6" 			(need to be subscribed to post)
7" Original Author:	Arthur van Leeuwen <arthurvl@cs.uu.nl>
8" Last Change:		2020 Feb 25
9" Version:		1.05
10"
11" Thanks to Ian Lynagh for thoughtful comments on initial versions and
12" for the inspiration for writing this in the first place.
13"
14" This style guesses as to the type of markup used in a literate haskell
15" file and will highlight (La)TeX markup if it finds any
16" This behaviour can be overridden, both glabally and locally using
17" the lhs_markup variable or b:lhs_markup variable respectively.
18"
19" lhs_markup	    must be set to either  tex	or  none  to indicate that
20"		    you always want (La)TeX highlighting or no highlighting
21"		    must not be set to let the highlighting be guessed
22" b:lhs_markup	    must be set to eiterh  tex	or  none  to indicate that
23"		    you want (La)TeX highlighting or no highlighting for
24"		    this particular buffer
25"		    must not be set to let the highlighting be guessed
26"
27"
28" 2004 February 18: New version, based on Ian Lynagh's TeX guessing
29"		    lhaskell.vim, cweb.vim, tex.vim, sh.vim and fortran.vim
30" 2004 February 20: Cleaned up the guessing and overriding a bit
31" 2004 February 23: Cleaned up syntax highlighting for \begin{code} and
32"		    \end{code}, added some clarification to the attributions
33" 2008 July 1:      Removed % from guess list, as it totally breaks plain
34"                   text markup guessing
35" 2009 April 29:    Fixed highlighting breakage in TeX mode, 
36"                   thanks to Kalman Noel
37"
38
39
40" quit when a syntax file was already loaded
41if 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\|md\|none\)\>'
49	    let b:lhs_markup = matchstr(lhs_markup,'\<\%(tex\|md\|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\|md\|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"
76    if search('\\documentclass\|\\begin{\(code}\)\@!\|\\\(sub\)*section\|\\chapter|\\part','W') != 0
77	let b:lhs_markup = "tex"
78    elseif search('```haskell','W') != 0
79        let b:lhs_markup = "md"
80    else
81	let b:lhs_markup = "plain"
82    endif
83endif
84
85" If user wants us to highlight TeX syntax or guess thinks it's TeX, read it.
86if b:lhs_markup == "tex"
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    syntax cluster lhsTeXContainer contains=tex.*Zone,texAbstract
92elseif b:lhs_markup == "md"
93    runtime! syntax/markdown.vim
94    unlet b:current_syntax
95    syntax cluster lhsTeXContainer contains=markdown.*
96else
97    syntax cluster lhsTeXContainer contains=.*
98endif
99
100" Literate Haskell is Haskell in between text, so at least read Haskell
101" highlighting
102syntax include @haskellTop syntax/haskell.vim
103
104syntax region lhsHaskellBirdTrack start="^>" end="\%(^[^>]\)\@=" contains=@haskellTop,lhsBirdTrack containedin=@lhsTeXContainer
105syntax region lhsHaskellBeginEndBlock start="^\\begin{code}\s*$" matchgroup=NONE end="\%(^\\end{code}.*$\)\@=" contains=@haskellTop,beginCodeBegin containedin=@lhsTeXContainer
106syntax region lhsHaskellMDBlock start="^```haskell$" matchgroup=NONE end="^```$" keepend contains=@haskellTop,lhsMarkdownCode containedin=@lhsTeXContainer
107
108syntax match lhsBirdTrack "^>" contained
109
110syntax match lhsMarkdownCode "^\(```haskell\|^```\)$" contained
111
112syntax match beginCodeBegin "^\\begin" nextgroup=beginCodeCode contained
113syntax region beginCodeCode  matchgroup=texDelimiter start="{" end="}"
114
115" Define the default highlighting.
116" Only when an item doesn't have highlighting yet
117
118hi def link lhsBirdTrack Comment
119
120hi def link lhsMarkdownCode Comment
121
122hi def link beginCodeBegin	      texCmdName
123hi def link beginCodeCode	      texSection
124
125
126" Restore cursor to original position, as it may have been disturbed
127" by the searches in our guessing code
128call cursor (s:oldline, s:oldcolumn)
129
130unlet s:oldline
131unlet s:oldcolumn
132
133let b:current_syntax = "lhaskell"
134
135" vim: ts=8