diff options
| -rw-r--r-- | lisp/ChangeLog | 18 | ||||
| -rw-r--r-- | lisp/font-lock.el | 130 |
2 files changed, 53 insertions, 95 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a8a1ffd790e..045122f2e41 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,21 @@ | |||
| 1 | 2000-11-02 Stefan Monnier <monnier@cs.yale.edu> | ||
| 2 | |||
| 3 | * font-lock.el (font-lock-buffers): Remove. | ||
| 4 | (font-lock-global-modes): Define with easy-mmode-define-global-mode. | ||
| 5 | (font-lock-change-major-mode): Remove. | ||
| 6 | (turn-on-font-lock-if-enabled): Only apply to the current buffer. | ||
| 7 | (font-lock-default-fontify-region): Extend the multiline | ||
| 8 | fontification to whole lines. | ||
| 9 | (font-lock-fontify-anchored-keywords) | ||
| 10 | (font-lock-fontify-keywords-region): If matching just one | ||
| 11 | line (with \n) only mark the \n as multiline. | ||
| 12 | |||
| 13 | * emacs-lisp/easy-mmode.el (define-minor-mode): Remove :toggle arg. | ||
| 14 | Correctly handle the case where several :group args are supplied. | ||
| 15 | Allow :extra-args. | ||
| 16 | (easy-mmode-define-global-mode): Allow :extra-args. | ||
| 17 | Correctly handle the case where several :group args are supplied. | ||
| 18 | |||
| 1 | 2000-11-02 Miles Bader <miles@gnu.org> | 19 | 2000-11-02 Miles Bader <miles@gnu.org> |
| 2 | 20 | ||
| 3 | * calendar/calendar.el (diary-face, calendar-today-face) | 21 | * calendar/calendar.el (diary-face, calendar-today-face) |
diff --git a/lisp/font-lock.el b/lisp/font-lock.el index 691c9f250dd..bf414031f80 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el | |||
| @@ -928,57 +928,6 @@ or nil. If nil, highlighting keywords are removed for the current buffer." | |||
| 928 | ;; loading a file tells you nothing about the feature or how to control it. It | 928 | ;; loading a file tells you nothing about the feature or how to control it. It |
| 929 | ;; would also be contrary to the Principle of Least Surprise. sm. | 929 | ;; would also be contrary to the Principle of Least Surprise. sm. |
| 930 | 930 | ||
| 931 | (defvar font-lock-buffers nil) ; For remembering buffers. | ||
| 932 | |||
| 933 | ;;;###autoload | ||
| 934 | (defun global-font-lock-mode (&optional arg message) | ||
| 935 | "Toggle Global Font Lock mode. | ||
| 936 | (Font Lock is also known as \"syntax highlighting\".) | ||
| 937 | With prefix ARG, turn Global Font Lock mode on if and only if ARG is positive. | ||
| 938 | Displays a message saying whether the mode is on or off if MESSAGE is non-nil. | ||
| 939 | Returns the new status of Global Font Lock mode (non-nil means on). | ||
| 940 | |||
| 941 | When Global Font Lock mode is enabled, Font Lock mode is automagically | ||
| 942 | turned on in a buffer if its major mode is one of `font-lock-global-modes'. | ||
| 943 | |||
| 944 | To customize the faces (colors, fonts, etc.) used by Font Lock for | ||
| 945 | highlighting different parts of buffer text, use \\[customize-face]." | ||
| 946 | (interactive "P\np") | ||
| 947 | (let ((on-p (if arg | ||
| 948 | (> (prefix-numeric-value arg) 0) | ||
| 949 | (not global-font-lock-mode)))) | ||
| 950 | (cond (on-p | ||
| 951 | (add-hook 'find-file-hooks 'turn-on-font-lock-if-enabled) | ||
| 952 | (add-hook 'post-command-hook 'turn-on-font-lock-if-enabled) | ||
| 953 | (setq font-lock-buffers (buffer-list))) | ||
| 954 | (t | ||
| 955 | (remove-hook 'find-file-hooks 'turn-on-font-lock-if-enabled) | ||
| 956 | (mapc (function (lambda (buffer) | ||
| 957 | (with-current-buffer buffer | ||
| 958 | (when font-lock-mode | ||
| 959 | (font-lock-mode))))) | ||
| 960 | (buffer-list)))) | ||
| 961 | (when message | ||
| 962 | (message "Global Font Lock mode %s." (if on-p "enabled" "disabled"))) | ||
| 963 | (setq global-font-lock-mode on-p))) | ||
| 964 | |||
| 965 | ;; This variable was originally a `defvar' to keep track of | ||
| 966 | ;; whether Global Font Lock mode was turned on or not. As a `defcustom' with | ||
| 967 | ;; special `:set' and `:require' forms, we can provide custom mode control. | ||
| 968 | ;;;###autoload | ||
| 969 | (defcustom global-font-lock-mode nil | ||
| 970 | "Toggle Global Font Lock mode. | ||
| 971 | When Global Font Lock mode is enabled, Font Lock mode is automagically | ||
| 972 | turned on in a buffer if its major mode is one of `font-lock-global-modes'. | ||
| 973 | Setting this variable directly does not take effect; | ||
| 974 | use either \\[customize] or the function `global-font-lock-mode'." | ||
| 975 | :set (lambda (symbol value) | ||
| 976 | (global-font-lock-mode (or value 0))) | ||
| 977 | :initialize 'custom-initialize-default | ||
| 978 | :type 'boolean | ||
| 979 | :group 'font-lock | ||
| 980 | :require 'font-lock) | ||
| 981 | |||
| 982 | (defcustom font-lock-global-modes t | 931 | (defcustom font-lock-global-modes t |
| 983 | "*Modes for which Font Lock mode is automagically turned on. | 932 | "*Modes for which Font Lock mode is automagically turned on. |
| 984 | Global Font Lock mode is controlled by the command `global-font-lock-mode'. | 933 | Global Font Lock mode is controlled by the command `global-font-lock-mode'. |
| @@ -997,38 +946,20 @@ means that Font Lock mode is turned on for buffers in C and C++ modes only." | |||
| 997 | (repeat :inline t (symbol :tag "mode")))) | 946 | (repeat :inline t (symbol :tag "mode")))) |
| 998 | :group 'font-lock) | 947 | :group 'font-lock) |
| 999 | 948 | ||
| 1000 | (defun font-lock-change-major-mode () | ||
| 1001 | ;; Turn off Font Lock mode if it's on. | ||
| 1002 | (when font-lock-mode | ||
| 1003 | (font-lock-mode)) | ||
| 1004 | ;; Gross hack warning: Delicate readers should avert eyes now. | ||
| 1005 | ;; Something is running `kill-all-local-variables', which generally means the | ||
| 1006 | ;; major mode is being changed. Run `turn-on-font-lock-if-enabled' after the | ||
| 1007 | ;; file is visited or the current command has finished. | ||
| 1008 | (when global-font-lock-mode | ||
| 1009 | (add-hook 'post-command-hook 'turn-on-font-lock-if-enabled) | ||
| 1010 | (add-to-list 'font-lock-buffers (current-buffer)))) | ||
| 1011 | |||
| 1012 | (defun turn-on-font-lock-if-enabled () | 949 | (defun turn-on-font-lock-if-enabled () |
| 1013 | ;; Gross hack warning: Delicate readers should avert eyes now. | 950 | (when (and (or font-lock-defaults |
| 1014 | ;; Turn on Font Lock mode if it's supported by the major mode and enabled by | 951 | (assq major-mode font-lock-defaults-alist)) |
| 1015 | ;; the user. | 952 | (or (eq font-lock-global-modes t) |
| 1016 | (remove-hook 'post-command-hook 'turn-on-font-lock-if-enabled) | 953 | (if (eq (car-safe font-lock-global-modes) 'not) |
| 1017 | (while font-lock-buffers | 954 | (not (memq major-mode (cdr font-lock-global-modes))) |
| 1018 | (when (buffer-live-p (car font-lock-buffers)) | 955 | (memq major-mode font-lock-global-modes)))) |
| 1019 | (save-excursion | 956 | (let (inhibit-quit) |
| 1020 | (set-buffer (car font-lock-buffers)) | 957 | (turn-on-font-lock)))) |
| 1021 | (when (and (or font-lock-defaults | 958 | |
| 1022 | (assq major-mode font-lock-defaults-alist)) | 959 | ;;;###autoload |
| 1023 | (or (eq font-lock-global-modes t) | 960 | (easy-mmode-define-global-mode |
| 1024 | (if (eq (car-safe font-lock-global-modes) 'not) | 961 | global-font-lock-mode font-lock-mode turn-on-font-lock-if-enabled |
| 1025 | (not (memq major-mode (cdr font-lock-global-modes))) | 962 | :extra-args (dummy)) |
| 1026 | (memq major-mode font-lock-global-modes)))) | ||
| 1027 | (let (inhibit-quit) | ||
| 1028 | (turn-on-font-lock))))) | ||
| 1029 | (setq font-lock-buffers (cdr font-lock-buffers)))) | ||
| 1030 | |||
| 1031 | (add-hook 'change-major-mode-hook 'font-lock-change-major-mode) | ||
| 1032 | 963 | ||
| 1033 | ;;; End of Global Font Lock mode. | 964 | ;;; End of Global Font Lock mode. |
| 1034 | 965 | ||
| @@ -1238,10 +1169,14 @@ The value of this variable is used when Font Lock mode is turned on." | |||
| 1238 | ;; We are just after or in a multiline match. | 1169 | ;; We are just after or in a multiline match. |
| 1239 | (setq beg (or (previous-single-property-change | 1170 | (setq beg (or (previous-single-property-change |
| 1240 | beg 'font-lock-multiline) | 1171 | beg 'font-lock-multiline) |
| 1241 | (point-min)))) | 1172 | (point-min))) |
| 1173 | (goto-char beg) | ||
| 1174 | (setq beg (line-beginning-position))) | ||
| 1242 | (setq end (or (text-property-any end (point-max) | 1175 | (setq end (or (text-property-any end (point-max) |
| 1243 | 'font-lock-multiline nil) | 1176 | 'font-lock-multiline nil) |
| 1244 | (point-max))) | 1177 | (point-max))) |
| 1178 | (goto-char end) | ||
| 1179 | (setq end (line-end-position)) | ||
| 1245 | ;; Now do the fontification. | 1180 | ;; Now do the fontification. |
| 1246 | (font-lock-unfontify-region beg end) | 1181 | (font-lock-unfontify-region beg end) |
| 1247 | (when font-lock-syntactic-keywords | 1182 | (when font-lock-syntactic-keywords |
| @@ -1589,13 +1524,13 @@ LIMIT can be modified by the value of its PRE-MATCH-FORM." | |||
| 1589 | (if (not (and (numberp pre-match-value) (> pre-match-value (point)))) | 1524 | (if (not (and (numberp pre-match-value) (> pre-match-value (point)))) |
| 1590 | (setq limit (line-end-position)) | 1525 | (setq limit (line-end-position)) |
| 1591 | (setq limit pre-match-value) | 1526 | (setq limit pre-match-value) |
| 1592 | (when (and font-lock-multiline | 1527 | (when (and font-lock-multiline (>= limit (line-beginning-position 2))) |
| 1593 | (funcall (if (eq font-lock-multiline t) '>= '>) | ||
| 1594 | pre-match-value | ||
| 1595 | (line-beginning-position 2))) | ||
| 1596 | ;; this is a multiline anchored match | 1528 | ;; this is a multiline anchored match |
| 1597 | (setq font-lock-multiline t) | 1529 | ;; (setq font-lock-multiline t) |
| 1598 | (put-text-property (min lead-start (point)) limit | 1530 | (put-text-property (if (= limit (line-beginning-position 2)) |
| 1531 | (1- limit) | ||
| 1532 | (min lead-start (point))) | ||
| 1533 | limit | ||
| 1599 | 'font-lock-multiline t))) | 1534 | 'font-lock-multiline t))) |
| 1600 | (save-match-data | 1535 | (save-match-data |
| 1601 | ;; Find an occurrence of `matcher' before `limit'. | 1536 | ;; Find an occurrence of `matcher' before `limit'. |
| @@ -1635,13 +1570,18 @@ START should be at the beginning of a line." | |||
| 1635 | (funcall matcher end))) | 1570 | (funcall matcher end))) |
| 1636 | (when (and font-lock-multiline | 1571 | (when (and font-lock-multiline |
| 1637 | (match-beginning 0) | 1572 | (match-beginning 0) |
| 1638 | (funcall (if (eq font-lock-multiline t) '>= '>) | 1573 | (>= (point) |
| 1639 | (point) | 1574 | (save-excursion (goto-char (match-beginning 0)) |
| 1640 | (save-excursion (goto-char (match-beginning 0)) | 1575 | (forward-line 1) (point)))) |
| 1641 | (forward-line 1) (point)))) | ||
| 1642 | ;; this is a multiline regexp match | 1576 | ;; this is a multiline regexp match |
| 1643 | (setq font-lock-multiline t) | 1577 | ;; (setq font-lock-multiline t) |
| 1644 | (put-text-property (match-beginning 0) (point) | 1578 | (put-text-property (if (= (point) |
| 1579 | (save-excursion | ||
| 1580 | (goto-char (match-beginning 0)) | ||
| 1581 | (forward-line 1) (point))) | ||
| 1582 | (1- (point)) | ||
| 1583 | (match-beginning 0)) | ||
| 1584 | (point) | ||
| 1645 | 'font-lock-multiline t)) | 1585 | 'font-lock-multiline t)) |
| 1646 | ;; Apply each highlight to this instance of `matcher', which may be | 1586 | ;; Apply each highlight to this instance of `matcher', which may be |
| 1647 | ;; specific highlights or more keywords anchored to `matcher'. | 1587 | ;; specific highlights or more keywords anchored to `matcher'. |