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> |
| 7 | " Last Change: 2004 May 16 |
| 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 |
| 37 | if version < 600 |
| 38 | syntax clear |
| 39 | elseif exists("b:current_syntax") |
| 40 | finish |
| 41 | endif |
| 42 | |
| 43 | " First off, see if we can inherit a user preference for lhs_markup |
| 44 | if !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 |
| 55 | else |
| 56 | if b:lhs_markup !~ '\<\%(tex\|none\)\>' |
| 57 | let b:lhs_markup = "unknown" |
| 58 | endif |
| 59 | endif |
| 60 | |
| 61 | " Remember where the cursor is, and go to upperleft |
| 62 | let s:oldline=line(".") |
| 63 | let s:oldcolumn=col(".") |
| 64 | call 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 |
| 73 | if 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 |
| 79 | endif |
| 80 | |
| 81 | " If user wants us to highlight TeX syntax, read it. |
| 82 | if b:lhs_markup == "tex" |
| 83 | if version < 600 |
| 84 | source <sfile>:p:h/tex.vim |
| 85 | else |
| 86 | runtime! syntax/tex.vim |
| 87 | unlet b:current_syntax |
| 88 | endif |
| 89 | endif |
| 90 | |
| 91 | " Literate Haskell is Haskell in between text, so at least read Haskell |
| 92 | " highlighting |
| 93 | if version < 600 |
| 94 | syntax include @haskellTop <sfile>:p:h/haskell.vim |
| 95 | else |
| 96 | syntax include @haskellTop syntax/haskell.vim |
| 97 | endif |
| 98 | |
| 99 | syntax region lhsHaskellBirdTrack start="^>" end="\%(^[^>]\)\@=" contains=@haskellTop,lhsBirdTrack |
| 100 | syntax region lhsHaskellBeginEndBlock start="^\\begin{code}\s*$" matchgroup=NONE end="\%(^\\end{code}.*$\)\@=" contains=@haskellTop,@beginCode |
| 101 | |
| 102 | syntax match lhsBirdTrack "^>" contained |
| 103 | |
| 104 | syntax match beginCodeBegin "^\\begin" nextgroup=beginCodeCode contained |
| 105 | syntax region beginCodeCode matchgroup=texDelimiter start="{" end="}" |
| 106 | syntax cluster beginCode contains=beginCodeBegin,beginCodeCode |
| 107 | |
| 108 | " Define the default highlighting. |
| 109 | " For version 5.7 and earlier: only when not done already |
| 110 | " For version 5.8 and later: only when an item doesn't have highlighting yet |
| 111 | if version >= 508 || !exists("did_tex_syntax_inits") |
| 112 | if version < 508 |
| 113 | let did_tex_syntax_inits = 1 |
| 114 | command -nargs=+ HiLink hi link <args> |
| 115 | else |
| 116 | command -nargs=+ HiLink hi def link <args> |
| 117 | endif |
| 118 | |
| 119 | HiLink lhsBirdTrack Comment |
| 120 | |
| 121 | HiLink beginCodeBegin texCmdName |
| 122 | HiLink beginCodeCode texSection |
| 123 | |
| 124 | delcommand HiLink |
| 125 | endif |
| 126 | |
| 127 | " Restore cursor to original position, as it may have been disturbed |
| 128 | " by the searches in our guessing code |
| 129 | call cursor (s:oldline, s:oldcolumn) |
| 130 | |
| 131 | unlet s:oldline |
| 132 | unlet s:oldcolumn |
| 133 | |
| 134 | let b:current_syntax = "lhaskell" |
| 135 | |
| 136 | " vim: ts=8 |