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