;;; font-lock.el --- Electric font lock mode
;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-;; 2000, 2001, 2002, 2003, 2004 2005 Free Software Foundation, Inc.
+;; 2000, 2001, 2002, 2003, 2004 2005 Free Software Foundation, Inc.
;; Author: jwz, then rms, then sm
;; Maintainer: FSF
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
(defgroup font-lock-extra-types nil
"Extra mode-specific type names for highlighting declarations."
:group 'font-lock)
-
-;; Define support mode groups here to impose `font-lock' group order.
-(defgroup fast-lock nil
- "Font Lock support mode to cache fontification."
- :load 'fast-lock
- :group 'font-lock)
-
-(defgroup lazy-lock nil
- "Font Lock support mode to fontify lazily."
- :load 'lazy-lock
- :group 'font-lock)
\f
;; User variables.
(integer :tag "size"))
:group 'font-lock)
-(defcustom font-lock-lines-before 1
+(defcustom font-lock-lines-before 0
"*Number of lines before the changed text to include in refontification."
:type 'integer
:group 'font-lock
the search, as for MATCH-HIGHLIGHT above, but with one exception; see below.
PRE-MATCH-FORM and POST-MATCH-FORM are evaluated before the first, and after
the last, instance MATCH-ANCHORED's MATCHER is used. Therefore they can be
-used to initialise before, and cleanup after, MATCHER is used. Typically,
+used to initialize before, and cleanup after, MATCHER is used. Typically,
PRE-MATCH-FORM is used to move to some position relative to the original
MATCHER, before starting with MATCH-ANCHORED's MATCHER. POST-MATCH-FORM might
be used to move back, before resuming with MATCH-ANCHORED's parent's MATCHER.
;; We use this to preserve or protect things when modifying text properties.
(defmacro save-buffer-state (varlist &rest body)
"Bind variables according to VARLIST and eval BODY restoring buffer state."
+ (declare (indent 1) (debug let))
(let ((modified (make-symbol "modified")))
`(let* ,(append varlist
`((,modified (buffer-modified-p))
,@body)
(unless ,modified
(restore-buffer-modified-p nil)))))
- (put 'save-buffer-state 'lisp-indent-function 1)
- (def-edebug-spec save-buffer-state let)
;;
;; Shut up the byte compiler.
(defvar font-lock-face-attributes)) ; Obsolete but respected if set.
(add-hook 'c-mode-hook
(lambda ()
- (font-lock-add-keywords 'c-mode
+ (font-lock-add-keywords nil
'((\"\\\\\\=<\\\\(FIXME\\\\):\" 1 font-lock-warning-face prepend)
(\"\\\\\\=<\\\\(and\\\\|or\\\\|not\\\\)\\\\\\=>\" .
font-lock-keyword-face)))))
'font-lock-after-change-function t)
(set (make-local-variable 'font-lock-fontify-buffer-function)
'jit-lock-refontify)
- ;; Don't fontify eagerly (and don't abort is the buffer is large).
+ ;; Don't fontify eagerly (and don't abort if the buffer is large).
(set (make-local-variable 'font-lock-fontified) t)
;; Use jit-lock.
(jit-lock-register 'font-lock-fontify-region
;; Use the fontification syntax table, if any.
(when font-lock-syntax-table
(set-syntax-table font-lock-syntax-table))
+ (goto-char beg)
+ (setq beg (line-beginning-position (- 1 font-lock-lines-before)))
;; check to see if we should expand the beg/end area for
;; proper multiline matches
(when (and font-lock-multiline
(save-match-data
;; Rescan between start of lines enclosing the region.
(font-lock-fontify-region
- (progn (goto-char beg)
- (forward-line (- font-lock-lines-before)) (point))
+ (progn (goto-char beg) (forward-line 0) (point))
(progn (goto-char end) (forward-line 1) (point)))))))
(defun font-lock-fontify-block (&optional arg)
(while (and (< (point) end)
(if (stringp matcher)
(re-search-forward matcher end t)
- (funcall matcher end)))
+ (funcall matcher end))
+ ;; Beware empty string matches since they will
+ ;; loop indefinitely.
+ (or (> (point) (match-beginning 0))
+ (progn (forward-char 1) t)))
(when (and font-lock-multiline
(>= (point)
(save-excursion (goto-char (match-beginning 0))
"Font Lock mode face used to highlight preprocessor directives."
:group 'font-lock-highlighting-faces)
+(defface font-lock-regexp-grouping-backslash
+ '((t :inherit bold))
+ "Font Lock mode face for backslashes in Lisp regexp grouping constructs."
+ :group 'font-lock-highlighting-faces)
+
+(defface font-lock-regexp-grouping-construct
+ '((t :inherit bold))
+ "Font Lock mode face used to highlight grouping constructs in Lisp regexps."
+ :group 'font-lock-highlighting-faces)
+
;;; End of Colour etc. support.
\f
;;; Menu support.
`(;; Control structures. Emacs Lisp forms.
(,(concat
"(" (regexp-opt
- '("cond" "if" "while" "let" "let*"
+ '("cond" "if" "while" "while-no-input" "let" "let*"
"prog" "progn" "progv" "prog1" "prog2" "prog*"
"inline" "lambda" "save-restriction" "save-excursion"
"save-window-excursion" "save-selected-window"
("\\<:\\sw+\\>" 0 font-lock-builtin-face)
;; ELisp and CLisp `&' keywords as types.
("\\&\\sw+\\>" . font-lock-type-face)
- ;; Make regexp grouping constructs bold, so they stand out, but only
- ;; in strings.
+ ;; ELisp regexp grouping constructs
((lambda (bound)
- (if (re-search-forward "\\(\\\\\\\\\\)\\([(|)]\\)\\(\\?:\\)?" bound t)
- (let ((face (get-text-property (1- (point)) 'face)))
- (if (listp face)
- (memq 'font-lock-string-face face)
- (eq 'font-lock-string-face face)))))
- ;; Should we introduce a lowlight face for this?
- ;; Ideally that would retain the color, dimmed.
- (1 font-lock-comment-face prepend)
- (2 'bold prepend)
- (3 font-lock-type-face prepend t))
- ;; Underline innermost grouping, so that you can more easily see what
- ;; belongs together. 2005-05-12: Font-lock can go into an
- ;; unbreakable endless loop on this -- something's broken.
- ;;("[\\][\\][(]\\(?:\\?:\\)?\\(\\(?:[^\\\"]+\\|[\\]\\(?:[^\\]\\|[\\][^(]\\)\\)+?\\)[\\][\\][)]"
- ;;1 'underline prepend)
+ (catch 'found
+ ;; The following loop is needed to continue searching after matches
+ ;; that do not occur in strings. The associated regexp matches one
+ ;; of `\\\\' `\\(' `\\(?:' `\\|' `\\)'. `\\\\' has been included to
+ ;; avoid highlighting, for example, `\\(' in `\\\\('.
+ (while (re-search-forward "\\(\\\\\\\\\\)\\(?:\\(\\\\\\\\\\)\\|\\((\\(?:\\?:\\)?\\|[|)]\\)\\)" bound t)
+ (unless (match-beginning 2)
+ (let ((face (get-text-property (1- (point)) 'face)))
+ (when (or (and (listp face)
+ (memq 'font-lock-string-face face))
+ (eq 'font-lock-string-face face))
+ (throw 'found t)))))))
+ (1 'font-lock-regexp-grouping-backslash prepend)
+ (3 'font-lock-regexp-grouping-construct prepend))
;;; This is too general -- rms.
;;; A user complained that he has functions whose names start with `do'
;;; and that they get the wrong color.