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