home *** CD-ROM | disk | FTP | other *** search
- I don't have any objection to making it possible to specify extent priorities
- and other things in font-lock mode, so long as it doesn't slow down the simple
- cases. But I don't see the things that you currently can't do as being very
- much of a limitation, so someone who disagrees should write the code and send
- it to me.
-
- (Instead of parsing font-lock-keywords in place, it might be worth considering
- having the format of font-lock-keywords be human-readable, perhaps with
- keyword instead of positional arguments, and have font-lock mode internally
- compile it to a form that is faster to traverse at fontification time.)
-
- Here's a patch against the 19.6 version of font-lock.el that fixes a few minor
- bugs, and adds highlighting for dired buffers.
-
- -- Jamie
-
- *** /cadillac-th2/lemacs-19.6/lisp/packages/font-lock.el Wed Mar 24 15:17:19 1993
- --- font-lock.el Sat Apr 17 16:27:36 1993
- ***************
- *** 28,33 ****
- --- 28,38 ----
- ;; displayed in `font-lock-function-name-face'.
- ;; Reserved words will be displayed in `font-lock-keyword-face'.
- ;;
- + ;; Don't let the name fool you: you can highlight things using different
- + ;; colors or background stipples instead of fonts, though that is not the
- + ;; default. See the documentation on faces and how to change their
- + ;; attributes.
- + ;;
- ;; To make the text you type be fontified, use M-x font-lock-mode.
- ;; When this minor mode is on, the fonts of the current line will be
- ;; updated with every insertion or deletion.
- ***************
- *** 36,52 ****
- ;; The default font-lock-mode-hook sets it to the value of the variables
- ;; lisp-font-lock-keywords, c-font-lock-keywords, etc, as appropriate.
- ;; The easiest way to change the highlighting patterns is to change the
- ! ;; values of c-font-lock-keywords and related variables.
- ;;
- ;; To turn this on automatically, add this to your .emacs file:
- ;;
- ;; (setq emacs-lisp-mode-hook '(lambda () (font-lock-mode 1)))
- ;;
- ;; On a Sparc2, the initial fontification takes about 12 seconds for a 120k
- ;; file of C code, using the default configuration. You can speed this up
- ;; substantially by removing some of the patterns that are highlighted by
- ;; default. Fontifying lisp code is significantly faster, because lisp has a
- ;; more regular syntax than C, so the expressions don't have to be as hairy.
-
-
- (make-face 'font-lock-comment-face)
- --- 41,71 ----
- ;; The default font-lock-mode-hook sets it to the value of the variables
- ;; lisp-font-lock-keywords, c-font-lock-keywords, etc, as appropriate.
- ;; The easiest way to change the highlighting patterns is to change the
- ! ;; values of c-font-lock-keywords and related variables. See the doc
- ! ;; string of the variable `font-lock-keywords' for the appropriate syntax.
- ;;
- ;; To turn this on automatically, add this to your .emacs file:
- ;;
- ;; (setq emacs-lisp-mode-hook '(lambda () (font-lock-mode 1)))
- + ;; (setq c-mode-hook '(lambda () (font-lock-mode 1)))
- + ;; (setq c++-mode-hook '(lambda () (font-lock-mode 1)))
- + ;; (setq dired-mode-hook '(lambda () (font-lock-mode 1)))
- ;;
- + ;; and so on.
- + ;;
- ;; On a Sparc2, the initial fontification takes about 12 seconds for a 120k
- ;; file of C code, using the default configuration. You can speed this up
- ;; substantially by removing some of the patterns that are highlighted by
- ;; default. Fontifying lisp code is significantly faster, because lisp has a
- ;; more regular syntax than C, so the expressions don't have to be as hairy.
- + ;;
- + ;; The default value for `lisp-font-lock-keywords' is the value of the variable
- + ;; `lisp-font-lock-keywords-1'. You may like `lisp-font-lock-keywords-2'
- + ;; better; it highlights many more words, but is slower and makes your buffers
- + ;; be very visually noisy.
- + ;;
- + ;; The same is true of `c-font-lock-keywords-1' and `c-font-lock-keywords-2';
- + ;; the former is subdued, the latter is loud.
-
-
- (make-face 'font-lock-comment-face)
- ***************
- *** 137,150 ****
- (t nil)))
-
-
- (defun font-lock-fontify-region (start end)
- ! (goto-char start)
- ! (if (> end (point-max)) (setq end (point-max)))
- ! (syntactically-sectionize start end
- ! (function
- ! (lambda (extent context depth)
- ! (set-extent-face extent (font-lock-context-face context depth))))
- ! 'font-lock))
-
- (defun font-lock-unfontify-region (beg end)
- ;; First delete all extents on this line (really, in this region).
- --- 156,179 ----
- (t nil)))
-
-
- + (defvar font-lock-use-syntax-tables t
- + "Whether font-lock should bother doing syntactic fontification.
- + This should be true for all ``language'' modes, but other modes, like
- + dired, do not have anything useful in the syntax tables (no comment
- + or string delimiters, etc) and so there is no need to use them.
- + You should not set this variable; its value is automatically computed
- + by examining the syntax table.")
- +
- (defun font-lock-fontify-region (start end)
- ! (if (not font-lock-use-syntax-tables)
- ! nil
- ! (goto-char start)
- ! (if (> end (point-max)) (setq end (point-max)))
- ! (syntactically-sectionize start end
- ! (function
- ! (lambda (extent context depth)
- ! (set-extent-face extent (font-lock-context-face context depth))))
- ! 'font-lock)))
-
- (defun font-lock-unfontify-region (beg end)
- ;; First delete all extents on this line (really, in this region).
- ***************
- *** 272,278 ****
-
- When font-lock mode is turned on/off, the buffer is fontified/defontified.
- To fontify a buffer without having newly typed text become fontified, you
- ! can use \\[font-lock-fontify-buffer]."
- (interactive "P")
- (let ((on-p (if (null arg)
- (not font-lock-mode)
- --- 301,309 ----
-
- When font-lock mode is turned on/off, the buffer is fontified/defontified.
- To fontify a buffer without having newly typed text become fontified, you
- ! can use \\[font-lock-fontify-buffer].
- !
- ! See the variable `font-lock-keywords' for customization."
- (interactive "P")
- (let ((on-p (if (null arg)
- (not font-lock-mode)
- ***************
- *** 281,287 ****
- (setq on-p nil))
- (or (memq after-change-function
- '(nil font-lock-after-change-function))
- ! (error "after-change-function is %s" after-change-function))
- (set (make-local-variable 'after-change-function)
- (if on-p 'font-lock-after-change-function nil))
- (set (make-local-variable 'font-lock-mode) on-p)
- --- 312,319 ----
- (setq on-p nil))
- (or (memq after-change-function
- '(nil font-lock-after-change-function))
- ! (error "after-change-function is %S" after-change-function))
- ! (if on-p (font-lock-examine-syntax-table))
- (set (make-local-variable 'after-change-function)
- (if on-p 'font-lock-after-change-function nil))
- (set (make-local-variable 'font-lock-mode) on-p)
- ***************
- *** 312,321 ****
- (if font-lock-verbose (message "Fontifying %s..." (buffer-name)))
- ;; Turn it on to run hooks and get the right font-lock-keywords.
- (or was-on (font-lock-mode 1))
- ! (map-extents (function (lambda (x y)
- ! (if (eq 'font-lock (extent-data x))
- ! (delete-extent x))))
- ! (current-buffer) (point-min) (point-max) nil)
- (if font-lock-verbose (message "Fontifying %s... (syntactically...)"
- (buffer-name)))
- (buffer-syntactic-context-flush-cache)
- --- 344,350 ----
- (if font-lock-verbose (message "Fontifying %s..." (buffer-name)))
- ;; Turn it on to run hooks and get the right font-lock-keywords.
- (or was-on (font-lock-mode 1))
- ! (font-lock-unfontify-region (point-min) (point-max))
- (if font-lock-verbose (message "Fontifying %s... (syntactically...)"
- (buffer-name)))
- (buffer-syntactic-context-flush-cache)
- ***************
- *** 324,334 ****
- (if font-lock-verbose (message "Fontifying %s... (regexps...)"
- (buffer-name)))
- (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose))
- ! (or was-on (font-lock-mode 0)) ; turn it off if it was off.
- (set (make-local-variable 'font-lock-fontified) t)
- (if font-lock-verbose (message "Fontifying %s... done." (buffer-name)))
- ))
-
-
- ;;; various mode interfaces
-
- --- 353,382 ----
- (if font-lock-verbose (message "Fontifying %s... (regexps...)"
- (buffer-name)))
- (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose))
- ! (or was-on ; turn it off if it was off.
- ! (let ((font-lock-fontified nil)) ; kludge to prevent defontification
- ! (font-lock-mode 0)))
- (set (make-local-variable 'font-lock-fontified) t)
- (if font-lock-verbose (message "Fontifying %s... done." (buffer-name)))
- ))
-
- + (defun font-lock-examine-syntax-table ()
- + "Computes the value of font-lock-use-syntax-tables for this buffer."
- + (let ((i (1- (length (syntax-table))))
- + (got-one nil))
- + (if (eq (syntax-table) (standard-syntax-table))
- + ;; Assume that modes which haven't bothered to install their own
- + ;; syntax table don't do anything syntactically interesting.
- + ;; Really, the standard-syntax-table shouldn't have comments and
- + ;; strings in it, but changing that now might break things.
- + nil
- + ;; else map over the syntax table looking for strings or comments.
- + (while (>= i 0)
- + (if (memq (char-syntax i) '(?\" ?\< ?\> ?\$))
- + (setq got-one t i 0))
- + (setq i (1- i))))
- + (set (make-local-variable 'font-lock-use-syntax-tables) got-one)))
- +
-
- ;;; various mode interfaces
-
- ***************
- *** 527,536 ****
- )
- "Additional expressions to highlight in TeXinfo-mode.")
-
-
- ;; Kludge
- (defun dummy-font-lock-mode-hook ()
- ! "sets font-lock-keywords to something appropriate for this mode."
- (setq font-lock-keywords
- (cond ((eq major-mode 'lisp-mode) lisp-font-lock-keywords)
- ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords)
- --- 575,599 ----
- )
- "Additional expressions to highlight in TeXinfo-mode.")
-
- + (defconst dired-font-lock-keywords
- + (let ((bn (concat "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|"
- + "Aug\\|Sep\\|Oct\\|Nov\\|Dec\\) +[0-9]+ +[0-9:]+")))
- + (list
- + '("^ [/~].*:$" . bold-italic) ; Header
- + (list (concat "^\\(\\([^ ].*\\)" bn "\\) \\(.*\\)$") 1 'bold) ; Marked
- + (list (concat "^. +d.*" bn " \\(.*\\)$") 2 'bold) ; Subdirs
- + (list (concat "^. +l.*" bn " \\(.*\\)$") 2 'italic) ; Links
- + (cons (concat "^. +-..[xsS]......\\|" ; Regular files with executable
- + "^. +-.....[xsS]...\\|" ; or setuid/setgid bits set
- + "^. +-........[xsS]")
- + 'bold)
- + ))
- + "Expressions to highlight in Dired buffers.")
- +
-
- ;; Kludge
- (defun dummy-font-lock-mode-hook ()
- ! "Sets font-lock-keywords to something appropriate for this mode."
- (setq font-lock-keywords
- (cond ((eq major-mode 'lisp-mode) lisp-font-lock-keywords)
- ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords)
- ***************
- *** 540,545 ****
- ((eq major-mode 'perl-mode) perl-font-lock-keywords)
- ((eq major-mode 'tex-mode) tex-font-lock-keywords)
- ((eq major-mode 'texinfo-mode) texi-font-lock-keywords)
- ! (t nil))))
-
- (add-hook 'font-lock-mode-hook 'dummy-font-lock-mode-hook)
- --- 603,609 ----
- ((eq major-mode 'perl-mode) perl-font-lock-keywords)
- ((eq major-mode 'tex-mode) tex-font-lock-keywords)
- ((eq major-mode 'texinfo-mode) texi-font-lock-keywords)
- ! ((eq major-mode 'dired-mode) dired-font-lock-keywords)
- ! (t font-lock-keywords))))
-
- (add-hook 'font-lock-mode-hook 'dummy-font-lock-mode-hook)
-
-