vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

mp.vim (12498B)


      1 vim9script
      2 
      3 # Vim syntax file
      4 # Language:           MetaPost
      5 # Maintainer:         Nicola Vitacolonna <nvitacolonna@gmail.com>
      6 # Former Maintainers: Andreas Scherer <andreas.scherer@pobox.com>
      7 # Latest Revision:    2026 Jan 10
      8 
      9 if exists("b:current_syntax")
     10   finish
     11 endif
     12 
     13 # Deprecation warnings: to be removed eventually
     14 if exists("g:plain_mp_macros")
     15   echomsg "[mp] g:plain_mp_macros is deprecated: use g:mp_plain_macros instead."
     16 endif
     17 if exists("mfplain_mp_macros")
     18   echomsg "[mp] g:mfplain_mp_macros is deprecated: use g:mp_mfplain_macros instead."
     19 endif
     20 if exists("other_mp_macros")
     21   echomsg "[mp] g:other_mp_macros is deprecated: use g:mp_other_macros instead."
     22 endif
     23 
     24 # Store the current values of METAFONT global options
     25 const mf_plain_macros = get(g:, "mf_plain_macros", get(g:, "plain_mf_macros", -1))
     26 const mf_plain_modes  = get(g:, "mf_plain_modes",  get(g:, "plain_mf_modes",  -1))
     27 const mf_other_macros = get(g:, "mf_other_macros", get(g:, "other_mf_macros", -1))
     28 
     29 g:mf_plain_macros = 0 # plain.mf has no special meaning for MetaPost
     30 g:mf_plain_modes  = 0 # No METAFONT modes
     31 g:mf_other_macros = 0 # cmbase.mf, logo.mf, ... neither
     32 
     33 # Read the METAFONT syntax to start with
     34 runtime! syntax/mf.vim
     35 unlet b:current_syntax # Necessary for syn include below
     36 
     37 # Restore the value of existing global variables
     38 if mf_plain_macros == -1
     39   unlet g:mf_plain_macros
     40 else
     41   g:plain_mf_macros = mf_plain_macros
     42 endif
     43 if mf_plain_modes == -1
     44   unlet g:mf_plain_modes
     45 else
     46   g:mf_plain_modes = mf_plain_modes
     47 endif
     48 if mf_other_macros == -1
     49   unlet g:mf_other_macros
     50 else
     51   g:mf_other_macros = mf_other_macros
     52 endif
     53 
     54 # Use TeX highlighting inside verbatimtex/btex... etex
     55 syn include @MPTeX syntax/tex.vim
     56 unlet b:current_syntax
     57 # These are defined as keywords rather than using matchgroup
     58 # in order to make them available to syntaxcomplete.
     59 syn keyword mpTeXdelim       btex etex verbatimtex contained
     60 syn region mpTeXinsert matchgroup=mpTeXdelim start=/\<verbatimtex\>\|\<btex\>/ end=/\<etex\>/ keepend contains=@MPTeX,mpTeXdelim
     61 
     62 # iskeyword must be set after the syn include above, because tex.vim sets `syn
     63 # iskeyword`. Note that keywords do not contain numbers (numbers are
     64 # subscripts)
     65 syntax iskeyword @,_
     66 
     67 # MetaPost primitives not found in METAFONT
     68 syn keyword mpBoolExp        bounded clipped filled stroked textual arclength
     69 syn keyword mpNumExp         arctime blackpart bluepart colormodel cyanpart
     70 syn keyword mpNumExp         fontsize greenpart greypart magentapart redpart
     71 syn keyword mpPairExp        yellowpart llcorner lrcorner ulcorner urcorner
     72 syn keyword mpPathExp        envelope pathpart
     73 syn keyword mpPenExp         penpart
     74 syn keyword mpPicExp         dashpart glyph infont
     75 syn keyword mpStringExp      fontpart readfrom textpart
     76 syn keyword mpType           cmykcolor color rgbcolor
     77 # Other MetaPost primitives listed in the manual
     78 syn keyword mpPrimitive      mpxbreak within
     79 # Internal quantities not found in METAFONT
     80 # (Table 6 in MetaPost: A User's Manual)
     81 syn keyword mpInternal       defaultcolormodel hour minute linecap linejoin
     82 syn keyword mpInternal       miterlimit mpprocset mpversion numberprecision
     83 syn keyword mpInternal       numbersystem outputfilename outputformat
     84 syn keyword mpInternal       outputformatoptions outputtemplate prologues
     85 syn keyword mpInternal       restoreclipcolor tracinglostchars troffmode
     86 syn keyword mpInternal       truecorners
     87 # List of commands not found in METAFONT (from MetaPost: A User's Manual)
     88 syn keyword mpCommand        clip closefrom dashed filenametemplate fontmapfile
     89 syn keyword mpCommand        fontmapline setbounds withcmykcolor withcolor
     90 syn keyword mpCommand        withgreyscale withoutcolor withpostscript
     91 syn keyword mpCommand        withprescript withrgbcolor write
     92 # METAFONT internal variables not found in MetaPost
     93 syn keyword notDefined       autorounding chardx chardy fillin granularity
     94 syn keyword notDefined       proofing smoothing tracingedges tracingpens
     95 syn keyword notDefined       turningcheck xoffset yoffset
     96 # Suffix defined only in METAFONT:
     97 syn keyword notDefined       nodot
     98 # Other not implemented primitives (see MetaPost: A User's Manual, §C.1)
     99 syn keyword notDefined       cull display openwindow numspecial totalweight
    100 syn keyword notDefined       withweight
    101 
    102 # Keywords defined by plain.mp
    103 if get(g:, "mp_plain_macros", get(g:, "plain_mp_macros", 1)) || get(b:, "mp_metafun", get(g:, "mp_metafun", 0))
    104   syn keyword mpDef          beginfig clear_pen_memory clearit clearpen clearpen
    105   syn keyword mpDef          clearxy colorpart cutdraw downto draw drawarrow
    106   syn keyword mpDef          drawdblarrow drawdot drawoptions endfig erase
    107   syn keyword mpDef          exitunless fill filldraw flex gobble hide interact
    108   syn keyword mpDef          label loggingall makelabel numtok penstroke pickup
    109   syn keyword mpDef          range reflectedabout rotatedaround shipit
    110   syn keyword mpDef          stop superellipse takepower tracingall tracingnone
    111   syn keyword mpDef          undraw undrawdot unfill unfilldraw upto
    112   syn match   mpDef          "???"
    113   syn keyword mpVardef       arrowhead bbox bot buildcycle byte ceiling center
    114   syn keyword mpVardef       counterclockwise decr dir direction directionpoint
    115   syn keyword mpVardef       dotlabel dotlabels image incr interpath inverse
    116   syn keyword mpVardef       labels lft magstep max min penlabels penpos round
    117   syn keyword mpVardef       rt savepen solve tensepath thelabel top unitvector
    118   syn keyword mpVardef       whatever z
    119   syn keyword mpPrimaryDef   div dotprod gobbled mod
    120   syn keyword mpSecondaryDef intersectionpoint
    121   syn keyword mpTertiaryDef  cutafter cutbefore softjoin thru
    122   syn keyword mpNewInternal  ahangle ahlength bboxmargin beveled butt defaultpen
    123   syn keyword mpNewInternal  defaultscale dotlabeldiam eps epsilon infinity
    124   syn keyword mpNewInternal  join_radius labeloffset mitered pen_bot pen_lft
    125   syn keyword mpNewInternal  pen_rt pen_top rounded squared tolerance
    126   # Predefined constants
    127   syn keyword mpConstant     EOF background base_name base_version black
    128   syn keyword mpConstant     blankpicture blue ditto down evenly fullcircle
    129   syn keyword mpConstant     green halfcircle identity left origin penrazor
    130   syn keyword mpConstant     penspeck pensquare quartercircle red right
    131   syn keyword mpConstant     unitsquare up white withdots
    132   # Other predefined variables
    133   syn keyword mpVariable     currentpen currentpen_path currentpicture cuttings
    134   syn keyword mpVariable     defaultfont extra_beginfig extra_endfig
    135   syn keyword mpVariable     laboff labxf labyf laboff labxf labyf
    136   syn match   mpVariable     /\.\%(lft\|rt\|bot\|top\|ulft\|urt\|llft\|lrt\)\>/
    137   # let statements:
    138   syn keyword mpnumExp       abs
    139   syn keyword mpDef          rotatedabout
    140   syn keyword mpCommand      bye relax
    141   # on and off are not technically keywords, but it is nice to highlight them
    142   # inside dashpattern().
    143   syn keyword mpOnOff        off on contained
    144   syn keyword mpDash         dashpattern contained
    145   syn region  mpDashPattern start="dashpattern\s*" end=")"he=e-1 contains=mfNumeric,mfLength,mpOnOff,mpDash
    146 endif
    147 
    148 # Keywords defined by mfplain.mp
    149 if get(g:, "mp_mfplain_macros", get(g:, "mfplain_mp_macros", 0))
    150   syn keyword mpDef          beginchar capsule_def change_width
    151   syn keyword mpDef          define_blacker_pixels define_corrected_pixels
    152   syn keyword mpDef          define_good_x_pixels define_good_y_pixels
    153   syn keyword mpDef          define_horizontal_corrected_pixels define_pixels
    154   syn keyword mpDef          define_whole_blacker_pixels define_whole_pixels
    155   syn keyword mpDef          define_whole_vertical_blacker_pixels
    156   syn keyword mpDef          define_whole_vertical_pixels endchar
    157   syn keyword mpDef          font_coding_scheme font_extra_space font_identifier
    158   syn keyword mpDef          font_normal_shrink font_normal_space
    159   syn keyword mpDef          font_normal_stretch font_quad font_size font_slant
    160   syn keyword mpDef          font_x_height italcorr labelfont lowres_fix makebox
    161   syn keyword mpDef          makegrid maketicks mode_def mode_setup proofrule
    162   syn keyword mpDef          smode
    163   syn keyword mpVardef       hround proofrulethickness vround
    164   syn keyword mpNewInternal  blacker o_correction
    165   syn keyword mpVariable     extra_beginchar extra_endchar extra_setup rulepen
    166   # plus some no-ops, also from mfplain.mp
    167   syn keyword mpDef          cull cullit gfcorners imagerules nodisplays
    168   syn keyword mpDef          notransforms openit proofoffset screenchars
    169   syn keyword mpDef          screenrule screenstrokes showit
    170   syn keyword mpVardef       grayfont slantfont titlefont
    171   syn keyword mpVariable     currenttransform
    172   syn keyword mpConstant     unitpixel
    173   # These are not listed in the MetaPost manual, and some are ignored by
    174   # MetaPost, but are nonetheless defined in mfplain.mp
    175   syn keyword mpDef          killtext
    176   syn match   mpVardef       "\<good\.\%(x\|y\|lft\|rt\|top\|bot\)\>"
    177   syn keyword mpVariable     aspect_ratio localfont mag mode mode_name
    178   syn keyword mpVariable     proofcolor
    179   syn keyword mpConstant     lowres proof smoke
    180   syn keyword mpNewInternal  autorounding bp_per_pixel granularity
    181   syn keyword mpNewInternal  number_of_modes proofing smoothing turningcheck
    182 endif
    183 
    184 # Keywords defined by all base macro packages:
    185 # - (r)boxes.mp
    186 # - format.mp
    187 # - graph.mp
    188 # - marith.mp
    189 # - sarith.mp
    190 # - string.mp
    191 # - TEX.mp
    192 if get(g:, "mp_other_macros", get(g:, "other_mp_macros", 1))
    193   # boxes and rboxes
    194   syn keyword mpDef          boxjoin drawboxed drawboxes drawunboxed
    195   syn keyword mpNewInternal  circmargin defaultdx defaultdy rbox_radius
    196   syn keyword mpVardef       boxit bpath circleit fixpos fixsize generic_declare
    197   syn keyword mpVardef       generic_redeclare generisize pic rboxit str_prefix
    198   # format
    199   syn keyword mpVardef       Mformat format init_numbers roundd
    200   syn keyword mpVariable     Fe_base Fe_plus
    201   syn keyword mpConstant     Ten_to
    202   # graph
    203   syn keyword mpDef          Gfor Gxyscale OUT auto begingraph endgraph gdata
    204   syn keyword mpDef          gdraw gdrawarrow gdrawdblarrow gfill plot
    205   syn keyword mpVardef       augment autogrid frame gdotlabel glabel grid itick
    206   syn keyword mpVardef       otick
    207   syn keyword mpVardef       Mreadpath setcoords setrange
    208   syn keyword mpNewInternal  Gmarks Gminlog Gpaths linear log
    209   syn keyword mpVariable     Autoform Gemarks Glmarks Gumarks
    210   syn keyword mpConstant     Gtemplate
    211   syn match   mpVariable     /Gmargin\.\%(low\|high\)/
    212   # marith
    213   syn keyword mpVardef       Mabs Meform Mexp Mexp_str Mlog Mlog_Str Mlog_str
    214   syn keyword mpPrimaryDef   Mdiv Mmul
    215   syn keyword mpSecondaryDef Madd Msub
    216   syn keyword mpTertiaryDef  Mleq
    217   syn keyword mpNewInternal  Mten Mzero
    218   # sarith
    219   syn keyword mpVardef       Sabs Scvnum
    220   syn keyword mpPrimaryDef   Sdiv Smul
    221   syn keyword mpSecondaryDef Sadd Ssub
    222   syn keyword mpTertiaryDef  Sleq Sneq
    223   # string
    224   syn keyword mpVardef       cspan isdigit loptok
    225   # TEX
    226   syn keyword mpVardef       TEX TEXPOST TEXPRE
    227 endif
    228 
    229 if get(b:, "mp_metafun", get(g:, "mp_metafun", 0))
    230   # MetaFun additions to MetaPost base file
    231   syn keyword mpConstant cyan magenta yellow
    232   syn keyword mpConstant penspec
    233   syn keyword mpNumExp   graypart greycolor graycolor
    234 
    235   # Highlight TeX keywords (for MetaPost embedded in ConTeXt documents)
    236   syn match   mpTeXKeyword  '\\[a-zA-Z@]\+'
    237 
    238   syn keyword mpPrimitive runscript
    239 
    240   runtime! syntax/shared/context-data-metafun.vim
    241 
    242   hi def link metafunCommands   Statement
    243   hi def link metafunInternals  Identifier
    244 endif
    245 
    246 # Define the default highlighting
    247 hi def link mpTeXdelim     mpPrimitive
    248 hi def link mpBoolExp      mfBoolExp
    249 hi def link mpNumExp       mfNumExp
    250 hi def link mpPairExp      mfPairExp
    251 hi def link mpPathExp      mfPathExp
    252 hi def link mpPenExp       mfPenExp
    253 hi def link mpPicExp       mfPicExp
    254 hi def link mpStringExp    mfStringExp
    255 hi def link mpInternal     mfInternal
    256 hi def link mpCommand      mfCommand
    257 hi def link mpType         mfType
    258 hi def link mpPrimitive    mfPrimitive
    259 hi def link mpDef          mfDef
    260 hi def link mpVardef       mpDef
    261 hi def link mpPrimaryDef   mpDef
    262 hi def link mpSecondaryDef mpDef
    263 hi def link mpTertiaryDef  mpDef
    264 hi def link mpNewInternal  mpInternal
    265 hi def link mpVariable     mfVariable
    266 hi def link mpConstant     mfConstant
    267 hi def link mpOnOff        mpPrimitive
    268 hi def link mpDash         mpPrimitive
    269 hi def link mpTeXKeyword   Identifier
    270 
    271 b:current_syntax = "mp"
    272 
    273 # vim: sw=2 fdm=marker