comparison lisp/font-lock.el @ 404:2f8bb876ab1d r21-2-32

Import from CVS: tag r21-2-32
author cvs
date Mon, 13 Aug 2007 11:16:07 +0200
parents a86b2b5e0111
children b8cc9ab3f761
comparison
equal deleted inserted replaced
403:9f011ab08d48 404:2f8bb876ab1d
582 font-lock-type-face 582 font-lock-type-face
583 font-lock-reference-face 583 font-lock-reference-face
584 font-lock-preprocessor-face 584 font-lock-preprocessor-face
585 font-lock-warning-face)) 585 font-lock-warning-face))
586 586
587 ;; #### There should be an emulation for the old font-lock-use-*
588 ;; settings!
589
590 (defface font-lock-comment-face 587 (defface font-lock-comment-face
591 '((((class color) (background dark)) (:foreground "gray80")) 588 '((((class color) (background dark)) (:foreground "gray80"))
589 ;; blue4 is hardly different from black on windows.
590 (((class color) (background light) (type mswindows)) (:foreground "blue"))
592 (((class color) (background light)) (:foreground "blue4")) 591 (((class color) (background light)) (:foreground "blue4"))
593 (((class grayscale) (background light)) 592 (((class grayscale) (background light))
594 (:foreground "DimGray" :bold t :italic t)) 593 (:foreground "DimGray" :bold t :italic t))
595 (((class grayscale) (background dark)) 594 (((class grayscale) (background dark))
596 (:foreground "LightGray" :bold t :italic t)) 595 (:foreground "LightGray" :bold t :italic t))
618 on the major mode's symbol." 617 on the major mode's symbol."
619 :group 'font-lock-faces) 618 :group 'font-lock-faces)
620 619
621 (defface font-lock-keyword-face 620 (defface font-lock-keyword-face
622 '((((class color) (background dark)) (:foreground "cyan")) 621 '((((class color) (background dark)) (:foreground "cyan"))
622 ;; red4 is hardly different from black on windows.
623 (((class color) (background light) (type mswindows)) (:foreground "red"))
623 (((class color) (background light)) (:foreground "red4")) 624 (((class color) (background light)) (:foreground "red4"))
624 (((class grayscale) (background light)) (:foreground "LightGray" :bold t)) 625 (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
625 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) 626 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
626 (t (:bold t))) 627 (t (:bold t)))
627 "Font Lock mode face used to highlight keywords." 628 "Font Lock mode face used to highlight keywords."
628 :group 'font-lock-faces) 629 :group 'font-lock-faces)
629 630
630 (defface font-lock-function-name-face 631 (defface font-lock-function-name-face
631 '((((class color) (background dark)) (:foreground "aquamarine")) 632 '((((class color) (background dark)) (:foreground "aquamarine"))
633 ;; brown4 is hardly different from black on windows.
634 ;; I changed it to red because IMO it's pointless and ugly to
635 ;; use a million slightly different colors for niggly syntactic
636 ;; differences. --ben
637 (((class color) (background light) (type mswindows)) (:foreground "red"))
632 (((class color) (background light)) (:foreground "brown4")) 638 (((class color) (background light)) (:foreground "brown4"))
633 (t (:bold t :underline t))) 639 (t (:bold t :underline t)))
634 "Font Lock mode face used to highlight function names." 640 "Font Lock mode face used to highlight function names."
635 :group 'font-lock-faces) 641 :group 'font-lock-faces)
636 642
832 (cond (font-lock-fontified 838 (cond (font-lock-fontified
833 nil) 839 nil)
834 ((or (null maximum-size) (<= (buffer-size) maximum-size)) 840 ((or (null maximum-size) (<= (buffer-size) maximum-size))
835 (font-lock-fontify-buffer)) 841 (font-lock-fontify-buffer))
836 (font-lock-verbose 842 (font-lock-verbose
837 (lmessage 'command "Fontifying %s... buffer too big." 843 (lprogress-display 'font-lock
838 (buffer-name))))) 844 "Fontifying %s... buffer too big." 'abort
845 (buffer-name)))))
839 (font-lock-fontified 846 (font-lock-fontified
840 (setq font-lock-fontified nil) 847 (setq font-lock-fontified nil)
841 (remove-hook 'before-revert-hook 'font-lock-revert-setup t) 848 (remove-hook 'before-revert-hook 'font-lock-revert-setup t)
842 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup t) 849 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup t)
843 (font-lock-unfontify-region (point-min) (point-max)) 850 (font-lock-unfontify-region (point-min) (point-max))
994 ;; the interrupt character at inopportune times. 1001 ;; the interrupt character at inopportune times.
995 ;; 1002 ;;
996 (condition-case nil 1003 (condition-case nil
997 (save-excursion 1004 (save-excursion
998 (font-lock-fontify-region (point-min) (point-max))) 1005 (font-lock-fontify-region (point-min) (point-max)))
999 (quit 1006 (t
1000 (setq aborted t))) 1007 (setq aborted t)))
1001 1008
1002 (or was-on ; turn it off if it was off. 1009 (or was-on ; turn it off if it was off.
1003 (let ((font-lock-fontified nil)) ; kludge to prevent defontification 1010 (let ((font-lock-fontified nil)) ; kludge to prevent defontification
1004 (font-lock-mode 0))) 1011 (font-lock-mode 0)))
1005 (set (make-local-variable 'font-lock-fontified) t) 1012 (set (make-local-variable 'font-lock-fontified) t)
1006 (when (and aborted font-lock-verbose) 1013 (when (and aborted font-lock-verbose)
1007 (lmessage 'command "Fontifying %s... aborted." (buffer-name)))) 1014 (lprogress-display 'font-lock "Fontifying %s... aborted." 'abort (buffer-name))))
1008 (run-hooks 'font-lock-after-fontify-buffer-hook)) 1015 (run-hooks 'font-lock-after-fontify-buffer-hook))
1009 1016
1010 (defun font-lock-default-unfontify-buffer () 1017 (defun font-lock-default-unfontify-buffer ()
1011 (font-lock-unfontify-region (point-min) (point-max)) 1018 (font-lock-unfontify-region (point-min) (point-max))
1012 (set (make-local-variable 'font-lock-fontified) nil)) 1019 (set (make-local-variable 'font-lock-fontified) nil))
1041 ; (font-lock-fontify-keywords-region beg end)) 1048 ; (font-lock-fontify-keywords-region beg end))
1042 1049
1043 (defun font-lock-default-unfontify-region (beg end &optional maybe-loudly) 1050 (defun font-lock-default-unfontify-region (beg end &optional maybe-loudly)
1044 (when (and maybe-loudly font-lock-verbose 1051 (when (and maybe-loudly font-lock-verbose
1045 (>= (- end beg) font-lock-message-threshold)) 1052 (>= (- end beg) font-lock-message-threshold))
1046 (lmessage 'progress "Fontifying %s..." (buffer-name))) 1053 (lprogress-display 'font-lock "Fontifying %s..." 0 (buffer-name)))
1047 (let ((modified (buffer-modified-p)) 1054 (let ((modified (buffer-modified-p))
1048 (buffer-undo-list t) (inhibit-read-only t) 1055 (buffer-undo-list t) (inhibit-read-only t)
1049 buffer-file-name buffer-file-truename) 1056 buffer-file-name buffer-file-truename)
1050 (font-lock-remove-face beg end) 1057 (font-lock-remove-face beg end)
1051 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))) 1058 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil))))
1303 START should be at the beginning of a line." 1310 START should be at the beginning of a line."
1304 (if font-lock-keywords-only 1311 (if font-lock-keywords-only
1305 nil 1312 nil
1306 (when (and font-lock-verbose 1313 (when (and font-lock-verbose
1307 (>= (- end start) font-lock-message-threshold)) 1314 (>= (- end start) font-lock-message-threshold))
1308 (lmessage 'progress "Fontifying %s... (syntactically...)" 1315 (lprogress-display 'font-lock "Fontifying %s... (syntactically)" 5
1309 (buffer-name))) 1316 (buffer-name)))
1310 (font-lock-unfontify-region start end loudly) 1317 (font-lock-unfontify-region start end loudly)
1311 (goto-char start) 1318 (goto-char start)
1312 (if (> end (point-max)) (setq end (point-max))) 1319 (if (> end (point-max)) (setq end (point-max)))
1313 (let ((lisp-like (font-lock-lisp-like major-mode))) 1320 (let ((lisp-like (font-lock-lisp-like major-mode)))
1314 (syntactically-sectionize 1321 (syntactically-sectionize
1491 (>= (- end start) font-lock-message-threshold)))) 1498 (>= (- end start) font-lock-message-threshold))))
1492 (let ((case-fold-search font-lock-keywords-case-fold-search) 1499 (let ((case-fold-search font-lock-keywords-case-fold-search)
1493 (keywords (cdr (if (eq (car-safe font-lock-keywords) t) 1500 (keywords (cdr (if (eq (car-safe font-lock-keywords) t)
1494 font-lock-keywords 1501 font-lock-keywords
1495 (font-lock-compile-keywords)))) 1502 (font-lock-compile-keywords))))
1496 (bufname (buffer-name)) (count 0) 1503 (bufname (buffer-name)) (count 5)
1497 keyword matcher highlights) 1504 keyword matcher highlights)
1498 ;; 1505 ;;
1499 ;; Fontify each item in `font-lock-keywords' from `start' to `end'. 1506 ;; Fontify each item in `font-lock-keywords' from `start' to `end'.
1500 (while keywords 1507 (while keywords
1501 (when loudly (lmessage 'progress "Fontifying %s... (regexps..%s)" 1508 (when loudly (lprogress-display 'font-lock "Fontifying %s... (regexps)"
1502 bufname 1509 (setq count (+ count 5)) bufname))
1503 (make-string (setq count (1+ count)) ?.)))
1504 ;; 1510 ;;
1505 ;; Find an occurrence of `matcher' from `start' to `end'. 1511 ;; Find an occurrence of `matcher' from `start' to `end'.
1506 (setq keyword (car keywords) matcher (car keyword)) 1512 (setq keyword (car keywords) matcher (car keyword))
1507 (goto-char start) 1513 (goto-char start)
1508 (while (and (< (point) end) 1514 (while (and (< (point) end)
1521 ;; expressions. 1527 ;; expressions.
1522 (and end (goto-char end))) 1528 (and end (goto-char end)))
1523 (font-lock-fontify-anchored-keywords (car highlights) end)) 1529 (font-lock-fontify-anchored-keywords (car highlights) end))
1524 (setq highlights (cdr highlights)))) 1530 (setq highlights (cdr highlights))))
1525 (setq keywords (cdr keywords)))) 1531 (setq keywords (cdr keywords))))
1526 (if loudly (lmessage 'progress "Fontifying %s... done." (buffer-name))))) 1532 (if loudly (lprogress-display 'font-lock "Fontifying %s... " 100 (buffer-name)))))
1527 1533
1528 1534
1529 ;; Various functions. 1535 ;; Various functions.
1530 1536
1531 ;; Turn off other related packages if they're on. I prefer a hook. --sm. 1537 ;; Turn off other related packages if they're on. I prefer a hook. --sm.
1546 (fast-lock-after-fontify-buffer)) 1552 (fast-lock-after-fontify-buffer))
1547 ((and (boundp 'lazy-lock-mode) lazy-lock-mode) 1553 ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
1548 (lazy-lock-after-fontify-buffer)))) 1554 (lazy-lock-after-fontify-buffer))))
1549 1555
1550 ;; If the buffer is about to be reverted, it won't be fontified afterward. 1556 ;; If the buffer is about to be reverted, it won't be fontified afterward.
1551 (defun font-lock-revert-setup () 1557 ;(defun font-lock-revert-setup ()
1552 (setq font-lock-fontified nil)) 1558 ; (setq font-lock-fontified nil))
1553 1559
1554 ;; If the buffer has just been reverted, normally that turns off 1560 ;; If the buffer has just been reverted, normally that turns off
1555 ;; Font Lock mode. So turn the mode back on if necessary. 1561 ;; Font Lock mode. So turn the mode back on if necessary.
1556 ;; sb 1999-03-03 -- The above comment no longer appears to be operative as 1562 ;; sb 1999-03-03 -- The above comment no longer appears to be operative as
1557 ;; the first call to normal-mode *will* restore the font-lock state and 1563 ;; the first call to normal-mode *will* restore the font-lock state and
1558 ;; this call forces a second font-locking to occur when reverting a buffer, 1564 ;; this call forces a second font-locking to occur when reverting a buffer,
1559 ;; which is wasteful at best. 1565 ;; which is wasteful at best.
1560 ;(defalias 'font-lock-revert-cleanup 'turn-on-font-lock) 1566 ;;(defun font-lock-revert-cleanup ())
1561 (defun font-lock-revert-cleanup ()) 1567
1568 ;; <andy@xemacs.org> 12-10-99. This still does not work right, I think
1569 ;; after change functions will still get us. The simplest thing to do
1570 ;; is unconditionally turn-off font-lock before revert (and thus nuke
1571 ;; all hooks) and then turn it on again afterwards. This also happens
1572 ;; to be much faster because fontifying from scratch is better than
1573 ;; trying to do incremental changes for the whole buffer.
1574
1575 (defalias 'font-lock-revert-cleanup 'turn-on-font-lock)
1576 (defalias 'font-lock-revert-setup 'turn-off-font-lock)
1562 1577
1563 1578
1564 ;; Various functions. 1579 ;; Various functions.
1565 1580
1566 (defun font-lock-compile-keywords (&optional keywords) 1581 (defun font-lock-compile-keywords (&optional keywords)