home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / packages / font-lock.el < prev    next >
Encoding:
Text File  |  1993-03-24  |  21.1 KB  |  546 lines

  1. ;; Electric Font Lock Mode, by jwz for the LISPM Preservation Society.
  2. ;; Copyright (C) 1992-1993 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 2, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. ;; Font-lock-mode is a minor mode that causes your comments to be 
  21. ;; displayed in one face, strings in another, reserved words in another,
  22. ;; documentation strings in another, and so on.
  23. ;;
  24. ;; Comments will be displayed in `font-lock-comment-face'.
  25. ;; Strings will be displayed in `font-lock-string-face'.
  26. ;; Doc strings will be displayed in `font-lock-doc-string-face'.
  27. ;; Function and variable names (in their defining forms) will be
  28. ;;  displayed in `font-lock-function-name-face'.
  29. ;; Reserved words will be displayed in `font-lock-keyword-face'.
  30. ;;
  31. ;; To make the text you type be fontified, use M-x font-lock-mode.
  32. ;; When this minor mode is on, the fonts of the current line will be
  33. ;; updated with every insertion or deletion.
  34. ;;
  35. ;; The `font-lock-keywords' variable defines other patterns to highlight.
  36. ;; The default font-lock-mode-hook sets it to the value of the variables
  37. ;; lisp-font-lock-keywords, c-font-lock-keywords, etc, as appropriate.
  38. ;; The easiest way to change the highlighting patterns is to change the
  39. ;; values of c-font-lock-keywords and related variables.
  40. ;;
  41. ;; To turn this on automatically, add this to your .emacs file:
  42. ;;
  43. ;;    (setq emacs-lisp-mode-hook '(lambda () (font-lock-mode 1)))
  44. ;;
  45. ;; On a Sparc2, the initial fontification takes about 12 seconds for a 120k
  46. ;; file of C code, using the default configuration.  You can speed this up
  47. ;; substantially by removing some of the patterns that are highlighted by
  48. ;; default.  Fontifying lisp code is significantly faster, because lisp has a
  49. ;; more regular syntax than C, so the expressions don't have to be as hairy.
  50.  
  51.  
  52. (make-face 'font-lock-comment-face)
  53. (make-face 'font-lock-doc-string-face)
  54. (make-face 'font-lock-string-face)
  55. (make-face 'font-lock-function-name-face)
  56. (make-face 'font-lock-keyword-face)
  57. (make-face 'font-lock-type-face)
  58.  
  59. (or (face-differs-from-default-p 'font-lock-comment-face)
  60.     (copy-face 'italic 'font-lock-comment-face))
  61.  
  62. (or (face-differs-from-default-p 'font-lock-doc-string-face)
  63.     (copy-face 'font-lock-comment-face 'font-lock-doc-string-face))
  64.  
  65. (or (face-differs-from-default-p 'font-lock-string-face)
  66.     (progn
  67.       (copy-face 'font-lock-doc-string-face 'font-lock-string-face)
  68.       (set-face-underline-p 'font-lock-string-face t)))
  69.  
  70. (or (face-differs-from-default-p 'font-lock-function-name-face)
  71.     (copy-face 'bold-italic 'font-lock-function-name-face))
  72.  
  73. (or (face-differs-from-default-p 'font-lock-keyword-face)
  74.     (copy-face 'bold 'font-lock-keyword-face))
  75.  
  76. (or (face-differs-from-default-p 'font-lock-type-face)
  77.     (copy-face 'italic 'font-lock-type-face))
  78.  
  79.  
  80. (make-variable-buffer-local 'font-lock-keywords)
  81. (defvar font-lock-keywords nil
  82.   "*The keywords to highlight.
  83. If this is a list, then elements may be of the forms:
  84.  
  85.   \"string\"              ; a regexp to highlight in the 
  86.                   ;  `font-lock-keyword-face'.
  87.   (\"string\" . integer)        ; match N of the regexp will be highlighted
  88.   (\"string\" . face-name)      ; use the named face
  89.   (\"string\" integer face-name)    ; both of the above
  90.   (\"string\" integer face-name t)  ; this allows highlighting to overlap
  91.                   ;  with already-highlighted regions.
  92.  
  93. These regular expressions should not match text which spans lines.  Multi-line
  94. patterns will be correctly fontified when \\[font-lock-fontify-buffer] is used,
  95. but will not be matched by the auto-fontification that font-lock-mode does,
  96. since it looks at only one line at a time.
  97.  
  98. Be careful composing regexps for this list; the wrong pattern can dramatically
  99. slow things down!")
  100.  
  101. (defvar font-lock-keywords-case-fold-search nil
  102.   "*Whether the strings in `font-lock-keywords' should be case-folded.")
  103.  
  104. (defvar font-lock-verbose t
  105.   "*Whether font-lock-fontify-buffer should print status messages.")
  106.  
  107. (defvar font-lock-mode-hook nil
  108.   "*Function or functions to run on entry to font-lock-mode.")
  109.  
  110. ;;; To fontify the whole buffer, we just go through it a character at a time,
  111. ;;; and create new extents when necessary (the extents we create span lines.)
  112. ;;;
  113. ;;; Each time a modification happens to a line, we remove all of the extents
  114. ;;; on that line (splitting line-spanning extents as necessary) and recompute
  115. ;;; the contexts for every character on the line.  This means that, as the
  116. ;;; user types, we repeatedly go back to the beginning of the line, doing more
  117. ;;; work the longer the line gets.  This happens in the buffer-syntactic-
  118. ;;; context subr, so it's plenty fast.
  119. ;;;
  120. ;;; We redo the whole line because that's a lot easier than dealing with the
  121. ;;; hair of modifying possibly-overlapping extents, and extents whose 
  122. ;;; endpoints were moved by the insertion we are reacting to.
  123. ;;;
  124. ;;; Extents as they now exist are not a good fit for this project, because
  125. ;;; extents talk about properties of *regions*, when what we want to talk
  126. ;;; about here are properties of *characters*.  
  127.  
  128. (defsubst font-lock-context-face (context depth)
  129.   (cond ((eq context 'comment) 'font-lock-comment-face)
  130.     ((eq context 'block-comment) 'font-lock-comment-face)
  131.     ((eq context 'string)
  132.      (if (= depth 1)
  133.          ;; really we should only use this if in position 3 depth 1, but
  134.          ;; that's too expensive to compute.
  135.          'font-lock-doc-string-face
  136.        'font-lock-string-face))
  137.     (t nil)))
  138.  
  139.  
  140. (defun font-lock-fontify-region (start end)
  141.   (goto-char start)
  142.   (if (> end (point-max)) (setq end (point-max)))
  143.   (syntactically-sectionize start end
  144.     (function
  145.      (lambda (extent context depth)
  146.        (set-extent-face extent (font-lock-context-face context depth))))
  147.    'font-lock))
  148.  
  149. (defun font-lock-unfontify-region (beg end)
  150.   ;; First delete all extents on this line (really, in this region).
  151.   ;; If extents span the line (region), divide them first so that
  152.   ;; previous and following lines are unaffected.
  153.   (let (s e extent2)
  154.     (map-extents
  155.      (function
  156.       (lambda (extent ignore)
  157.     (if (not (eq 'font-lock (extent-data extent)))
  158.         nil                ; if it's not ours, leave it alone...
  159.       (setq s (extent-start-position extent)
  160.         e (extent-end-position extent))
  161.       (cond ((< s beg)        ; starts before line
  162.          (set-extent-endpoints extent s (1- beg))
  163.          (if (> e (1+ end))    ; ...and ends after line
  164.              (progn
  165.                (setq extent2 (make-extent (1+ end) e))
  166.                (set-extent-face extent2 (extent-face extent))
  167.                (set-extent-data extent2 (extent-data extent)))))
  168.         ((> e (1+ end))        ; starts on line and ends after
  169.          (set-extent-endpoints extent (1+ end) e))
  170.         (t            ; contained on line
  171.          (delete-extent extent))))))
  172.      (current-buffer) beg end nil)))
  173.  
  174.  
  175. (defun font-lock-after-change-function (beg end old-len)
  176.   ;; called when any modification is made to buffer text.
  177.   (save-excursion
  178.     (let ((data (match-data))
  179.       (zmacs-region-stays zmacs-region-stays)) ; protect from change!
  180.       (goto-char beg)
  181.       (if (or (> old-len 0)        ; Deletions mean the cache is invalid.
  182.           (= (preceding-char) ?\n)    ; Insertions at bol/bob mean that the
  183.           (bobp))            ; bol cache might be invalid.
  184.       (buffer-syntactic-context-flush-cache))
  185.       (goto-char end)
  186.       (end-of-line)
  187.       (setq end (point))
  188.       (goto-char beg)
  189.       (beginning-of-line)
  190.       (setq beg (point))
  191.       (font-lock-unfontify-region beg end)
  192.       (font-lock-fontify-region beg (1+ end))
  193.       (font-lock-hack-keywords beg end)
  194.       ;; it would be bad if `insert' were to stomp the match data...
  195.       (store-match-data data))))
  196.  
  197.  
  198. ;;; Fontifying arbitrary patterns
  199.  
  200. (defsubst font-lock-any-extents-p (start end)
  201.   (catch 'done
  202.     (map-extents (function (lambda (extent ignore)
  203.                  (if (eq 'font-lock (extent-data extent))
  204.                  (throw 'done t))))
  205.          (current-buffer) start end nil)
  206.     nil))
  207.  
  208. (defun font-lock-hack-keywords (start end &optional loudly)
  209.   (goto-char start)
  210.   (let ((case-fold-search font-lock-keywords-case-fold-search)
  211.     (rest font-lock-keywords)
  212.     (count 0)
  213.     str match face s e extent allow-overlap-p)
  214.     (while rest
  215.       (goto-char start)
  216.       (cond ((consp (car rest))
  217.          (setq str (car (car rest)))
  218.          (cond ((consp (cdr (car rest)))
  219.             (setq match (car (cdr (car rest)))
  220.               face (car (cdr (cdr (car rest))))
  221.               allow-overlap-p (car (cdr (cdr (cdr (car rest)))))))
  222.            ((symbolp (cdr (car rest)))
  223.             (setq match 0 allow-overlap-p nil
  224.               face (cdr (car rest))))
  225.            (t
  226.             (setq match (cdr (car rest))
  227.               allow-overlap-p nil
  228.               face 'font-lock-keyword-face))))
  229.         (t
  230.          (setq str (car rest) match 0 allow-overlap-p nil
  231.            face 'font-lock-keyword-face)))
  232.       (while (re-search-forward str end t)
  233.     (setq s (match-beginning match)
  234.           e (match-end match))
  235.     (or s (error "expression did not match subexpression %d" match))
  236.     ;; don't fontify this keyword if we're already in some other context.
  237.     (or (if allow-overlap-p nil (font-lock-any-extents-p s e))
  238.         (progn
  239.           (setq extent (make-extent s e))
  240.           (set-extent-face extent face)
  241.           (set-extent-data extent 'font-lock))))
  242.       (if loudly (message (format "Fontifying %s... (regexps...%s)"
  243.                   (buffer-name)
  244.                   (make-string (setq count (1+ count)) ?.))))
  245.       (setq rest (cdr rest)))))
  246.  
  247.  
  248. ;; The user level functions
  249.  
  250. (defvar font-lock-mode nil) ; for modeline
  251. (or (assq 'font-lock-mode minor-mode-alist)
  252.     (setq minor-mode-alist
  253.       (purecopy
  254.        (append minor-mode-alist
  255.            '((font-lock-mode " Font-Lock"))))))
  256.  
  257. (defvar font-lock-fontified nil) ; whether we have hacked this buffer
  258. (put 'font-lock-fontified 'permanent-local t)
  259.  
  260. (defun font-lock-mode (&optional arg)
  261.   "Toggle Font Lock Mode.
  262. With arg, turn font-lock mode on if and only if arg is positive.
  263. In the font-lock minor mode, text is fontified as you type it:
  264.  
  265.  - comments are displayed in font-lock-comment-face;
  266.  - strings are displayed in font-lock-string-face;
  267.  - documentation strings are displayed in font-lock-doc-string-face;
  268.  - function and variable names in their defining forms are displayed
  269.    in font-lock-function-name-face;
  270.  - and certain other expressions are displayed in other faces
  271.    according to the value of the variable `font-lock-keywords'.
  272.  
  273. When font-lock mode is turned on/off, the buffer is fontified/defontified.
  274. To fontify a buffer without having newly typed text become fontified, you
  275. can use \\[font-lock-fontify-buffer]."
  276.   (interactive "P")
  277.   (let ((on-p (if (null arg)
  278.           (not font-lock-mode)
  279.         (> (prefix-numeric-value arg) 0))))
  280.     (if (equal (buffer-name) " *Compiler Input*") ; hack for bytecomp...
  281.     (setq on-p nil))
  282.     (or (memq after-change-function
  283.           '(nil font-lock-after-change-function))
  284.     (error "after-change-function is %s" after-change-function))
  285.     (set (make-local-variable 'after-change-function)
  286.      (if on-p 'font-lock-after-change-function nil))
  287.     (set (make-local-variable 'font-lock-mode) on-p)
  288.     (cond (on-p
  289.        (run-hooks 'font-lock-mode-hook)
  290.        (or font-lock-fontified (font-lock-fontify-buffer)))
  291.       (font-lock-fontified
  292.        (setq font-lock-fontified nil)
  293.        (font-lock-unfontify-region (point-min) (point-max))))
  294.     (redraw-mode-line)))
  295.  
  296.  
  297. (defun font-lock-fontify-buffer ()
  298.   "Fontify the current buffer the way `font-lock-mode' would:
  299.  
  300.  - comments are displayed in font-lock-comment-face;
  301.  - strings are displayed in font-lock-string-face;
  302.  - documentation strings are displayed in font-lock-doc-string-face;
  303.  - function and variable names in their defining forms are displayed
  304.    in font-lock-function-name-face;
  305.  - and certain other expressions are displayed in other faces
  306.    according to the value of the variable `font-lock-keywords'.
  307.  
  308. This can take a while for large buffers."
  309.   (interactive)
  310.   (let ((was-on font-lock-mode)
  311.     (font-lock-verbose (or font-lock-verbose (interactive-p))))
  312.     (if font-lock-verbose (message "Fontifying %s..." (buffer-name)))
  313.     ;; Turn it on to run hooks and get the right font-lock-keywords.
  314.     (or was-on (font-lock-mode 1))
  315.     (map-extents (function (lambda (x y)
  316.                  (if (eq 'font-lock (extent-data x))
  317.                  (delete-extent x))))
  318.          (current-buffer) (point-min) (point-max) nil)
  319.     (if font-lock-verbose (message "Fontifying %s... (syntactically...)"
  320.                    (buffer-name)))
  321.     (buffer-syntactic-context-flush-cache)
  322.     (save-excursion
  323.       (font-lock-fontify-region (point-min) (point-max))
  324.       (if font-lock-verbose (message "Fontifying %s... (regexps...)"
  325.                      (buffer-name)))
  326.       (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose))
  327.     (or was-on (font-lock-mode 0)) ; turn it off if it was off.
  328.     (set (make-local-variable 'font-lock-fontified) t)
  329.     (if font-lock-verbose (message "Fontifying %s... done." (buffer-name)))
  330.     ))
  331.  
  332.  
  333. ;;; various mode interfaces
  334.  
  335. (defconst lisp-font-lock-keywords-1
  336.  '(;;
  337.    ;; highlight defining forms.  This doesn't work too nicely for
  338.    ;; (defun (setf foo) ...) but it does work for (defvar foo) which
  339.    ;; is more important.
  340.    ("^(def[-a-z]+\\s +\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face)
  341.    ;;
  342.    ;; highlight CL keywords
  343.    ("\\s :\\(\\sw\\|\\s_\\)+\\>" . 1)
  344.    ;;
  345.    ;; this is highlights things like (def* (setf foo) (bar baz)), but may
  346.    ;; be slower (I haven't really thought about it)
  347. ;   ("^(def[-a-z]+\\s +\\(\\s(\\S)*\\s)\\|\\S(\\S *\\)"
  348. ;    1 font-lock-function-name-face)
  349.    )
  350.  "For consideration as a value of `lisp-font-lock-keywords'.
  351. This does fairly subdued highlighting.")
  352.  
  353. (defconst lisp-font-lock-keywords-2
  354.   (append
  355.    lisp-font-lock-keywords-1
  356.    '(;;
  357.      ;; Highlight control structures
  358.      ("(\\(cond\\|if\\|when\\|unless\\|[ec]?\\(type\\)?case\\)[ \t\n]" . 1)
  359.      ("(\\(while\\|do\\|let*?\\|flet\\|labels\\|prog[nv12*]?\\)[ \t\n]" . 1)
  360.      ("(\\(catch\\|\\throw\\|block\\|return\\|return-from\\)[ \t\n]" . 1)
  361.      ("(\\(save-restriction\\|save-window-restriction\\)[ \t\n]" . 1)
  362.      ("(\\(save-excursion\\|unwind-protect\\|condition-case\\)[ \t\n]" . 1)
  363.      ;;
  364.      ;; highlight function names in emacs-lisp docstrings (in the syntax
  365.      ;; that substitute-command-keys understands.)
  366.      ("\\\\\\\\\\[\\([^]\\\n]+\\)]" 1 font-lock-keyword-face t)
  367.      ;;
  368.      ;; highlight words inside `' which tend to be function names
  369.      ("`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'"
  370.       1 font-lock-keyword-face t)
  371.      ))
  372.  "For consideration as a value of `lisp-font-lock-keywords'.
  373. This does a lot more highlighting.")
  374.  
  375. ;; default to the gaudier variety?
  376. ;(defconst lisp-font-lock-keywords lisp-font-lock-keywords-2
  377. ;  "Additional expressions to highlight in lisp modes.")
  378. (defconst lisp-font-lock-keywords lisp-font-lock-keywords-1
  379.   "Additional expressions to highlight in lisp modes.")
  380.  
  381.  
  382. (defvar c-font-lock-keywords-1 nil
  383.  "For consideration as a value of `c-font-lock-keywords'.
  384. This does fairly subdued highlighting.")
  385.  
  386. (defvar c-font-lock-keywords-2 nil
  387.  "For consideration as a value of `c-font-lock-keywords'.
  388. This does a lot more highlighting.")
  389.  
  390. (let ((storage "auto\\|extern\\|register\\|static\\|volatile")
  391.       (prefixes "unsigned\\|short\\|long")
  392.       (types (concat "int\\|char\\|float\\|double\\|void\\|struct\\|"
  393.              "union\\|enum\\|typedef"))
  394.       (ctoken "\\(\\sw\\|\\s_\\|[:~*]\\)+")
  395.       )
  396.   (setq c-font-lock-keywords-1
  397.    (list
  398.     ;; fontify preprocessor directives as comments.
  399.     '("^#[ \t]*[a-z]+" . font-lock-comment-face)
  400.     ;;
  401.     ;; fontify names being defined.
  402.     '("^#[ \t]*\\(define\\|undef\\)[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 2
  403.       font-lock-function-name-face)
  404.     ;;
  405.     ;; fontify other preprocessor lines.
  406.     '("^#[ \t]*\\(if\\|ifn?def\\)[ \t]+\\([^\n]+\\)"
  407.       2 font-lock-function-name-face t)
  408.     ;;
  409.     ;; fontify the filename in #include <...>
  410.     ;; don't need to do this for #include "..." because those were
  411.     ;; already fontified as strings by the syntactic pass.
  412.     '("^#[ \t]*include[ \t]+<\\([^>\"\n]+\\)>" 1 font-lock-string-face)
  413.     ;;
  414.     ;; fontify the names of functions being defined.
  415.     ;; I think this should be fast because it's anchored at bol, but it's not.
  416.     (list (concat
  417.        "^\\(" ctoken "[ \t]+\\)?"    ; type specs; there can be no
  418.        "\\(" ctoken "[ \t]+\\)?"    ; more than 3 tokens, right?
  419.        "\\(" ctoken "[ \t]+\\)?"
  420.        "\\(\\*+[ \t]*\\)?"        ; pointer
  421.        ctoken "[ \t]*(")        ; name
  422.       8 'font-lock-function-name-face)
  423.     ;;
  424.     ;; This is faster but not by much.  I don't see why not.
  425. ;    (list (concat "^" ctoken "[ \t]*(") 1 'font-lock-function-name-face)
  426.     ;;
  427.     ;; Fontify structure names (in structure definition form).
  428.     (list (concat "^\\(typedef[ \t]+struct\\|struct\\|static[ \t]+struct\\)"
  429.           "[ \t]+" ctoken "[ \t]*\\(\{\\|$\\)")
  430.       2 'font-lock-function-name-face)
  431.     ;;
  432.     ;; Fontify case clauses.  This is fast because its anchored on the left.
  433.     '("case[ \t]+\\(\\sw\\|\\s_\\)+:". 1)
  434.     '("\\<\\(default\\):". 1)
  435.     ))
  436.  
  437.   (setq c-font-lock-keywords-2
  438.    (append c-font-lock-keywords-1
  439.     (list
  440.      ;;
  441.      ;; fontify all storage classes and type specifiers
  442.      (cons (concat "\\<\\(" storage "\\)\\>") 'font-lock-type-face)
  443.      (cons (concat "\\<\\(" types "\\)\\>") 'font-lock-type-face)
  444.      (cons (concat "\\<\\(" prefixes "[ \t]+" types "\\)\\>")
  445.        'font-lock-type-face)
  446.      ;;
  447.      ;; fontify all builtin tokens
  448.      (cons (concat
  449.         "[ \t]\\("
  450.         (mapconcat 'identity
  451.          '("for" "while" "do" "return" "goto" "case" "break" "switch"
  452.            "if" "then" "else if" "else" "return" "default" "continue"
  453.            "default"
  454.            )
  455.          "\\|")
  456.         "\\)[ \t\n(){};,]")
  457.        1)
  458.      ;;
  459.      ;; fontify case targets and goto-tags.  This is slow because the
  460.      ;; expression is anchored on the right.
  461.      "\\(\\sw\\|\\s_\\)+:"
  462.      ;;
  463.      ;; Fontify variables declared with structures, or typedef names.
  464.      '("}[ \t*]*\\(\\sw\\|\\s_\\)+[ \t]*[,;]" 1 font-lock-function-name-face)
  465.      ;;
  466.      ;; Fontify global variables without a type.
  467. ;     '("^\\([_a-zA-Z0-9:~*]+\\)[ \t]*[[;={]" 1 font-lock-function-name-face)
  468.  
  469.      )))
  470.   )
  471.  
  472.  
  473. ;; default to the gaudier variety?
  474. ;(defconst c-font-lock-keywords c-font-lock-keywords-2
  475. ;  "Additional expressions to highlight in C mode.")
  476. (defconst c-font-lock-keywords c-font-lock-keywords-1
  477.   "Additional expressions to highlight in C mode.")
  478.  
  479. (defconst c++-font-lock-keywords c-font-lock-keywords
  480.   "Additional expressions to highlight in C++ mode.")
  481.  
  482.  
  483. (defconst perl-font-lock-keywords
  484.   (list
  485.    (concat "[ \n\t{]*\\("
  486.        (mapconcat 'identity
  487.               '("if" "until" "while" "elsif" "else" "unless" "for"
  488.             "foreach" "continue" "exit" "die" "last" "goto" "next"
  489.             "redo" "return" "local" "exec")
  490.               "\\|")
  491.        "\\)[ \n\t;(]")
  492.    (mapconcat 'identity
  493.           '("#endif" "#else" "#ifdef" "#ifndef" "#if" "#include"
  494.         "#define" "#undef")
  495.           "\\|")
  496.    '("^[ \n\t]*sub[ \t]+\\([^ \t{]+\\)\\{" . font-lock-function-name-face)
  497.    '("[ \n\t{]*\\(eval\\)[ \n\t(;]" . font-lock-function-name-face)
  498.    '("\\(--- .* ---\\|=== .* ===\\)" . font-lock-doc-string-face)
  499.    )
  500.   "Additional expressions to highlight in Perl-mode.")
  501.  
  502. (defconst tex-font-lock-keywords
  503.   (list
  504.    '("\\(\\\\\\w+\\)" 1 font-lock-keyword-face t)
  505.    '("{\\\\em\\([^}]+\\)}" 1 font-lock-comment-face t)
  506.    '("{\\\\bf\\([^}]+\\)}" 1 font-lock-keyword-face t)
  507.    '("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face t)
  508.    '("\\\\\\(begin\\|end\\){\\([a-zA-Z0-9\\*]+\\)}"
  509.      2 font-lock-function-name-face t)
  510.    '("[^\\\\]\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
  511. ;   '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
  512.    )
  513.   "Additional expressions to highlight in TeX-mode.")
  514.  
  515. (defconst texi-font-lock-keywords
  516.   (list
  517.    "@\\(@\\|[^}\t \n{]+\\)"                    ;commands
  518.    '("^\\(@c\\|@comment\\)[ \t].*$" . font-lock-comment-face)    ;comments
  519.    '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t)    ;menu items
  520.    '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face t)
  521.    '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face t)
  522.    '("@\\(samp\\|code\\|var\\){\\([^}]+\\)" 2 font-lock-function-name-face t)
  523.    '("@\\(xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-keyword-face t)
  524.    '("@end *\\([a-zA-Z0-9]+\\)[ \t]*$" 1 font-lock-function-name-face t)
  525.    '("@item \\(.*\\)$" 1 font-lock-function-name-face t)
  526.    '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
  527.    )
  528.   "Additional expressions to highlight in TeXinfo-mode.")
  529.  
  530.  
  531. ;; Kludge
  532. (defun dummy-font-lock-mode-hook ()
  533.   "sets font-lock-keywords to something appropriate for this mode."
  534.   (setq font-lock-keywords
  535.     (cond ((eq major-mode 'lisp-mode)    lisp-font-lock-keywords)
  536.           ((eq major-mode 'emacs-lisp-mode)    lisp-font-lock-keywords)
  537.           ((eq major-mode 'c-mode)        c-font-lock-keywords)
  538.           ((eq major-mode 'c++-c-mode)    c-font-lock-keywords)
  539.           ((eq major-mode 'c++-mode)    c++-font-lock-keywords)
  540.           ((eq major-mode 'perl-mode)    perl-font-lock-keywords)
  541.           ((eq major-mode 'tex-mode)    tex-font-lock-keywords)
  542.           ((eq major-mode 'texinfo-mode)    texi-font-lock-keywords)
  543.           (t nil))))
  544.  
  545. (add-hook 'font-lock-mode-hook 'dummy-font-lock-mode-hook)
  546.