annotate lisp/auctex/font-latex.el @ 138:6608ceec7cf8 r20-2b3

Import from CVS: tag r20-2b3
author cvs
date Mon, 13 Aug 2007 09:31:46 +0200
parents 4be1180a9e89
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1 ;;; font-latex.el --- LaTeX fontification for Font Lock mode.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996 Peter S. Galbraith
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
4
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
5 ;; Authors: Peter S. Galbraith <galbraith@mixing.qc.dfo.ca>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
6 ;; Simon Marshall <Simon.Marshall@esrin.esa.it>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
7 ;; Maintainer: Peter S. Galbraith <galbraith@mixing.qc.dfo.ca>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
8 ;; Created: 06 July 1996
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
9 ;; Version: 0.403 *Beta* (19 Nov 96)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
10 ;; Keywords: LaTeX faces
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
11
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
12 ;; RCS $Id: font-latex.el,v 1.1 1997/02/20 02:17:35 steve Exp $
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
13 ;; Note: RCS version number does not correspond to release number.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
14
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
15 ;; LCD Archive Entry: (Not yet submitted!)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
16 ;; font-latex|Peter Galbraith|galbraith@mixing.qc.dfo.ca|
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
17 ;; LaTeX fontification for font-lock|
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
18 ;; 06-Jul-1996|0.01|~/modes/font-latex.el|
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
19
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
20 ;; The archive is archive.cis.ohio-state.edu in /pub/gnu/emacs/elisp-archive.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
21
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
22 ;;; This file is not part of GNU Emacs.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
23
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
24 ;; This package is free software; you can redistribute it and/or modify
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
25 ;; it under the terms of the GNU General Public License as published by
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
26 ;; the Free Software Foundation; either version 2, or (at your option)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
27 ;; any later version.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
28
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
29 ;; This package is distributed in the hope that it will be useful,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
30 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
31 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
32 ;; GNU General Public License for more details.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
33
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
34 ;; You should have received a copy of the GNU General Public License
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
35 ;; along with GNU Emacs; see the file COPYING. If not, write to the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
36 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
37 ;; Boston, MA 02111-1307, USA.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
38
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
39 ;;; Commentary:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
40
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
41 ;; New versions of this package (if they exist) may be found at:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
42 ;; ftp://ftp.phys.ocean.dal.ca/users/rhogee/elisp/font-latex.el
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
43
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
44 ;; Description:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
45 ;; This package enhances font-lock fontification patterns for LaTeX.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
46 ;; font-lock mode is a minor mode that causes your comments to be
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
47 ;; displayed in one face, strings in another, reserved words in another,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
48 ;; and so on.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
49 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
50 ;; Please see the accompanying file font-latex.tex for a demo of what
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
51 ;; font-latex is supposed to do at different fontification levels.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
52
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
53 ;; Installation instructions:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
54 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
55 ;; Put this file in your emacs load-path, and byte-compile it:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
56 ;; M-x byte-compile-file
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
57 ;; ** It runs faster when you byte-compile it! **
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
58 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
59 ;; Then all you need to do is add this form to your .emacs file:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
60 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
61 ;; (if window-system
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
62 ;; (require 'font-latex))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
63 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
64 ;; There are two levels of fontification, selected by the value of the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
65 ;; font-lock variable font-lock-maximum-decoration. font-latex uses two
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
66 ;; levels. There are ways documented in font-latex.el to set this
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
67 ;; differently for each mode that uses font-lock, but if you are unsure and
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
68 ;; are running on a fast enough machine, try putting this in your ~/.emacs
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
69 ;; file:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
70 ;; (setq font-lock-maximum-decoration t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
71 ;; It probably best to put it before the (require 'font-latex) statement.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
72 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
73 ;; Lazy-lock users:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
74 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
75 ;; lazy-lock and font-lock don't work too well together (up to Emacs 19.33
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
76 ;; and XEmacs 19.14 anyway). font-latex uses functions to find text to
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
77 ;; fontify that may span more than one line, and this doesn't suit
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
78 ;; lazy-lock's search limits too well.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
79 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
80 ;; Old hilit19 (and hilit-LaTeX) users:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
81 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
82 ;; If you are upgrading from using hilit-LaTeX.el or were using hilit19,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
83 ;; you must disable hilit19 (at least for latex mode) in order to use
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
84 ;; font-latex.el. Here's how:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
85 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
86 ;; - If you don't care to use hilit19 at all, don't `load' or `require' it
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
87 ;; in your ~/.emacs file by removing the "(require 'hilit-LaTeX)" line.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
88 ;; - If you wish to use hilit19 everywhere but in latex mode, add the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
89 ;; following before your `load' or `require' hilit19:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
90 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
91 ;; (setq hilit-mode-enable-list '(not latex-mode))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
92 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
93 ;; You can tell you using font-latex instead of hilit-LaTeX because:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
94 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
95 ;; - colours will be different
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
96 ;; - You'll see a message like `Fontifying font-latex.tex...done'
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
97 ;; instead of `highlighting 1: \(^\|[^\\]\)\(\\[a-zA-Z\\]+\)'
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
98 ;; ----------------------------------------------------------------------------
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
99 ;;; Change log:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
100 ;; V0.403 19Nov96 (RCS V1.37)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
101 ;; - Christoph Wedler <wedler@fmi.uni-passau.de>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
102 ;; XEmacs patch for local math-font
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
103 ;; - Changed scheme for fontification of \section*{...}
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
104 ;; V0.402 13Nov96 PSG (RCS V1.35)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
105 ;; - Embeded comments handled.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
106 ;; - Better XEmacs initilisation.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
107 ;; V0.401 12Nov96 PSG (RCS V1.34) - Nothing fontified when commented-out.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
108 ;; V0.400 11Nov96 PSG (RCS V1.33)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
109 ;; - Stab at on-the-fly multiline.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
110 ;; - mono support: <Johannes.Weinert@Informatik.Uni-Oldenburg.DE>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
111 ;; V0.314 16Oct96 PSG - Support for dark background removed for XEmacs.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
112 ;; V0.313 07Oct96 PSG (RCS V1.31) - Support for dark background.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
113 ;; V0.312 26Aug96 PSG (RCS V1.30) - Added font-latex-commented-outp.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
114 ;; V0.311 22Aug96 PSG (RCS V1.29) - fixed for XEmacs.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
115 ;; V0.310 22Aug96 simon (RCS V1.27)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
116 ;; - make font-latex-setup run font-lock-make-faces before variable trickery.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
117 ;; - set font-latex-string-face to the global value of font-lock-string-face.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
118 ;; V0.309 21Aug96 PSG (RCS V1.26)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
119 ;; - new font-latex-math-face done by string syntax. User may modify it.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
120 ;; - new font-latex-string-face.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
121 ;; V0.308 15Aug96 PSG (RCS V1.25)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
122 ;; - $$...$$ gets font-latex-math-face
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
123 ;; - font-latex-match-math-envII fixed.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
124 ;; V0.307 14Aug96 PSG (RCS V1.23) - setup okay if loaded in a latex-mode-hook
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
125 ;; V0.306 14Aug96 PSG (RCS V1.22) - added "item" to font-latex-match-function
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
126 ;; V0.305 14Aug96 PSG (RCS V1.20) - use keep in font-latex-match-math-envII
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
127 ;; V0.304 14Aug96 PSG (RCS V1.18) - minor comment edits.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
128 ;; V0.303 14Aug96 simon (RCS V1.17)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
129 ;; - rewrote font-latex-match-math-envII like font-latex-match-quotation
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
130 ;; V0.302 12Aug96 PSG (RCS V1.16)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
131 ;; - (goto-char end) in condition-case error to avoid infinite loops.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
132 ;; V0.301 08Aug96 PSG (RCS V1.14)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
133 ;; - Better faces in XEmacs.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
134 ;; V0.300 07Aug96 PSG (RCS V1.12)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
135 ;; - Changed font-latex-match-font-inside-braces again for stranded \bf
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
136 ;; - "[a-z]+box" changed
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
137 ;; - font-latex-match-math-env checks preceding-char for \\[
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
138 ;; - use eval-after-compile in font-latex-match-math-envII
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
139 ;; V0.201 05Aug96 PSG added \\(display\\)?math to Simon's changes
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
140 ;; V0.200 05Aug96 simon: (RCS V1.10)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
141 ;; - fixed font-latex-match-command-outside-arguments
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
142 ;; - rewrote font-latex-match-font-outside-braces like above
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
143 ;; - rewrote font-latex-match-font-inside-braces like above
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
144 ;; V0.101 01Aug96 PSG added \\(display\\)?math
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
145 ;; V0.100 01Aug96 PSG - massive new test version
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
146 ;; V0.061 23Jul96 PSG
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
147 ;; - Removed trailing "\\>" in warning-face regexp (fails with \\ \- \\*)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
148 ;; V0.06 23Jul96 PSG
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
149 ;; - fixed dobib in font-latex-labels.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
150 ;; - shorter font regexp in levels 3+4.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
151 ;; - removed \item and & from type
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
152 ;; - fixed font-latex-math-envII regexp
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
153 ;; V0.05 22Jul96 PSG
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
154 ;; - changed \ref etc to reference-face.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
155 ;; - \\b added in buggy \item[option] regexp (not really fixed).
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
156 ;; - font-latex-labels regexp bug
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
157 ;; V0.041 simon:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
158 ;; - added font-latex-match-command-outside-arguments
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
159 ;; - rewrote font-latex-match-quotation and font-latex-bib-highlight-mouse
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
160 ;; - rewrote then removed bib-cite functionality.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
161 ;; - general top-level cleanup
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
162 ;; V0.04 11Jul96 PSG
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
163 ;; - added font-lock-comment-start-regexp defined in 19.32
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
164 ;; - encoded 8-bit characters to 7-bit.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
165 ;; V0.03 10Jul96 PSG
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
166 ;; - font-latex-bib-cite-mouse-highlight-p can change after font-lock-defaults
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
167 ;; is constructed.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
168 ;; V0.02 09Jul96 PSG
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
169 ;; - added font-latex-bib-cite-mouse-highlight-p
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
170 ;; - Fixed `overwrite' flags
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
171 ;; V0.01 06Jul96 Peter S Galbraith - Created
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
172 ;; ----------------------------------------------------------------------------
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
173 ;;; Code:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
174 (require 'font-lock)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
175
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
176 (defvar font-latex-warning-face 'font-latex-warning-face
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
177 "Face to use for LaTeX major keywords.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
178 (defvar font-latex-sedate-face 'font-latex-sedate-face
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
179 "Face to use for LaTeX minor keywords.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
180 (defvar font-latex-italic-face 'font-latex-italic-face
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
181 "Face to use for LaTeX italics.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
182 (defvar font-latex-bold-face 'font-latex-bold-face
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
183 "Face to use for LaTeX bolds.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
184 (defvar font-latex-math-face 'font-latex-math-face
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
185 "Face to use for LaTeX math environments.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
186
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
187 ;; End-User can stop reading here.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
188
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
189 ;; Make sure font-latex.el is supported. I don't claim to have tested this...
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
190 (if (if (save-match-data (string-match "Lucid\\|XEmacs" (emacs-version)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
191 (and (= emacs-major-version 19) (< emacs-minor-version 14))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
192 (and (= emacs-major-version 19) (< emacs-minor-version 29)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
193 (error "`font-latex' was written for Emacs 19.29/XEmacs 19.14 or later"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
194
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
195 (defvar font-latex-is-XEmacs
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
196 (not (null (save-match-data (string-match "XEmacs\\|Lucid" emacs-version)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
197
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
198 (defvar font-latex-string-face nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
199 "Face to use for strings. This is set by Font LaTeX.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
200
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
201 (defvar font-lock-comment-start-regexp nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
202 "Regexp to match the start of a comment.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
203
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
204 (eval-when-compile
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
205 (require 'cl))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
206
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
207 (cond
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
208 ((not font-latex-is-XEmacs)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
209 ;;; emacs:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
210 ;; Otherwise I overwrite fock-lock-face-attributes.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
211 ;; font-lock.el needs a better way to add these faces!
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
212 (if (not font-lock-face-attributes)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
213 (font-lock-make-faces))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
214 (unless (assq 'font-latex-sedate-face font-lock-face-attributes)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
215 (cond
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
216 ;; FIXME: Add better conditions for grayscale.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
217 ((memq font-lock-display-type '(mono monochrome grayscale greyscale
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
218 grayshade greyshade))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
219 (setq font-lock-face-attributes
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
220 (append
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
221 font-lock-face-attributes
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
222 (list '(font-latex-bold-face nil nil t nil nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
223 '(font-latex-italic-face nil nil nil t nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
224 '(font-latex-math-face nil nil nil nil t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
225 '(font-latex-sedate-face nil nil nil t nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
226 (list
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
227 'font-latex-warning-face
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
228 (cdr (assq 'background-color (frame-parameters)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
229 (cdr (assq 'foreground-color (frame-parameters)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
230 nil nil nil)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
231 ((eq font-lock-background-mode 'light) ; light colour background
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
232 (setq font-lock-face-attributes
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
233 (append
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
234 font-lock-face-attributes
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
235 ;;;FIXME: These won't follow font-lock-type-face's changes.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
236 ;;; Should I change to a (copy-face) scheme?
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
237 '((font-latex-bold-face "DarkOliveGreen" nil t nil nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
238 (font-latex-italic-face "DarkOliveGreen" nil nil t nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
239 (font-latex-math-face "green4")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
240 (font-latex-sedate-face "grey50")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
241 (font-latex-warning-face "red" nil t nil nil)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
242 (t ; dark colour background
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
243 (setq font-lock-face-attributes
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
244 (append
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
245 font-lock-face-attributes
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
246 '((font-latex-bold-face "OliveGreen" nil t nil nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
247 (font-latex-italic-face "OliveGreen" nil nil t nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
248 (font-latex-math-face "LightSeaGreen")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
249 ;; good are > LightSeaGreen, LightCoral, coral, orchid, orange
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
250 (font-latex-sedate-face "grey60")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
251 (font-latex-warning-face "red" nil t nil nil))))))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
252 (t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
253 ;;; XEmacs:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
254 (make-face 'font-latex-string-face "Face to use for LaTeX string.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
255 (copy-face 'font-lock-string-face 'font-latex-string-face)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
256
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
257 (make-face 'font-latex-bold-face "Face to use for LaTeX bolds.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
258 (copy-face 'font-lock-type-face 'font-latex-bold-face)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
259 (make-face-bold 'font-latex-bold-face)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
260
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
261 (make-face 'font-latex-italic-face "Face to use for LaTeX italics.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
262 (copy-face 'font-lock-type-face 'font-latex-italic-face)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
263 (make-face-italic 'font-latex-italic-face)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
264
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
265 (make-face 'font-latex-math-face "Face to use for LaTeX math.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
266 (make-face 'font-latex-sedate-face "Face to use for LaTeX minor keywords.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
267 (make-face 'font-latex-warning-face "Face to use for LaTeX major keywords.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
268 (make-face-bold 'font-latex-warning-face)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
269 ;; XEmacs uses a tag-list thingy to determine if we are using color
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
270 ;; or mono (and I assume a dark background).
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
271 (set-face-foreground 'font-latex-math-face "green4" 'global nil 'append)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
272 (set-face-foreground 'font-latex-sedate-face "grey50" 'global nil 'append)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
273 (set-face-foreground 'font-latex-warning-face "red" 'global nil 'append)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
274
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
275 (defun font-latex-setup ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
276 "Setup this buffer for LaTeX font-lock. Usually called from a hook."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
277 ;; Trickery to make $$ fontification be in `font-latex-math-face' while
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
278 ;; strings get whatever `font-lock-string-face' has been set to.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
279 (if font-latex-is-XEmacs
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
280 ;; Cool patch from Christoph Wedler...
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
281 (let (instance)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
282 (mapcar (function
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
283 (lambda (property)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
284 (setq instance
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
285 (face-property-instance 'font-latex-math-face property
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
286 nil 0 t))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
287 (if (numberp instance)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
288 (setq instance
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
289 (face-property-instance 'default property nil 0)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
290 (or (numberp instance)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
291 (set-face-property 'font-lock-string-face property
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
292 instance (current-buffer)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
293 (built-in-face-specifiers)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
294 (font-lock-make-faces)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
295 (make-local-variable 'font-lock-string-face)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
296 (setq font-lock-string-face font-latex-math-face
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
297 font-latex-string-face (default-value 'font-lock-string-face))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
298 ;; Tell Font Lock about the support.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
299 (make-local-variable 'font-lock-defaults)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
300 ;; Parentheses () are disabled because they should not delimit fontification
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
301 ;; in LaTeX text.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
302 (setq font-lock-defaults
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
303 '((font-latex-keywords font-latex-keywords-1 font-latex-keywords-2)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
304 nil nil ((?\( . ".") (?\) . ".") (?$ . "\"")) nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
305 (font-lock-comment-start-regexp . "%")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
306 (font-lock-mark-block-function . mark-paragraph)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
307
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
308 (when font-latex-is-XEmacs
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
309 (put 'latex-mode 'font-lock-defaults
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
310 '((font-latex-keywords font-latex-keywords-1 font-latex-keywords-2)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
311 nil nil ((?\( . ".") (?\) . ".") (?$ . "\"")) nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
312 (font-lock-comment-start-regexp . "%")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
313 (font-lock-mark-block-function . mark-paragraph)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
314 (put 'latex-tex-mode 'font-lock-defaults 'latex-mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
315 (put 'LaTex-tex-mode 'font-lock-defaults 'latex-mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
316 (put 'LaTeX-mode 'font-lock-defaults 'latex-mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
317 (put 'japanese-LaTeX-mode 'font-lock-defaults 'latex-mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
318 (put 'LATeX-MoDe 'font-lock-defaults 'latex-mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
319 (put 'lATEx-mODe 'font-lock-defaults 'latex-mode))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
320
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
321 (defconst font-latex-keywords-1
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
322 (list
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
323 ;; FIXME: Maybe I should put this in a function, use override but let
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
324 ;; the function determine if commented-out.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
325 (list (concat "\\\\\\(\\(no\\)?pagebreak\\|\\(new\\|clear\\(double\\)?\\)"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
326 "page\\|enlargethispage\\|\\(no\\)?linebreak\\|newline\\|"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
327 "-\\|\\\\\\(\*\\)?\\|displaybreak\\|allowdisplaybreaks\\)")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
328 '(0 font-latex-warning-face))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
329 '("\\$\\$\\([^$]+\\)\\$\\$" 1 font-latex-math-face) ;;; $$...$$
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
330 '(font-latex-match-quotation . font-latex-string-face) ;;; ``...''
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
331 '(font-latex-match-font-outside-braces ;;;\textit{text}
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
332 (0 font-lock-keyword-face
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
333 append ;Override? [t 'keep 'prepend 'append]
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
334 ;; Can't use prepend because that overwrites syntax fontification
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
335 ;; e.g. comments.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
336 t) ;Laxmatch? if t, do not signal error
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
337 (1 font-latex-italic-face append t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
338 (2 font-latex-bold-face append t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
339 (3 font-lock-type-face append t))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
340 '(font-latex-match-font-inside-braces ;;;{\it text}
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
341 (0 font-lock-keyword-face append t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
342 (1 font-latex-italic-face append t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
343 (2 font-latex-bold-face append t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
344 (3 font-lock-type-face append t)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
345 "Subdued level highlighting for LaTeX modes.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
346
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
347 (defconst font-latex-keywords-2
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
348 (append font-latex-keywords-1
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
349 '((font-latex-match-reference ;;;\cite
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
350 (0 font-lock-keyword-face append t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
351 (1 font-lock-variable-name-face append t) ;;; [opt]
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
352 (2 font-lock-reference-face append t)) ;;; {key}
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
353 (font-latex-match-function ;;;\section
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
354 (0 font-lock-keyword-face append t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
355 (1 font-lock-variable-name-face append t) ;;; [opt]
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
356 (2 font-lock-function-name-face append t)) ;;; {text}
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
357 (font-latex-match-variable
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
358 (0 font-lock-keyword-face nil t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
359 (1 font-lock-variable-name-face nil t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
360 (2 font-lock-variable-name-face nil t))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
361 (font-latex-match-math-env
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
362 (0 font-latex-math-face append t)) ;;;\(...\)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
363 (font-latex-match-math-envII ;;;Math environ.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
364 (0 font-latex-math-face append t))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
365 ("\\\\[@A-Za-z]+" ;;;Other commands
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
366 (0 font-latex-sedate-face append))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
367 "High level highlighting for LaTeX modes.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
368
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
369 (defvar font-latex-keywords font-latex-keywords-1
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
370 "Default expressions to highlight in TeX mode.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
371
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
372
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
373 (defun font-latex-match-reference (limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
374 (font-latex-match-command-outside-arguments
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
375 (eval-when-compile
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
376 (concat "\\\\" "\\("
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
377 (mapconcat 'identity
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
378 '("[A-Za-z]*cite[A-Za-z]*" "label" "\\(page\\|v\\|eq\\)?ref"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
379 "index" "glossary" "\\(footnote\\(mark\\|text\\)?\\)")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
380 "\\|")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
381 "\\)\\>"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
382 limit nil nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
383
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
384 (defun font-latex-match-function (limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
385 "Fontify things like \\section{text}"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
386 (font-latex-match-command-outside-arguments
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
387 (eval-when-compile
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
388 (concat "\\\\" "\\("
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
389 (mapconcat 'identity
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
390 ;; \\*? doesn't work with \\> at the end of the regexp.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
391 ;; Instead, allow `*' for all commands (!)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
392 '("item" ;;;FIXME: does not have an {arg} so should treated elsewhere.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
393 "include" "input" "bibliography"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
394 "part" "chapter" "\\(sub\\)*section" "\\(sub\\)*paragraph"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
395 "begin" "end"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
396 "title" "author" "date" "thanks" "address"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
397 "pagenumbering"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
398 "\\(this\\)?pagestyle"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
399 "nofiles" "includeonly"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
400 "bibliographystyle" "\\(document\\(style\\|class\\)\\)"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
401 "\\(re\\)?new\\(environment\\|command\\|length\\|theorem\\|counter\\)"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
402 "usepackage" "caption" "\\(f\\|m\\|s\\)box" "\\(v\\|h\\)space")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
403 "\\|")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
404 "\\)\\>"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
405 limit nil t))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
406
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
407 (defun font-latex-match-variable (limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
408 "Fontify things like \\newcommand{stuff}"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
409 (font-latex-match-command-outside-arguments
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
410 (eval-when-compile
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
411 (concat "\\\\" "\\("
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
412 "set\\(length\\|towidth\\|counter\\)\\|"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
413 "addto\\(length\\|counter\\)"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
414 "\\)\\>"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
415 limit t nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
416
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
417
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
418 ;; FIXME: --About font-latex-commented-outp--
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
419 ;; Fontification is *slower* for affected functions (in particular
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
420 ;; font-latex-match-function), so it will be worth it to increase
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
421 ;; performance in the algorithm.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
422 ;; - don't return (store-match-data (list nil nil)) in
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
423 ;; font-latex-match-command-outside-arguments, instead skip over
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
424 ;; commented-out parts internally.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
425 ;; - Perhaps handling outlined code is excessive and slows down the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
426 ;; search too much?
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
427 ;; - Is save-match-data expensive? The calling function could store
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
428 ;; the match-data before it calls (font-latex-commented-outp) knowing
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
429 ;; that is would trash the list.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
430 (defun font-latex-commented-outp ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
431 "Return t is comment character is found between bol and point."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
432 (save-excursion
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
433 (let ((limit (point)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
434 (save-match-data
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
435 ;; Handle outlined code
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
436 (re-search-backward "^\\|\C-m" (point-min) t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
437 (if (re-search-forward "^%\\|[^\\]%" limit t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
438 t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
439 nil)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
440
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
441 (defvar font-latex-match-command-cache-state nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
442 "Cache state of unterminated match to fontify")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
443 (defvar font-latex-match-command-cache-start nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
444 "Cache start of unterminated match to fontify")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
445 (defvar font-latex-match-command-cache-limit nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
446 "Cache end of unterminated match to fontify")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
447 (defvar font-latex-match-command-cache-keywords nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
448 "Cache keywords of unterminated match to fontify")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
449 (make-variable-buffer-local 'font-latex-match-command-cache-state)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
450 (make-variable-buffer-local 'font-latex-match-command-cache-start)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
451 (make-variable-buffer-local 'font-latex-match-command-cache-limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
452 (make-variable-buffer-local 'font-latex-match-command-cache-keywords)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
453
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
454 ;; FIXME - Note to myself
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
455 ;; In call to font-latex-match-command-outside-arguments, I could arrange
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
456 ;; such that keywords which cannot use [options] have this set to nil.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
457 ;; LaTeX code woulldn't fontify if options are used illegally in commands,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
458 ;; cuing users in that they are doing something wrong. (See RCS V1.11 for
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
459 ;; useopt option)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
460 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
461 ;; NOTE - Without an override flag, font-lock does not re-fontify the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
462 ;; option `opt' when the `t' is typed-in in "\cite[opt". The first `o'
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
463 ;; was fontified and now has a face, which font-lock-apply-highlight
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
464 ;; won't override. The `p' and `t' get a face as they are typed by
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
465 ;; inheriting from left-stickyness on the `o'.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
466 ;; THEREFORE, I cannot rely on font-lock-apply-highlight to continue
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
467 ;; multi-line incomplete patterns, because the first character of the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
468 ;; pattern on the first line has a face. I must use `prepend'.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
469 (defun font-latex-match-command-outside-arguments (keywords limit twoargs
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
470 asterix)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
471 "Search for regexp command KEYWORDS[opt]{arg} before LIMIT.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
472 If TWOARG is t, allow two arguments {arg1}{arg2}
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
473 If ASTERIX is t, fontify trailing asterix in command.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
474 Sets `match-data' so that:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
475 subexpression 0 is the keyword,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
476 subexpression 1 is the contents of any following [...] forms
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
477 subexpression 2 is the contents of any following {...} forms.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
478 Returns nil if none of KEYWORDS is found."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
479 ;; Prior incomplete match?
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
480 (if font-latex-match-command-cache-state
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
481 (setq font-latex-match-command-cache-state nil) ;Stop now!
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
482 (when (and font-latex-match-command-cache-keywords
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
483 (equal font-latex-match-command-cache-keywords keywords)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
484 (>= font-latex-match-command-cache-limit (point))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
485 (< font-latex-match-command-cache-start (point)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
486 (goto-char font-latex-match-command-cache-start)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
487 (setq font-latex-match-command-cache-state 'stop)) ;Can only do once
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
488 (when (re-search-forward keywords limit t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
489 (let ((this-start (match-beginning 0)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
490 (cond
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
491 ((font-latex-commented-outp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
492 ;; Return a nul match such that we skip over this pattern.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
493 ;; (Would be better to skip over internally to this function)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
494 (store-match-data (list nil nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
495 t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
496 (t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
497 (let ((kbeg (match-beginning 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
498 (kend (+ (match-end 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
499 (if (and asterix (eq (following-char) ?\*)) 1 0)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
500 sbeg send cbeg cend)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
501 (goto-char kend) ;May be moved by asterix
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
502 (while (eq (following-char) ?\[)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
503 (save-restriction
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
504 ;; Restrict to LIMIT.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
505 (narrow-to-region (point-min) limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
506 (setq sbeg (1+ kend))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
507 (if (condition-case nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
508 (goto-char (or (scan-sexps (point) 1) (point-max)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
509 (error))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
510 (setq send (1- (point)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
511 (setq send (point-max))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
512 (goto-char send)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
513 (setq font-latex-match-command-cache-state 'stop))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
514 (when (eq (following-char) ?\{)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
515 (save-restriction
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
516 ;; Restrict to LIMIT.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
517 (narrow-to-region (point-min) limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
518 (setq cbeg (1+ (point)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
519 (if (condition-case nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
520 (goto-char (or (scan-sexps (point) 1) (point-max)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
521 (error))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
522 (setq cend (1- (point)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
523 (setq cend (point-max))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
524 (goto-char cend)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
525 (setq font-latex-match-command-cache-state 'stop))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
526 (when (and twoargs (eq (following-char) ?\{))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
527 (save-restriction
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
528 ;; Restrict to LIMIT.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
529 (narrow-to-region (point-min) limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
530 (if (condition-case nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
531 (goto-char (or (scan-sexps (point) 1) (point-max)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
532 (error))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
533 (setq cend (1- (point)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
534 (setq cend (point-max))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
535 (goto-char cend)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
536 (setq font-latex-match-command-cache-state 'stop))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
537 (store-match-data (list kbeg kend sbeg send cbeg cend))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
538 (when font-latex-match-command-cache-state
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
539 (setq font-latex-match-command-cache-start this-start)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
540 (setq font-latex-match-command-cache-limit (point))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
541 (setq font-latex-match-command-cache-keywords keywords))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
542 t)))))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
543
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
544 (defvar font-latex-match-font-cache-state nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
545 "Cache state of unterminated match to fontify")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
546 (defvar font-latex-match-font-cache-start nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
547 "Cache start of unterminated match to fontify")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
548 (defvar font-latex-match-font-cache-limit nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
549 "Cache end of unterminated match to fontify")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
550 (defvar font-latex-match-font-cache-keywords nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
551 "Cache keywords of unterminated match to fontify")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
552 (make-variable-buffer-local 'font-latex-match-font-cache-state)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
553 (make-variable-buffer-local 'font-latex-match-font-cache-start)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
554 (make-variable-buffer-local 'font-latex-match-font-cache-limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
555 (make-variable-buffer-local 'font-latex-match-font-cache-keywords)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
556
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
557 (defun font-latex-match-font-outside-braces (limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
558 "Search for font-changing command like \textbf{fubar} before LIMIT.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
559 Sets `match-data' so that:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
560 subexpression 0 is the keyword,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
561 subexpression 1 is the content to fontify in italic.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
562 subexpression 2 is the content to fontify in bold.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
563 subexpression 3 is the content to fontify in type-face.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
564 Returns nil if no font-changing command is found."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
565 (if font-latex-match-font-cache-state
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
566 (setq font-latex-match-font-cache-state nil) ;Stop now!
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
567 (when (and font-latex-match-font-cache-keywords
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
568 (equal font-latex-match-font-cache-keywords keywords)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
569 (>= font-latex-match-font-cache-limit (point))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
570 (< font-latex-match-font-cache-start (point)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
571 (goto-char font-latex-match-font-cache-start)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
572 (setq font-latex-match-font-cache-state 'stop)) ;Can only do once
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
573 (when (re-search-forward
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
574 (eval-when-compile
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
575 (concat "\\\\" "\\("
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
576 "\\(emph\\)\\|" ;;; 2 - italic
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
577 "\\(text\\("
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
578 "\\(it\\|sl\\)\\|" ;;; 5 - italic
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
579 "\\(md\\|rm\\|sf\\|tt\\)\\|" ;;; 6 - type
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
580 "\\(bf\\|sc\\|up\\)" ;;; 7 - bold
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
581 "\\)\\)\\|"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
582 "\\(boldsymbol\\|pmb\\)" ;;; 8 - bold
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
583 "\\)" "{"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
584 limit t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
585 (cond
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
586 ((font-latex-commented-outp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
587 ;; Return a nul match such that we skip over this pattern.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
588 ;; (Would be better to skip over internally to this function)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
589 ;; Using `prepend' won't help here, because the problem is that
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
590 ;; scan-sexp *fails* to find a commented-out matching bracket!
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
591 (store-match-data (list nil nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
592 t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
593 (t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
594 (let ((kbeg (match-beginning 0)) (kend (match-end 1))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
595 (beg (match-end 0)) end itbeg itend bfbeg bfend ttbeg ttend)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
596 (goto-char kend)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
597 (save-restriction
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
598 ;; Restrict to LIMIT.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
599 (narrow-to-region (point-min) limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
600 (if (condition-case nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
601 (goto-char (or (scan-sexps (point) 1) (point-max)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
602 (error))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
603 (setq end (1- (point)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
604 (setq end (point-max))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
605 (goto-char end)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
606 (setq font-latex-match-font-cache-state 'stop)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
607 (cond ((or (match-beginning 2) (match-beginning 5))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
608 (setq itbeg beg
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
609 itend end))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
610 ((match-beginning 6)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
611 (setq ttbeg beg
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
612 ttend end))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
613 (t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
614 (setq bfbeg beg
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
615 bfend end)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
616 (store-match-data
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
617 (list kbeg kend itbeg itend bfbeg bfend ttbeg ttend))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
618 (when font-latex-match-font-cache-state
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
619 (setq font-latex-match-font-cache-start kbeg)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
620 (setq font-latex-match-font-cache-limit (point))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
621 (setq font-latex-match-font-cache-keywords keywords))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
622 ;; Start the subsequent search immediately after this keyword.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
623 (goto-char kend)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
624 t))))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
625
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
626 (defvar font-latex-match-infont-cache-state nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
627 "Cache state of unterminated match to fontify")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
628 (defvar font-latex-match-infont-cache-start nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
629 "Cache start of unterminated match to fontify")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
630 (defvar font-latex-match-infont-cache-limit nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
631 "Cache end of unterminated match to fontify")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
632 (defvar font-latex-match-infont-cache-keywords nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
633 "Cache keywords of unterminated match to fontify")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
634 (make-variable-buffer-local 'font-latex-match-infont-cache-state)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
635 (make-variable-buffer-local 'font-latex-match-infont-cache-start)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
636 (make-variable-buffer-local 'font-latex-match-infont-cache-limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
637 (make-variable-buffer-local 'font-latex-match-infont-cache-keywords)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
638
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
639 (defun font-latex-match-font-inside-braces (limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
640 "Search for font-changing command like {\bf fubar} before LIMIT.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
641 Sets `match-data' so that:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
642 subexpression 0 is the keyword.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
643 subexpression 1 is the content to fontify in italic.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
644 subexpression 2 is the content to fontify in bold.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
645 subexpression 3 is the content to fontify in type-face.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
646 Returns nil if no font-changing command is found."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
647 (if font-latex-match-infont-cache-state
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
648 (setq font-latex-match-infont-cache-state nil) ;Stop now!
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
649 (when (and font-latex-match-infont-cache-keywords
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
650 (equal font-latex-match-infont-cache-keywords keywords)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
651 (>= font-latex-match-infont-cache-limit (point))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
652 (< font-latex-match-infont-cache-start (point)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
653 (goto-char font-latex-match-infont-cache-start)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
654 (setq font-latex-match-infont-cache-state 'stop)) ;Can only do once
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
655 (when (re-search-forward
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
656 (eval-when-compile
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
657 (concat "\\\\" "\\("
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
658 ;;; 2 - italic
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
659 "\\(em\\|it\\(shape\\)?\\|sl\\(shape\\)?\\)\\|"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
660 ;;; 5 - bold
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
661 "\\(bf\\(series\\)?\\|upshape\\|sc\\(shape\\)?\\)\\|"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
662 "mdseries\\|tt\\(family\\)?\\|"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
663 "sf\\(family\\)?\\|rm\\(family\\)?\\|"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
664 "tiny\\|scriptsize\\|footnotesize\\|"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
665 "small\\|normalsize\\|large\\|Large\\|LARGE\\|huge\\|Huge"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
666 "\\)\\>[ \t]*"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
667 limit t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
668 (cond
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
669 ((font-latex-commented-outp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
670 ;; Return a nul match such that we skip over this pattern.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
671 ;; (Would be better to skip over internally to this function)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
672 ;; Using `prepend' won't help here, because the problem is that
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
673 ;; scan-sexp *fails* to find a commented-out matching bracket!
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
674 (store-match-data (list nil nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
675 t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
676 (t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
677 (let ((kbeg (match-beginning 0)) (kend (match-end 1))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
678 (beg (match-end 0)) end itbeg itend bfbeg bfend ttbeg ttend)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
679 (goto-char (match-beginning 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
680 (cond
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
681 ((not (eq (preceding-char) ?\{))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
682 ;; Fontify only the keyword as bf/it/type (no argument found).
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
683 (cond ((match-beginning 2) (setq itbeg kbeg itend kend))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
684 ((match-beginning 5) (setq bfbeg kbeg bfend kend))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
685 (t (setq ttbeg kbeg ttend kend)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
686 (goto-char (match-end 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
687 (store-match-data
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
688 (list nil nil itbeg itend bfbeg bfend ttbeg ttend))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
689 t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
690 (t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
691 (condition-case nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
692 (forward-char -1)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
693 (error))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
694 (save-restriction
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
695 ;; Restrict to LIMIT.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
696 (narrow-to-region (point-min) limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
697 (if (condition-case nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
698 (goto-char (or (scan-sexps (point) 1) (point-max)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
699 (error))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
700 (setq end (1- (point)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
701 (setq end (point-max))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
702 (goto-char end)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
703 (setq font-latex-match-infont-cache-state 'stop)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
704 (cond ((match-beginning 2) (setq itbeg beg itend end))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
705 ((match-beginning 5) (setq bfbeg beg bfend end))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
706 (t (setq ttbeg beg ttend end)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
707 (store-match-data
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
708 (list kbeg kend itbeg itend bfbeg bfend ttbeg ttend))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
709 (when font-latex-match-infont-cache-state
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
710 (setq font-latex-match-infont-cache-start kbeg)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
711 (setq font-latex-match-infont-cache-limit (point))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
712 (setq font-latex-match-infont-cache-keywords keywords))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
713 ;; Start the subsequent search immediately after this keyword.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
714 (goto-char kend)))))))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
715
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
716 ;;; FIXME: Add caches for math-env, math-envII and quotations.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
717 (defun font-latex-match-math-env (limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
718 "Used for patterns like:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
719 \\( F = ma \\)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
720 \\ [ F = ma \\] but not \\\\ [len]"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
721 (when (re-search-forward "\\(\\\\(\\)\\|\\(\\\\\\[\\)" limit t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
722 (goto-char (match-beginning 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
723 (if (eq (preceding-char) ?\\) ; \\[ is not a math environment
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
724 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
725 (goto-char (match-end 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
726 (store-match-data (list nil nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
727 t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
728 (let ((b1start (point)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
729 (search-forward (cond ((match-beginning 1) "\\)")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
730 (t "\\]"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
731 limit 'move)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
732 (let ((b2end (or (match-end 0) (point))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
733 (store-match-data (list b1start b2end))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
734 t)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
735
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
736 (defun font-latex-match-math-envII (limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
737 "Used for patterns like:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
738 \\begin{equation}
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
739 fontified stuff
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
740 \\end{equation}
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
741 The \\begin{equation} and \\end{equation are not fontified here."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
742 (when (re-search-forward
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
743 (eval-when-compile
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
744 (concat "\\\\begin{\\(\\(display\\)?math\\|equation\\|eqnarray"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
745 "\\|gather\\|multline\\|align\\|x*alignat"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
746 "\\)\\*?}"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
747 limit t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
748 (let ((beg (match-end 0)) end)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
749 (if (search-forward (concat "\\end{" (buffer-substring
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
750 (match-beginning 1)(match-end 0)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
751 limit 'move)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
752 (setq end (match-beginning 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
753 (setq end (point)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
754 (store-match-data (list beg end))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
755 t)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
756
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
757 (defun font-latex-match-quotation (limit)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
758 "Used for patterns like:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
759 ``this is a normal quote'' and these are multilingual quoted strings:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
760 \"< french \"> and \"`german\"' quotes, << french >> and 8-bit french."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
761 (when (re-search-forward
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
762 (eval-when-compile
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
763 (concat "\\(``\\)\\|\\(\"<\\)\\|\\(\"`\\)\\|\\(<<\\)\\|"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
764 "\\(" (char-to-string 171) "\\)")) ; An 8-bit "<<"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
765 limit t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
766 (let ((beg (match-beginning 0)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
767 (search-forward
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
768 (cond ((match-beginning 1) "''")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
769 ((match-beginning 2) "\">")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
770 ((match-beginning 3) "\"'")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
771 ((match-beginning 4) ">>")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
772 ((match-beginning 5) (eval-when-compile (char-to-string 187))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
773 limit 'move)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
774 (store-match-data (list beg (point)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
775 t)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
776
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
777 ;; Install ourselves
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
778
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
779 (add-hook 'LaTeX-mode-hook 'font-latex-setup)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
780 (add-hook 'latex-mode-hook 'font-latex-setup)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
781 ;; If font-latex is loaded using a latex-mode-hook, then the add-hook above
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
782 ;; won't be called this time around. Check for this now:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
783 (if (eq major-mode 'latex-mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
784 (font-latex-setup))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
785
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
786 ;; Provide ourselves:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
787
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
788 (provide 'font-latex)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
789
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
790 ;;; font-latex.el ends here