home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / packages / font-lock.el < prev    next >
Encoding:
Text File  |  1995-08-31  |  55.2 KB  |  1,354 lines

  1. ;;; font-lock.el --- decorating source files with fonts/colors based on syntax
  2. ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
  3. ;; Copyright (C) 1995 Amdahl Corporation.
  4.  
  5. ;; Author: Jamie Zawinski <jwz@lucid.com>, for the LISPM Preservation Society.
  6. ;; Modified by: Ben Wing <wing@spg.amdahl.com>
  7. ;;    made configuration easier, added some code to delay fontification
  8. ;;    of adjacent pieces of inserted text until the post-command-hook
  9. ;;    is called
  10. ;; Keywords: languages, faces
  11.  
  12. ;; This file is part of XEmacs.
  13.  
  14. ;; XEmacs is free software; you can redistribute it and/or modify it
  15. ;; under the terms of the GNU General Public License as published by
  16. ;; the Free Software Foundation; either version 2, or (at your option)
  17. ;; any later version.
  18.  
  19. ;; XEmacs is distributed in the hope that it will be useful, but
  20. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  21. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  22. ;; General Public License for more details.
  23.  
  24. ;; You should have received a copy of the GNU General Public License
  25. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  26. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  27.  
  28. ;;; Synched up with: Not synched with FSF.
  29.  
  30. ;;; Commentary:
  31.  
  32. ;; Font-lock-mode is a minor mode that causes your comments to be
  33. ;; displayed in one face, strings in another, reserved words in another,
  34. ;; documentation strings in another, and so on.
  35. ;;
  36. ;; Comments will be displayed in `font-lock-comment-face'.
  37. ;; Strings will be displayed in `font-lock-string-face'.
  38. ;; Doc strings will be displayed in `font-lock-doc-string-face'.
  39. ;; Function and variable names (in their defining forms) will be
  40. ;;  displayed in `font-lock-function-name-face'.
  41. ;; Reserved words will be displayed in `font-lock-keyword-face'.
  42. ;;
  43. ;; Don't let the name fool you: you can highlight things using different
  44. ;; colors or background stipples instead of fonts, though that is not the
  45. ;; default.  See the variables `font-lock-use-colors' and
  46. ;; `font-lock-use-fonts' for broad control over this, or see the
  47. ;; documentation on faces and how to change their attributes for
  48. ;; fine-grained control.
  49. ;;
  50. ;; To make the text you type be fontified, use M-x font-lock-mode.  When
  51. ;; this minor mode is on, the fonts of the current line will be updated
  52. ;; with every insertion or deletion.
  53. ;;
  54. ;; By default, font-lock will automatically put newly loaded files
  55. ;; into font-lock-mode if it knows about the file's mode.  See the
  56. ;; variables `font-lock-auto-fontify', `font-lock-mode-enable-list',
  57. ;; and `font-lock-mode-disable-list' for control over this.
  58. ;;
  59. ;; The `font-lock-keywords' variable defines other patterns to highlight.
  60. ;; The default font-lock-mode-hook sets it to the value of the variables
  61. ;; lisp-font-lock-keywords, c-font-lock-keywords, etc, as appropriate.
  62. ;; The easiest way to change the highlighting patterns is to change the
  63. ;; values of c-font-lock-keywords and related variables.  See the doc
  64. ;; string of the variable `font-lock-keywords' for the appropriate syntax.
  65. ;;
  66. ;; The default value for `lisp-font-lock-keywords' is the value of the variable
  67. ;; `lisp-font-lock-keywords-1'.  You may like `lisp-font-lock-keywords-2' 
  68. ;; better; it highlights many more words, but is slower and makes your buffers
  69. ;; be very visually noisy.
  70. ;;
  71. ;; The same is true of `c-font-lock-keywords-1' and `c-font-lock-keywords-2';
  72. ;; the former is subdued, the latter is loud.
  73. ;;
  74. ;; You can make font-lock default to the gaudier variety of keyword
  75. ;; highlighting by setting the variable `font-lock-use-maximal-decoration'
  76. ;; before loading font-lock, or by calling the functions
  77. ;; `font-lock-use-default-maximal-decoration' or
  78. ;; `font-lock-use-default-minimal-decoration'.
  79. ;;
  80. ;; On a Sparc10, the initial fontification takes about 6 seconds for a typical
  81. ;; 140k file of C code, using the default configuration.  The actual speed
  82. ;; depends heavily on the type of code in the file, and how many non-syntactic
  83. ;; patterns match; for example, Xlib.h takes 23 seconds for 101k, because many
  84. ;; patterns match in it.  You can speed this up substantially by removing some
  85. ;; of the patterns that are highlighted by default.  Fontifying lisp code is
  86. ;; significantly faster, because lisp has a more regular syntax than C, so the
  87. ;; regular expressions don't have to be as complicated.
  88. ;;
  89. ;; It's called font-lock-mode here because on the Lispms it was called
  90. ;; "Electric Font Lock Mode."  It was called that because there was an older
  91. ;; mode called "Electric Caps Lock Mode" which had the function of causing all
  92. ;; of your source code to be in upper case except for strings and comments,
  93. ;; without you having to blip the caps lock key by hand all the time (thus the
  94. ;; "electric", as in `electric-c-brace'.)
  95.  
  96. ;; See also the related packages `fast-lock' and `lazy-lock'.  Both
  97. ;; attempt to speed up the initial fontification.  `fast-lock' saves
  98. ;; the fontification info when you exit Emacs and reloads it next time
  99. ;; you load the file, so that the file doesn't have to be fontified
  100. ;; again.  `lazy-lock' does "lazy" fontification -- i.e. it only
  101. ;; fontifies the text as it becomes visible rather than fontifying
  102. ;; the whole file when it's first loaded in.
  103.  
  104. ;;; Code:
  105.  
  106. (require 'text-props)
  107.  
  108. ;;;;;;;;;;;;;;;;;;;;;;      user variables       ;;;;;;;;;;;;;;;;;;;;;;
  109.  
  110. ;;;###autoload
  111. (make-variable-buffer-local 'font-lock-keywords)
  112. ;;;###autoload
  113. (defvar font-lock-keywords nil
  114.   "*The keywords to highlight.
  115. If this is a list, then elements may be of the forms:
  116.  
  117.   \"string\"              ; a regexp to highlight in the 
  118.                   ;  `font-lock-keyword-face'.
  119.   (\"string\" . integer)        ; match N of the regexp will be highlighted
  120.   (\"string\" . face-name)      ; use the named face
  121.   (\"string\" integer face-name)    ; both of the above
  122.   (\"string\" integer face-name t)  ; this allows highlighting to overlap
  123.                   ;  with already-highlighted regions.
  124.  
  125. These regular expressions should not match text which spans lines.  Multi-line
  126. patterns will be correctly fontified when \\[font-lock-fontify-buffer] is used,
  127. but will not be matched by the auto-fontification that font-lock-mode does,
  128. since it looks at only one line at a time.
  129.  
  130. Be careful composing regexps for this list; the wrong pattern can dramatically
  131. slow things down!")
  132.  
  133. (defvar font-lock-keywords-case-fold-search nil
  134.   "*Whether the strings in `font-lock-keywords' should be case-folded.
  135. This variable is automatically buffer-local, as the correct value depends
  136. on the language in use.")
  137. (make-variable-buffer-local 'font-lock-keywords-case-fold-search)
  138.  
  139. (defvar font-lock-verbose t
  140.   "*Whether `font-lock-fontify-buffer' should print status messages.
  141. See also `font-lock-message-threshold'.")
  142.  
  143. (defvar font-lock-message-threshold 6000
  144.   "*Minimum size of region being fontified for status messages to appear.
  145.  
  146. The size is measured in characters.  This affects `font-lock-fontify-region'
  147. but not `font-lock-fontify-buffer'. (In other words, when you first visit
  148. a file and it gets fontified, you will see status messages no matter what
  149. size the file is.  However, if you do something else like paste a
  150. chunk of text or revert a buffer, you will see status messages only if the
  151. changed region is large enough.)
  152.  
  153. Note that setting `font-lock-verbose' to nil disables the status
  154. messages entirely.")
  155.  
  156. (defvar font-lock-mode-hook nil
  157.   "Function or functions to run on entry to font-lock-mode.")
  158.  
  159. (defvar font-lock-after-fontify-buffer-hook nil
  160.   "Function or functions to run after completion of font-lock-fontify-buffer.")
  161.  
  162. (defvar font-lock-use-syntax-tables t
  163.   "Whether font-lock should bother doing syntactic fontification.
  164. This should be true for all ``language'' modes, but other modes, like
  165. dired, do not have anything useful in the syntax tables (no comment
  166. or string delimiters, etc) and so there is no need to use them.
  167. You should not set this variable; its value is automatically computed
  168. by examining the syntax table.")
  169.  
  170. ;;;###autoload
  171. (defvar font-lock-auto-fontify t
  172.   "*Whether font-lock should automatically fontify files as they're loaded.
  173. This will only happen if font-lock has fontifying keywords for the major
  174. mode of the file.  You can get finer-grained control over auto-fontification
  175. by using this variable in combination with `font-lock-mode-enable-list' or
  176. `font-lock-mode-disable-list'.")
  177.  
  178. ;;;###autoload
  179. (defvar font-lock-mode-enable-list nil
  180.   "*List of modes to auto-fontify, if `font-lock-auto-fontify' is nil.")
  181.  
  182. ;;;###autoload
  183. (defvar font-lock-mode-disable-list nil
  184.   "*List of modes not to auto-fontify, if `font-lock-auto-fontify' is t.")
  185.  
  186. ;;;###autoload
  187. (defvar font-lock-use-colors nil
  188.   "*If true, font-lock will by default use colors to fontify text.
  189. Set this *before* loading font-lock (e.g. in your init file).  You can
  190. also explicitly reset the font-lock faces to these colors at any time by
  191. calling the function `font-lock-use-default-colors'.
  192.  
  193. See also `font-lock-use-fonts'.  If you want more control over the faces
  194. used for fontification, see the documentation of `font-lock-mode' for
  195. how to do it.  In such a case, you might want to consider setting both
  196. `font-lock-use-colors' and `font-lock-use-fonts' to nil to prevent
  197. font-lock from initializing the faces.")
  198.  
  199. ;;;###autoload
  200. (defvar font-lock-use-fonts t
  201.   "*If true, font-lock will by default use different fonts to fontify text.
  202. Set this *before* loading font-lock (e.g. in your init file).  You can
  203. also explicitly reset the font-lock faces to these fonts at any time by
  204. calling the function `font-lock-use-default-fonts'.
  205.  
  206. See also `font-lock-use-colors'.  If you want more control over the faces
  207. used for fontification, see the documentation of `font-lock-mode' for
  208. how to do it.  In such a case, you might want to consider setting both
  209. `font-lock-use-colors' and `font-lock-use-fonts' to nil to prevent
  210. font-lock from initializing the faces.")
  211.  
  212. ;;;###autoload
  213. (defvar font-lock-use-maximal-decoration nil
  214.   "*If true, font-lock will use a larger set of decorations than normal.
  215. Set this *before* loading font-lock (e.g. in your init file).  This
  216. typically results in keywords being fontified as well as comments
  217. and strings and such; however, fontification will take longer.  If you
  218. want to change this when font-lock is already loaded, use the functions
  219. `font-lock-use-default-minimal-decoration' or
  220. `font-lock-use-default-maximal-decoration'.")
  221.  
  222.  
  223. ;;;;;;;;;;;;;;;;;;;;;;        actual code        ;;;;;;;;;;;;;;;;;;;;;;
  224.  
  225. ;;; To fontify the whole buffer by language syntax, we go through it a
  226. ;;; character at a time, creating extents on the boundary of each syntactic
  227. ;;; unit (that is, one extent for each block comment, one for each line
  228. ;;; comment, one for each string, etc.)  This is done with the C function
  229. ;;; syntactically-sectionize.  It's in C for speed (the speed of lisp function
  230. ;;; calls was a real bottleneck for this task since it involves examining each
  231. ;;; character in turn.)
  232. ;;;
  233. ;;; Then we make a second pass, to fontify the buffer based on other patterns
  234. ;;; specified by regexp.  When we find a match for a region of text, we need
  235. ;;; to change the fonts on those characters.  This is done with the
  236. ;;; put-text-property function, which knows how to efficiently share extents.
  237. ;;; Conceptually, we are attaching some particular face to each of the
  238. ;;; characters in a range, but the implementation of this involves creating
  239. ;;; extents, or resizing existing ones.
  240. ;;;
  241. ;;; Each time a modification happens to a line, we re-fontify the entire line.
  242. ;;; We do this by first removing the extents (text properties) on the line,
  243. ;;; and then doing the syntactic and keyword passes again on that line.  (More
  244. ;;; generally, each modified region is extended to include the preceeding and
  245. ;;; following BOL or EOL.)
  246. ;;;
  247. ;;; This means that, as the user types, we repeatedly go back to the beginning
  248. ;;; of the line, doing more work the longer the line gets.  This doesn't cost
  249. ;;; much in practice, and if we don't, then we incorrectly fontify things when,
  250. ;;; for example, inserting spaces into `intfoo () {}'.
  251. ;;;
  252.  
  253. (defsubst font-lock-set-face (start end face)
  254.   ;; Set the face on the characters in the range.
  255.   (put-nonduplicable-text-property start end 'face face)
  256.   (put-nonduplicable-text-property start end 'font-lock t))
  257.  
  258. (defsubst font-lock-unfontify-region (start end &optional maybe-loudly)
  259.   (if (and maybe-loudly font-lock-verbose
  260.        (>= (- end start) font-lock-message-threshold))
  261.       (message "Fontifying %s..." (buffer-name)))
  262.   ;; Clear all font-lock data on the characters in the range.
  263.   (put-nonduplicable-text-property start end 'face nil)
  264.   (put-nonduplicable-text-property start end 'font-lock nil))
  265.  
  266. (defsubst font-lock-any-extents-p (start end)
  267.   ;; used to look for 'text-prop property, but this has problems
  268.   ;; if you put any other text properties in the vicinity.
  269.   ;; Simon Marshall suggested looking for the 'face property,
  270.   ;; but that's equally bogus.  Only reliable way is for font-lock
  271.   ;; to specially mark its extents.
  272.   (map-extents 'extent-property (current-buffer) start end 'font-lock))
  273.  
  274. (defun font-lock-fontify-region (start end)
  275.   (if (not font-lock-use-syntax-tables)
  276.       nil
  277.     (if (and font-lock-verbose
  278.          (>= (- end start) font-lock-message-threshold))
  279.     (message "Fontifying %s... (syntactically...)" (buffer-name)))
  280.     (goto-char start)
  281.     (if (> end (point-max)) (setq end (point-max)))
  282.     (syntactically-sectionize
  283.       #'(lambda (s e context depth)
  284.       (let (face)
  285.         (cond ((eq context 'string)
  286.            ;;#### Should only do this is Lisp-like modes!
  287.            (setq face
  288.              (if (= depth 1)
  289.                  ;; really we should only use this if
  290.                  ;;  in position 3 depth 1, but that's
  291.                  ;;  too expensive to compute.
  292.                  'font-lock-doc-string-face
  293.                'font-lock-string-face)))
  294.           ((or (eq context 'comment)
  295.                (eq context 'block-comment))
  296.            (setq face 'font-lock-comment-face)
  297. ;         ;; Don't fontify whitespace at the beginning of lines;
  298. ;         ;;  otherwise comment blocks may not line up with code.
  299. ;         ;; (This is sometimes a good idea, sometimes not; in any
  300. ;         ;; event it should be in C for speed --jwz)
  301. ;         (save-excursion
  302. ;             (goto-char s)
  303. ;             (while (prog1 (search-forward "\n" (1- e) 'move)
  304. ;                  (setq face 'font-lock-comment-face)
  305. ;                  (setq e (point)))
  306. ;               (skip-chars-forward " \t\n")
  307. ;               (setq s (point)))
  308.            ))
  309.         (font-lock-set-face s e face)))
  310.       start end)
  311.     ))
  312.  
  313. (defvar font-lock-old-extent nil)
  314. (defvar font-lock-old-len 0)
  315.  
  316. (defun font-lock-fontify-glumped-region ()
  317.   ;; even if something goes wrong in the fontification, mark the glumped
  318.   ;; region as fontified; otherwise, the same error might get signaled
  319.   ;; after every command.
  320.   (unwind-protect
  321.       ;; buffer may be deleted.
  322.       (if (buffer-live-p (extent-buffer font-lock-old-extent))
  323.       (save-excursion
  324.         (set-buffer (extent-buffer font-lock-old-extent))
  325.         (font-lock-after-change-function-1
  326.          (extent-start-position font-lock-old-extent)
  327.          (extent-end-position font-lock-old-extent)
  328.          font-lock-old-len)))
  329.     (detach-extent font-lock-old-extent)
  330.     (setq font-lock-old-extent nil)))
  331.  
  332. (defvar font-lock-executing-command-p nil)
  333.  
  334. (defun font-lock-pre-command-hook ()
  335.   (setq font-lock-executing-command-p t))
  336.   
  337. (defun font-lock-post-command-hook ()
  338.   (setq font-lock-executing-command-p nil)
  339.   (if (and font-lock-old-extent
  340.        (not (input-pending-p)))
  341.       (font-lock-fontify-glumped-region)))
  342.  
  343. ;; Setting this to true disables the attempts that font-lock would otherwise
  344. ;; make to delay after-change fontifying until the post-command-hook is
  345. ;; called.  We set this to true because this stuff doesn't quite work yet.
  346.  
  347. (defvar font-lock-always-fontify-immediately t)
  348.  
  349. ;;; called when any modification is made to buffer text.  This function
  350. ;;; attempts to glump adjacent changes together so that excessive
  351. ;;; fontification is avoided.  This function could easily be adapted
  352. ;;; to other after-change-functions.
  353.  
  354. (defun font-lock-after-change-function (beg end old-len)
  355.   (let ((obeg (and font-lock-old-extent
  356.            (extent-start-position font-lock-old-extent)))
  357.     (oend (and font-lock-old-extent
  358.            (extent-end-position font-lock-old-extent)))
  359.     (bc-end (+ beg old-len)))
  360.  
  361.     ;; If this change can't be merged into the glumped one,
  362.     ;; we need to fontify the glumped one right now.
  363.     (if (and font-lock-old-extent
  364.          (or (not (eq (current-buffer)
  365.               (extent-buffer font-lock-old-extent)))
  366.          (< bc-end obeg)
  367.          (> beg oend)))
  368.     (font-lock-fontify-glumped-region))
  369.   
  370.     (if font-lock-old-extent
  371.     ;; Update glumped region.
  372.     (progn
  373.       ;; Any characters in the before-change region that are
  374.       ;; outside the glumped region go into the glumped
  375.       ;; before-change region.
  376.       (if (> bc-end oend)
  377.           (setq font-lock-old-len (+ font-lock-old-len (- bc-end oend))))
  378.       (if (> obeg beg)
  379.           (setq font-lock-old-len (+ font-lock-old-len (- obeg beg))))
  380.       ;; New glumped region is the union of the glumped region
  381.       ;; and the new region.
  382.       (set-extent-endpoints font-lock-old-extent
  383.                 (min obeg beg)
  384.                 (max oend end)))
  385.  
  386.       ;; No glumped region, so create one.
  387.       (setq font-lock-old-extent (make-extent beg end))
  388.       (set-extent-property font-lock-old-extent 'detachable nil)
  389.       (set-extent-property font-lock-old-extent 'end-open nil)
  390.       (setq font-lock-old-len old-len))
  391.  
  392.     (if (or font-lock-always-fontify-immediately
  393.         (not font-lock-executing-command-p))
  394.     (font-lock-fontify-glumped-region))))
  395.  
  396. (defun font-lock-after-change-function-1 (beg end old-len)
  397.   (if (null font-lock-mode)
  398.       nil
  399.     (save-excursion
  400.       (save-restriction
  401.     ;; if we don't widen, then fill-paragraph (and any command that
  402.     ;; operates on a narrowed region) confuses things, because the C
  403.     ;; code will fail to realize that we're inside a comment.
  404.     (widen)
  405.     (save-match-data
  406.       (let ((zmacs-region-stays zmacs-region-stays)) ; protect from change!
  407.         (goto-char beg)
  408.         ;; Maybe flush the internal cache used by syntactically-sectionize.
  409.         ;; (It'd be nice if this was more automatic.)  Any deletions mean
  410.         ;; the cache is invalid, and insertions at beginning or end of line
  411.         ;; mean that the bol cache might be invalid.
  412. ;;        (if (or (> old-len 0) (bobp) (= (preceding-char) ?\n))
  413. ;;        (buffer-syntactic-context-flush-cache))
  414.  
  415.         ;; Always recompute the whole line.
  416.         (goto-char end)
  417.         (forward-line 1)
  418.         (setq end (point))
  419.         (goto-char beg)
  420.         (beginning-of-line)
  421.         (setq beg (point))
  422.         (font-lock-unfontify-region beg end t)
  423.         (font-lock-fontify-region beg end)
  424.         (font-lock-hack-keywords beg end)))))))
  425.  
  426.  
  427. ;;; Fontifying arbitrary patterns
  428.  
  429. (defun font-lock-hack-keywords (start end)
  430.   (let ((loudly (and font-lock-verbose
  431.              (>= (- end start) font-lock-message-threshold))))
  432.     (if loudly (message "Fontifying %s... (regexps...)" (buffer-name)))
  433.     (goto-char start)
  434.     (let ((case-fold-search font-lock-keywords-case-fold-search)
  435.       (rest font-lock-keywords)
  436.       (count 0)
  437.       first str match face s e allow-overlap-p)
  438.       (while rest
  439.     (setq first (car rest))
  440.     (goto-char start)
  441.     (cond ((consp first)
  442.            (setq str (car first))
  443.            (cond ((consp (cdr first))
  444.               (setq match (nth 1 first)
  445.                 face (nth 2 first)
  446.                 allow-overlap-p (nth 3 first)))
  447.              ((symbolp (cdr first))
  448.               (setq match 0 allow-overlap-p nil
  449.                 face (cdr first)))
  450.              (t
  451.               (setq match (cdr first)
  452.                 allow-overlap-p nil
  453.                 face 'font-lock-keyword-face))))
  454.           (t
  455.            (setq str first
  456.              match 0
  457.              allow-overlap-p nil
  458.              face 'font-lock-keyword-face)))
  459.     (while (re-search-forward str end t)
  460.       (setq s (match-beginning match)
  461.         e (match-end match))
  462.       (goto-char e) ;; tlp00 hack to allow for back to back fonts
  463.       (or s (error "expression did not match subexpression %d" match))
  464.       ;; don't fontify this keyword if we're already in some other context.
  465.       (or (= s e)
  466.           (if allow-overlap-p nil (font-lock-any-extents-p s (1- e)))
  467.           (font-lock-set-face s e face)))
  468.     (if loudly (message "Fontifying %s... (regexps...%s)"
  469.                 (buffer-name)
  470.                 (make-string (setq count (1+ count)) ?.)))
  471.     (setq rest (cdr rest))))
  472.     (if loudly (message "Fontifying %s... done." (buffer-name)))))
  473.  
  474.  
  475. ;; The user level functions
  476.  
  477. ;;;###autoload
  478. (defvar font-lock-mode nil) ; for modeline
  479. (add-minor-mode 'font-lock-mode " FLock" nil)
  480.  
  481. (defvar font-lock-fontified nil) ; whether we have hacked this buffer
  482. (put 'font-lock-fontified 'permanent-local t)
  483.  
  484. ;;;###autoload
  485. (defun font-lock-mode (&optional arg)
  486.   "Toggle Font Lock Mode.
  487. With arg, turn font-lock mode on if and only if arg is positive.
  488. In the font-lock minor mode, text is fontified as you type it:
  489.  
  490.  - comments are displayed in font-lock-comment-face;
  491.  - strings are displayed in font-lock-string-face;
  492.  - documentation strings are displayed in font-lock-doc-string-face;
  493.  - function and variable names in their defining forms are displayed
  494.    in font-lock-function-name-face;
  495.  - and certain other expressions are displayed in other faces
  496.    according to the value of the variable `font-lock-keywords'.
  497.  
  498. When font-lock mode is turned on/off, the buffer is fontified/defontified.
  499. To fontify a buffer without having newly typed text become fontified, you
  500. can use \\[font-lock-fontify-buffer].
  501.  
  502. See the variable `font-lock-keywords' for customization."
  503.   (interactive "P")
  504.   (let ((on-p (if (null arg)
  505.           (not font-lock-mode)
  506.         (> (prefix-numeric-value arg) 0))))
  507.     ;; Font-lock mode will refuse to turn itself on if in batch mode, or if
  508.     ;; the current buffer is "invisible".  The latter is because packages
  509.     ;; sometimes put their temporary buffers into some particular major mode
  510.     ;; to get syntax tables and variables and whatnot, but we don't want the
  511.     ;; fact that the user has font-lock-mode on a mode hook to slow these
  512.     ;; things down.
  513.     (if (or noninteractive (eq (aref (buffer-name) 0) ?\ ))
  514.     (setq on-p nil))
  515.     (cond (on-p
  516.        ;; make it all local so as not to clutter up all the buffers
  517.        (add-hook (make-local-variable 'after-change-functions)
  518.              'font-lock-after-change-function)
  519.        (add-hook 'local-pre-command-hook 'font-lock-pre-command-hook)
  520.        (add-hook 'local-post-command-hook 'font-lock-post-command-hook))
  521.       (t
  522.        (remove-hook 'after-change-functions
  523.             'font-lock-after-change-function)
  524.        (remove-hook 'local-pre-command-hook 'font-lock-pre-command-hook)
  525.        (remove-hook 'local-post-command-hook 'font-lock-post-command-hook)
  526.        ))
  527.     (set (make-local-variable 'font-lock-mode) on-p)
  528.     (cond (on-p
  529.        (font-lock-examine-syntax-table)
  530.        (font-lock-set-defaults)
  531.        (run-hooks 'font-lock-mode-hook)
  532.        (or font-lock-fontified (font-lock-fontify-buffer)))
  533.       (font-lock-fontified
  534.        (setq font-lock-fontified nil)
  535.        (font-lock-unfontify-region (point-min) (point-max))))
  536.     (redraw-modeline)))
  537.  
  538.  
  539. ;; For init-file hooks
  540. ;;;###autoload
  541. (defun turn-on-font-lock ()
  542.   "Unconditionally turn on Font Lock mode."
  543.   (font-lock-mode 1))
  544.  
  545. ;;;###autoload
  546. (defun font-lock-fontify-buffer ()
  547.   "Fontify the current buffer the way `font-lock-mode' would:
  548.  
  549.  - comments are displayed in font-lock-comment-face;
  550.  - strings are displayed in font-lock-string-face;
  551.  - documentation strings are displayed in font-lock-doc-string-face;
  552.  - function and variable names in their defining forms are displayed
  553.    in font-lock-function-name-face;
  554.  - and certain other expressions are displayed in other faces
  555.    according to the value of the variable `font-lock-keywords'.
  556.  
  557. This can take a while for large buffers."
  558.   (interactive)
  559.   (let ((was-on font-lock-mode)
  560.     (font-lock-verbose (or font-lock-verbose (interactive-p)))
  561.     (font-lock-message-threshold 0)
  562.     (aborted nil))
  563.     ;; Turn it on to run hooks and get the right font-lock-keywords.
  564.     (or was-on (font-lock-mode 1))
  565.     (font-lock-unfontify-region (point-min) (point-max) t)
  566. ;;    (buffer-syntactic-context-flush-cache)
  567.     
  568.     ;; If a ^G is typed during fontification, abort the fontification, but
  569.     ;; return normally (do not signal.)  This is to make it easy to abort
  570.     ;; fontification if it's taking a long time, without also causing the
  571.     ;; buffer not to pop up.  If a real abort is desired, the user can ^G
  572.     ;; again.
  573.     ;;
  574.     ;; Possibly this should happen down in font-lock-fontify-region instead
  575.     ;; of here, but since that happens from the after-change-hook (meaning
  576.     ;; much more frequently) I'm afraid of the bad consequences of stealing
  577.     ;; the interrupt character at inopportune times.
  578.     ;;
  579.     (condition-case nil
  580.     (save-excursion
  581.       (font-lock-fontify-region (point-min) (point-max))
  582.       (font-lock-hack-keywords (point-min) (point-max)))
  583.       (quit
  584.        (setq aborted t)))
  585.  
  586.     (or was-on        ; turn it off if it was off.
  587.     (let ((font-lock-fontified nil)) ; kludge to prevent defontification
  588.       (font-lock-mode 0)))
  589.     (set (make-local-variable 'font-lock-fontified) t)
  590.     (if (and aborted font-lock-verbose)
  591.     (message "Fontifying %s... aborted." (buffer-name)))
  592.     )
  593.   (run-hooks 'font-lock-after-fontify-buffer-hook))
  594.  
  595. (defun font-lock-examine-syntax-table ()
  596.   "Computes the value of font-lock-use-syntax-tables for this buffer."
  597.   (let ((i (1- (length (syntax-table))))
  598.     (got-one nil))
  599.     (if (eq (syntax-table) (standard-syntax-table))
  600.     ;; Assume that modes which haven't bothered to install their own
  601.     ;; syntax table don't do anything syntactically interesting.
  602.     ;; Really, the standard-syntax-table shouldn't have comments and
  603.     ;; strings in it, but changing that now might break things.
  604.     nil
  605.       ;; else map over the syntax table looking for strings or comments.
  606.       (while (>= i 0)
  607.     (if (memq (char-syntax i) '(?\" ?\< ?\> ?\$))
  608.         (setq got-one t i 0))
  609.     (setq i (1- i))))
  610.     (set (make-local-variable 'font-lock-use-syntax-tables) got-one)))
  611.  
  612. (defun font-lock-find-file-hook ()
  613.   "Find-file hook for the font-lock package.
  614. See the variable `font-lock-auto-fontify'."
  615.   (if font-lock-mode
  616.       nil        ; don't do anything if font-lock is already active
  617.     (font-lock-set-defaults) ; determine if we have keywords for this mode
  618.     (if (and font-lock-keywords
  619.          (or (and font-lock-auto-fontify
  620.               (not (memq major-mode font-lock-mode-disable-list)))
  621.          (and (not font-lock-auto-fontify)
  622.               (memq major-mode font-lock-mode-enable-list))))
  623.     (turn-on-font-lock))))
  624.  
  625.  
  626. ;;; Cruftiness for the Options menu
  627.  
  628. (defun font-lock-reset-face (face)
  629.   "Reset FACE its default state (from the X resource database).
  630. Returns whether it is indistinguishable from the default face."
  631.   (reset-face face)
  632.   (init-face-from-resources face)
  633.   (face-differs-from-default-p face))
  634.  
  635. (defun font-lock-copy-face (from to)
  636.   (if (font-lock-reset-face to)
  637.       ;; warnings disabled because it's reasonable to do this on purpose
  638.       '(warn "X resources override default for %s" to)
  639.     (copy-face from to)))
  640.  
  641. (defun font-lock-set-foreground (color to)
  642.   (if (font-lock-reset-face to)
  643.       '(warn "X resources override default for %s" to)
  644.     (set-face-foreground to color)))
  645.  
  646. (defun font-lock-use-default-fonts ()
  647.   "Reset the font-lock faces to a default set of fonts."
  648.   (interactive)
  649.   (font-lock-copy-face 'italic 'font-lock-comment-face)
  650.   ;; Underling comments looks terrible on tty's
  651.   (set-face-underline-p 'font-lock-comment-face nil 'global 'tty)
  652.   (set-face-highlight-p 'font-lock-comment-face t 'global 'tty)
  653.   (font-lock-copy-face 'font-lock-comment-face 'font-lock-string-face)
  654.   (font-lock-copy-face 'font-lock-string-face 'font-lock-doc-string-face)
  655.   (font-lock-copy-face 'bold-italic 'font-lock-function-name-face)
  656.   (font-lock-copy-face 'bold 'font-lock-keyword-face)
  657.   (font-lock-copy-face 'bold 'font-lock-preprocessor-face)
  658.   (font-lock-copy-face 'italic 'font-lock-type-face)
  659.   ;; is this necessary?
  660.   (remove-hook 'font-lock-mode-hook 'font-lock-use-default-fonts)
  661.   nil)
  662.  
  663. (defun font-lock-use-default-colors ()
  664.   "Reset the font-lock faces to a default set of colors."
  665.   (interactive)
  666.   (font-lock-copy-face 'default 'font-lock-comment-face)
  667.   (font-lock-set-foreground "#6920ac" 'font-lock-comment-face)
  668.   (font-lock-copy-face 'default 'font-lock-string-face)
  669.   (font-lock-set-foreground "green4" 'font-lock-string-face)
  670.   (font-lock-copy-face 'default 'font-lock-doc-string-face)
  671.   (font-lock-set-foreground "green4" 'font-lock-doc-string-face)
  672.   (font-lock-copy-face 'default 'font-lock-function-name-face)
  673.   (font-lock-set-foreground "red3" 'font-lock-function-name-face)
  674.   (font-lock-copy-face 'default 'font-lock-keyword-face)
  675.   (font-lock-set-foreground "blue3" 'font-lock-keyword-face)
  676.   (font-lock-copy-face 'default 'font-lock-preprocessor-face)
  677.   (font-lock-set-foreground "blue3" 'font-lock-preprocessor-face)
  678.   (font-lock-copy-face 'default 'font-lock-type-face)
  679.   (font-lock-set-foreground "blue3" 'font-lock-type-face)
  680.   ;; is this necessary?
  681.   (remove-hook 'font-lock-mode-hook 'font-lock-use-default-colors)
  682.   nil)
  683.  
  684. (defun font-lock-use-default-minimal-decoration ()
  685.   "Reset the font-lock patterns to a fast, minimal set of decorations."
  686.   (setq lisp-font-lock-keywords lisp-font-lock-keywords-1)
  687.   (setq c-font-lock-keywords c-font-lock-keywords-1)
  688.   (setq c++-font-lock-keywords c++-font-lock-keywords-1)
  689.   (setq fortran-font-lock-keywords fortran-font-lock-keywords-1)
  690.   ;; is this necessary?
  691.   (remove-hook 'font-lock-mode-hook
  692.            'font-lock-use-default-minimal-decoration)
  693.   nil)
  694.  
  695. (defun font-lock-use-default-maximal-decoration ()
  696.   "Reset the font-lock patterns to a larger set of decorations."
  697.   (setq lisp-font-lock-keywords lisp-font-lock-keywords-2)
  698.   (setq c-font-lock-keywords c-font-lock-keywords-2)
  699.   (setq c++-font-lock-keywords c++-font-lock-keywords-2)
  700.   (setq fortran-font-lock-keywords fortran-font-lock-keywords-2)
  701.   ;; is this necessary?
  702.   (remove-hook 'font-lock-mode-hook
  703.            'font-lock-use-default-maximal-decoration)
  704.   nil)
  705.  
  706.  
  707. ;;; Determining which set of font-lock keywords to use.
  708.  
  709. (defun font-lock-set-defaults ()
  710.   ;; Tries to set font-lock-keywords to something appropriate for this mode.
  711.   (let ((major (symbol-name major-mode))
  712.         (try #'(lambda (n)
  713.                  (if (stringp n) (setq n (intern-soft n)))
  714.                  (if (and n
  715.                           (boundp n))
  716.                      n
  717.                      nil))))
  718.     (setq font-lock-keywords 
  719.           (symbol-value
  720.            (or (funcall try (get major-mode 'font-lock-keywords))
  721.                (funcall try (concat major "-font-lock-keywords"))
  722.                (funcall try (and (string-match "-mode\\'" major)
  723.                                  (concat (substring 
  724.                                           major 0 (match-beginning 0))
  725.                                          "-font-lock-keywords")))
  726.                'font-lock-keywords)))
  727.     (setq font-lock-keywords-case-fold-search ; buffer-local
  728.       (get major-mode 'font-lock-keywords-case-fold-search))
  729.     ))
  730.  
  731.  
  732. ;;;;;;;;;;;;;;;;;;;;;;         keywords         ;;;;;;;;;;;;;;;;;;;;;;
  733.  
  734. ;;; Various major-mode interfaces.
  735. ;;; Probably these should go in with the source of the respective major modes.
  736.  
  737.  
  738. ;; These are the modes where the font-lock keywords are not trivially
  739. ;; deducible from the mode name (that is, modes where `FOO-mode' does
  740. ;; not use `FOO-font-lock-keywords'.)
  741. ;;
  742. (put 'emacs-lisp-mode    'font-lock-keywords 'lisp-font-lock-keywords)
  743. (put 'c++-c-mode    'font-lock-keywords 'c-font-lock-keywords)
  744. ;; the nine billion names of TeX mode...
  745. (put 'plain-tex-mode    'font-lock-keywords 'tex-font-lock-keywords)
  746. (put 'slitex-tex-mode    'font-lock-keywords 'tex-font-lock-keywords)
  747. (put 'latex-tex-mode    'font-lock-keywords 'tex-font-lock-keywords)
  748. (put 'LaTex-tex-mode    'font-lock-keywords 'tex-font-lock-keywords)
  749. (put 'latex-mode        'font-lock-keywords 'tex-font-lock-keywords)
  750. (put 'LaTeX-mode        'font-lock-keywords 'tex-font-lock-keywords)
  751. (put 'japanese-LaTeX-mode 'font-lock-keywords 'text-font-lock-keywords)
  752. (put 'japanese-SliTeX-mode 'font-lock-keywords 'text-font-lock-keywords)
  753. (put 'SliTeX-mode    'font-lock-keywords 'text-font-lock-keywords)
  754. (put 'FoilTeX-mode    'font-lock-keywords 'text-font-lock-keywords)
  755.  
  756. (defconst lisp-font-lock-keywords-1 (purecopy
  757.  '(;;
  758.    ;; highlight defining forms.  This doesn't work too nicely for
  759.    ;; (defun (setf foo) ...) but it does work for (defvar foo) which
  760.    ;; is more important.
  761.    ("^(def[-a-z]+\\s +\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face)
  762.    ;;
  763.    ;; highlight CL keywords (three clauses seems faster than one)
  764.    ("\\s :\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
  765.    ("(:\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
  766.    ("':\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
  767.    ;;
  768.    ;; this is highlights things like (def* (setf foo) (bar baz)), but may
  769.    ;; be slower (I haven't really thought about it)
  770. ;   ("^(def[-a-z]+\\s +\\(\\s(\\S)*\\s)\\|\\S(\\S *\\)"
  771. ;    1 font-lock-function-name-face)
  772.    ))
  773.  "For consideration as a value of `lisp-font-lock-keywords'.
  774. This does fairly subdued highlighting.")
  775.  
  776. (defconst lisp-font-lock-keywords-2 (purecopy
  777.   (append
  778.    lisp-font-lock-keywords-1
  779.    '(;;
  780.      ;; Highlight control structures
  781.      ("(\\(cond\\|if\\|when\\|unless\\|[ec]?\\(type\\)?case\\)[ \t\n]" . 1)
  782.      ("(\\(while\\|do\\|let\\*?\\|flet\\|labels\\|prog[nv12*]?\\)[ \t\n]" . 1)
  783.      ("(\\(do\\*\\|dotimes\\|dolist\\|loop\\)[ \t\n]" . 1)
  784.      ("(\\(catch\\|\\throw\\|block\\|return\\|return-from\\)[ \t\n]" . 1)
  785.      ("(\\(save-restriction\\|save-window-restriction\\)[ \t\n]" . 1)
  786.      ("(\\(save-excursion\\|unwind-protect\\|condition-case\\)[ \t\n]" . 1)
  787.      ;;
  788.      ;; highlight function names in emacs-lisp docstrings (in the syntax
  789.      ;; that substitute-command-keys understands.)
  790.      ("\\\\\\\\\\[\\([^]\\\n]+\\)]" 1 font-lock-keyword-face t)
  791.      ;;
  792.      ;; highlight words inside `' which tend to be function names
  793.      ("`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'"
  794.       1 font-lock-keyword-face t)
  795.      )))
  796.  "For consideration as a value of `lisp-font-lock-keywords'.
  797. This does a lot more highlighting.")
  798.  
  799. ;; default to the gaudier variety?
  800. ;(defconst lisp-font-lock-keywords lisp-font-lock-keywords-2
  801. ;  "Additional expressions to highlight in lisp modes.")
  802. (defconst lisp-font-lock-keywords lisp-font-lock-keywords-1
  803.   "Additional expressions to highlight in lisp modes.")
  804.  
  805.  
  806. (defconst c-font-lock-keywords-1 nil
  807.  "For consideration as a value of `c-font-lock-keywords'.
  808. This does fairly subdued highlighting.")
  809.  
  810. (defconst c-font-lock-keywords-2 nil
  811.  "For consideration as a value of `c-font-lock-keywords'.
  812. This does a lot more highlighting.")
  813.  
  814. (let ((storage "auto\\|extern\\|register\\|static\\|volatile")
  815.       (prefixes "unsigned\\|short\\|long\\|const")
  816.       (types (concat "int\\|long\\|char\\|float\\|double\\|void\\|struct\\|"
  817.              "union\\|enum\\|typedef"))
  818.       (ctoken "\\(\\sw\\|\\s_\\|[:~*&]\\)+")
  819.       )
  820.   (setq c-font-lock-keywords-1 (purecopy
  821.    (list
  822.     ;; fontify preprocessor directives.
  823.     '("^#[ \t]*[a-z]+" . font-lock-preprocessor-face)
  824.     ;;
  825.     ;; fontify names being defined.
  826.     '("^#[ \t]*\\(define\\|undef\\)[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 2
  827.       font-lock-function-name-face)
  828.     ;;
  829.     ;; fontify other preprocessor lines.
  830.     '("^#[ \t]*\\(if\\|ifn?def\\|elif\\)[ \t]+\\([^\n]+\\)"
  831.       2 font-lock-function-name-face t)
  832.     ;;
  833.     ;; fontify the filename in #include <...>
  834.     ;; don't need to do this for #include "..." because those were
  835.     ;; already fontified as strings by the syntactic pass.
  836.     ;; (Changed to not include the <> in the face, since "" aren't.)
  837.     '("^#[ \t]*include[ \t]+<\\([^>\"\n]+\\)>" 1 font-lock-string-face)
  838.     ;;
  839.     ;; fontify the names of functions being defined.
  840.     ;; I think this should be fast because it's anchored at bol, but it's not.
  841.     (list (concat
  842.        "^\\(" ctoken "[ \t]+\\)?"    ; type specs; there can be no
  843.        "\\(" ctoken "[ \t]+\\)?"    ; more than 3 tokens, right?
  844.        "\\(" ctoken "[ \t]+\\)?"
  845.        "\\([*&]+[ \t]*\\)?"        ; pointer
  846.        "\\(" ctoken "\\)[ \t]*(")    ; name
  847.       8 'font-lock-function-name-face)
  848.     ;;
  849.     ;; This is faster but not by much.  I don't see why not.
  850. ;    (list (concat "^\\(" ctoken "\\)[ \t]*(") 1 'font-lock-function-name-face)
  851.     ;;
  852.     ;; Fontify structure names (in structure definition form).
  853.     (list (concat "^\\(typedef[ \t]+struct\\|struct\\|static[ \t]+struct\\)"
  854.           "[ \t]+\\(" ctoken "\\)[ \t]*\\(\{\\|$\\)")
  855.       2 'font-lock-function-name-face)
  856.     ;;
  857.     ;; Fontify case clauses.  This is fast because its anchored on the left.
  858.     '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\):". 1)
  859.     '("\\<\\(default\\):". 1)
  860.     )))
  861.  
  862.   (setq c-font-lock-keywords-2 (purecopy
  863.    (append c-font-lock-keywords-1
  864.     (list
  865.      ;;
  866.      ;; fontify all storage classes and type specifiers
  867.      ;; types should be surrounded by non alphanumerics (Raymond Toy)
  868.      (cons (concat "\\<\\(" storage "\\)\\>") 'font-lock-type-face)
  869.      (list (concat "\\([^a-zA-Z0-9_]\\|^\\)\\("
  870.            types
  871.            "\\)\\([^a-zA-Z0-9_]\\|$\\)")
  872.        2 'font-lock-type-face)
  873.      ;; fontify the prefixes now.  The types should have been fontified
  874.      ;; previously.
  875.      (list (concat "\\<\\(" prefixes "\\)[ \t]+\\(" types "\\)\\>")
  876.        1 'font-lock-type-face)
  877.      ;;
  878.      ;; fontify all builtin tokens
  879.      (cons (concat
  880.         "[ \t]\\("
  881.         (mapconcat 'identity
  882.          '("for" "while" "do" "return" "goto" "case" "break" "switch"
  883.            "if" "then" "else if" "else" "return" "continue" "default"
  884.            )
  885.          "\\|")
  886.         "\\)[ \t\n(){};,]")
  887.        1)
  888.      ;;
  889.      ;; fontify case targets and goto-tags.  This is slow because the
  890.      ;; expression is anchored on the right.
  891.      "\\(\\(\\sw\\|\\s_\\)+\\):"
  892.      ;;
  893.      ;; Fontify variables declared with structures, or typedef names.
  894.      '("}[ \t*]*\\(\\(\\sw\\|\\s_\\)+\\)[ \t]*[,;]"
  895.        1 font-lock-function-name-face)
  896.      ;;
  897.      ;; Fontify global variables without a type.
  898. ;     '("^\\([_a-zA-Z0-9:~*]+\\)[ \t]*[[;={]" 1 font-lock-function-name-face)
  899.  
  900.      ))))
  901.   )
  902.  
  903.  
  904. ;; default to the gaudier variety?
  905. ;(defconst c-font-lock-keywords c-font-lock-keywords-2
  906. ;  "Additional expressions to highlight in C mode.")
  907. (defconst c-font-lock-keywords c-font-lock-keywords-1
  908.   "Additional expressions to highlight in C mode.")
  909.  
  910. (defconst c++-font-lock-keywords-1 nil
  911.  "For consideration as a value of `c++-font-lock-keywords'.
  912. This does fairly subdued highlighting.")
  913.  
  914. (defconst c++-font-lock-keywords-2 nil
  915.  "For consideration as a value of `c++-font-lock-keywords'.
  916. This does a lot more highlighting.")
  917.  
  918. (let ((ctoken "\\(\\sw\\|\\s_\\|[:~*&]\\)+")
  919.       (c++-types (concat "complex\\|public\\|private\\|protected\\|virtual\\|"
  920.              "friend\\|inline"))
  921.       c++-font-lock-keywords-internal-1
  922.       c++-font-lock-keywords-internal-2
  923.       )
  924.   (setq c++-font-lock-keywords-internal-1 (purecopy
  925.    (list
  926.     ;;
  927.     ;; fontify friend operator functions
  928.     '("^\\(operator[^(]*\\)(" 1 font-lock-function-name-face)
  929.     '("^\\(operator[ \\t]*([ \\t]*)[^(]*\\)(" 1 font-lock-function-name-face)
  930.  
  931.     ;; fontify the class names only in the definition
  932.     (list (concat "^class[ \t]+" ctoken "[ \t\n{: ;]") 1
  933.       'font-lock-function-name-face)
  934.  
  935.     (list (concat
  936.        "^\\(" ctoken "[ \t]+\\)?" ; type specs; there can be no
  937.        "\\(" ctoken "[ \t]+\\)?" ; more than 3 tokens, right?
  938.        "\\(" ctoken "[ \t]+\\)?"
  939.        "\\(\\*+[ \t]*\\)?"    ; pointer
  940.        "\\(" ctoken "\\(::\\)?~?\\(\\(operator[ \t]*[^ \ta-zA-Z]+\\)\\|"
  941.        ctoken "\\)\\)[ \t]*(") ; name
  942.       8 'font-lock-function-name-face t)
  943.     )))
  944.  
  945.   (setq c++-font-lock-keywords-internal-2 (purecopy
  946.    (list
  947.     ;; fontify extra c++ storage classes and type specifiers
  948.     (cons (concat "\\<\\(" c++-types "\\)\\>") 'font-lock-type-face)
  949.  
  950.     ;;special check for class
  951.     '("^\\(\\<\\|template[ \t]+<[ \t]*\\)\\(class\\)[ \t\n]+" 2
  952.       font-lock-type-face)
  953.  
  954.     ;; special handling of template
  955.     "^\\(template\\)\\>"
  956.     ;; fontify extra c++ builtin tokens
  957.     (cons (concat
  958.        "[ \t]\\("
  959.        (mapconcat 'identity
  960.               '("asm" "catch" "throw" "try" "delete" "new" "operator"
  961.             "sizeof" "this"
  962.             )
  963.               "\\|")
  964.        "\\)[ \t\n(){};,]")
  965.       1)
  966.     )))
  967.  
  968.   (setq c++-font-lock-keywords-1 (purecopy
  969.    (append c-font-lock-keywords-1 c++-font-lock-keywords-internal-1)))
  970.  
  971.   (setq c++-font-lock-keywords-2 (purecopy
  972.    (append c-font-lock-keywords-2 c++-font-lock-keywords-internal-1
  973.        c++-font-lock-keywords-internal-2)))
  974.   )
  975.  
  976. (defconst c++-font-lock-keywords c++-font-lock-keywords-1
  977.   "Additional expressions to highlight in C++ mode.")
  978.  
  979.  
  980. ;; Added by Bob Weiner, Motorola, Inc., 2/16/94.
  981. ;; Lots of embedded developers still program in assembler and this
  982. ;; works well for a number of assemblers.  Comments are handled by the
  983. ;; syntax tables.
  984. (defconst asm-font-lock-keywords (purecopy
  985.  '(
  986.    ("^\\(\\sw\\|\\s_\\)+" 0 font-lock-function-name-face)
  987.    ("^\\(\\sw\\|\\s_\\)+:?\\s +\\(\\sw+\\)" 2 font-lock-keyword-face)
  988.    ("^\\s +\\(\\(\\sw\\|\\s_\\)+\\)" 1 font-lock-keyword-face)
  989.    ))
  990.  "Additional expressions to highlight in assembler mode.")
  991.  
  992. (defconst perl-font-lock-keywords (purecopy
  993.   (list
  994.    (cons (concat "[ \n\t{]*\\("
  995.          (mapconcat 'identity
  996.                 '("if" "until" "while" "elsif" "else" "unless"
  997.                   "for" "foreach" "continue" "exit" "die" "last"
  998.                   "goto" "next" "redo" "return" "local" "exec")
  999.                 "\\|")
  1000.          "\\)[ \n\t;(]")
  1001.      1)
  1002.         (mapconcat 'identity
  1003.                    '("#endif" "#else" "#ifdef" "#ifndef" "#if" "#include"
  1004.                      "#define" "#undef")
  1005.                    "\\|")
  1006.         '("^[ \n\t]*sub[ \t]+\\([^ \t{]+\\)[ \n\t]*\\{"
  1007.           1 font-lock-function-name-face)
  1008.         '("[ \n\t{]*\\(eval\\)[ \n\t(;]" 
  1009.           1 font-lock-function-name-face)
  1010.         ;; '("\\(--- .* ---\\|=== .* ===\\)" 1 font-lock-doc-string-face)
  1011.         ))
  1012.   "Additional expressions to highlight in Perl mode.")
  1013.  
  1014. (defconst tex-font-lock-keywords (purecopy
  1015.   (list
  1016.    ;; Lionel Mallet: Thu Oct 14 09:41:38 1993
  1017.    ;; I've added an exit condition to the regexp below, and the other
  1018.    ;; regexps for the second part.
  1019.    ;; What would be useful here is something like:
  1020.    ;; ("\\(\\\\\\w+\\)\\({\\(\\w+\\)}\\)+" 1 font-lock-keyword-face t 3
  1021.    ;;  font-lock-function-name-face t)
  1022.    '("\\(\\\\\\w+\\)\\W" 1 font-lock-keyword-face t)
  1023.    '("\\(\\\\\\w+\\){\\([^}\n]+\\)}" 2 font-lock-function-name-face t)
  1024.    '("\\(\\\\\\w+\\){\\(\\w+\\)}{\\(\\w+\\)}" 3
  1025.      font-lock-function-name-face t)
  1026.    '("\\(\\\\\\w+\\){\\(\\w+\\)}{\\(\\w+\\)}{\\(\\w+\\)}" 4
  1027.      font-lock-function-name-face t)
  1028.    '("{\\\\em\\([^}]+\\)}" 1 font-lock-comment-face t)
  1029.    '("{\\\\bf\\([^}]+\\)}" 1 font-lock-keyword-face t)
  1030.    '("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)\\W" 1 font-lock-function-name-face t)
  1031.    ;; Lionel Mallet: Thu Oct 14 09:40:10 1993
  1032.    ;; the regexp below is useless as it is now covered by the first 2 regexps
  1033.    ;;   '("\\\\\\(begin\\|end\\){\\([a-zA-Z0-9\\*]+\\)}"
  1034.    ;;     2 font-lock-function-name-face t)
  1035.    '("[^\\\\]\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
  1036. ;   '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
  1037.    ))
  1038.   "Additional expressions to highlight in TeX mode.")
  1039.  
  1040. (defconst texinfo-font-lock-keywords (purecopy
  1041.   (list
  1042.    "@\\(@\\|[^}\t \n{]+\\)"                    ;commands
  1043.    '("^\\(@c\\|@comment\\)[ \t].*$" 0 font-lock-comment-face t)    ;comments
  1044.    '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t)    ;menu items
  1045.    '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face t)
  1046.    '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face t)
  1047.    '("@\\(samp\\|code\\|var\\){\\([^}]+\\)" 2 font-lock-function-name-face t)
  1048.    '("@\\(xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-keyword-face t)
  1049.    '("@end *\\([a-zA-Z0-9]+\\)[ \t]*$" 1 font-lock-function-name-face t)
  1050.    '("@item \\(.*\\)$" 1 font-lock-function-name-face t)
  1051.    '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
  1052.    ))
  1053.   "Additional expressions to highlight in TeXinfo mode.")
  1054.  
  1055. (defconst postscript-font-lock-keywords (purecopy
  1056.    (list
  1057.     ;; Proper rule for Postscript strings
  1058.     '("(\\([^)]\\|\\\\.\\|\\\\\n\\)*)" . font-lock-string-face)
  1059.     ;; Make any line beginning with a / be a ``keyword''
  1060.     '("^/[^\n%]*" . font-lock-keyword-face)
  1061.     ;; Make brackets of all forms be keywords
  1062.     '("[][<>{}]+" . font-lock-keyword-face)
  1063.     ;; Keywords
  1064.     (list (concat 
  1065.        "[][ \t\f\n\r()<>{}/%]"    ;delimiter
  1066.        "\\("
  1067.        (mapconcat 'identity
  1068.               '("begin" "end" 
  1069.             "save" "restore" "gsave" "grestore"
  1070.             ;; Any delimited name ending in 'def'
  1071.             "[a-zA-Z0-9-._]*def"
  1072.             "[Dd]efine[a-zA-Z0-9-._]*")
  1073.               "\\|")
  1074.        "\\)"
  1075.        "\\([][ \t\f\n\r()<>{}/%]\\|$\\)" ;delimiter
  1076.        )
  1077.       1 'font-lock-keyword-face)))
  1078.    "Expressions to highlight in Postscript buffers.")
  1079.  
  1080. (defconst scheme-font-lock-keywords (purecopy
  1081.  '(("(define[ \t]+(?\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face)
  1082.    ("(\\(cond\\|lambda\\|begin\\|if\\|else\\|case\\|do\\)[ \t\n]" . 1)
  1083.    ("(\\(\\|letrec\\|let\\*?\\|set!\\|and\\|or\\)[ \t\n]" . 1)
  1084.    ("(\\(quote\\|unquote\\|quasiquote\\|unquote-splicing\\)[ \t\n]" . 1)
  1085.    ("(\\(syntax\\|syntax-rules\\|define-syntax\\|let-syntax\\|letrec-syntax\\)[ \t\n]" . 1)))
  1086.   "Expressions to highlight in Scheme buffers.")
  1087.  
  1088. (defconst dired-font-lock-keywords (purecopy
  1089.   (let ((bn (concat "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|"
  1090.             "Aug\\|Sep\\|Oct\\|Nov\\|Dec\\) +[0-9]+ +[0-9:]+")))
  1091.     (list
  1092.      '("^  [/~].*:$" . bold-italic)                   ; Header
  1093.      (list (concat "^\\(\\([^ ].*\\)" bn "\\) \\(.*\\)$") 1 'bold) ; Marked
  1094.      (list (concat "^. +d.*" bn " \\(.*\\)$") 2 'bold)           ; Subdirs
  1095.      (list (concat "^. +l.*" bn " \\(.*\\)$") 2 'italic)       ; Links
  1096.      (cons (concat "^. +-..[xsS]......\\|"    ; Regular files with executable
  1097.            "^. +-.....[xsS]...\\|"    ; or setuid/setgid bits set
  1098.            "^. +-........[xsS]")
  1099.        'bold)
  1100.      ;; Possibly we should highlight more types of files differently:
  1101.      ;; backups; autosaves; core files?  Those with ignored-extensions?
  1102.      )))
  1103.   "Expressions to highlight in Dired buffers.")
  1104.  
  1105. (defconst ada-font-lock-keywords (purecopy
  1106.   (let ((ident  "\\(\\(\\sw\\|\\s_\\)+\\)") ; indent is 2nd capture
  1107.     (decl-1 "\\(procedure\\|function\\|package\\)[ \t]+") ; 1 ()
  1108.     (decl-2 "\\(task\\|package\\)[ \t]+body[ \t]+")    ; 1()
  1109.     (kwords-1            ; "normal" keywords
  1110.      '("abort" "abs" "accept" "access" "array" "begin" "body" "case"
  1111.        "constant" "declare" "delay" "delta" "digits" "else" "elsif"
  1112.        "entry" "exception" "exit" "function"  "generic" "goto" "if"
  1113.        "others" "limited" "loop" "mod" "new" "null" "out" "subtype"
  1114.        "package" "pragma" "private" "procedure" "raise" "range" "record"
  1115.        "rem" "renames" "return" "reverse" "select" "separate" "task"
  1116.        "terminate" "then" "type" "when" "while" "with" "xor"))
  1117.     (kwords-2    ; keywords that may appear at the end of a word AND
  1118.             ; may also be preceeded by a non-space.
  1119.      '("and" "at" "do" "end" "for" "in" "is" "not" "of" "or" "use"))
  1120.     )
  1121.     (list
  1122.      ;;'("\\(--.*\\)" 1 font-lock-comment-face t) ; syntax table should do this
  1123.      (list (concat "^[ \t]*" decl-2 ident) 3 'font-lock-function-name-face)
  1124.      (list (concat "^[ \t]*" decl-1 ident) 3 'font-lock-function-name-face)
  1125.      (cons (concat "\\(" (mapconcat 'identity kwords-1 "\\|") "\\)[ \n\t;(]")
  1126.        1)
  1127.      (cons (concat "[ \t+=*/---]\\(" (mapconcat 'identity kwords-2 "\\|")
  1128.            "\\)[ \n\t;(]")
  1129.        1)
  1130.      (cons "^\\(end\\)[ \n\t;(]" 1)
  1131.      (cons "\\.\\(all\\)" 1)
  1132.      )))
  1133.   "Expressions to highlight in Ada buffers.")
  1134.  
  1135. (defconst ksh-font-lock-keywords (purecopy
  1136.   (list
  1137.    '("\\(^\\|[^\$\\\]\\)#.*" . font-lock-comment-face)
  1138.    '("\\<\\(if\\|then\\|else\\|elif\\|fi\\|case\\|esac\\|for\\|do\\|done\\|foreach\\|in\\|end\\|select\\|while\\|repeat\\|time\\|function\\|until\\|exec\\|command\\|coproc\\|noglob\\|nohup\\|nocorrect\\|source\\|autoload\\|alias\\|unalias\\|export\\|set\\|echo\\|eval\\|cd\\|log\\|compctl\\)\\>" . font-lock-keyword-face)
  1139.    '("\\<\\[\\[.*\\]\\]\\>" . font-lock-type-face)
  1140.    '("\$\(.*\)" . font-lock-type-face)
  1141.    ))
  1142.   "Additional expressions to highlight in ksh-mode.")
  1143.  
  1144. (defconst sh-font-lock-keywords (purecopy
  1145.   (list
  1146.    '("\\(^\\|[^\$\\\]\\)#.*" . font-lock-comment-face)
  1147.    '("\\<\\(if\\|then\\|else\\|elif\\|fi\\|case\\|esac\\|for\\|do\\|done\\|in\\|while\\|exec\\|export\\|set\\|echo\\|eval\\|cd\\)\\>" . font-lock-keyword-face)
  1148.    '("\\[.*\\]" . font-lock-type-face)
  1149.    '("`.*`" . font-lock-type-face)
  1150.    ))
  1151.   "Additional expressions to highlight in sh-mode.")
  1152.  
  1153. (defconst pascal-font-lock-keywords (purecopy
  1154.   (list
  1155.    '("^[ \t]*\\(function\\|pro\\(cedure\\|gram\\)\\)\\>[ \t]*\\(\\sw+\\)?"
  1156.      1 font-lock-keyword-face)
  1157.    '("^[ \t]*\\(function\\|pro\\(cedure\\|gram\\)\\)\\>[ \t]*\\(\\sw+\\)?"
  1158.      3 font-lock-function-name-face t)
  1159. ;   ("type" "const" "real" "integer" "char" "boolean" "var"
  1160. ;    "record" "array" "file")
  1161.    (cons (concat "\\<\\(array\\|boolean\\|c\\(har\\|onst\\)\\|file\\|"
  1162.          "integer\\|re\\(al\\|cord\\)\\|type\\|var\\)\\>")
  1163.      'font-lock-type-face)
  1164.    '("\\<\\(label\\|external\\|forward\\)\\>" . font-lock-reference-face)
  1165.    '("\\<\\([0-9]+\\)[ \t]*:" 1 font-lock-reference-face)
  1166. ;   ("of" "to" "for" "if" "then" "else" "case" "while"
  1167. ;    "do" "until" "and" "or" "not" "in" "with" "repeat" "begin" "end")
  1168.    (concat "\\<\\("
  1169.        "and\\|begin\\|case\\|do\\|e\\(lse\\|nd\\)\\|for\\|i[fn]\\|"
  1170.        "not\\|o[fr]\\|repeat\\|t\\(hen\\|o\\)\\|until\\|w\\(hile\\|ith\\)"
  1171.        "\\)\\>")
  1172.    '("\\<\\(goto\\)\\>[ \t]*\\([0-9]+\\)?"
  1173.      1 font-lock-keyword-face)
  1174.    '("\\<\\(goto\\)\\>[ \t]*\\([0-9]+\\)?"
  1175.      2 font-lock-reference-face t)))
  1176.   "Additional expressions to highlight in Pascal mode.")
  1177.  
  1178. (defconst python-font-lock-keywords
  1179.   (purecopy
  1180.    (list
  1181.     (cons (concat "\\b\\("
  1182.                   (mapconcat 'identity
  1183.                              '("access"     "del"        "from"
  1184.                                "lambda"     "return"     "and"
  1185.                                "elif"       "global"     "not"
  1186.                                "try:"       "break "     "else:"
  1187.                                "if"         "or"         "while"
  1188.                                "except"     "except:"    "import"
  1189.                                "pass"       "continue"   "finally:"
  1190.                                "in"         "print"      "for"
  1191.                                "is"         "raise")
  1192.                              "\\|")
  1193.                   "\\)[ \n\t(]")
  1194.           1)
  1195.     '("\\bclass[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)"
  1196.       1 font-lock-type-face)
  1197.     '("\\bdef[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)"
  1198.       1 font-lock-function-name-face)
  1199.     ))
  1200.   "Additional expressions to highlight in Python mode.")
  1201.  
  1202. (defconst compilation-font-lock-keywords (purecopy
  1203.   (list
  1204.    '("^[-_.\"A-Za-z0-9/+]+\\(:\\|, line \\)[0-9]+: \\([wW]arning:\\).*$" .
  1205.      font-lock-keyword-face)
  1206.    '("^[-_.\"A-Za-z0-9/+]+\\(: *\\|, line \\)[0-9]+:.*$" . font-lock-function-name-face)
  1207.    '("^[^:\n]+-[a-zA-Z][^:\n]+$" . font-lock-doc-string-face)
  1208.    '("\\(^[-_.\"A-Za-z0-9/+]+\\)\\(: *\\|, line \\)[0-9]+" 1 font-lock-string-face t)
  1209.    '("^[-_.\"A-Za-z0-9/+]+\\(: *[0-9]+\\|, line [0-9]+\\)" 1 bold t)
  1210.    ))
  1211.   "Additional expressions to highlight in compilation buffers.")
  1212.  
  1213. (defconst makefile-font-lock-keywords (purecopy
  1214.   (list
  1215.    '("^#.*$" . font-lock-comment-face)
  1216.    '("[^$]#.*$" . font-lock-comment-face)
  1217.    ;; rules
  1218.    '("^\\([^ \t\n]*%?[^ \t\n]*[ \t]*::?\\)[ \t]" 1 font-lock-type-face t)
  1219.    '("^\\(\\.[A-Za-z][A-Za-z]?\\..[ \t]*::?\\)" 1 font-lock-type-face t)
  1220.    '("^[^ \t\n]+[ \t]*:;?\\(.*\\)$" 1 font-lock-doc-string-face t)
  1221.    ;; variable definition
  1222.    '("^[_A-Za-z0-9]+[ \t]*\+?=" . font-lock-function-name-face)
  1223.    '("\\( \\|:=\\)[_A-Za-z0-9]+[ \t]*\\+=" . font-lock-function-name-face)
  1224.    ;; variable references
  1225.    '("\\(\\$\\$?\\([^ \t\n{(]\\|[{(][^ \t\n)}]+[)}]\\)\\)" 
  1226.      1 font-lock-keyword-face t)
  1227.    '("^include " . font-lock-string-face)
  1228.    ))
  1229.   "Additional expressions to highlight in makefiles")
  1230.  
  1231. (defconst rexx-font-lock-keywords
  1232.   (purecopy
  1233.    (list
  1234.     (cons (concat "\\<\\("
  1235.      (mapconcat 'identity
  1236.      '("address" "arg" "break" "call" "do" "drop" "echo" "else" "end"
  1237.       "exit" "if" "interpret" "iterate" "leave" "nop" "numeric"
  1238.       "options" "otherwise" "parse" "procedure" "pull" "push" "queue"
  1239.       "return" "say" "select" "shell" "signal" "then" "trace" "upper"
  1240.       "when" "value" "to" "by" "for" "forever" "while" "until" "form"
  1241.       "digits" "fuzz" "scientific" "engineering" "failat" "prompt"
  1242.       "results" "upper" "external" "source" "with" "command"
  1243.       "function" "var" "version" "expose" "on" "off")
  1244.      "\\|") "\\)\\>") 'font-lock-keyword-face)
  1245.    '("\\(\\sw+\\):" 1 font-lock-function-name-face)))
  1246.   "Additional expressions to highlight in Rexx mode.")
  1247.  
  1248. (defconst fortran-font-lock-keywords-1
  1249.   (purecopy
  1250.    (list
  1251.     ;; fontify comments
  1252.     '("^[cC*].*$" . font-lock-comment-face)
  1253.     ;;
  1254.     ;; fontify preprocessor directives.
  1255.     '("^#[ \t]*[a-z]+" . font-lock-preprocessor-face)
  1256.     ;;
  1257.     ;; fontify names being defined.
  1258.     '("^#[ \t]*\\(define\\|undef\\)[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 2
  1259.       font-lock-function-name-face)
  1260.     ;;
  1261.     ;; fontify other preprocessor lines.
  1262.     '("^#[ \t]*\\(if\\|ifn?def\\|elif\\)[ \t]+\\([^\n]+\\)"
  1263.       2 font-lock-function-name-face t)
  1264.  
  1265.     ;; Subroutine and function declarations
  1266.     '("^[ \t]*subroutine.*$" . font-lock-function-name-face)
  1267.     '("^[ \t].*function.*$" . font-lock-function-name-face)
  1268.     '("^[ \t].*program.*$" . font-lock-function-name-face)
  1269.     '("^[ \t].*entry.*$" . font-lock-function-name-face)
  1270.     ))
  1271.   "For consideration as a value of `fortran-font-lock-keywords'.
  1272. This does fairly subdued highlighting of comments and function names.")
  1273.  
  1274. (defconst fortran-font-lock-keywords-2
  1275.   (purecopy
  1276.    (append fortran-font-lock-keywords-1
  1277.     (list
  1278.      ;; Variable declarations
  1279.      '("^[ \t]*\\(\\(integer\\|logical\\|real\\|complex\\|double[ \t]*precision\\|character\\|parameter\\)[^ \t]*\\)" 
  1280.        1 font-lock-keyword-face)
  1281.      ;; Common blocks, external, etc
  1282.      '("^[ \t]*\\(common\\|save\\|external\\|intrinsic\\|data\\)" 1 font-lock-keyword-face)
  1283.      ;; Other keywords
  1284.      '("^[ \t]*[0-9]*[ \t]*\\(if\\)[ \t]*("
  1285.        1 font-lock-keyword-face)
  1286.  
  1287.      ;; Then
  1288.      ;; '("^\\(\\([ \t]*[0-9]*[ \t]*\\)\\|\\(      [^ ]\\)\\).*[ \t]*\\(then\\)[ \t]*"
  1289.      ;;   4 font-lock-keyword-face)
  1290.      '("\\(then\\)[ \t]*$" 1 font-lock-keyword-face)
  1291.  
  1292.      ;; '("^[ \t]*[0-9]*[ \t]*\\(end[ \t]*if\\)[ \t]*$"
  1293.      '("\\(end[ \t]*if\\)[ \t]*$"
  1294.        1 font-lock-keyword-face)      
  1295.      ;; '("\\(else[ \t]*\\(if\\)?\\)"
  1296.      ;; the below works better <mdb@cdc.noaa.gov>
  1297.      '("^[ \t]*[0-9]*[ \t]*\\(else[ \t]*\\(if\\)?\\)"
  1298.        1 font-lock-keyword-face)
  1299.      '("^[ \t]*[0-9]*[ \t]*\\(do\\)[ \t]*[0-9]+"
  1300.        1 font-lock-keyword-face)
  1301.      '("^[ \t]*[0-9]*[ \t]*\\(do\\)[ \t]*[a-z0-9_$]+[ \t]*="
  1302.        1 font-lock-keyword-face)
  1303.      '("^[ \t]*[0-9]*[ \t]*\\(end[ \t]*do\\)"
  1304.        1 font-lock-keyword-face)
  1305.      '("^[ \t]*[0-9]+[ \t]*\\(continue\\)" 1 font-lock-keyword-face)
  1306.      '("^[ \t]*[0-9]*[ \t]*\\(call\\)" 1 font-lock-keyword-face)
  1307.      '("^[ \t]*[0-9]*[ \t]*\\(go[ \t]*to\\)" 1 font-lock-keyword-face)
  1308.  
  1309.      '("^[ \t]*[0-9]*[ \t]*\\(open\\|close\\|read\\|write\\|format\\)[ \t]*("
  1310.        1 font-lock-keyword-face)
  1311.      '("^[ \t]*[0-9]*[ \t]*\\(print\\)[ \t]*[*'0-9]+" 1 font-lock-keyword-face)
  1312.  
  1313.      '("^[ \t]*[0-9]*[ \t]*\\(end\\|return\\)[ \t]*$" 1 font-lock-keyword-face)
  1314.  
  1315.      '("^[ \t]*[0-9]*[ \t]*\\(stop\\)[ \t]*['0-9]*" 1 font-lock-keyword-face)
  1316.  
  1317.      ;; Boolean and relational operations, logical true and false
  1318.      '("\\.\\(and\\|or\\|not\\|lt\\|le\\|eq\\|ge\\|gt\\|ne\\|true\\|false\\)\\."
  1319.        . font-lock-keyword-face)
  1320.      )))
  1321.   "For consideration as a value of `fortran-font-lock-keywords'.
  1322. This highlights variable types, \"keywords,\" etc.")
  1323.  
  1324. ;; The keywords in the preceding lists assume case-insensitivity.
  1325. (put 'fortran-mode 'font-lock-keywords-case-fold-search t)
  1326. (put 'ada-mode 'font-lock-keywords-case-fold-search t)
  1327.  
  1328. (defconst fortran-font-lock-keywords fortran-font-lock-keywords-1
  1329.   "Additional expressions to highlight in Fortran mode.")
  1330.  
  1331.  
  1332. ;;;;;;;;;;;;;;;;;;;;;;      initialization       ;;;;;;;;;;;;;;;;;;;;;;
  1333.  
  1334. (add-hook 'find-file-hooks 'font-lock-find-file-hook t)
  1335.  
  1336. (make-face 'font-lock-comment-face)
  1337. (make-face 'font-lock-doc-string-face)
  1338. (make-face 'font-lock-string-face)
  1339. (make-face 'font-lock-function-name-face)
  1340. (make-face 'font-lock-keyword-face)
  1341. (make-face 'font-lock-preprocessor-face)
  1342. (make-face 'font-lock-type-face)
  1343.  
  1344. (cond (font-lock-use-colors (font-lock-use-default-colors))
  1345.       (font-lock-use-fonts (font-lock-use-default-fonts)))
  1346.  
  1347. (if font-lock-use-maximal-decoration
  1348.     (font-lock-use-default-maximal-decoration))
  1349.  
  1350.  
  1351. (provide 'font-lock)
  1352.  
  1353. ;;; font-lock.el ends here
  1354.