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