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