Mercurial > emacs
annotate lisp/progmodes/meta-mode.el @ 21930:b84bfe98263d
* progmodes/compile.el (compilation-directory-stack): Doc fix.
(compilation-mode): Accept optional parameter and initialize
mode-name from it.
(compile-internal): Pass name-of-mode to compilation-mode. Don't
set mode-name here.
(compilation-minor-mode): Don't let mode-line-process change.
(compilation-next-error-locus): Use forward-char instead of
move-to-column.
(compilation-parse-errors): Set default-directory from head of
compilation-directory-stack.
author | Andreas Schwab <schwab@suse.de> |
---|---|
date | Mon, 04 May 1998 08:35:40 +0000 |
parents | f3f9df46d008 |
children | b174db545cfd |
rev | line source |
---|---|
18388 | 1 ;;; meta-mode.el --- major mode for editing Metafont or MetaPost sources. |
2 | |
18924
f4b6329afef0
Update copyright notice and permission notice.
Richard M. Stallman <rms@gnu.org>
parents:
18388
diff
changeset
|
3 ;; Copyright (C) 1997 Free Software Foundation, Inc. |
18388 | 4 |
5 ;; Author: Ulrik Vieth <vieth@thphy.uni-duesseldorf.de> | |
6 ;; Version: 1.0 | |
7 ;; Keywords: Metafont, MetaPost, tex, languages | |
8 | |
18924
f4b6329afef0
Update copyright notice and permission notice.
Richard M. Stallman <rms@gnu.org>
parents:
18388
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
18388 | 10 |
18924
f4b6329afef0
Update copyright notice and permission notice.
Richard M. Stallman <rms@gnu.org>
parents:
18388
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
18388 | 12 ;; it under the terms of the GNU General Public License as published by |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
18924
f4b6329afef0
Update copyright notice and permission notice.
Richard M. Stallman <rms@gnu.org>
parents:
18388
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
18388 | 17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; Description: | |
29 ;; | |
30 ;; This Emacs Lisp package provides a major mode for editing Metafont | |
31 ;; or MetaPost sources. It includes all the necessary code to set up | |
32 ;; a major mode including an approriate syntax table, keymap, and a | |
33 ;; mode-specific pull-down menu. It also provides a sophisticated set | |
34 ;; of font-lock patterns, a fancy indentation function adapted from | |
35 ;; AUC-TeX's latex.el, and some basic mode-specific editing functions | |
36 ;; such as functions to move to the beginning or end of the enclosing | |
37 ;; environment, or to mark, re-indent, or comment-out environments. | |
38 ;; On the other hand, it doesn't yet provide any functionality for | |
39 ;; running Metafont or MetaPost in a shell buffer form within Emacs, | |
40 ;; but such functionality might be added later, either as part of this | |
41 ;; package or as a separate Emacs Lisp package. | |
42 | |
43 ;; Installation: | |
44 ;; | |
45 ;; An interface to running Metafont or MetaPost as a shell process | |
46 ;; from within Emacs is currently under development as a separate | |
47 ;; Emacs Lisp package (meta-buf.el). In order to have that package | |
48 ;; loaded automatically when first entering Metafont or MetaPost mode, | |
49 ;; you might use the load-hook provided in this package by adding | |
50 ;; these lines to your startup file: | |
51 ;; | |
52 ;; (add-hook 'meta-mode-load-hook | |
53 ;; '(lambda () (require 'meta-buf))) | |
54 ;; | |
55 ;; The add-on package loaded this way may in turn make use of the | |
56 ;; mode-hooks provided in this package to activate additional features | |
57 ;; when entering Metafont or MetaPost mode. | |
58 | |
59 ;; Font Lock Support: | |
60 ;; | |
61 ;; If you are using global-font-lock-mode (introduced in Emacs 19.31), | |
62 ;; fontification in Metafont and/or MetaPost mode will be activated | |
63 ;; automatically. To speed up fontification for the rather complex | |
64 ;; patterns used in these modes, it may be a good idea to activate | |
65 ;; lazy-lock as a font-lock-support-mode (introduced in Emacs 19.32) | |
66 ;; by adding these lines to your startup file: | |
67 ;; | |
68 ;; (global-font-lock-mode t) | |
69 ;; (setq font-lock-support-mode 'lazy-lock-mode) | |
70 ;; | |
71 ;; If you are using an older version of Emacs, which doesn't provide | |
72 ;; global-font-lock-mode or font-lock-support-mode, you can also | |
73 ;; activate fontification in Metafont and/or MetaPost mode by adding | |
74 ;; the following lines to your startup file: | |
75 ;; | |
76 ;; (add-hook 'meta-common-mode-hook 'turn-on-font-lock) | |
77 ;; (add-hook 'meta-common-mode-hook 'turn-on-lazy-lock) | |
78 | |
79 ;; Customization: | |
80 ;; | |
81 ;; Following the usual Emacs Lisp coding conventions, the major modes | |
82 ;; defined in this package provide several hook variables to allow for | |
83 ;; local customization when entering the modes. In particular, there | |
84 ;; is a `meta-common-mode-hook' which applies to both modes as well as | |
85 ;; `metafont-mode-hook' and `metapost-mode-hook' which apply to the | |
86 ;; individual modes. In addition, there are several variables and | |
87 ;; regexps controlling e.g. the behavior of the indentation function, | |
88 ;; which may be customized via `edit-options'. Please refer to the | |
89 ;; docstrings in the code below for details. | |
90 | |
91 ;; Availability: | |
92 ;; | |
93 ;; This package is currently available via my "TeX Software" WWW page: | |
94 ;; | |
95 ;; http://www.thphy.uni-duesseldorf.de/~vieth/subjects/tex/software.html | |
96 ;; | |
97 ;; As of this version 1.0, this package will be uploaded to CTAN | |
98 ;; archives, where it shall find a permanent home, presumably in | |
99 ;; tex-archive/support/emacs-modes. It will also be submitted for | |
100 ;; integration into the GNU Emacs distribution at that time. | |
101 ;; | |
102 ;; History: | |
103 ;; | |
104 ;; v 0.0 -- 1997/02/01 UV Started writing meta-mode.el. | |
105 ;; v 0.1 -- 1997/02/02 UV Added preliminary set of font-lock patterns. | |
106 ;; v 0.2 -- 1997/02/03 UV Improved and debugged font-lock patterns. | |
107 ;; Added indent-line-function for TAB. | |
108 ;; v 0.3 -- 1997/02/17 UV Improved font-lock patterns and syntax table. | |
109 ;; Improved and debbuged indentation function. | |
110 ;; v 0.4 -- 1997/02/18 UV Added functions to indent regions for M-C-q, | |
111 ;; also added a preliminary mode-specific menu. | |
112 ;; v 0.5 -- 1997/02/19 UV Added functions to skip to next or previous | |
113 ;; defun and to re-indent or comment-out defuns. | |
114 ;; v 0.6 -- 1997/02/20 UV More debugging, testing and clean-up. | |
115 ;; v 0.7 -- 1997/02/22 UV Use easymenu to define mode-specific menu. | |
116 ;; v 0.8 -- 1997/02/24 UV Added completion function for M-TAB. | |
117 ;; v 0.9 -- 1997/03/08 UV Added fill-paragraph function for comments. | |
118 ;; Also fixed a few remaining font-lock problems. | |
119 ;; Added meta-mode-load-hook to load meta-buf.el. | |
120 ;; v 1.0 -- 1997/04/07 UV Cleanup for official public release. | |
121 ;; | |
122 ;; Historical Footnote: | |
123 ;; | |
124 ;; This package was begun on February 1, 1997, exactly 20 years after | |
125 ;; the genesis of TeX took place according to Don Knuth's own account | |
126 ;; (cf. ``The Errors of TeX'', reprinted in ``Literate Programming'', | |
127 ;; Chapter 10, p. 249). What better date could there be to choose? | |
128 ;; | |
129 | |
130 | |
131 ;;; Code: | |
132 | |
133 (require 'easymenu) | |
134 | |
20781 | 135 (defgroup meta-font nil |
136 "Major mode for editing Metafont or MetaPost sources." | |
137 :group 'languages) | |
138 | |
18388 | 139 ;;; Fontification. |
140 | |
141 (defvar meta-font-lock-keywords | |
142 (let ((input-keywords | |
143 "\\(input\\|generate\\)") | |
144 (begin-keywords | |
145 (concat "\\(begin\\(char\\|fig\\|graph\\|logochar\\)\\|" | |
146 "\\cmchar\\|dcchar\\|ecchar\\)")) | |
147 (end-keywords | |
148 "\\(end\\(char\\|fig\\|graph\\)\\)") | |
149 (macro-keywords-1 | |
150 "\\(def\\|let\\|mode_def\\|vardef\\)") | |
151 (macro-keywords-2 | |
152 "\\(primarydef\\|secondarydef\\|tertiarydef\\)") | |
153 ;(make-regexp | |
154 ; '("expr" "suffix" "text" "primary" "secondary" "tertiary") t) | |
155 (args-keywords | |
156 (concat "\\(expr\\|primary\\|s\\(econdary\\|uffix\\)\\|" | |
157 "te\\(rtiary\\|xt\\)\\)")) | |
158 ;(make-regexp | |
159 ; '("boolean" "color" "numeric" "pair" "path" "pen" "picture" | |
160 ; "string" "transform" "newinternal") t) | |
161 (type-keywords | |
162 (concat "\\(boolean\\|color\\|n\\(ewinternal\\|umeric\\)\\|" | |
163 "p\\(a\\(ir\\|th\\)\\|en\\|icture\\)\\|string\\|" | |
164 "transform\\)")) | |
165 ;(make-regexp | |
166 ; '("for" "forever" "forsuffixes" "endfor" | |
167 ; "step" "until" "upto" "downto" "thru" "within" | |
168 ; "iff" "if" "elseif" "else" "fi" "exitif" "exitunless" | |
169 ; "let" "def" "vardef" "enddef" "mode_def" | |
170 ; "true" "false" "known" "unknown" "and" "or" "not" | |
171 ; "save" "interim" "inner" "outer" "relax" | |
172 ; "begingroup" "endgroup" "expandafter" "scantokens" | |
173 ; "generate" "input" "endinput" "end" "bye" | |
174 ; "message" "errmessage" "errhelp" "special" "numspecial" | |
175 ; "readstring" "readfrom" "write") t) | |
176 (syntactic-keywords | |
177 (concat "\\(and\\|b\\(egingroup\\|ye\\)\\|" | |
178 "d\\(ef\\|ownto\\)\\|e\\(lse\\(\\|if\\)" | |
179 "\\|nd\\(\\|def\\|for\\|group\\|input\\)" | |
180 "\\|rr\\(help\\|message\\)" | |
181 "\\|x\\(it\\(if\\|unless\\)\\|pandafter\\)\\)\\|" | |
182 "f\\(alse\\|i\\|or\\(\\|ever\\|suffixes\\)\\)\\|" | |
183 "generate\\|i\\(ff?\\|n\\(ner\\|put\\|terim\\)\\)\\|" | |
184 "known\\|let\\|m\\(essage\\|ode_def\\)\\|" | |
185 "n\\(ot\\|umspecial\\)\\|o\\(r\\|uter\\)\\|" | |
186 "re\\(ad\\(from\\|string\\)\\|lax\\)\\|" | |
187 "s\\(ave\\|cantokens\\|pecial\\|tep\\)\\|" | |
188 "t\\(hru\\|rue\\)\\|" | |
189 "u\\(n\\(known\\|til\\)\\|pto\\)\\|" | |
190 "vardef\\|w\\(ithin\\|rite\\)\\)")) | |
191 ) | |
192 (list | |
193 ;; embedded TeX code in btex ... etex | |
194 (cons (concat "\\(btex\\|verbatimtex\\)" | |
195 "[ \t]+\\(.*\\)[ \t]+" | |
196 "\\(etex\\)") | |
197 '((1 font-lock-keyword-face) | |
198 (2 font-lock-string-face) | |
199 (3 font-lock-keyword-face))) | |
200 ;; unary macro definitions: def, vardef, let | |
201 (cons (concat "\\<" macro-keywords-1 "\\>" | |
202 "[ \t]+\\(\\sw+\\|\\s_+\\|\\s.+\\)") | |
203 '((1 font-lock-keyword-face) | |
204 (2 font-lock-function-name-face))) | |
205 ;; binary macro defintions: <leveldef> x operator y | |
206 (cons (concat "\\<" macro-keywords-2 "\\>" | |
207 "[ \t]+\\(\\sw+\\)" | |
208 "[ \t]*\\(\\sw+\\|\\s.+\\)" | |
209 "[ \t]*\\(\\sw+\\)") | |
210 '((1 font-lock-keyword-face) | |
211 (2 font-lock-variable-name-face nil t) | |
212 (3 font-lock-function-name-face nil t) | |
213 (4 font-lock-variable-name-face nil t))) | |
214 ;; variable declarations: numeric, pair, color, ... | |
215 (cons (concat "\\<" type-keywords "\\>" | |
216 "\\([ \t]+\\(\\sw+\\)\\)*") | |
217 '((1 font-lock-type-face) | |
218 (font-lock-match-meta-declaration-item-and-skip-to-next | |
219 (goto-char (match-end 1)) nil | |
220 (1 font-lock-variable-name-face nil t)))) | |
221 ;; argument declarations: expr, suffix, text, ... | |
222 (cons (concat "\\<" args-keywords "\\>" | |
223 "\\([ \t]+\\(\\sw+\\|\\s_+\\)\\)*") | |
224 '((1 font-lock-type-face) | |
225 (font-lock-match-meta-declaration-item-and-skip-to-next | |
226 (goto-char (match-end 1)) nil | |
227 (1 font-lock-variable-name-face nil t)))) | |
228 ;; special case of arguments: expr x of y | |
229 (cons (concat "\\(expr\\)[ \t]+\\(\\sw+\\)" | |
230 "[ \t]+\\(of\\)[ \t]+\\(\\sw+\\)") | |
231 '((1 font-lock-type-face) | |
232 (2 font-lock-variable-name-face) | |
233 (3 font-lock-keyword-face nil t) | |
234 (4 font-lock-variable-name-face nil t))) | |
235 ;; syntactic keywords | |
236 (cons (concat "\\<" syntactic-keywords "\\>") | |
237 'font-lock-keyword-face) | |
238 ;; beginchar, beginfig | |
239 (cons (concat "\\<" begin-keywords "\\>") | |
240 'font-lock-keyword-face) | |
241 ;; endchar, endfig | |
242 (cons (concat "\\<" end-keywords "\\>") | |
243 'font-lock-keyword-face) | |
244 ;; input, generate | |
245 (cons (concat "\\<" input-keywords "\\>" | |
246 "[ \t]+\\(\\sw+\\)") | |
247 '((1 font-lock-keyword-face) | |
20953
f3f9df46d008
Changed font-lock-reference-face to font-lock-constant-face.
Simon Marshall <simon@gnu.org>
parents:
20781
diff
changeset
|
248 (2 font-lock-constant-face))) |
18388 | 249 ;; embedded Metafont/MetaPost code in comments |
250 (cons "|\\([^|]+\\)|" | |
20953
f3f9df46d008
Changed font-lock-reference-face to font-lock-constant-face.
Simon Marshall <simon@gnu.org>
parents:
20781
diff
changeset
|
251 '(1 font-lock-constant-face t)) |
18388 | 252 )) |
253 "Default expressions to highlight in Metafont or MetaPost mode.") | |
254 | |
255 | |
256 (defun font-lock-match-meta-declaration-item-and-skip-to-next (limit) | |
257 ;; Match and move over Metafont/MetaPost declaration item after point. | |
258 ;; | |
259 ;; The expected syntax of an item is either "word" or "symbol", | |
260 ;; possibly ending with optional whitespace. Everything following | |
261 ;; the item (but belonging to it) is expected to by skipable by | |
262 ;; `forward-sexp'. The list of items is expected to be separated | |
263 ;; by commas and terminated by semicolons or equals signs. | |
264 ;; | |
265 (if (looking-at "[ \t]*\\(\\sw+\\|\\s_+\\)") | |
266 (save-match-data | |
267 (condition-case nil | |
268 (save-restriction | |
269 ;; Restrict to end of line, currently guaranteed to be LIMIT. | |
270 (narrow-to-region (point-min) limit) | |
271 (goto-char (match-end 1)) | |
272 ;; Move over any item value, etc., to the next item. | |
273 (while (not (looking-at "[ \t]*\\(\\(,\\)\\|;\\|=\\|$\\)")) | |
274 (goto-char (or (scan-sexps (point) 1) (point-max)))) | |
275 (goto-char (match-end 2))) | |
276 (error t))))) | |
277 | |
278 | |
279 | |
280 ;;; Completion. | |
281 | |
282 ;; The data used to prepare the following lists of primitives and | |
283 ;; standard macros available in Metafont or MetaPost was extracted | |
284 ;; from the original sources like this: | |
285 ;; | |
286 ;; grep '^primitive' texk-7.0/web2c/{mf,mp}.web |\ | |
287 ;; sed 's/primitive(\("[a-zA-Z]*"\).*/\1/' > {mf,mp}_prim.list | |
288 ;; | |
289 ;; grep '\(let\|def\|vardef\|primarydef\|secondarydef\|tertiarydef\)' | |
290 ;; texmf/meta{font,post}/plain.{mf,mp} > {mf,mp}_plain.list | |
291 | |
292 (defconst meta-common-primitives-list | |
293 '("ASCII" "addto" "also" "and" "angle" "atleast" "batchmode" | |
294 "begingroup" "boolean" "boundarychar" "char" "charcode" "chardp" | |
295 "charexists" "charext" "charht" "charic" "charlist" "charwd" | |
296 "contour" "controls" "cosd" "curl" "cycle" "day" "decimal" "def" | |
297 "delimiters" "designsize" "directiontime" "doublepath" "dump" "else" | |
298 "elseif" "end" "enddef" "endfor" "endgroup" "endinput" "errhelp" | |
299 "errmessage" "errorstopmode" "everyjob" "exitif" "expandafter" | |
300 "expr" "extensible" "false" "fi" "floor" "fontdimen" "fontmaking" | |
301 "for" "forever" "forsuffixes" "headerbyte" "hex" "if" "inner" | |
302 "input" "interim" "intersectiontimes" "jobname" "kern" "known" | |
303 "length" "let" "ligtable" "makepath" "makepen" "message" "mexp" | |
304 "mlog" "month" "newinternal" "nonstopmode" "normaldeviate" "not" | |
305 "nullpen" "nullpicture" "numeric" "oct" "odd" "of" "or" "outer" | |
306 "pair" "path" "pausing" "pen" "pencircle" "penoffset" "picture" | |
307 "point" "postcontrol" "precontrol" "primary" "primarydef" "quote" | |
308 "randomseed" "readstring" "reverse" "rotated" "save" "scaled" | |
309 "scantokens" "scrollmode" "secondary" "secondarydef" "shifted" | |
310 "shipout" "show" "showdependencies" "showstats" "showstopping" | |
311 "showtoken" "showvariable" "sind" "skipto" "slanted" "special" | |
312 "sqrt" "step" "str" "string" "subpath" "substring" "suffix" | |
313 "tension" "tertiary" "tertiarydef" "text" "time" "to" | |
314 "tracingcapsules" "tracingchoices" "tracingcommands" | |
315 "tracingequations" "tracingmacros" "tracingonline" "tracingoutput" | |
316 "tracingrestores" "tracingspecs" "tracingstats" "tracingtitles" | |
317 "transform" "transformed" "true" "turningnumber" "uniformdeviate" | |
318 "unknown" "until" "vardef" "warningcheck" "withpen" "xpart" | |
319 "xscaled" "xxpart" "xypart" "year" "ypart" "yscaled" "yxpart" | |
320 "yypart" "zscaled") | |
321 "List of primitives common to Metafont and MetaPost.") | |
322 | |
323 (defconst metafont-primitives-list | |
324 '("at" "autorounding" "chardx" "chardy" "cull" "display" | |
325 "dropping" "fillin" "from" "granularity" "hppp" "inwindow" | |
326 "keeping" "numspecial" "openwindow" "proofing" "smoothing" | |
327 "totalweight" "tracingedges" "tracingpens" "turningcheck" "vppp" | |
328 "withweight" "xoffset" "yoffset") | |
329 "List of primitives only defined in Metafont.") | |
330 | |
331 (defconst metapost-primitives-list | |
332 '("arclength" "arctime" "bluepart" "bounded" "btex" "clip" | |
333 "clipped" "color" "dashed" "dashpart" "etex" "filled" "fontpart" | |
334 "fontsize" "greenpart" "infont" "linecap" "linejoin" "llcorner" | |
335 "lrcorner" "miterlimit" "mpxbreak" "pathpart" "penpart" | |
336 "prologues" "readfrom" "redpart" "setbounds" "stroked" "textpart" | |
337 "textual" "tracinglostchars" "truecorners" "ulcorner" "urcorner" | |
338 "verbatimtex" "withcolor" "within" "write") | |
339 "List of primitives only defined in MetaPost.") | |
340 | |
341 (defconst meta-common-plain-macros-list | |
342 '( "abs" "bot" "bye" "byte" "ceiling" "clear_pen_memory" | |
343 "clearit" "clearpen" "clearxy" "counterclockwise" "cutdraw" "decr" | |
344 "dir" "direction" "directionpoint" "div" "dotprod" "downto" "draw" | |
345 "drawdot" "erase" "exitunless" "fill" "filldraw" "flex" "gobble" | |
346 "hide" "incr" "interact" "interpath" "intersectionpoint" "inverse" | |
347 "label" "labels" "lft" "loggingall" "magstep" "makelabel" "max" | |
348 "min" "mod" "numtok" "penlabels" "penpos" "penstroke" "pickup" | |
349 "range" "reflectedabout" "relax" "rotatedabout" "rotatedaround" | |
350 "round" "rt" "savepen" "shipit" "softjoin" "solve" "stop" | |
351 "superellipse" "takepower" "tensepath" "thru" "top" "tracingall" | |
352 "tracingnone" "undraw" "undrawdot" "unfill" "unfilldraw" | |
353 "unitvector" "upto" "whatever") | |
354 "List of macros common to plain Metafont and MetaPost.") | |
355 | |
356 (defconst metafont-plain-macros-list | |
357 '("beginchar" "change_width" "culldraw" "cullit" "cutoff" | |
358 "define_blacker_pixels" "define_corrected_pixels" | |
359 "define_good_x_pixels" "define_good_y_pixels" | |
360 "define_horizontal_corrected_pixels" "define_pixels" | |
361 "define_whole_blacker_pixels" "define_whole_pixels" | |
362 "define_whole_vertical_blacker_pixels" | |
363 "define_whole_vertical_pixels" "endchar" "fix_units" | |
364 "font_coding_scheme" "font_extra_space" "font_identifier" | |
365 "font_normal_shrink" "font_normal_space" "font_normal_stretch" | |
366 "font_quad" "font_size" "font_slant" "font_x_height" "gfcorners" | |
367 "good.bot" "good.lft" "good.rt" "good.top" "good.x" "good.y" | |
368 "grayfont" "hround" "imagerules" "italcorr" "labelfont" | |
369 "lowres_fix" "makebox" "makegrid" "maketicks" "mode_lowres" | |
370 "mode_proof" "mode_setup" "mode_smoke" "nodisplays" "notransforms" | |
371 "openit" "penrazor" "pensquare" "proofoffset" "proofrule" | |
372 "proofrulethickness" "screenchars" "screenrule" "screenstrokes" | |
373 "showit" "slantfont" "smode" "titlefont" "vround") | |
374 "List of macros only defined in plain Metafont.") | |
375 | |
376 (defconst metapost-plain-macros-list | |
377 '("arrowhead" "bbox" "beginfig" "buildcycle" "center" "cutafter" | |
378 "cutbefore" "dashpattern" "dotlabel" "dotlabels" "drawarrow" | |
379 "drawdblarrow" "drawoptions" "endfig" "image" "label" "off" "on" | |
380 "thelabel") | |
381 "List of macros only defined in plain MetaPost.") | |
382 | |
383 (defconst metapost-graph-macros-list | |
384 '("augment" "auto.x" "auto.y" "autogrid" "begingraph" "endgraph" | |
385 "format" "frame" "gdata" "gdotlabel" "gdraw" "gdrawarrow" | |
386 "gdrawdblarrow" "gfill" "glabel" "grid" "itick" "otick" "plot" | |
387 "setcoords" "setrange") | |
388 "List of macros only defined in MetaPost \"graph\" package.") | |
389 | |
390 (defconst metapost-boxes-macros-list | |
391 '("boxit" "boxjoin" "bpath" "circleit" "drawboxed" "drawboxes" | |
392 "drawunboxed" "fixpos" "fixsize" "pic" "rboxit") | |
393 "List of macros only defined in MetaPost \"boxes\" package.") | |
394 | |
395 | |
396 (defvar metafont-symbol-list | |
397 (append meta-common-primitives-list | |
398 metafont-primitives-list | |
399 meta-common-plain-macros-list | |
400 metafont-plain-macros-list) | |
401 "List of known symbols to complete in Metafont mode.") | |
402 | |
403 (defvar metapost-symbol-list | |
404 (append meta-common-primitives-list | |
405 metapost-primitives-list | |
406 meta-common-plain-macros-list | |
407 metapost-plain-macros-list | |
408 metapost-graph-macros-list | |
409 metapost-boxes-macros-list) | |
410 "List of known symbols to complete in MetaPost mode.") | |
411 | |
412 | |
413 (defvar meta-symbol-list nil | |
414 "List of known symbols to complete in Metafont or MetaPost mode.") | |
415 | |
416 (defvar meta-symbol-changed nil | |
417 "Flag indicating whether `meta-symbol-list' has been initialized.") | |
418 | |
419 (defvar meta-complete-list nil | |
420 ; (list (list "\\<\\(\\sw+\\)" 1 'meta-symbol-list) | |
421 ; (list "" 'ispell-complete-word)) | |
422 "List of ways to perform completion in Metafont or MetaPost mode. | |
423 | |
424 Each entry is a list with the following elements: | |
425 1. Regexp matching the preceding text. | |
426 2. A number indicating the subgroup in the regexp containing the text. | |
427 3. A function returning an alist of possible completions. | |
428 4. Text to append after a succesful completion (if any). | |
429 | |
430 Or alternatively: | |
431 1. Regexp matching the preceding text. | |
432 2. Function to do the actual completion.") | |
433 | |
434 | |
435 (defun meta-add-symbols (&rest entries) | |
436 "Add entries to list of known symbols in Metafont or MetaPost mode." | |
437 (if meta-symbol-changed | |
438 (setq meta-symbol-list (cons entries meta-symbol-list)) | |
439 (setq meta-symbol-changed t) | |
440 (setq meta-symbol-list (cons entries meta-symbol-list)))) | |
441 | |
442 (defun meta-symbol-list () | |
443 "Return value of list of known symbols in Metafont or MetaPost mode. | |
444 If the list was changed, sort the list and remove duplicates first." | |
445 (if (not meta-symbol-changed) | |
446 () | |
447 (setq meta-symbol-changed nil) | |
448 (message "Preparing completion list...") | |
449 ;; sort list of symbols | |
450 (setq meta-symbol-list | |
451 (sort (mapcar 'meta-listify (apply 'append meta-symbol-list)) | |
452 'meta-car-string-lessp)) | |
453 ;; remove duplicates | |
454 (let ((entry meta-symbol-list)) | |
455 (while (and entry (cdr entry)) | |
456 (let ((this (car entry)) | |
457 (next (car (cdr entry)))) | |
458 (if (not (string-equal (car this) (car next))) | |
459 (setq entry (cdr entry)) | |
460 (if (> (length next) (length this)) | |
461 (setcdr this (cdr next))) | |
462 (setcdr entry (cdr (cdr entry))))))) | |
463 (message "Preparing completion list... done")) | |
464 meta-symbol-list) | |
465 | |
466 (defun meta-listify (a) | |
467 ;; utility function used in `meta-add-symbols' | |
468 (if (listp a) a (list a))) | |
469 | |
470 (defun meta-car-string-lessp (a b) | |
471 ;; utility function used in `meta-add-symbols' | |
472 (string-lessp (car a) (car b))) | |
473 | |
474 | |
475 (defun meta-complete-symbol () | |
476 "Perform completion on Metafont or MetaPost symbol preceding point." | |
477 (interactive "*") | |
478 (let ((list meta-complete-list) | |
479 entry) | |
480 (while list | |
481 (setq entry (car list) | |
482 list (cdr list)) | |
483 (if (meta-looking-at-backward (car entry) 200) | |
484 (setq list nil))) | |
485 (if (numberp (nth 1 entry)) | |
486 (let* ((sub (nth 1 entry)) | |
487 (close (nth 3 entry)) | |
488 (begin (match-beginning sub)) | |
489 (end (match-end sub)) | |
490 (pattern (meta-match-buffer 0)) | |
491 (symbol (buffer-substring begin end)) | |
492 (list (funcall (nth 2 entry))) | |
493 (completion (try-completion symbol list))) | |
494 (cond ((eq completion t) | |
495 (and close | |
496 (not (looking-at (regexp-quote close))) | |
497 (insert close))) | |
498 ((null completion) | |
499 (error "Can't find completion for \"%s\"" pattern)) | |
500 ((not (string-equal symbol completion)) | |
501 (delete-region begin end) | |
502 (insert completion) | |
503 (and close | |
504 (eq (try-completion completion list) t) | |
505 (not (looking-at (regexp-quote close))) | |
506 (insert close))) | |
507 (t | |
508 (message "Making completion list...") | |
509 (let ((list (all-completions symbol list nil))) | |
510 (with-output-to-temp-buffer "*Completions*" | |
511 (display-completion-list list))) | |
512 (message "Making completion list... done")))) | |
513 (funcall (nth 1 entry))))) | |
514 | |
515 | |
516 (defun meta-looking-at-backward (regexp &optional limit) | |
517 ;; utility function used in `meta-complete-symbol' | |
518 (let ((pos (point))) | |
519 (save-excursion | |
520 (and (re-search-backward | |
521 regexp (if limit (max (point-min) (- (point) limit))) t) | |
522 (eq (match-end 0) pos))))) | |
523 | |
524 (defun meta-match-buffer (n) | |
525 ;; utility function used in `meta-complete-symbol' | |
526 (if (match-beginning n) | |
527 (let ((str (buffer-substring (match-beginning n) (match-end n)))) | |
528 (set-text-properties 0 (length str) nil str) | |
529 (copy-sequence str)) | |
530 "")) | |
531 | |
532 | |
533 | |
534 ;;; Indentation. | |
535 | |
20781 | 536 (defcustom meta-indent-level 2 |
537 "*Indentation of begin-end blocks in Metafont or MetaPost mode." | |
538 :type 'integer | |
539 :group 'meta-font) | |
18388 | 540 |
541 | |
20781 | 542 (defcustom meta-left-comment-regexp "%%+" |
543 "*Regexp matching comments that should be placed on the left margin." | |
544 :type 'regexp | |
545 :group 'meta-font) | |
18388 | 546 |
20781 | 547 (defcustom meta-right-comment-regexp nil |
548 "*Regexp matching comments that should be placed to the right margin." | |
549 :type '(choice regexp | |
550 (const :tag "None" nil)) | |
551 :group 'meta-font) | |
18388 | 552 |
20781 | 553 (defcustom meta-ignore-comment-regexp "%[^%]" |
554 "*Regexp matching comments that whose indentation should not be touched." | |
555 :type 'regexp | |
556 :group 'meta-font) | |
18388 | 557 |
558 | |
20781 | 559 (defcustom meta-begin-environment-regexp |
18388 | 560 (concat "\\(begin\\(char\\|fig\\|gr\\(aph\\|oup\\)\\|logochar\\)\\|" |
561 "def\\|for\\(\\|ever\\|suffixes\\)\\|if\\|mode_def\\|" | |
562 "primarydef\\|secondarydef\\|tertiarydef\\|vardef\\)") | |
20781 | 563 "*Regexp matching the beginning of environments to be indented." |
564 :type 'regexp | |
565 :group 'meta-font) | |
18388 | 566 |
20781 | 567 (defcustom meta-end-environment-regexp |
18388 | 568 (concat "\\(end\\(char\\|def\\|f\\(ig\\|or\\)\\|gr\\(aph\\|oup\\)\\)" |
569 "\\|fi\\)") | |
20781 | 570 "*Regexp matching the end of environments to be indented." |
571 :type 'regexp | |
572 :group 'meta-font) | |
18388 | 573 |
20781 | 574 (defcustom meta-within-environment-regexp |
18388 | 575 ; (concat "\\(e\\(lse\\(\\|if\\)\\|xit\\(if\\|unless\\)\\)\\)") |
576 (concat "\\(else\\(\\|if\\)\\)") | |
20781 | 577 "*Regexp matching keywords within environments not to be indented." |
578 :type 'regexp | |
579 :group 'meta-font) | |
18388 | 580 |
581 | |
582 (defun meta-comment-indent () | |
583 "Return the indentation for a comment in Metafont or MetaPost mode." | |
584 (if (and meta-left-comment-regexp | |
585 (looking-at meta-left-comment-regexp)) | |
586 (current-column) | |
587 (skip-chars-backward "\t ") | |
588 (max (if (bolp) 0 (1+ (current-column))) | |
589 comment-column))) | |
590 | |
591 (defun meta-indent-line () | |
592 "Indent the line containing point as Metafont or MetaPost source." | |
593 (interactive) | |
594 (let ((indent (meta-indent-calculate))) | |
595 (save-excursion | |
596 (if (/= (current-indentation) indent) | |
597 (let ((beg (progn (beginning-of-line) (point))) | |
598 (end (progn (back-to-indentation) (point)))) | |
599 (delete-region beg end) | |
600 (indent-to indent)))) | |
601 (if (< (current-column) indent) | |
602 (back-to-indentation)))) | |
603 | |
604 (defun meta-indent-calculate () | |
605 "Return the indentation of current line of Metafont or MetaPost source." | |
606 (save-excursion | |
607 (back-to-indentation) | |
608 (cond | |
609 ;; Comments to the left margin. | |
610 ((and meta-left-comment-regexp | |
611 (looking-at meta-left-comment-regexp)) | |
612 0) | |
613 ;; Comments to the right margin. | |
614 ((and meta-right-comment-regexp | |
615 (looking-at meta-right-comment-regexp)) | |
616 comment-column) | |
617 ;; Comments best left alone. | |
618 ((and meta-ignore-comment-regexp | |
619 (looking-at meta-ignore-comment-regexp)) | |
620 (current-indentation)) | |
621 ;; Backindent at end of environments. | |
622 ((looking-at | |
623 (concat "\\<" meta-end-environment-regexp "\\>")) | |
624 (- (meta-indent-calculate-last) meta-indent-level)) | |
625 ;; Backindent at keywords within environments. | |
626 ((looking-at | |
627 (concat "\\<" meta-within-environment-regexp "\\>")) | |
628 (- (meta-indent-calculate-last) meta-indent-level)) | |
629 (t (meta-indent-calculate-last))))) | |
630 | |
631 (defun meta-indent-calculate-last () | |
632 "Return the indentation of previous line of Metafont or MetaPost source." | |
633 (save-restriction | |
634 (widen) | |
635 (skip-chars-backward "\n\t ") | |
636 (move-to-column (current-indentation)) | |
637 ;; Ignore comments. | |
638 (while (and (looking-at comment-start) (not (bobp))) | |
639 (skip-chars-backward "\n\t ") | |
640 (if (not (bobp)) | |
641 (move-to-column (current-indentation)))) | |
642 (cond | |
643 ((bobp) 0) | |
644 (t (+ (current-indentation) | |
645 (meta-indent-level-count) | |
646 (cond | |
647 ;; Compensate for backindent at end of environments. | |
648 ((looking-at | |
649 (concat "\\<"meta-end-environment-regexp "\\>")) | |
650 meta-indent-level) | |
651 ;; Compensate for backindent within environments. | |
652 ((looking-at | |
653 (concat "\\<" meta-within-environment-regexp "\\>")) | |
654 meta-indent-level) | |
655 (t 0))))) | |
656 )) | |
657 | |
658 (defun meta-indent-level-count () | |
659 "Count indentation change for begin-end commands in the current line." | |
660 (save-excursion | |
661 (save-restriction | |
662 (let ((count 0)) | |
663 (narrow-to-region | |
664 (point) (save-excursion | |
665 (re-search-forward "[^\\\\\"]%\\|\n\\|\\'" nil t) | |
666 (backward-char) (point))) | |
667 (while (re-search-forward "\\<\\sw+\\>\\|(\\|)" nil t) | |
668 (save-excursion | |
669 (goto-char (match-beginning 0)) | |
670 (cond | |
671 ;; Count number of begin-end keywords within line. | |
672 ((looking-at | |
673 (concat "\\<" meta-begin-environment-regexp "\\>")) | |
674 (setq count (+ count meta-indent-level))) | |
675 ((looking-at | |
676 (concat "\\<" meta-end-environment-regexp "\\>")) | |
677 (setq count (- count meta-indent-level))) | |
678 ;; Count number of open-close parentheses within line. | |
679 ((looking-at "(") | |
680 (setq count (+ count meta-indent-level))) | |
681 ((looking-at ")") | |
682 (setq count (- count meta-indent-level))) | |
683 ))) | |
684 count)))) | |
685 | |
686 | |
687 | |
688 ;;; Filling paragraphs. | |
689 | |
690 (defun meta-fill-paragraph (&optional justify) | |
691 "Like \\[fill-paragraph], but handle Metafont or MetaPost comments. | |
692 If any part of the current line is a comment, fill the comment or the | |
693 paragraph of it that point is in, preserving the comment's indentation | |
694 and initial semicolons." | |
695 (interactive "P") | |
696 (let (has-comment ; Non-nil if line contains a comment. | |
697 has-code-and-comment ; Non-nil if line contains code and a comment. | |
698 comment-fill-prefix ; If has-comment, fill-prefix for the comment. | |
699 ) | |
700 ;; Figure out what kind of comment we are looking at. | |
701 (save-excursion | |
702 (beginning-of-line) | |
703 (cond | |
704 ;; A line with nothing but a comment on it? | |
705 ((looking-at (concat "[ \t]*" comment-start-skip)) | |
706 (setq has-comment t) | |
707 (setq comment-fill-prefix | |
708 (buffer-substring (match-beginning 0) (match-end 0)))) | |
709 ;; A line with some code, followed by a comment? | |
710 ((condition-case nil | |
711 (save-restriction | |
712 (narrow-to-region (point-min) | |
713 (save-excursion (end-of-line) (point))) | |
714 (while (not (looking-at (concat comment-start "\\|$"))) | |
715 (skip-chars-forward (concat "^" comment-start "\n\"\\\\")) | |
716 (cond | |
717 ((eq (char-after (point)) ?\\) (forward-char 2)) | |
718 ((eq (char-after (point)) ?\") (forward-sexp 1)))) | |
719 (looking-at comment-start-skip)) | |
720 (error nil)) | |
721 (setq has-comment t | |
722 has-code-and-comment t) | |
723 (setq comment-fill-prefix | |
724 (concat (make-string (/ (current-column) 8) ?\t) | |
725 (make-string (% (current-column) 8) ?\ ) | |
726 (buffer-substring (match-beginning 0) (match-end 0))))) | |
727 )) | |
728 (if (not has-comment) | |
729 (fill-paragraph justify) | |
730 ;; Narrow to include only the comment, and then fill the region. | |
731 (save-excursion | |
732 (save-restriction | |
733 (beginning-of-line) | |
734 (narrow-to-region | |
735 ;; Find the first line we should include in the region to fill. | |
736 (save-excursion | |
737 (while (and (zerop (forward-line -1)) | |
738 (looking-at (concat "^[ \t]*" comment-start)))) | |
739 (or (looking-at (concat ".*" comment-start)) | |
740 (forward-line 1)) | |
741 (point)) | |
742 ;; Find the beginning of the first line past the region to fill. | |
743 (save-excursion | |
744 (while (progn (forward-line 1) | |
745 (looking-at (concat "^[ \t]*" comment-start)))) | |
746 (point))) | |
747 (let* ((paragraph-start | |
748 (concat paragraph-start "\\|[ \t%]*$")) | |
749 (paragraph-separate | |
750 (concat paragraph-start "\\|[ \t%]*$")) | |
751 (paragraph-ignore-fill-prefix nil) | |
752 (fill-prefix comment-fill-prefix) | |
753 (after-line (if has-code-and-comment | |
754 (save-excursion (forward-line 1) (point)))) | |
755 (end (progn (forward-paragraph) | |
756 (or (bolp) (newline 1)) | |
757 (point))) | |
758 (beg (progn (backward-paragraph) | |
759 (if (eq (point) after-line) (forward-line -1)) | |
760 (point))) | |
761 (after-pos (save-excursion | |
762 (goto-char beg) | |
763 (if (not (looking-at fill-prefix)) | |
764 (progn | |
765 (re-search-forward comment-start-skip) | |
766 (point))))) | |
767 ) | |
768 (fill-region-as-paragraph beg end justify nil after-pos)) | |
769 ))) | |
770 t)) | |
771 | |
772 | |
773 | |
774 ;;; Editing commands. | |
775 | |
20781 | 776 (defcustom meta-begin-defun-regexp |
18388 | 777 (concat "\\(begin\\(char\\|fig\\|logochar\\)\\|def\\|mode_def\\|" |
778 "primarydef\\|secondarydef\\|tertiarydef\\|vardef\\)") | |
20781 | 779 "*Regexp matching beginning of defuns in Metafont or MetaPost mode." |
780 :type 'regexp | |
781 :group 'meta-font) | |
18388 | 782 |
20781 | 783 (defcustom meta-end-defun-regexp |
18388 | 784 (concat "\\(end\\(char\\|def\\|fig\\)\\)") |
20781 | 785 "*Regexp matching the end of defuns in Metafont or MetaPost mode." |
786 :type 'regexp | |
787 :group 'meta-font) | |
18388 | 788 |
789 | |
790 (defun meta-beginning-of-defun (&optional arg) | |
791 "Move backward to beginnning of a defun in Metafont or MetaPost code. | |
792 With numeric argument, do it that many times. | |
793 Negative arg -N means move forward to Nth following beginning of defun. | |
794 Returns t unless search stops due to beginning or end of buffer." | |
795 (interactive "p") | |
796 (if (or (null arg) (= 0 arg)) (setq arg 1)) | |
797 (and arg (< arg 0) (not (eobp)) (forward-char 1)) | |
798 (and (re-search-backward | |
799 (concat "\\<" meta-begin-defun-regexp "\\>") nil t arg) | |
800 (progn (goto-char (match-beginning 0)) | |
801 (skip-chars-backward "%") | |
802 (skip-chars-backward " \t") t))) | |
803 | |
804 (defun meta-end-of-defun (&optional arg) | |
805 "Move forward to end of a defun in Metafont or MetaPost code. | |
806 With numeric argument, do it that many times. | |
807 Negative argument -N means move back to Nth preceding end of defun. | |
808 Returns t unless search stops due to beginning or end of buffer." | |
809 (interactive "p") | |
810 (if (or (null arg) (= 0 arg)) (setq arg 1)) | |
811 (and (< arg 0) (not (bobp)) (forward-line -1)) | |
812 (and (re-search-forward | |
813 (concat "\\<" meta-end-defun-regexp "\\>") nil t arg) | |
814 (progn (goto-char (match-end 0)) | |
815 (skip-chars-forward ";") | |
816 (skip-chars-forward " \t") | |
817 (if (looking-at "\n") (forward-line 1)) t))) | |
818 | |
819 | |
820 (defun meta-comment-region (beg end &optional arg) | |
821 "Comment out active region as Metafont or MetaPost source." | |
822 (interactive "r") | |
823 (comment-region beg end arg)) | |
824 | |
825 (defun meta-uncomment-region (beg end) | |
826 "Uncomment active region as Metafont or MetaPost source." | |
827 (interactive "r") | |
828 (comment-region beg end -1)) | |
829 | |
830 (defun meta-comment-defun (&optional arg) | |
831 "Comment out current environment as Metafont or MetaPost source. | |
832 With prefix argument, uncomment the environment. | |
833 The environment used is the one that contains point or follows point." | |
834 (interactive "P") | |
835 (save-excursion | |
836 (let* ((end (if (meta-end-of-defun) (point) (point-max))) | |
837 (beg (if (meta-beginning-of-defun) (point) (point-min)))) | |
838 (comment-region beg end arg)))) | |
839 | |
840 (defun meta-uncomment-defun () | |
841 "Uncomment current environment as Metafont or MetaPost source." | |
842 (interactive) | |
843 (meta-comment-defun -1)) | |
844 | |
845 | |
846 (defun meta-indent-region (beg end) | |
847 "Indent the active region as Metafont or MetaPost source." | |
848 (interactive "r") | |
849 (indent-region beg end nil)) | |
850 | |
851 (defun meta-indent-buffer () | |
852 "Indent the whole buffer contents as Metafont or MetaPost source." | |
853 (interactive) | |
854 (save-excursion | |
855 (indent-region (point-min) (point-max) nil))) | |
856 | |
857 (defun meta-indent-defun () | |
858 "Indent the current environment as Metafont or MetaPost source. | |
859 The environment indented is the one that contains point or follows point." | |
860 (interactive) | |
861 (save-excursion | |
862 (let* ((end (if (meta-end-of-defun) (point) (point-max))) | |
863 (beg (if (meta-beginning-of-defun) (point) (point-min)))) | |
864 (indent-region beg end nil)))) | |
865 | |
866 | |
867 (defun meta-mark-defun () | |
868 "Put mark at end of the environment, point at the beginning. | |
869 The environment marked is the one that contains point or follows point." | |
870 (interactive) | |
871 (push-mark (point)) | |
872 (meta-end-of-defun) | |
873 (push-mark (point) nil t) | |
874 (meta-beginning-of-defun)) | |
875 | |
876 | |
877 | |
878 ;;; Syntax table, keymap and menu. | |
879 | |
880 (defvar meta-mode-abbrev-table nil | |
881 "Abbrev table used in Metafont or MetaPost mode.") | |
882 (define-abbrev-table 'meta-mode-abbrev-table ()) | |
883 | |
884 (defvar meta-mode-syntax-table nil | |
885 "Syntax table used in Metafont or MetaPost mode.") | |
886 (if meta-mode-syntax-table | |
887 () | |
888 (setq meta-mode-syntax-table (make-syntax-table)) | |
889 ;; underscores are word constituents | |
890 (modify-syntax-entry ?_ "w" meta-mode-syntax-table) | |
891 ;; miscellaneous non-word symbols | |
892 (modify-syntax-entry ?# "_" meta-mode-syntax-table) | |
893 (modify-syntax-entry ?@ "_" meta-mode-syntax-table) | |
894 (modify-syntax-entry ?$ "_" meta-mode-syntax-table) | |
895 (modify-syntax-entry ?? "_" meta-mode-syntax-table) | |
896 (modify-syntax-entry ?! "_" meta-mode-syntax-table) | |
897 ;; binary operators | |
898 (modify-syntax-entry ?& "." meta-mode-syntax-table) | |
899 (modify-syntax-entry ?+ "." meta-mode-syntax-table) | |
900 (modify-syntax-entry ?- "." meta-mode-syntax-table) | |
901 (modify-syntax-entry ?/ "." meta-mode-syntax-table) | |
902 (modify-syntax-entry ?* "." meta-mode-syntax-table) | |
903 (modify-syntax-entry ?. "." meta-mode-syntax-table) | |
904 (modify-syntax-entry ?: "." meta-mode-syntax-table) | |
905 (modify-syntax-entry ?= "." meta-mode-syntax-table) | |
906 (modify-syntax-entry ?< "." meta-mode-syntax-table) | |
907 (modify-syntax-entry ?> "." meta-mode-syntax-table) | |
908 (modify-syntax-entry ?| "." meta-mode-syntax-table) | |
909 ;; opening and closing delimiters | |
910 (modify-syntax-entry ?\( "()" meta-mode-syntax-table) | |
911 (modify-syntax-entry ?\) ")(" meta-mode-syntax-table) | |
912 (modify-syntax-entry ?\[ "(]" meta-mode-syntax-table) | |
913 (modify-syntax-entry ?\] ")[" meta-mode-syntax-table) | |
914 (modify-syntax-entry ?\{ "(}" meta-mode-syntax-table) | |
915 (modify-syntax-entry ?\} "){" meta-mode-syntax-table) | |
916 ;; comment character | |
917 (modify-syntax-entry ?% "<" meta-mode-syntax-table) | |
918 (modify-syntax-entry ?\n ">" meta-mode-syntax-table) | |
919 ;; escape character, needed for embedded TeX code | |
920 (modify-syntax-entry ?\\ "\\" meta-mode-syntax-table) | |
921 ) | |
922 | |
923 (defvar meta-mode-map nil | |
924 "Keymap used in Metafont or MetaPost mode.") | |
925 (if meta-mode-map | |
926 () | |
927 (setq meta-mode-map (make-sparse-keymap)) | |
928 (define-key meta-mode-map "\t" 'meta-indent-line) | |
929 (define-key meta-mode-map "\C-m" 'reindent-then-newline-and-indent) | |
930 ;; Comment Paragraphs: | |
931 ; (define-key meta-mode-map "\M-a" 'backward-sentence) | |
932 ; (define-key meta-mode-map "\M-e" 'forward-sentence) | |
933 ; (define-key meta-mode-map "\M-h" 'mark-paragraph) | |
934 ; (define-key meta-mode-map "\M-q" 'fill-paragraph) | |
935 ;; Navigation: | |
936 (define-key meta-mode-map "\M-\C-a" 'meta-beginning-of-defun) | |
937 (define-key meta-mode-map "\M-\C-e" 'meta-end-of-defun) | |
938 (define-key meta-mode-map "\M-\C-h" 'meta-mark-defun) | |
939 ;; Indentation: | |
940 (define-key meta-mode-map "\M-\C-q" 'meta-indent-defun) | |
941 (define-key meta-mode-map "\C-c\C-qe" 'meta-indent-defun) | |
942 (define-key meta-mode-map "\C-c\C-qr" 'meta-indent-region) | |
943 (define-key meta-mode-map "\C-c\C-qb" 'meta-indent-buffer) | |
944 ;; Commenting Out: | |
945 (define-key meta-mode-map "\C-c%" 'meta-comment-defun) | |
946 ; (define-key meta-mode-map "\C-uC-c%" 'meta-uncomment-defun) | |
947 (define-key meta-mode-map "\C-c;" 'meta-comment-region) | |
948 (define-key meta-mode-map "\C-c:" 'meta-uncomment-region) | |
949 ;; Symbol Completion: | |
950 (define-key meta-mode-map "\M-\t" 'meta-complete-symbol) | |
951 ;; Shell Commands: | |
952 ; (define-key meta-mode-map "\C-c\C-c" 'meta-command-file) | |
953 ; (define-key meta-mode-map "\C-c\C-k" 'meta-kill-job) | |
954 ; (define-key meta-mode-map "\C-c\C-l" 'meta-recenter-output) | |
955 ) | |
956 | |
957 (easy-menu-define | |
958 meta-mode-menu meta-mode-map | |
959 "Menu used in Metafont or MetaPost mode." | |
960 (list "Meta" | |
961 ["Forward Environment" meta-beginning-of-defun t] | |
962 ["Backward Environment" meta-end-of-defun t] | |
963 "--" | |
964 ["Indent Line" meta-indent-line t] | |
965 ["Indent Environment" meta-indent-defun t] | |
966 ["Indent Region" meta-indent-region | |
967 :active (meta-mark-active)] | |
968 ["Indent Buffer" meta-indent-buffer t] | |
969 "--" | |
970 ["Comment Out Environment" meta-comment-defun t] | |
971 ["Uncomment Environment" meta-uncomment-defun t] | |
972 ["Comment Out Region" meta-comment-region | |
973 :active (meta-mark-active)] | |
974 ["Uncomment Region" meta-uncomment-region | |
975 :active (meta-mark-active)] | |
976 "--" | |
977 ["Complete Symbol" meta-complete-symbol t] | |
978 ; "--" | |
979 ; ["Command on Buffer" meta-command-file t] | |
980 ; ["Kill Job" meta-kill-job t] | |
981 ; ["Recenter Output Buffer" meta-recenter-output-buffer t] | |
982 )) | |
983 | |
984 ;; Compatibility: XEmacs doesn't have the `mark-active' variable. | |
985 (defun meta-mark-active () | |
986 "Return whether the mark and region are currently active in this buffer." | |
987 (or (and (boundp 'mark-active) mark-active) (mark))) | |
988 | |
989 | |
990 | |
991 ;;; Hook variables. | |
992 | |
20781 | 993 (defcustom meta-mode-load-hook nil |
994 "*Hook evaluated when first loading Metafont or MetaPost mode." | |
995 :type 'hook | |
996 :group 'meta-font) | |
18388 | 997 |
20781 | 998 (defcustom meta-common-mode-hook nil |
999 "*Hook evaluated by both `metafont-mode' and `metapost-mode'." | |
1000 :type 'hook | |
1001 :group 'meta-font) | |
18388 | 1002 |
20781 | 1003 (defcustom metafont-mode-hook nil |
1004 "*Hook evaluated by `metafont-mode' after `meta-common-mode-hook'." | |
1005 :type 'hook | |
1006 :group 'meta-font) | |
1007 (defcustom metapost-mode-hook nil | |
1008 "*Hook evaluated by `metapost-mode' after `meta-common-mode-hook'." | |
1009 :type 'hook | |
1010 :group 'meta-font) | |
18388 | 1011 |
1012 | |
1013 | |
1014 ;;; Initialization. | |
1015 | |
1016 (defun meta-common-initialization () | |
1017 "Common initialization for Metafont or MetaPost mode." | |
1018 (kill-all-local-variables) | |
1019 | |
1020 (make-local-variable 'paragraph-start) | |
1021 (make-local-variable 'paragraph-separate) | |
1022 (setq paragraph-start | |
1023 (concat page-delimiter "\\|$")) | |
1024 (setq paragraph-separate | |
1025 (concat page-delimiter "\\|$")) | |
1026 | |
1027 (make-local-variable 'paragraph-ignore-fill-prefix) | |
1028 (setq paragraph-ignore-fill-prefix t) | |
1029 | |
1030 (make-local-variable 'comment-start-skip) | |
1031 (make-local-variable 'comment-start) | |
1032 (make-local-variable 'comment-end) | |
1033 (make-local-variable 'comment-multi-line) | |
1034 (setq comment-start-skip "%+[ \t]*") | |
1035 (setq comment-start "%") | |
1036 (setq comment-end "") | |
1037 (setq comment-multi-line nil) | |
1038 | |
1039 (make-local-variable 'parse-sexp-ignore-comments) | |
1040 (setq parse-sexp-ignore-comments t) | |
1041 | |
1042 (make-local-variable 'comment-indent-function) | |
1043 (setq comment-indent-function 'meta-comment-indent) | |
1044 (make-local-variable 'fill-paragraph-function) | |
1045 (setq fill-paragraph-function 'meta-fill-paragraph) | |
1046 (make-local-variable 'indent-line-function) | |
1047 (setq indent-line-function 'meta-indent-line) | |
1048 ;; No need to define a mode-specific 'indent-region-function. | |
1049 ;; Simply use the generic 'indent-region and 'comment-region. | |
1050 | |
1051 ;; Set defaults for font-lock mode. | |
1052 (make-local-variable 'font-lock-defaults) | |
1053 (setq font-lock-defaults | |
1054 '(meta-font-lock-keywords | |
1055 nil nil ((?_ . "w")) nil | |
1056 (font-lock-comment-start-regexp . "%"))) | |
1057 | |
1058 ;; Activate syntax table, keymap and menu. | |
1059 (setq local-abbrev-table meta-mode-abbrev-table) | |
1060 (set-syntax-table meta-mode-syntax-table) | |
1061 (use-local-map meta-mode-map) | |
1062 (easy-menu-add meta-mode-menu) | |
1063 ) | |
1064 | |
1065 | |
18924
f4b6329afef0
Update copyright notice and permission notice.
Richard M. Stallman <rms@gnu.org>
parents:
18388
diff
changeset
|
1066 ;;;###autoload |
18388 | 1067 (defun metafont-mode () |
1068 "Major mode for editing Metafont sources. | |
1069 Special commands: | |
1070 \\{meta-mode-map} | |
1071 | |
1072 Turning on Metafont mode calls the value of the variables | |
1073 `meta-common-mode-hook' and `metafont-mode-hook'." | |
1074 (interactive) | |
1075 (meta-common-initialization) | |
1076 (setq mode-name "Metafont") | |
1077 (setq major-mode 'metafont-mode) | |
1078 | |
1079 ;; Set defaults for completion function. | |
1080 (make-local-variable 'meta-symbol-list) | |
1081 (make-local-variable 'meta-symbol-changed) | |
1082 (make-local-variable 'meta-complete-list) | |
1083 (setq meta-symbol-list nil) | |
1084 (setq meta-symbol-changed nil) | |
1085 (apply 'meta-add-symbols metafont-symbol-list) | |
1086 (setq meta-complete-list | |
1087 (list (list "\\<\\(\\sw+\\)" 1 'meta-symbol-list) | |
1088 (list "" 'ispell-complete-word))) | |
1089 (run-hooks 'meta-common-mode-hook 'metafont-mode-hook)) | |
1090 | |
18924
f4b6329afef0
Update copyright notice and permission notice.
Richard M. Stallman <rms@gnu.org>
parents:
18388
diff
changeset
|
1091 ;;;###autoload |
18388 | 1092 (defun metapost-mode () |
1093 "Major mode for editing MetaPost sources. | |
1094 Special commands: | |
1095 \\{meta-mode-map} | |
1096 | |
1097 Turning on MetaPost mode calls the value of the variable | |
1098 `meta-common-mode-hook' and `metafont-mode-hook'." | |
1099 (interactive) | |
1100 (meta-common-initialization) | |
1101 (setq mode-name "MetaPost") | |
1102 (setq major-mode 'metapost-mode) | |
1103 | |
1104 ;; Set defaults for completion function. | |
1105 (make-local-variable 'meta-symbol-list) | |
1106 (make-local-variable 'meta-symbol-changed) | |
1107 (make-local-variable 'meta-complete-list) | |
1108 (setq meta-symbol-list nil) | |
1109 (setq meta-symbol-changed nil) | |
1110 (apply 'meta-add-symbols metapost-symbol-list) | |
1111 (setq meta-complete-list | |
1112 (list (list "\\<\\(\\sw+\\)" 1 'meta-symbol-list) | |
1113 (list "" 'ispell-complete-word))) | |
1114 (run-hooks 'meta-common-mode-hook 'metapost-mode-hook)) | |
1115 | |
1116 | |
1117 ;;; Just in case ... | |
1118 | |
1119 (provide 'meta-mode) | |
1120 (run-hooks 'meta-mode-load-hook) | |
1121 | |
1122 ;;; meta-mode.el ends here |