]> code.delx.au - gnu-emacs/blob - lisp/hilit19.el
Provide XXX-util instead of
[gnu-emacs] / lisp / hilit19.el
1 ;;; hilit19.el --- customizable highlighting for Emacs19
2
3 ;; Copyright (c) 1993, 1994 Free Software Foundation, Inc.
4
5 ;; Author: Jonathan Stigelman <stig@hackvan.com>
6 ;; Maintainer: FSF
7 ;; (actually no longer maintained)
8 ;; Keywords: faces
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;; Hilit19.el is a customizable highlighting package for Emacs19. It supports
30 ;; not only source code highlighting, but also Info, RMAIL, VM, gnus...
31 ;; Hilit19 knows (or thinks it knows) how to highlight emacs buffers in
32 ;; about 25 different modes.
33 ;;
34 ;; WHERE TO GET THE LATEST VERSIONS OF HILIT19.EL (beta and release),
35 ;; PLUS LOTS OF OTHER *WAY COOL* STUFF VIA ANONYMOUS FTP:
36 ;;
37 ;; ftp.hackvan.com:/pub/stig/src/elisp/hilit19.el.gz
38 ;;
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 ;;
41 ;; TO SUBMIT BUG REPORTS (or feedback of any sort)...
42 ;;
43 ;; M-x hilit-submit-feedback RET
44 ;;
45 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
46 ;;
47 ;; hilit19.el,v 2.19 1993/09/08 18:44:10 stig Release
48 ;;
49 ;; LCD Archive Entry:
50 ;; hilit19|Jonathan Stigelman|stig@hackvan.com|
51 ;; Comprehensive (and comparatively fast) regex-based highlighting for Emacs 19|
52 ;; 1993/09/08 18:44:10|Release 2.19|~/packages/hilit19.el.Z|
53 ;;
54 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55 ;;
56 ;; GENERAL OVERVIEW
57 ;;
58 ;; This package installs numerous hooks to colorfully highlight your
59 ;; source code buffers as well as mail and news buffers. Most
60 ;; programming languages have predefined highlighting patterns.
61 ;; Just load hilit19 and files will be automatically highlighted as
62 ;; they're loaded.
63 ;;
64 ;; Rehighlight a buffer by typing C-S-l (control-shift-lowercase-L).
65 ;;
66 ;; If, when you edit the buffer, the coloring gets messed up, just
67 ;; redraw and the coloring will be adjusted. If automatic highlighting
68 ;; in the current buffer has been turned off, then typing C-u C-S-l will
69 ;; force a rehighlight of the entire buffer.
70 ;;
71 ;; Hilit19 can build faces by examining the names that you give to them
72 ;; For example, green/black-bold-italic-underline would be created as
73 ;; a face with a green foreground, and a black background, using a
74 ;; bold-italic font...with underlining for good measure.
75 ;;
76 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
77 ;;
78 ;; SETUP -- In your .emacs:
79 ;;
80 ;;
81 ;; (cond (window-system
82 ;; (setq hilit-mode-enable-list '(not text-mode)
83 ;; hilit-background-mode 'light
84 ;; hilit-inhibit-hooks nil
85 ;; hilit-inhibit-rebinding nil)
86 ;;
87 ;; (require 'hilit19)
88 ;; ))
89 ;;
90 ;; If you like font-lock-mode and want to use both packages, then you can
91 ;; disable hilit for the modes in which you want to use font-lock by listing
92 ;; said modes in hilit-mode-enable-list.
93 ;;
94 ;; (hilit-translate type 'RoyalBlue ; enable highlighting in C/C++
95 ;; string nil) ; disable string highlighting
96 ;;
97 ;; To get 100% of the utility of hilit19, you may also have to apply the
98 ;; patches below for info.el and vm5.33L_19/vm-summary.el
99 ;;
100 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
101 ;;
102 ;; SETUP -- Are you using the right font for Emacs?
103 ;;
104 ;; Emacs cannot properly find bold and italic fonts unless you specify a
105 ;; verbose X11 font name. If you specify a font for emacs in your
106 ;; .Xdefaults, it *MUST* be specified using the long form of the font name.
107 ;; Here's a good font menu:
108 ;;
109 ;; (setq
110 ;; x-fixed-font-alist
111 ;; '("Font Menu"
112 ;; ("Misc"
113 ;; ("6x12" "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-*-1")
114 ;; ("6x13" "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-*-1")
115 ;; ("lucida 13"
116 ;; "-b&h-lucidatypewriter-medium-r-normal-sans-0-0-0-0-m-0-*-1")
117 ;; ("7x13" "-misc-fixed-medium-r-normal--13-120-75-75-c-70-*-1")
118 ;; ("7x14" "-misc-fixed-medium-r-normal--14-130-75-75-c-70-*-1")
119 ;; ("9x15" "-misc-fixed-medium-r-normal--15-140-*-*-c-*-*-1")
120 ;; ("")
121 ;; ("clean 8x8" "-schumacher-clean-medium-r-normal--*-80-*-*-c-*-*-1")
122 ;; ("clean 8x14" "-schumacher-clean-medium-r-normal--*-140-*-*-c-*-*-1")
123 ;; ("clean 8x10" "-schumacher-clean-medium-r-normal--*-100-*-*-c-*-*-1")
124 ;; ("clean 8x16" "-schumacher-clean-medium-r-normal--*-160-*-*-c-*-*-1")
125 ;; ("")
126 ;; ("sony 8x16" "-sony-fixed-medium-r-normal--16-120-100-100-c-80-*-1")
127 ;; ("")
128 ;; ("-- Courier --")
129 ;; ("Courier 10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-*-1")
130 ;; ("Courier 12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-*-1")
131 ;; ("Courier 14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-*-1")
132 ;; ("Courier 18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-*-1")
133 ;; ("Courier 18-b" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-*-1")
134 ;; )))
135 ;;
136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
137 ;;
138 ;; KNOWN BUGS/TO DO LIST/HELP WANTED/APPLY WITHIN
139 ;;
140 ;; * unbalanced, unescaped double quote characters can confuse hilit19.
141 ;; This will be fixed someday, so don't bug me about it.
142 ;;
143 ;; * ALTHOUGH HILIT19 IS FASTER THAN FONT-LOCK-MODE...
144 ;; For various reasons, the speed of the package could still stand to be
145 ;; improved. If you care to do a little profiling and make things tighter...
146 ;;
147 ;; * hilit-toggle-highlight is flaky when auto-rehighlight is neither t nor nil.
148 ;; Does anyone actually USE this? I think I might just remove it.
149 ;;
150 ;; PROJECTS THAT YOU CAN TAKE OVER BECAUSE I DON'T MUCH CARE ABOUT THEM...
151 ;;
152 ;; * Moved hilit-wysiwyg-replace here from my version of man.el, this is not
153 ;; a bug. The bug is that I don't have a reverse operation yet...just a
154 ;; stub Wysiwyg-anything really belongs in a package of its own.
155 ;;
156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
157 ;;
158 ;; Thanks to the following people for their input:
159 ;; ebert@enpc.enpc.fr (Rolf EBERT), ada, LaTeX & bibtex highlights
160 ;; Vivek Khera <khera@cs.duke.edu>, gnus hooks + random advice & patches
161 ;; brian@athe.WUstl.EDU (Brian Dunford-Shore), prolog highlights
162 ;; John Ladwig <jladwig@soils.umn.edu>, 1st pass nroff highlights
163 ;; campo@sunthpi3.difi.unipi.it (Massimo Campostrini), fortran highlights
164 ;; jayb@laplace.MATH.ColoState.EDU (Jay Bourland), 1st pass dired
165 ;; Yoshio Turner <yoshio@CS.UCLA.EDU>, modula 2 highlights
166 ;; Fritz Knabe <knabe@ecrc.de>, advice & patches
167 ;; Alon Albert <alon@milcse.rtsg.mot.com>, advice & patches
168 ;; dana@thumper.bellcore.com (Dana A. Chee), working on the multi-frame bug
169 ;; derway@ndc.com (Don Erway), for breaking it...
170 ;; moss_r@summer.chem.su.oz.au (Richard Moss), first pass at add-pattern
171 ;; Olivier Lecarme <ol@aiguemarine.unice.fr>, Pascal & Icon patterns
172 ;;
173 ;; With suggestions and minor regex patches from numerous others...
174 ;;
175 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
176 ;;
177 ;; hilit19.el,v
178 ;; Revision 2.19 1993/09/08 18:44:10 stig
179 ;; installed patch for elusive bug in hilit-rehighlight-region that caused
180 ;; hilit-unhighlight-region to hang in an infinite loop.
181 ;;
182 ;; Revision 2.18 1993/08/27 03:51:00 stig
183 ;; minor mods to lisp-mode and c/c++ mode patterns
184 ;;
185 ;; Revision 2.17 1993/08/25 02:19:17 stig
186 ;; work-around for bug in next-overlay-change that caused dired and jargon-mode
187 ;; to hang in an endless loop. Perhaps other modes were doing this too.
188 ;;
189 ;; Revision 2.16 1993/08/22 19:46:00 stig
190 ;; bug fix for next-overlay-change and accompanying change to
191 ;; hilit-unhighlight-region
192 ;;
193 ;; Revision 2.15 1993/08/20 12:16:22 stig
194 ;; minor change to fortran patterns
195 ;;
196 ;; Revision 2.14 1993/08/17 14:12:10 stig
197 ;; added default face mapping for 'formula' which is needed for new latex
198 ;; patterns.
199 ;;
200 ;; twiddled the calendar-mode patterns a bit.
201 ;;
202 ;; Revision 2.13 1993/08/16 04:33:54 stig
203 ;; hilit-set-mode-patterns was screwing up two part patterns. it doesn't now.
204 ;;
205 ;; Revision 2.12 1993/08/16 00:16:41 stig
206 ;; changed references to default-bold-italic to just bold-italic because the
207 ;; font for that face is maintained by emacs.
208 ;;
209 ;; the pattern matcher now starts its searches from the end of the most
210 ;; recently highlighted region (which is not necessarily the end of the most
211 ;; recently matched regex).
212 ;;
213 ;; multiple errors in pattern matcher now just give an error instead of lots of
214 ;; annoying messages and dings.
215 ;;
216 ;; no longer use vm-summary-mode-hooks.
217 ;;
218 ;; some code moved from hilit-highlight-region to hilit-set-mode-patterns.
219 ;; This will affect you if you pass your patterns directly to
220 ;; hilit-highlight-region....use a pseudo-mode instead.
221 ;;
222 ;; pattern changes to C/C++, latex, texinfo, fortran, nroff, etc.
223 ;;
224 ;; Revision 2.11 1993/08/13 12:12:37 stig
225 ;; removed some crufty commented-out code
226 ;;
227 ;; diverged lisp-mode and emacs-lisp-mode...also added lisp keywords.
228 ;;
229 ;; Revision 2.10 1993/08/13 09:47:06 stig
230 ;; added calendar-mode, icon-mode and pascal-mode patterns
231 ;;
232 ;; commented out hilit-toggle-highlight because I want to phase it out entirely
233 ;;
234 ;; Revision 2.9 1993/08/13 08:44:22 stig
235 ;; added optional case-fold argument to hilit-set-mode-patterns, this case-fold
236 ;; parameter is now stored in hilit-patterns-alist.
237 ;;
238 ;; Revision 2.8 1993/08/12 22:05:03 stig
239 ;; fixed some typos in documentation
240 ;;
241 ;; twiddled some of the color defaults for dark backgrounds
242 ;;
243 ;; always get 'mono color defaults if (not (x-display-color-p))
244 ;;
245 ;; added hilit-rehighlight-buffer-quietly to dired-after-readin-hook
246 ;;
247 ;; fixed bug in hilit-string-find that mishandled strings of the form: "\\"
248 ;;
249 ;; NEW FUNCTION: hilit-add-mode-pattern... kinda like add-hook for patterns
250 ;;
251 ;; fixed minor pattern bugs for latex-mode and emacs-lisp-mode
252 ;;
253 ;; Revision 2.7 1993/07/30 02:43:01 stig
254 ;; added const to the list of modifiers for C/C++ types
255 ;;
256 ;; Revision 2.6 1993/07/30 00:30:54 stig
257 ;; now permit selection of arbitrary subexpressions for highlighting...
258 ;; fixed keyword patterns for C/C++ using this technique.
259 ;;
260 ;; Revision 2.5 1993/07/28 05:02:56 stig
261 ;; improvements to makefile regular expressions
262 ;; removed about 130 lines just by compacting the big defconst for
263 ;; hilit-face-translation-table into a mapcar and defining a separate table
264 ;; of default faces.
265 ;;
266 ;; Revision 2.4 1993/07/27 14:09:05 stig
267 ;; documented another "known problem" to "head off gripe mail at the pass."
268 ;;
269 ;; Revision 2.3 1993/07/27 02:15:49 stig
270 ;; (hilit-lookup-face-create) incorporated patch which improves its behavior
271 ;; with more than one frame... Still can't have bold on the same face in two
272 ;; different fonts sizes at the same time...
273 ;;
274 ;; Revision 2.2 1993/07/27 02:02:59 stig
275 ;; vastly improved the makefile patterns
276 ;; added hook for mh-show-mode
277 ;;
278 ;; Revision 2.1 1993/07/24 17:46:21 stig
279 ;; Phasing out Info-select-hook... Version 19.18 will use Info-selection-hook.
280 ;;
281 ;; Revision 2.0 1993/07/24 13:50:10 stig
282 ;; better documentation and added the function hilit-submit-feedback.
283 ;; C-S-l (control shift l) repaints the buffer. Other bindings are optional.
284 ;; multi-line highlights no longer cause problems when
285 ;; hilit-auto-rehighlight is 'visible
286 ;; added hilit-predefined-face-list...
287 ;; changed name of hilit-mode-alist to hilit-patterns-alist
288 ;; added hilit-message-quietly to mail-setup-hook
289 ;; added hilit-parser-alist which can be used to apply different patterns to
290 ;; different parts of a buffer. This could be integrated in a far more
291 ;; elegant manner, but it presently serves the purpose of not applying
292 ;; message header patterns to message bodies in mail-mode and its kin.
293 ;; hilit-set-mode-patterns now takes a list of modes and an optional parse-fn
294 ;;
295
296 ;;;;;; AND THIS CAN BE APPLIED TO VM 5.33L_19
297 ;;
298 ;; *** ../site/vm5.33L_19/vm-summary.el Fri Jun 4 22:17:11 1993
299 ;; --- ./vm-summary.el Tue Jun 22 16:39:30 1993
300 ;; ***************
301 ;; *** 152,158 ****
302 ;; (insert "->")
303 ;; (delete-char 2)
304 ;; (forward-char -2)
305 ;; ! (and w vm-auto-center-summary (vm-auto-center-summary))))
306 ;; (and old-window (select-window old-window)))))))
307 ;;
308 ;; (defun vm-mark-for-display-update (message)
309 ;; --- 152,159 ----
310 ;; (insert "->")
311 ;; (delete-char 2)
312 ;; (forward-char -2)
313 ;; ! (and w vm-auto-center-summary (vm-auto-center-summary))
314 ;; ! (run-hooks 'vm-summary-pointer-hook)))
315 ;; (and old-window (select-window old-window)))))))
316 ;;
317 ;; (defun vm-mark-for-display-update (message)
318 ;;
319 ;;;;;;
320 \f
321 ;;; Code:
322
323 ;; User Options:
324
325 (defvar hilit-quietly nil
326 "* If non-nil, this inhibits progress indicators during highlighting")
327
328 (defvar hilit-auto-highlight t
329 "* T if we should highlight all buffers as we find 'em, nil to disable
330 automatic highlighting by the find-file hook.")
331
332 (defvar hilit-auto-highlight-maxout 60000 ; hilit19 keeps getting bigger...
333 "* auto-highlight is disabled in buffers larger than this")
334
335 (defvar hilit-auto-rehighlight t
336 "* If this is non-nil, then hilit-redraw and hilit-recenter will also
337 rehighlight part or all of the current buffer. T will rehighlight the
338 whole buffer, a NUMBER will rehighlight that many lines before and after
339 the cursor, and the symbol 'visible' will rehighlight only the visible
340 portion of the current buffer. This variable is buffer-local.")
341
342 (make-variable-buffer-local 'hilit-auto-rehighlight)
343
344 (defvar hilit-auto-rehighlight-fallback '(20000 . 100)
345 "* Cons of the form (THRESHOLD . FALLBACK), where FALLBACK is assigned to
346 hilit-auto-rehighlight if the size of a newly opened buffer is larger than
347 THRESHOLD.")
348
349 (defvar hilit-face-check t
350 "* T slows down highlighting but permits the user to change fonts without
351 losing bold and italic faces... T causes hilit-lookup-face-create to dig
352 through the frame parameters for the current window every time it's called.
353 If you never change fonts in emacs, set this to NIL.")
354
355 ;; Variables which must be set before loading hilit19.
356
357 (defvar hilit-inhibit-rebinding nil
358 "If non-nil, this inhibits replacement of recenter, yank, and yank-pop.")
359
360 (defvar hilit-inhibit-hooks nil
361 "If non-nil, this inhibits installation of hooks for Info, gnus, & vm.")
362
363 (defvar hilit-background-mode 'light
364 "'mono inhibits color, 'dark or 'light indicate the background brightness.")
365
366 (defvar hilit-mode-enable-list nil
367 "If a list of modes to exclusively enable or specifically disable.
368 The sense of the list is negated if it begins with the symbol 'not'.
369 Set this variable before you load hilit19.
370
371 Ex: (perl-mode jargon-mode c-mode) ; just perl, C, and jargon modes
372 (not text-mode) ; all modes except text mode")
373
374 ;; Variables that are not generally modified directly
375
376 (defvar hilit-parser-alist nil
377 "alist of major-mode values and parsers called by hilit-rehighlight-buffer.
378
379 Parsers for a given mode are IGNORED for partial rehighlights...maybe you'd
380 like to make this more universal?")
381
382 (defvar hilit-patterns-alist nil
383 "alist of major-mode values and default highlighting patterns
384
385 A highlighting pattern is a list of the form (start end face), where
386 start is a regex, end is either a regex or a match number for start, and face
387 is the name of an entry in hilit-face-translation-table, the name of a face,
388 or nil (which disables the pattern).
389
390 Each entry in the alist is of the form:
391 (mode . (case-fold pattern [pattern ...]))
392
393 See the hilit-lookup-face-create documentation for valid face names.")
394
395 (defvar hilit-predefined-face-list (face-list)
396 "List of faces with which hilit-lookup-face-create will NOT tamper.
397
398 If hilit19 is dumped into emacs at your site, you may have to set this in
399 your init file.")
400
401 (eval-when-compile (setq byte-optimize t))
402
403 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
404 ;; Use this to report bugs:
405
406 (eval-when-compile (require 'reporter)) ; no compilation gripes
407
408 (defun hilit-submit-feedback ()
409 "Submit feedback on hilit19 to the author: stig@hackvan.com"
410 (interactive)
411 (require 'reporter)
412 (and (y-or-n-p "Do you really want to submit a report on hilit19? ")
413 (reporter-submit-bug-report
414 "Jonathan Stigelman <stig@hackvan.com>"
415 "hilit19.el (Release 2.19)"
416 (and (y-or-n-p "Do you need to include a dump hilit variables? ")
417 (append
418 '(
419 hilit-quietly hilit-inhibit-hooks
420 hilit-background-mode hilit-mode-enable-list
421 hilit-auto-highlight hilit-auto-highlight-maxout
422 hilit-auto-rehighlight hilit-auto-rehighlight-fallback
423 hilit-face-check
424 )
425 (and (y-or-n-p "Have you modified the standard patterns? ")
426 (yes-or-no-p "Are your patterns *REALLY* relevant? ")
427 '(hilit-parser-alist
428 hilit-patterns-alist
429 hilit-predefined-face-list
430 ))))
431 (function
432 (lambda ()
433 (and (y-or-n-p "Is this a problem with font display? ")
434 (insert "\nFrame Configuration:\n====================\n"
435 (prin1-to-string (frame-configuration-to-register ?F))
436 "\n"
437 ))))
438 nil
439 (concat
440 "This is (check all that apply, and delete what's irrelevant):\n"
441 " [ ] a _MASSIVE_THANK_YOU_ for writing hilit19.el\n"
442 " [ ] An invitation to attend the next Hackers Conference\n"
443 " [ ] You're a RIGHTEOUS HACKER, what are your rates?\n"
444 " [ ] I've used the force and read the source, but I'M CONFUSED\n"
445 " [ ] a PATCH. (output of 'diff -uw old.el new.el' or 'diff -cw')\n"
446 " [ ] a SERIOUS AND REPRODUCIBLE BUG that is not an EMACS bug\n"
447 " - I *swear* that it's not already mentioned in the KNOWN BUGS\n"
448 " - I HAVE CHECKED ftp.hackvan.com:/pub/stig/src/elisp/hilit19.el.gz\n"
449 " for a newer release that fixes the problem.\n"
450 " >> I HAVE ALSO CHECKED ftp.hackvan.com:/pub/stig/src/elisp/hl319.el.gz\n"
451 " This is the alpha version...what will become hilit19 (Beta 3.0).\n"
452 "\n"
453 "Hey Stig, I *know* you're busy but...\n"))))
454
455 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
456 ;;
457 ;; These faces are either a valid face name, or nil
458 ;; if you want to change them, you must do so AFTER hilit19 is loaded
459
460 (defconst hilit-default-face-table
461 '(
462 ;; used for C/C++ and Emacs Lisp and perl
463 (comment firebrick-italic moccasin italic)
464 (include purple Plum1 bold-italic)
465 (define ForestGreen-bold green bold)
466 (defun blue-bold cyan-bold bold-italic)
467 (decl RoyalBlue cyan bold)
468 (type nil yellow nil)
469 (keyword RoyalBlue cyan bold-italic)
470 (label red-underline orange-underlined underline)
471 (string grey40 orange underline)
472
473 ;; some further faces for Ada
474 (struct black-bold white-bold bold)
475 (glob-struct magenta Plum1 default-bold-underline)
476 (named-param DarkGoldenrod Goldenrod underline)
477
478 ;; and another one for LaTeX
479 (crossref DarkGoldenrod Goldenrod underline)
480 (formula Goldenrod DarkGoldenrod underline)
481
482 ;; compilation buffers
483 (active-error default/pink-bold default/DeepPink-bold default-underline)
484 (error red-bold yellow bold)
485 (warning blue-italic green italic)
486
487 ;; Makefiles (some faces borrowed from C/C++ too)
488 (rule blue-bold-underline cyan-underline default-bold-underline)
489
490 ;; VM, GNUS and Text mode
491 (msg-subject blue-bold yellow bold)
492 (msg-from purple-bold green bold)
493 (msg-header firebrick-bold cyan italic)
494 (msg-separator black/tan-bold black/lightblue nil)
495 (msg-quote ForestGreen pink italic)
496
497 (summary-seen grey40 white nil)
498 (summary-killed grey50 white nil)
499 (summary-Xed OliveDrab2 green nil)
500 (summary-deleted firebrick white italic)
501 (summary-unread RoyalBlue yellow bold)
502 (summary-new blue-bold yellow-bold bold-italic)
503 (summary-current default/skyblue-bold green/dimgrey-bold reverse-default)
504
505 (gnus-group-unsubscribed grey50 white nil)
506 (gnus-group-empty nil nil nil)
507 (gnus-group-full ForestGreen green italic)
508 (gnus-group-overflowing firebrick red bold-italic)
509
510 ;; dired mode
511 (dired-directory blue-bold cyan bold)
512 (dired-link firebrick-italic green italic)
513 (dired-ignored ForestGreen moccasin nil)
514 (dired-deleted red-bold-italic orange bold-italic)
515 (dired-marked purple Plum1 nil)
516
517 ;; Info-mode, and jargon-mode.el and prep.ai.mit.edu:/pub/gnu/jargon*
518 (jargon-entry blue-bold cyan bold)
519 (jargon-xref purple-bold Plum1 italic)
520 (jargon-keyword firebrick-underline yellow underline)
521 )
522 "alist of default faces (face . (light-default dark-default mono-default))
523
524 There is no way for the user to modify this table such that it will have any
525 effect upon the translations used by hilit19. Instead, use the function
526 hilit-translate AFTER hilit19 has been loaded.
527
528 See also the documentation for hilit-lookup-face-create.")
529
530 (defconst hilit-face-translation-table
531 (let ((index (or (and (x-display-color-p)
532 (cdr (assq hilit-background-mode
533 '((light . 1) (dark . 2)))))
534 3)))
535 (mapcar (function (lambda (x) (cons (car x) (nth index x))))
536 hilit-default-face-table))
537 "alist that maps symbolic face-names to real face names")
538
539 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
540 ;; To translate one face to another...
541 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
542
543 (defmacro hilit-translate (&rest args)
544 "(hilit-translate FROM TO FROM TO ...): translate each face FROM to the
545 value of its TO face. This is like setq for faces.
546
547 The function hilit-lookup-face-create will repeatedly translate until no more
548 translations for the face exist in the translation table.
549
550 See the documentation for hilit-lookup-face-create for names of valid faces."
551 (or (zerop (% (length args) 2))
552 (error "wrong number of args"))
553 (let (cmdl from to)
554 (while args
555 (setq from (car args) to (nth 1 args) args (nthcdr 2 args)
556 cmdl (cons (list 'hilit-associate ''hilit-face-translation-table
557 (list 'quote from) to)
558 cmdl)))
559 (cons 'progn cmdl)))
560
561 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
562 ;; This function actually translates and then creates the faces...
563 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
564
565 (defun hilit-lookup-face-create (face &optional force)
566 "Get a FACE, or create it if it doesn't exist. In order for it to
567 properly create the face, the following naming convention must be used:
568 [reverse-](fgcolor[/bgcolor])[-bold][-italic][-underline]
569 Example: (hilit-lookup-face-create 'comment-face) might create and return 'red
570
571 Each color is either the name of an X color (see .../X11/lib/X11/rgb.txt),
572 a hexadecimal specification of the form \"hex-[0-9A-Fa-f]+\", or \"default\".
573
574 An optional argument, FORCE, will cause the face to be recopied from the
575 default...which is probably of use only if you've changed fonts.
576
577 See the documentation for hilit-translate and hilit-face-translation-table."
578
579 ;; translate the face ...
580 (let ((trec t) visited)
581 (while trec
582 (cond ((memq face visited) (error "face translation loop: %S" visited))
583 (t (setq visited (cons face visited)
584 trec (assq face hilit-face-translation-table))
585 (and trec (setq face (cdr trec)))))))
586
587 ;; make the face if we need to...
588 (let* ((fn (symbol-name face))
589 (frame (selected-frame))
590 (basefont (cdr (assq 'font (frame-parameters frame))))
591 error fgcolor bgcolor)
592 (cond
593 ((or (null face)
594 (memq face hilit-predefined-face-list))
595 ;; do nothing if the face is nil or if it's predefined.
596 )
597 ((or force
598 (not (memq face (face-list)))
599 (and hilit-face-check
600 (not (string= (get face 'basefont) basefont))))
601 (copy-face 'default 'scratch-face)
602 (if (string-match "^reverse-?" fn)
603 (progn (invert-face 'scratch-face)
604 (setq fn (substring fn (match-end 0)))))
605
606 ;; parse foreground color
607 (if (string-match "^\\(hex-\\)?\\([A-Za-z0-9]+\\)" fn)
608 (setq fgcolor (concat
609 (if (match-beginning 1) "#")
610 (substring fn (match-beginning 2) (match-end 2)))
611 fn (substring fn (match-end 0)))
612 (error "bad face name %S" face))
613
614 ;; parse background color
615 (if (string-match "^/\\(hex-\\)?\\([A-Za-z0-9]+\\)" fn)
616 (setq bgcolor (concat
617 (and (match-beginning 1) "#")
618 (substring fn (match-beginning 2) (match-end 2)))
619 fn (substring fn (match-end 0))))
620
621 (and (string= "default" fgcolor) (setq fgcolor nil))
622 (and (string= "default" bgcolor) (setq bgcolor nil))
623
624 ;; catch errors if we can't allocate the color(s)
625 (condition-case nil
626 (progn (set-face-foreground 'scratch-face fgcolor)
627 (set-face-background 'scratch-face bgcolor)
628 (copy-face 'scratch-face face)
629 (put face 'basefont basefont))
630 (error (message "couldn't allocate color for '%s'"
631 (symbol-name face))
632 (setq face 'default)
633 (setq error t)))
634 (or error
635 ;; don't bother w/ bold or italic if we didn't get the color
636 ;; we wanted, but ignore errors making the face bold or italic
637 ;; if the font isn't available, there's nothing to do about it...
638 (progn
639 (set-face-font face nil frame)
640 (set-face-underline-p face (string-match "underline" fn))
641 (if (string-match ".*bold" fn)
642 ;; make face bold in all frames
643 (make-face-bold face nil 'noerr))
644 (if (string-match ".*italic" fn)
645 ;; make face italic in all frames
646 (make-face-italic face nil 'noerr))
647 ))
648 )))
649 face)
650
651 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
652 ;; Region Highlight/Unhighlight code (Both overlay and text-property versions)
653 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
654
655 (defsubst hilit-region-set-face (start end face-name &optional prio prop)
656 "Highlight region from START to END using FACE and, optionally, PRIO.
657 The optional 5th arg, PROP is a property to set instead of 'hilit."
658 (let ((overlay (make-overlay start end)))
659 (overlay-put overlay 'face face-name)
660 (overlay-put overlay (or prop 'hilit) t)
661 (and prio (overlay-put overlay 'priority prio))))
662
663 (defun hilit-unhighlight-region (start end &optional quietly)
664 "Unhighlights the region from START to END, optionally in a QUIET way"
665 (interactive "r")
666 (or quietly hilit-quietly (message "Unhighlighting"))
667 (let ((lstart 0))
668 (while (and start (> start lstart) (< start end))
669 (mapcar (function (lambda (ovr)
670 (and (overlay-get ovr 'hilit) (delete-overlay ovr))))
671 (overlays-at start))
672 (setq lstart start start (next-overlay-change start))))
673 (or quietly hilit-quietly (message "Done unhighlighting")))
674
675 ;;;; These functions use text properties instead of overlays. Text properties
676 ;;;; are copied through kill and yank...which might be convenient, but is not
677 ;;;; terribly efficient as of 19.12, ERGO it's been disabled
678 ;;
679 ;;(defsubst hilit-region-set-face (start end face-name &optional prio prop)
680 ;; "Highlight region from START to END using FACE and, optionally, PRIO.
681 ;;The optional 5th arg, PROP is a property to set instead of 'hilit."
682 ;; (put-text-property start end 'face face-name)
683 ;; )
684 ;;
685 ;;(defun hilit-unhighlight-region (start end &optional quietly)
686 ;; "Unhighlights the region from START to END, optionally in a QUIET way"
687 ;; (interactive "r")
688 ;; (let ((buffer-read-only nil)
689 ;; (bm (buffer-modified-p)))
690 ;; (remove-text-properties start end '(face))
691 ;; (set-buffer-modified-p bm)))
692 ;;;;
693
694 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
695 ;; Pattern Application code and user functions
696 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
697
698 (defun hilit-highlight-region (start end &optional patterns quietly)
699 "Highlights the area of the buffer between START and END (the region when
700 interactive). Without the optional PATTERNS argument, the pattern for
701 major-mode is used. If PATTERNS is a symbol, then the patterns associated
702 with that symbol are used. QUIETLY suppresses progress messages if
703 non-nil."
704 (interactive "r")
705 (cond ((null patterns)
706 (setq patterns (cdr (assq major-mode hilit-patterns-alist))))
707 ((symbolp patterns)
708 (setq patterns (cdr (assq patterns hilit-patterns-alist)))))
709 ;; txt prop: (setq patterns (reverse patterns))
710 (let ((case-fold-search (car patterns))
711 (prio (1- (length patterns)))
712 ;; txt prop: (buffer-read-only nil)
713 ;; txt prop: (bm (buffer-modified-p))
714 p pstart pend face mstart (puke-count 0))
715 ;; txt prop: (unwind-protect
716 (setq patterns (cdr patterns)) ; remove case-fold from head of pattern
717 (save-excursion
718 (save-restriction
719 (narrow-to-region start end)
720 (while patterns
721 (setq p (car patterns))
722 (setq pstart (car p)
723 pend (nth 1 p)
724 face (hilit-lookup-face-create (nth 2 p)))
725 (if (not face) ; skipped if nil
726 nil
727 (or quietly hilit-quietly
728 (message "highlighting %d: %s%s" prio pstart
729 (if (stringp pend) (concat " ... " pend) "")))
730 (goto-char (point-min))
731 (condition-case msg
732 (cond
733 ((symbolp pstart)
734 ;; inner loop -- special function to find pattern
735 (let (region)
736 (while (setq region (funcall pstart pend))
737 (hilit-region-set-face (car region) (cdr region)
738 face prio))))
739 ((stringp pend)
740 ;; inner loop -- regex-start ... regex-end
741 (while (re-search-forward pstart nil t nil)
742 (goto-char (setq mstart (match-beginning 0)))
743 (if (re-search-forward pend nil t nil)
744 (hilit-region-set-face mstart (match-end 0)
745 face prio)
746 (forward-char 1))))
747 ((numberp pend)
748 ;; inner loop -- just one regex to match whole pattern
749 (while (re-search-forward pstart nil t nil)
750 (goto-char (match-end pend))
751 (hilit-region-set-face (match-beginning pend)
752 (match-end pend) face prio)))
753 (t (error "malformed pattern")))
754 (error (if (> (setq puke-count (1+ puke-count)) 1)
755 (error msg)
756 (message "Error: '%s'" msg)
757 (ding) (sit-for 4)))))
758 (setq prio (1- prio)
759 patterns (cdr patterns)))
760 ))
761 (or quietly hilit-quietly (message "")) ; "Done highlighting"
762 ;; txt prop: (set-buffer-modified-p bm)) ; unwind protection
763 ))
764
765 (defun hilit-rehighlight-region (start end &optional quietly)
766 "Re-highlights the region, optionally in a QUIET way"
767 (interactive "r")
768 (save-restriction
769 (widen)
770 (setq start (apply 'min start (mapcar 'overlay-start (overlays-at start)))
771 end (apply 'max end (mapcar 'overlay-end (overlays-at end))))
772 (hilit-unhighlight-region start end quietly)
773 (hilit-highlight-region start end nil quietly)))
774
775 (defun hilit-rehighlight-buffer (&optional quietly)
776 "Re-highlights the buffer, optionally in a QUIET way"
777 (interactive "")
778 (let ((parse-fn (cdr (assq major-mode hilit-parser-alist))))
779 (if parse-fn
780 (funcall parse-fn quietly)
781 (hilit-rehighlight-region (point-min) (point-max) quietly)))
782 nil)
783
784 (defun hilit-rehighlight-buffer-quietly ()
785 (hilit-rehighlight-buffer t))
786
787 (defun hilit-rehighlight-message (quietly)
788 "Highlight a buffer containing a news article or mail message."
789 (save-excursion
790 (goto-char (point-min))
791 ;; find separation between headers and body (either a blank line or
792 ;; the message separator line in mail-mode)
793 (re-search-forward "^\\(\\|--text follows this line--\\)$" nil 'noerr)
794 (hilit-unhighlight-region (point-min) (point-max) quietly)
795 (hilit-highlight-region (point-min) (point) 'msg-header quietly)
796 (hilit-highlight-region (point) (point-max) 'msg-body quietly)))
797
798 (defalias 'hilit-highlight-buffer 'hilit-rehighlight-buffer)
799
800 ;; Well, I want to remove this function...there's one sure way to find out if
801 ;; anyone uses it or not...and that's to comment it out.
802 ;;
803 ;; (defun hilit-toggle-highlight (arg)
804 ;; "Locally toggle highlighting. With arg, forces highlighting off."
805 ;; (interactive "P")
806 ;; ;; FIXME -- this loses numeric information in hilit-auto-rehighlight
807 ;; (setq hilit-auto-rehighlight
808 ;; (and (not arg) (not hilit-auto-rehighlight)))
809 ;; (if hilit-auto-rehighlight
810 ;; (hilit-rehighlight-buffer)
811 ;; (hilit-unhighlight-region (point-min) (point-max)))
812 ;; (message "Rehighlighting is set to %s" hilit-auto-rehighlight))
813
814 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
815 ;; HOOKS
816 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
817
818 (defun hilit-find-file-hook ()
819 "Find-file hook for hilit package. See the variable hilit-auto-highlight."
820 (cond ((and hilit-auto-highlight
821 (assq major-mode hilit-patterns-alist))
822 (if (> buffer-saved-size (car hilit-auto-rehighlight-fallback))
823 (setq hilit-auto-rehighlight
824 (cdr hilit-auto-rehighlight-fallback)))
825 (if (> buffer-saved-size hilit-auto-highlight-maxout)
826 nil
827 (let ((bm (buffer-modified-p)))
828 (hilit-rehighlight-buffer)
829 (set-buffer-modified-p bm))))))
830
831 (defun hilit-repaint-command (arg)
832 "Rehighlights according to the value of hilit-auto-rehighlight, or the
833 prefix argument if that is specified.
834 \t\\[hilit-repaint-command]\t\trepaint according to hilit-auto-rehighlight
835 \t^U \\[hilit-repaint-command]\trepaint entire buffer
836 \t^U - \\[hilit-repaint-command]\trepaint visible portion of buffer
837 \t^U n \\[hilit-repaint-command]\trepaint n lines to either side of point"
838 (interactive "P")
839 (let (st en quietly)
840 (or arg (setq arg hilit-auto-rehighlight))
841 (cond ((or (eq arg 'visible) (eq arg '-))
842 (setq st (window-start) en (window-end) quietly t))
843 ((numberp arg)
844 (setq st (save-excursion (forward-line (- arg)) (point))
845 en (save-excursion (forward-line arg) (point))))
846 (arg
847 (hilit-rehighlight-buffer)))
848 (if st
849 (hilit-rehighlight-region st en quietly))))
850
851 (defun hilit-recenter (arg)
852 "Recenter, then rehighlight according to hilit-auto-rehighlight. If called
853 with an unspecified prefix argument (^U but no number), then a rehighlight of
854 the entire buffer is forced."
855 (interactive "P")
856 (recenter arg)
857 ;; force display update
858 (sit-for 0)
859 (hilit-repaint-command (consp arg)))
860
861 (defun hilit-yank (arg)
862 "Yank with rehighlighting"
863 (interactive "*P")
864 (let ((transient-mark-mode nil))
865 (yank arg)
866 (and hilit-auto-rehighlight
867 (hilit-rehighlight-region (region-beginning) (region-end) t))
868 (setq this-command 'yank)))
869
870 (defun hilit-yank-pop (arg)
871 "Yank-pop with rehighlighting"
872 (interactive "*p")
873 (let ((transient-mark-mode nil))
874 (yank-pop arg)
875 (and hilit-auto-rehighlight
876 (hilit-rehighlight-region (region-beginning) (region-end) t))
877 (setq this-command 'yank)))
878
879 ;;; this line highlighting stuff is untested. play with it only if you feel
880 ;;; adventurous...don't ask me to fix it...though you're welcome to. -- Stig
881 ;;
882 ;; (defun hilit-rehighlight-line-quietly (&rest args)
883 ;; "Quietly rehighlight just this line.
884 ;; Useful as an after change hook in VM/gnus summary buffers and dired buffers.
885 ;; If only there were an after-change-function, that is..."
886 ;; (save-excursion
887 ;; (push-mark nil t)
888 ;; (hilit-rehighlight-yank-region)
889 ;; (and orig-achange-function (apply orig-achange-function args))))
890 ;;
891 ;; (defun hilit-install-line-hooks ()
892 ;; (make-variable-buffer-local 'after-change-function)
893 ;; (make-local-variable 'orig-achange-function)
894 ;; (setq orig-achange-function after-change-function)
895 ;; (setq after-change-function 'hilit-rehighlight-line-quietly))
896
897 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
898 ;; Wysiwyg Stuff... take it away and build a whole package around it!
899 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
900 ;;
901 ;; ; For the Jargon-impaired, WYSIWYG === What You See Is What You Get
902 ;; ; Sure, it sucks to type. Oh, well.
903 ;; (defun hilit-wysiwyg-replace ()
904 ;; "Replace overstruck text with normal text that's been overlaid with the
905 ;; appropriate text attribute. Suitable for a find-file hook."
906 ;; (save-excursion
907 ;; (goto-char (point-min))
908 ;; (let ((wysb (hilit-lookup-face-create 'wysiwyg-bold))
909 ;; (wysu (hilit-lookup-face-create 'wysiwyg-underline))
910 ;; (bmod (buffer-modified-p)))
911 ;; (while (re-search-forward "\\(.\b.\\)+" nil t)
912 ;; (let ((st (match-beginning 0)) (en (match-end 0)))
913 ;; (goto-char st)
914 ;; (if (looking-at "_")
915 ;; (hilit-region-set-face st en wysu 100 'wysiwyg)
916 ;; (hilit-region-set-face st en wysb 100 'wysiwyg))
917 ;; (while (and (< (point) en) (looking-at ".\b"))
918 ;; (replace-match "") (forward-char))
919 ;; ))
920 ;; (set-buffer-modified-p bmod))))
921 ;;
922 ;; ; is this more appropriate as a write-file-hook or a write-contents-hook?
923 ;; (defun hilit-wysiwyg-write-repair ()
924 ;; "Replace wysiwyg overlays with overstrike text."
925 ;; (message "*sigh* hilit-wysiwyg-write-repair not implemented yet")
926 ;;
927 ;; For efficiency, this hook should copy the current buffer to a scratch
928 ;; buffer and do its overstriking there. Overlays are not copied, so it'll
929 ;; be necessary to hop back and forth. This is OK since you're not fiddling
930 ;; with--making or deleting--any overlays. THEN write the new buffer,
931 ;; delete it, and RETURN T. << important
932 ;;
933 ;; Just so you know...there is already an emacs function called
934 ;; underline-region that does underlining. I think that the thing to do is
935 ;; extend that to do overstriking as well.
936 ;;
937 ;; (while (< start end)
938 ;; (mapcar (function (lambda (ovr)
939 ;; (and (overlay-get ovr 'hilit) (delete-overlay ovr))))
940 ;; (overlays-at start))
941 ;; (setq start (next-overlay-change start)))
942 ;; nil)
943
944 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
945 ;; Initialization.
946 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
947
948 (and (not hilit-inhibit-rebinding)
949 window-system
950 (progn
951 (substitute-key-definition 'yank 'hilit-yank
952 (current-global-map))
953 (substitute-key-definition 'yank-pop 'hilit-yank-pop
954 (current-global-map))
955 (substitute-key-definition 'recenter 'hilit-recenter
956 (current-global-map))))
957
958 (global-set-key [?\C-\S-l] 'hilit-repaint-command)
959
960 (and window-system
961 (add-hook 'find-file-hooks 'hilit-find-file-hook t))
962
963 (eval-when-compile (require 'gnus)) ; no compilation gripes
964
965 (and (not hilit-inhibit-hooks)
966 window-system
967 (condition-case c
968 (progn
969
970 ;; BUFFER highlights...
971 (mapcar (function
972 (lambda (hook)
973 (add-hook hook 'hilit-rehighlight-buffer-quietly)))
974 '(
975 Info-selection-hook
976
977 ;; runs too early vm-summary-mode-hooks
978 vm-summary-pointer-hook
979 vm-preview-message-hook
980 vm-show-message-hook
981
982 rmail-show-message-hook
983 mail-setup-hook
984 mh-show-mode-hook
985
986 dired-after-readin-hook
987 ))
988 )
989 (error (message "Error loading highlight hooks: %s" c)
990 (ding) (sit-for 1))))
991
992 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
993 ;; Default patterns for various modes.
994 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
995
996 ;;; do I need this? I changed the defconst to a defvar because defconst is
997 ;;; inappropriate, but I don't know why I wanted hilit-patterns-alist to be
998 ;;; reset on every reload...
999
1000 (setq hilit-patterns-alist nil)
1001
1002 (defun hilit-associate (alist key val)
1003 "creates, or destructively replaces, the pair (key . val) in alist"
1004 (let ((oldentry (assq key (eval alist))))
1005 (if oldentry
1006 (setcdr oldentry val)
1007 (set alist (cons (cons key val) (eval alist))))))
1008
1009 (defun hilit-set-mode-patterns (modelist patterns
1010 &optional parse-fn case-fold)
1011 "Sets the default highlighting patterns for MODE to PATTERNS.
1012 See the variable hilit-mode-enable-list.
1013
1014 Takes optional arguments PARSE-FN and CASE-FOLD."
1015 ;; change pattern
1016 (mapcar (function (lambda (p)
1017 (and (stringp (car p))
1018 (null (nth 1 p))
1019 (setcar (cdr p) 0))))
1020 patterns)
1021 (setq patterns (cons case-fold patterns))
1022
1023 (or (consp modelist) (setq modelist (list modelist)))
1024 (let (ok (flip (eq (car hilit-mode-enable-list) 'not)))
1025 (mapcar (function
1026 (lambda (m)
1027 (setq ok (or (null hilit-mode-enable-list)
1028 (memq m hilit-mode-enable-list)))
1029 (and flip (setq ok (not ok)))
1030 (and ok
1031 (progn
1032 (and parse-fn
1033 (hilit-associate 'hilit-parser-alist m parse-fn))
1034 (hilit-associate 'hilit-patterns-alist m patterns)))))
1035 modelist)))
1036
1037 (defun hilit-add-pattern (pstart pend face &optional mode first)
1038 "Highlight pstart with face for the current major-mode.
1039 Optionally, place the new pattern first in the pattern list"
1040 (interactive "sPattern start regex: \nsPattern end regex (default none): \nxFace: ")
1041
1042 (and (equal pstart "") (error "Must specify starting regex"))
1043 (cond ((equal pend "") (setq pend 0))
1044 ((string-match "^[0-9]+$" pend) (setq pend (string-to-int pend))))
1045 (or mode (setq mode major-mode))
1046 (let ((old-patterns (cdr (assq mode hilit-patterns-alist)))
1047 (new-pat (list pstart pend face)))
1048 (cond ((not old-patterns)
1049 (hilit-set-mode-patterns mode (list new-pat)))
1050 (first
1051 (setcdr old-patterns (cons new-pat (cdr old-patterns))))
1052 (t
1053 (nconc old-patterns (list new-pat)))))
1054 (and (interactive-p) (hilit-rehighlight-buffer)))
1055
1056 (defun hilit-string-find (qchar)
1057 "looks for a string and returns (start . end) or NIL. The argument QCHAR
1058 is the character that would precede a character constant double quote.
1059 Finds strings delimited by double quotes. The first double quote may not be
1060 preceded by QCHAR and the closing double quote may not be preceded by an odd
1061 number of backslashes."
1062 (let (st en)
1063 (while (and (search-forward "\"" nil t)
1064 (eq qchar (char-after (1- (setq st (match-beginning 0)))))))
1065 (while (and (search-forward "\"" nil t)
1066 (save-excursion
1067 (setq en (point))
1068 (forward-char -1)
1069 (skip-chars-backward "\\\\")
1070 (forward-char 1)
1071 (not (zerop (% (- en (point)) 2))))))
1072 (and en (cons st en))))
1073
1074 ;; return types on same line...
1075 ;; ("^[a-zA-z].*\\(\\w\\|[$_]\\)+\\s *\\(\\(\\w\\|[$_]\\)+\\s *((\\|(\\)[^)]*)+" nil defun)
1076
1077 ;; On another note, a working pattern for grabbing function definitions for C is
1078 ;;
1079 ;; ("^[a-zA-Z_]+.*[;{]$" nil ForestGreen) ; global defns ( start at col 1 )
1080 ;; ("^[a-zA-Z_]+.*(" ")" defun)
1081 ;; ; defuns assumed to start at col 1, not with # or {
1082 ;;
1083 ;; this will make external declarations/definitions green, and function
1084 ;; definitions the defun face. Hmmm - seems to work for me anyway.
1085
1086 (let ((comments '(("/\\*" "\\*/" comment)))
1087 (c++-comments '(("//.*$" nil comment)
1088 ("^/.*$" nil comment)))
1089 (strings '((hilit-string-find ?' string)))
1090 (preprocessor '(("^#[ \t]*\\(undef\\|define\\).*$" "[^\\]$" define)
1091 ("^#.*$" nil include))))
1092
1093 (hilit-set-mode-patterns
1094 '(c-mode c++-c-mode elec-c-mode)
1095 (append
1096 comments strings preprocessor
1097 '(
1098 ;; function decls are expected to have types on the previous line
1099 ("^\\(\\w\\|[$_]\\)+\\s *\\(\\(\\w\\|[$_]\\)+\\s *((\\|(\\)[^)]*)+" nil defun)
1100 ("^\\(typedef\\|struct\\|union\\|enum\\).*$" nil decl)
1101 ;; datatype -- black magic regular expression
1102 ("[ \n\t({]\\(\\(const\\|register\\|volatile\\|unsigned\\|extern\\|static\\)\\s +\\)*\\(\\(\\w\\|[$_]\\)+_t\\|float\\|double\\|void\\|char\\|short\\|int\\|long\\|FILE\\|\\(\\(struct\\|union\\|enum\\)\\([ \t]+\\(\\w\\|[$_]\\)*\\)\\)\\)\\(\\s +\\*+)?\\|[ \n\t;()]\\)" nil type)
1103 ;; key words
1104 ("[^_]\\<\\(return\\|goto\\|if\\|else\\|case\\|default\\|switch\\|break\\|continue\\|while\\|do\\|for\\)\\>[^_]" 1 keyword)
1105 )))
1106
1107 (hilit-set-mode-patterns
1108 'c++-mode
1109 (append
1110 comments c++-comments strings preprocessor
1111 '(
1112 ;; function decls are expected to have types on the previous line
1113 ("^\\(\\(\\w\\|[$_]\\)+::\\)?\\(\\w\\|[$_]\\)+\\s *\\(\\(\\w\\|[$_]\\)+\\s *((\\|(\\)[^)]*)+" nil defun)
1114 ("^\\(\\(\\w\\|[$_]\\)+[ \t]*::[ \t]*\\)?\\(\\(\\w\\|[$_]\\)+\\|operator.*\\)\\s *\\(\\(\\w\\|[$_]\\)+\\s *((\\|(\\)[^)]*)+" nil defun)
1115 ("^\\(template\\|typedef\\|struct\\|union\\|class\\|enum\\|public\\|private\\|protected\\).*$" nil decl)
1116 ;; datatype -- black magic regular expression
1117 ("[ \n\t({]\\(\\(const\\|register\\|volatile\\|unsigned\\|extern\\|static\\)\\s +\\)*\\(\\(\\w\\|[$_]\\)+_t\\|float\\|double\\|void\\|char\\|short\\|int\\|long\\|FILE\\|\\(\\(struct\\|union\\|enum\\|class\\)\\([ \t]+\\(\\w\\|[$_]\\)*\\)\\)\\)\\(\\s +\\*+)?\\|[ \n\t;()]\\)" nil type)
1118 ;; key words
1119 ("[^_]\\<\\(return\\|goto\\|if\\|else\\|case\\|default\\|switch\\|break\\|continue\\|while\\|do\\|for\\|public\\|protected\\|private\\|delete\\|new\\)\\>[^_]"
1120 1 keyword))))
1121
1122 (hilit-set-mode-patterns
1123 '(objc-mode objective-C-mode)
1124 (append
1125 comments c++-comments strings preprocessor
1126 '(
1127 ;; function decls are expected to have types on the previous line
1128 ("^\\(\\(\\w\\|[$_]\\)+::\\)?\\(\\w\\|[$_]\\)+\\s *\\(\\(\\w\\|[$_]\\)+\\s *((\\|(\\)[^)]*)+" nil defun)
1129 ("^\\(\\(\\w\\|[$_]\\)+[ \t]*::[ \t]*\\)?\\(\\(\\w\\|[$_]\\)+\\|operator.*\\)\\s *\\(\\(\\w\\|[$_]\\)+\\s *((\\|(\\)[^)]*)+" nil defun)
1130
1131 ("^\\(template\\|typedef\\|struct\\|union\\|class\\|enum\\|public\\|private\\|protected\\).*$" nil decl)
1132 ;; datatype -- black magic regular expression
1133 ("[ \n\t({]\\(\\(const\\|register\\|volatile\\|unsigned\\|extern\\|static\\)\\s +\\)*\\(\\(\\w\\|[$_]\\)+_t\\|float\\|double\\|void\\|char\\|short\\|int\\|long\\|FILE\\|\\(\\(struct\\|union\\|enum\\|class\\)\\([ \t]+\\(\\w\\|[$_]\\)*\\)\\)\\)\\(\\s +\\*+)?\\|[ \n\t;()]\\)" nil type)
1134 ;; key words
1135 ("[^_]\\<\\(return\\|goto\\|if\\|else\\|case\\|default\\|switch\\|break\\|continue\\|while\\|do\\|for\\|public\\|protected\\|private\\|interface\\|implementation\\|end\\|super\\|self\\)\\>[^_]"
1136 1 keyword))))
1137 )
1138
1139 (hilit-set-mode-patterns
1140 'perl-mode
1141 '(("\\s #.*$" nil comment)
1142 ("^#.*$" nil comment)
1143 ("\"[^\\\"]*\\(\\\\\\(.\\|\n\\)[^\\\"]*\\)*\"" nil string)
1144 ("^\\(__....?__\\|\\s *\\sw+:\\)" nil label)
1145 ("^require.*$" nil include)
1146 ("^package.*$" nil decl)
1147 ("^\\s *sub\\s +\\(\\w\\|[_']\\)+" nil defun)
1148 ("\\b\\(do\\|if\\|unless\\|while\\|until\\|else\\|elsif\\|for\\|foreach\\|continue\\|next\\|redo\\|last\\|goto\\|return\\|die\\|exit\\)\\b" nil keyword)))
1149
1150 (hilit-set-mode-patterns
1151 'ada-mode
1152 '(;; comments
1153 ("--.*$" nil comment)
1154 ;; main structure
1155 ("[ \t\n]procedure[ \t]" "\\([ \t]\\(is\\|renames\\)\\|);\\)" glob-struct)
1156 ("[ \t\n]task[ \t]" "[ \t]is" glob-struct)
1157 ("[ \t\n]function[ \t]" "return[ \t]+[A-Za-z_0-9]+[ \t]*\\(is\\|;\\|renames\\)" glob-struct)
1158 ("[ \t\n]package[ \t]" "[ \t]\\(is\\|renames\\)" glob-struct)
1159 ;; if there is nothing before "private", it is part of the structure
1160 ("^[ \t]*private[ \t\n]" nil glob-struct)
1161 ;; if there is no indentation before the "end", then it is most
1162 ;; probably the end of the package
1163 ("^end.*$" ";" glob-struct)
1164 ;; program structure -- "null", "delay" and "terminate" omitted
1165 ("[ \n\t]\\(in\\|out\\|select\\|if\\|else\\|case\\|when\\|and\\|or\\|not\\|accept\\|loop\\|do\\|then\\|elsif\\|else\\|for\\|while\\|exit\\)[ \n\t;]" nil struct)
1166 ;; block structure
1167 ("[ \n\t]\\(begin\\|end\\|declare\\|exception\\|generic\\|raise\\|return\\|package\\|body\\)[ \n\t;]" nil struct)
1168 ;; type declaration
1169 ("^[ \t]*\\(type\\|subtype\\).*$" ";" decl)
1170 ("[ \t]+is record.*$" "end record;" decl)
1171 ;; "pragma", "with", and "use" are close to C cpp directives
1172 ("^[ \t]*\\(with\\|pragma\\|use\\)" ";" include)
1173 ;; nice for named parameters, but not so beautiful in case statements
1174 ("[A-Za-z_0-9.]+[ \t]*=>" nil named-param)
1175 ;; string constants probably not everybody likes this one
1176 ("\"" ".*\"" string)))
1177
1178 (hilit-set-mode-patterns
1179 'fortran-mode
1180 '(("^[*Cc].*$" nil comment)
1181 ("'[^'\n]*'" nil string)
1182 ("\\(^[ \t]*[0-9]+\\|[ \t]continue[ \t\n]\\|format\\)" nil define)
1183 ("[ \t]\\(do\\|do[ \t]*[0-9]+\\|go[ \t]*to[ \t]*[0-9]+\\|end[ \t]*do\\|if\\|else[ \t]*if\\|then\\|else\\|end[ \t]*if\\)[ \t\n(]" nil define)
1184 ("[ \t]\\(call\\|program\\|subroutine\\|function\\|stop\\|return\\|end\\|include\\)[ \t\n]" nil include)
1185 ("[ \t]\\(parameter[\t\n ]*([^)]*)\\|data\\|save\\|common[ \t\n]*/[^/]*/\\)"
1186 nil decl)
1187 ("^ ." nil type)
1188 ("implicit[ \t]*none" nil decl)
1189 ("\\([ \t]\\|implicit[ \t]*\\)\\(dimension\\|integer\\|real\\|double[ \t]*precision\\|character\\|logical\\|complex\\|double[ \t]*complex\\)\\([*][0-9]*\\|[ \t\n]\\)" nil keyword)
1190 )
1191 nil 'case-insensitive)
1192
1193 (hilit-set-mode-patterns
1194 '(m2-mode modula-2-mode)
1195 '(("(\\*" "\\*)" comment)
1196 (hilit-string-find ?\\ string)
1197 ("^[ \t]*PROCEDURE[ \t]+\\w+[^ \t(;]*" nil defun)
1198 ("\\<\\(RECORD\\|ARRAY\\|OF\\|POINTER\\|TO\\|BEGIN\\|END\\|FOR\\|IF\\|THEN\\|ELSE\\|ELSIF\\|CASE\\|WHILE\\|DO\\|MODULE\\|FROM\\|RETURN\\|IMPORT\\|EXPORT\\|VAR\\|LOOP\\|UNTIL\\|\\DEFINITION\\|IMPLEMENTATION\\|AND\\|OR\\|NOT\\|CONST\\|TYPE\\|QUALIFIED\\)\\>" nil keyword)
1199 )
1200 nil 'case-insensitive)
1201
1202 (hilit-set-mode-patterns 'prolog-mode
1203 '(("/\\*" "\\*/" comment)
1204 ("%.*$" nil comment)
1205 (":-" nil defun)
1206 ("!" nil label)
1207 ("\"[^\\\"]*\\(\\\\\\(.\\|\n\\)[^\\\"]*\\)*\"" nil string)
1208 ("\\b\\(is\\|mod\\)\\b" nil keyword)
1209 ("\\(->\\|-->\\|;\\|==\\|\\\\==\\|=<\\|>=\\|<\\|>\\|=\\|\\\\=\\|=:=\\|=\\\.\\\.\\|\\\\\\\+\\)" nil decl)
1210 ("\\(\\\[\\||\\|\\\]\\)" nil include)))
1211
1212 (hilit-set-mode-patterns
1213 '(
1214 LaTeX-mode japanese-LaTeX-mode SliTeX-mode
1215 japanese-SliTeX-mode FoilTeX-mode latex-mode
1216 )
1217 '(
1218 ;; comments
1219 ("[^\\]%.*$" nil comment)
1220
1221 ;; the following two match \foo[xx]{xx} or \foo*{xx} or \foo{xx}
1222 ("\\\\\\(sub\\)*\\(paragraph\\|section\\)\\(\*\\|\\[.*\\]\\)?{" "}"
1223 keyword)
1224 ("\\\\\\(chapter\\|part\\)\\(\*\\|\\[.*\\]\\)?{" "}" keyword)
1225 ("\\\\footnote\\(mark\\|text\\)?{" "}" keyword)
1226 ("\\\\[a-z]+box" nil keyword)
1227 ("\\\\\\(v\\|h\\)space\\(\*\\)?{" "}" keyword)
1228
1229 ;; (re-)define new commands/environments/counters
1230 ("\\\\\\(re\\)?new\\(environment\\|command\\){" "}" defun)
1231 ("\\\\new\\(length\\|theorem\\|counter\\){" "}" defun)
1232
1233 ;; various declarations/definitions
1234 ("\\\\\\(setlength\\|settowidth\\|addtolength\\|setcounter\\|addtocounter\\)" nil define)
1235 ("\\\\\\(title\\|author\\|date\\|thanks\\){" "}" define)
1236
1237 ("\\\\documentstyle\\(\\[.*\\]\\)?{" "}" decl)
1238 ("\\\\\\(begin\\|end\\|nofiles\\|includeonly\\){" "}" decl)
1239 ("\\\\\\(raggedright\\|makeindex\\|makeglossary\\|maketitle\\)\\b" nil
1240 decl)
1241 ("\\\\\\(pagestyle\\|thispagestyle\\|pagenumbering\\){" "}" decl)
1242 ("\\\\\\(normalsize\\|small\\|footnotesize\\|scriptsize\\|tiny\\|large\\|Large\\|LARGE\\|huge\\|Huge\\)\\b" nil decl)
1243 ("\\\\\\(appendix\\|tableofcontents\\|listoffigures\\|listoftables\\)\\b"
1244 nil decl)
1245 ("\\\\\\(bf\\|em\\|it\\|rm\\|sf\\|sl\\|ss\\|tt\\)\\b" nil decl)
1246
1247 ;; label-like things
1248 ("\\\\item\\(\\[[^]]*\\]\\)?" nil label)
1249 ("\\\\caption\\(\\[[^]]*\\]\\)?{" "}" label)
1250
1251 ;; formulas
1252 ("[^\\]\\\\(" "\\\\)" formula) ; \( \)
1253 ("[^\\]\\\\\\[" "\\\\\\]" formula) ; \[ \]
1254 ("[^\\$]\\(\\$\\(\\$[^$]*\\$\\|[^$]*\\)\\$\\)" 1 formula) ; '$...$' or '$$...$$'
1255
1256 ;; things that bring in external files
1257 ("\\\\\\(include\\|input\\|bibliography\\){" "}" include)
1258
1259 ;; "wysiwyg" emphasis -- these don't work with nested expressions
1260 ;; ("{\\\\\\(em\\|it\\|sl\\)" "}" italic)
1261 ;; ("{\\\\bf" "}" bold)
1262
1263 ("``" "''" string)
1264
1265 ;; things that do some sort of cross-reference
1266 ("\\\\\\(\\(no\\)?cite\\|\\(page\\)?ref\\|label\\|index\\|glossary\\){" "}" crossref)
1267 ))
1268
1269 (hilit-set-mode-patterns
1270 'bibtex-mode
1271 '(;;(";.*$" nil comment)
1272 ("%.*$" nil comment)
1273 ("@[a-zA-Z]+" nil keyword)
1274 ("{[ \t]*[-a-z:_A-Z0-9]+," nil label) ; is wrong sometimes
1275 ("^[ \t]*[a-zA-Z]+[ \t]*=" nil define)))
1276
1277 (hilit-set-mode-patterns
1278 'compilation-mode
1279 '(
1280 ("^[-_.\"A-Za-z0-9]+\\(:\\|, line \\)[0-9]+: warning:.*$" nil warning)
1281 ("^[-_.\"A-Za-z0-9]+\\(:\\|, line \\)[0-9]+:.*$" nil error)
1282 ))
1283
1284 (hilit-set-mode-patterns
1285 'makefile-mode
1286 '(("^#.*$" nil comment)
1287 ("[^$]#.*$" nil comment)
1288 ;; rules
1289 ("^[^ \t\n]*%[^ \t\n]*[ \t]*::?[ \t]*[^ \t\n]*[ \t]*\\(#.*\\)?$" nil rule)
1290 ("^[.][A-Za-z][A-Za-z]?\..*$" nil rule)
1291 ;; variable definition
1292 ("^[_A-Za-z0-9]+[ \t]*\+?=" nil define)
1293 ("\\( \\|:=\\)[_A-Za-z0-9]+[ \t]*\\+=" nil define)
1294 ;; variable references
1295 ("\\$\\([^ \t\n{(]\\|[{(]@?[_A-Za-z0-9:.,%/=]+[)}]\\)" nil keyword)
1296 ("^[A-Za-z0-9.,/_-]+[ \t]*:.*$" nil defun)
1297 ("^include " nil include)))
1298
1299 (let* ((header-patterns '(("^Subject:.*$" nil msg-subject)
1300 ("^From:.*$" nil msg-from)
1301 ("^--text follows this line--$" nil msg-separator)
1302 ("^[A-Za-z][A-Za-z0-9-]+:" nil msg-header)))
1303 (body-patterns '(("^\\(In article\\|[ \t]*\\w*[]<>}|]\\).*$"
1304 nil msg-quote)))
1305 (message-patterns (append header-patterns body-patterns)))
1306 (hilit-set-mode-patterns 'msg-header header-patterns)
1307 (hilit-set-mode-patterns 'msg-body body-patterns)
1308 (hilit-set-mode-patterns '(vm-mode text-mode mail-mode rmail-mode
1309 gnus-article-mode news-reply-mode mh-show-mode)
1310 message-patterns
1311 'hilit-rehighlight-message))
1312
1313 (hilit-set-mode-patterns
1314 'gnus-group-mode
1315 '(("^ U.*$" nil gnus-group-unsubscribed)
1316 ("^\\*? +[01]?[0-9]:.*$" nil gnus-group-empty)
1317 ("^ +[2-9][0-9]:.*$" nil gnus-group-full)
1318 ("^ +[0-9][0-9][0-9]+:.*$" nil gnus-group-overflowing)))
1319
1320 (hilit-set-mode-patterns
1321 'vm-summary-mode
1322 '(("^ .*$" nil summary-seen)
1323 ("^->.*$" nil summary-current)
1324 ("^ D.*$" nil summary-deleted)
1325 ("^ U.*$" nil summary-unread)
1326 ("^ N.*$" nil summary-new)))
1327
1328
1329 ;;; this will match only comments w/ an even (zero is even) number of quotes...
1330 ;;; which is still inadequate because it matches comments in multi-line strings
1331 ;;; how anal do you want to get about never highlighting comments in strings?
1332 ;;; I could twiddle with this forever and still it wouldn't be perfect.
1333 ;;; (";\\([^\"\n]*\"[^\"\n]*\"\\)*[^\"\n]*$" nil comment)
1334
1335 (hilit-set-mode-patterns
1336 '(emacs-lisp-mode lisp-interaction-mode)
1337 '(
1338 (";.*" nil comment)
1339
1340 ;;; This almost works...but I think I'll stick with the parser function
1341 ;;;("[^?]\\(\"\\(\"\\||\\([^\"]+\\|[\\]\\([\\][\\]\\)*\"\\)*\"\\)\\)" 1 string)
1342 (hilit-string-find ?\\ string)
1343
1344 ("^\\s *(def\\(un\\|macro\\|advice\\|alias\\|subst\\)[ \t\n]"
1345 "\\()\\|nil\\)" defun)
1346 ("^\\s *(defvar\\s +\\S +" nil decl)
1347 ("^\\s *(defconst\\s +\\S +" nil define)
1348 ("^\\s *(\\(provide\\|require\\|\\(auto\\)?load\\).*$" nil include)
1349 ("\\s *\\&\\(rest\\|optional\\)\\s *" nil keyword)
1350 ("(\\(let\\*?\\|cond\\|if\\|or\\|and\\|map\\(car\\|concat\\)\\|prog[n1*]?\\|while\\|lambda\\|function\\|set\\([qf]\\|car\\|cdr\\)?\\|nconc\\|eval-when-compile\\|condition-case\\|unwind-protect\\|catch\\|throw\\|error\\)[ \t\n]" 1 keyword)
1351 ))
1352
1353 (hilit-set-mode-patterns
1354 '(lisp-mode ilisp-mode)
1355 '(
1356 (";.*" nil comment)
1357 ("#|" "|#" comment)
1358 ;;; This almost works...but I think I'll stick with the parser function
1359 ;;;("[^?]\\(\"\\(\"\\||\\([^\"]+\\|[\\]\\([\\][\\]\\)*\"\\)*\"\\)\\)" 1 string)
1360 (hilit-string-find ?\\ string)
1361
1362 ;; this is waaaaaaaay too slow
1363 ;; ("^\\s *(def\\(un\\|macro\\|advice\\|alias\\|method\\|subst\\)\\s \\S +[ \t\n]+\\(nil\\|(\\(([^()]*)\\|[^()]+\\)*)\\)" nil defun)
1364 ("^\\s *(def\\(un\\|macro\\|advice\\|subst\\|method\\)\\s " "\\()\\|nil\\)" defun)
1365
1366 ("^\\s *(\\(def\\(var\\|type\\|parameter\\)\\|declare\\)\\s +\\S +" nil decl)
1367 ("^\\s *(def\\(const\\(ant\\)?\\|class\\|struct\\)\\s \\S +[ \t\n]+" nil define)
1368 ("^\\s *(\\(provide\\|require\\|\\(auto\\)?load\\).*$" nil include)
1369 ("[ \t]\\&\\(key\\|rest\\|optional\\|aux\\)\\s *" nil keyword)
1370 ("(\\(let\\*?\\|locally\\|cond\\|if\\*?\\|or\\|and\\|map\\(car\\|c[ao]n\\)?\\|prog[nv1*]?\\|while\\|when\\|unless\\|do\\(\\*\\|list\\|times\\)\\|list\\|lambda\\|function\\|values\\|set\\([qf]\\|car\\|cdr\\)?\\|rplac[ad]\\|nconc\\|block\\|go\\|return\\(-from\\)?\\|[ec]?\\(type\\)?case\\|multiple-value-\\(bind\\|setq\\|list\\|call\\|prog1\\)\\|unwind-protect\\|handler-case\\|catch\\|throw\\|eval-when\\(-compile\\)?\\)[ \t\n]" 1 keyword)
1371 ))
1372
1373
1374 (hilit-set-mode-patterns
1375 'plain-tex-mode
1376 '(("^%%.*$" nil comment)
1377 ("{\\\\em\\([^}]+\\)}" nil comment)
1378 ("\\(\\\\\\w+\\)" nil keyword)
1379 ("{\\\\bf\\([^}]+\\)}" nil keyword)
1380 ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" nil defun)
1381 ("\\\\\\(begin\\|end\\){\\([A-Za-z0-9\\*]+\\)}" nil defun)
1382 ;; ("[^\\\\]\\$\\([^$]*\\)\\$" nil string)
1383 ("\\$\\([^$]*\\)\\$" nil string)
1384 ))
1385
1386 ;; Reasonable extensions would include smarter parameter handling for such
1387 ;; things as the .IX and .I macros, which alternate the handling of following
1388 ;; arguments.
1389
1390 (hilit-set-mode-patterns
1391 'nroff-mode
1392 '(("^\\.[\\\][\\\"].*$" nil comment)
1393 ("^\\.so .*$" nil include)
1394 ("^\\.[ST]H.*$" nil defun)
1395 ;; ("^[^\\.].*\"[^\\\"]*\\(\\\\\\(.\\)[^\\\"]*\\)*\"" nil string)
1396 ("\"" "[^\\]\"" string)
1397 ("^\\.[A-Z12\\\\].*$" nil define)
1398 ("\\([\\\][^ ]*\\)" nil keyword)
1399 ("^\\.[A-Z].*$" nil keyword))
1400 nil 'case-insensitive)
1401
1402 (hilit-set-mode-patterns
1403 'texinfo-mode
1404 '(("^\\(@c\\|@comment\\)\\>.*$" nil comment)
1405 ("@\\(emph\\|strong\\|b\\|i\\){[^}]+}" nil comment)
1406 ;; seems broken
1407 ;; ("\\$[^$]*\\$" nil string)
1408 ("@\\(file\\|kbd\\|key\\){[^}]+}" nil string)
1409 ("^\\*.*$" nil defun)
1410 ("@\\(if\\w+\\|format\\|item\\)\\b.*$" nil defun)
1411 ("@end +[A-Za-z0-9]+[ \t]*$" nil defun)
1412 ("@\\(samp\\|code\\|var\\){[^}]+}" nil defun)
1413 ("@\\w+\\({[^}]+}\\)?" nil keyword)
1414 ))
1415
1416 (hilit-set-mode-patterns
1417 'dired-mode
1418 (append
1419 '(("^D.*$" nil dired-deleted)
1420 ("^\\*.*$" nil dired-marked)
1421 ("^ d.*$" nil dired-directory)
1422 ("^ l.*$" nil dired-link)
1423 ("^ -.*#.*#$" nil dired-ignored))
1424 (list (cons
1425 (concat "^ .*\\("
1426 (mapconcat 'regexp-quote completion-ignored-extensions "\\|")
1427 "\\)$")
1428 '(nil dired-ignored)))))
1429
1430 (hilit-set-mode-patterns
1431 'jargon-mode
1432 '(("^:[^:]*:" nil jargon-entry)
1433 ("{[^}]*}+" nil jargon-xref)))
1434
1435 (hilit-set-mode-patterns
1436 'Info-mode
1437 '(("^\\* [^:]+:+" nil jargon-entry)
1438 ("\\*[Nn]ote\\b[^:]+:+" nil jargon-xref)
1439 (" \\(Next\\|Prev\\|Up\\):" nil jargon-xref)
1440 ("- \\(Variable\\|Function\\|Macro\\|Command\\|Special Form\\|User Option\\):.*$"
1441 nil jargon-keyword))) ; lisp manual
1442
1443 (hilit-set-mode-patterns
1444 'calendar-mode
1445 '(("[A-Z][a-z]+ [0-9]+" nil define) ; month and year
1446 ("S M Tu W Th F S" nil label))) ; week days
1447
1448 (hilit-set-mode-patterns
1449 'asm-mode
1450 '(("/\\*" "\\*/" comment)
1451 ("^#[ \t]*\\(undef\\|define\\).*$" "[^\\]$" define)
1452 ("^#.*$" nil include)
1453 ;; labels
1454 ("^.+:" nil defun)
1455 ;; assembler directives
1456 ("^[ \t]*\\..*$" nil decl)
1457 ;; register names
1458 ("\\$[a-z0-9]+" nil string)
1459 ;; mnemonics
1460 ("^[ \t]*[a-z]+" nil struct)))
1461
1462 (hilit-set-mode-patterns
1463 'pascal-mode
1464 '(("(\\*" "\\*)" comment)
1465 ("{" "}" comment)
1466 ;; Doesn't work when there are strings in comments....
1467 ;; ("'[^']*'" nil string)
1468 ("^#.*$" nil include)
1469 ("^[ \t]*\\(procedure\\|function\\)[ \t]+\\w+[^ \t(;]*" nil defun)
1470 ("\\<\\(program\\|begin\\|end\\)\\>" nil defun)
1471 ("\\<\\(external\\|forward\\)\\>" nil include)
1472 ("\\<\\(label\\|const\\|type\\|var\\)\\>" nil define)
1473 ("\\<\\(record\\|array\\|file\\)\\>" nil type)
1474 ("\\<\\(of\\|to\\|for\\|if\\|then\\|else\\|case\\|while\\|do\\|until\\|and\\|or\\|not\\|with\\|repeat\\)\\>" nil keyword)
1475 )
1476 nil 'case-insensitive)
1477
1478 (hilit-set-mode-patterns
1479 'icon-mode
1480 '(("#.*$" nil comment)
1481 ("\"[^\\\"]*\\(\\\\.[^\\\"]*\\)*\"" nil string)
1482 ;; charsets: these do not work because of a conflict with strings
1483 ;; ("'[^\\']*\\(\\\\.[^\\']*\\)*'" nil string)
1484 ("^[ \t]*procedure[ \t]+\\w+[ \t]*(" ")" defun)
1485 ("^[ \t]*record.*(" ")" include)
1486 ("^[ \t]*\\(global\\|link\\)[ \t\n]+[A-Za-z_0-9]+\\([ \t\n]*,[ \t\n]*[A-Za-z_0-9]+\\)*" nil include)
1487 ("^[ \t]*\\(local\\|static\\)[ \t\n]+[A-Za-z_0-9]+\\([ \t\n]*,[ \t\n]*[A-Za-z_0-9]+\\)*" nil decl)
1488 ("\\<\\(initial\\|end\\)\\>" nil glob-struct)
1489 ("\\<\\(while\\|until\\|return\\|every\\|if\\|then\\|else\\|to\\|case\\|of\\|suspend\\|create\\|do\\|repeat\\|break\\)\\>" nil keyword)
1490 ))
1491
1492 ;; as you can see, I had two similar problems for Pascal and Icon. In
1493 ;; Pascal, strings are delimited with ' and an embedded quote is doubled,
1494 ;; thus string syntax would be extremely simple. However, if a string
1495 ;; occurs within a comment, the following text is considered a string.
1496 ;;
1497 ;; In Icon, strings are similar to C ones, but there are also charsets,
1498 ;; delimited with simple quotes. I could not manage to use both regexps at
1499 ;; the same time.
1500
1501 ;; The problem I have with my patterns for Icon is that this language has a
1502 ;; string similar constant to the C one (but a string can be cut on several
1503 ;; lines, if terminated by a dash and continued with initial blanks, like
1504 ;; this:
1505 ;; "This is a somewhat long -
1506 ;; string, written on three -
1507 ;; successive lines"
1508 ;; in order to insert a double quote in a string, you have to escape it
1509 ;; with a \), bu also a character set constant (named a charset), which
1510 ;; uses single quotes instead of double ones. It would seem intuitive to
1511 ;; highlight both constants in the same way.
1512
1513
1514 (provide 'hilit19)
1515
1516 ;;; hilit19 ends here.