mp.vim 12 KB

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