Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 <haskell-cafe@haskell.org> |
| 6 | " Original Author: Arthur van Leeuwen <arthurvl@cs.uu.nl> |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7 | " Last Change: 2010 Apr 11 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 8 | " Version: 1.04 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 32 | " 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 Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 36 | " |
| 37 | |
| 38 | |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 39 | " quit when a syntax file was already loaded |
| 40 | if exists("b:current_syntax") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 41 | finish |
| 42 | endif |
| 43 | |
| 44 | " First off, see if we can inherit a user preference for lhs_markup |
| 45 | if !exists("b:lhs_markup") |
| 46 | if exists("lhs_markup") |
| 47 | if lhs_markup =~ '\<\%(tex\|none\)\>' |
| 48 | let b:lhs_markup = matchstr(lhs_markup,'\<\%(tex\|none\)\>') |
| 49 | else |
| 50 | echohl WarningMsg | echo "Unknown value of lhs_markup" | echohl None |
| 51 | let b:lhs_markup = "unknown" |
| 52 | endif |
| 53 | else |
| 54 | let b:lhs_markup = "unknown" |
| 55 | endif |
| 56 | else |
| 57 | if b:lhs_markup !~ '\<\%(tex\|none\)\>' |
| 58 | let b:lhs_markup = "unknown" |
| 59 | endif |
| 60 | endif |
| 61 | |
| 62 | " Remember where the cursor is, and go to upperleft |
| 63 | let s:oldline=line(".") |
| 64 | let s:oldcolumn=col(".") |
| 65 | call cursor(1,1) |
| 66 | |
| 67 | " If no user preference, scan buffer for our guess of the markup to |
| 68 | " highlight. We only differentiate between TeX and plain markup, where |
| 69 | " plain is not highlighted. The heuristic for finding TeX markup is if |
| 70 | " one of the following occurs anywhere in the file: |
| 71 | " - \documentclass |
| 72 | " - \begin{env} (for env != code) |
| 73 | " - \part, \chapter, \section, \subsection, \subsubsection, etc |
| 74 | if b:lhs_markup == "unknown" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 75 | if search('\\documentclass\|\\begin{\(code}\)\@!\|\\\(sub\)*section\|\\chapter|\\part','W') != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 76 | let b:lhs_markup = "tex" |
| 77 | else |
| 78 | let b:lhs_markup = "plain" |
| 79 | endif |
| 80 | endif |
| 81 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 82 | " If user wants us to highlight TeX syntax or guess thinks it's TeX, read it. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 83 | if b:lhs_markup == "tex" |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 84 | runtime! syntax/tex.vim |
| 85 | unlet b:current_syntax |
| 86 | " Tex.vim removes "_" from 'iskeyword', but we need it for Haskell. |
| 87 | setlocal isk+=_ |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 88 | syntax cluster lhsTeXContainer contains=tex.*Zone,texAbstract |
| 89 | else |
| 90 | syntax cluster lhsTeXContainer contains=.* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 91 | endif |
| 92 | |
| 93 | " Literate Haskell is Haskell in between text, so at least read Haskell |
| 94 | " highlighting |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 95 | syntax include @haskellTop syntax/haskell.vim |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 96 | |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 97 | syntax region lhsHaskellBirdTrack start="^>" end="\%(^[^>]\)\@=" contains=@haskellTop,lhsBirdTrack containedin=@lhsTeXContainer |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 98 | syntax region lhsHaskellBeginEndBlock start="^\\begin{code}\s*$" matchgroup=NONE end="\%(^\\end{code}.*$\)\@=" contains=@haskellTop,beginCodeBegin containedin=@lhsTeXContainer |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 99 | |
| 100 | syntax match lhsBirdTrack "^>" contained |
| 101 | |
| 102 | syntax match beginCodeBegin "^\\begin" nextgroup=beginCodeCode contained |
| 103 | syntax region beginCodeCode matchgroup=texDelimiter start="{" end="}" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 104 | |
| 105 | " Define the default highlighting. |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 106 | " Only when an item doesn't have highlighting yet |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 107 | |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 108 | hi def link lhsBirdTrack Comment |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 109 | |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 110 | hi def link beginCodeBegin texCmdName |
| 111 | hi def link beginCodeCode texSection |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 112 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 113 | |
| 114 | " Restore cursor to original position, as it may have been disturbed |
| 115 | " by the searches in our guessing code |
| 116 | call cursor (s:oldline, s:oldcolumn) |
| 117 | |
| 118 | unlet s:oldline |
| 119 | unlet s:oldcolumn |
| 120 | |
| 121 | let b:current_syntax = "lhaskell" |
| 122 | |
| 123 | " vim: ts=8 |