neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

lhaskell.vim (4973B)


      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
     41 if exists("b:current_syntax")
     42  finish
     43 endif
     44 
     45 " First off, see if we can inherit a user preference for lhs_markup
     46 if !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
     57 else
     58    if b:lhs_markup !~ '\<\%(tex\|md\|none\)\>'
     59 let b:lhs_markup = "unknown"
     60    endif
     61 endif
     62 
     63 " Remember where the cursor is, and go to upperleft
     64 let s:oldline=line(".")
     65 let s:oldcolumn=col(".")
     66 call 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
     75 if 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
     83 endif
     84 
     85 " If user wants us to highlight TeX syntax or guess thinks it's TeX, read it.
     86 if 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
     92 elseif b:lhs_markup == "md"
     93    runtime! syntax/markdown.vim
     94    unlet b:current_syntax
     95    syntax cluster lhsTeXContainer contains=markdown.*
     96 else
     97    syntax cluster lhsTeXContainer contains=.*
     98 endif
     99 
    100 " Literate Haskell is Haskell in between text, so at least read Haskell
    101 " highlighting
    102 syntax include @haskellTop syntax/haskell.vim
    103 
    104 syntax region lhsHaskellBirdTrack start="^>" end="\%(^[^>]\)\@=" contains=@haskellTop,lhsBirdTrack containedin=@lhsTeXContainer
    105 syntax region lhsHaskellBeginEndBlock start="^\\begin{code}\s*$" matchgroup=NONE end="\%(^\\end{code}.*$\)\@=" contains=@haskellTop,beginCodeBegin containedin=@lhsTeXContainer
    106 syntax region lhsHaskellMDBlock start="^```haskell$" matchgroup=NONE end="^```$" keepend contains=@haskellTop,lhsMarkdownCode containedin=@lhsTeXContainer
    107 
    108 syntax match lhsBirdTrack "^>" contained
    109 
    110 syntax match lhsMarkdownCode "^\(```haskell\|^```\)$" contained
    111 
    112 syntax match beginCodeBegin "^\\begin" nextgroup=beginCodeCode contained
    113 syntax region beginCodeCode  matchgroup=texDelimiter start="{" end="}"
    114 
    115 " Define the default highlighting.
    116 " Only when an item doesn't have highlighting yet
    117 
    118 hi def link lhsBirdTrack Comment
    119 
    120 hi def link lhsMarkdownCode Comment
    121 
    122 hi def link beginCodeBegin	      texCmdName
    123 hi 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
    128 call cursor (s:oldline, s:oldcolumn)
    129 
    130 unlet s:oldline
    131 unlet s:oldcolumn
    132 
    133 let b:current_syntax = "lhaskell"
    134 
    135 " vim: ts=8