aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2006-08-03 05:42:53 +0000
committerStefan Monnier2006-08-03 05:42:53 +0000
commitab0dd59ce73e9b13b44ffe52d9937a7a7221e000 (patch)
tree866f8533d299269ab9692786ed9eba0324e6939d
parent2e3ef421a9e7888ed48241bbeecedaeefb58ab54 (diff)
downloademacs-ab0dd59ce73e9b13b44ffe52d9937a7a7221e000.tar.gz
emacs-ab0dd59ce73e9b13b44ffe52d9937a7a7221e000.zip
(font-lock-extend-after-change-region-function):
Rename from font-lock-extend-region-function. (font-lock-extend-region): Remove by inlining at call sites. (font-lock-after-change-function): Don't needlessly round up to a whole number of lines. (font-lock-extend-jit-lock-region-after-change): Be more careful about the boundary conditions and the interactions between the various ways to extend the region.
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/font-lock.el87
-rw-r--r--lispref/modes.texi2
3 files changed, 54 insertions, 46 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a92c989b9b5..dd1b63ba4ee 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12006-08-03 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * font-lock.el (font-lock-extend-after-change-region-function):
4 Rename from font-lock-extend-region-function.
5 (font-lock-extend-region): Remove by inlining at call sites.
6 (font-lock-after-change-function): Don't needlessly round up to a whole
7 number of lines.
8 (font-lock-extend-jit-lock-region-after-change): Be more careful about
9 the boundary conditions and the interactions between the various ways
10 to extend the region.
11
12006-08-02 Stefan Monnier <monnier@iro.umontreal.ca> 122006-08-02 Stefan Monnier <monnier@iro.umontreal.ca>
2 13
3 * jit-lock.el (jit-lock-fontify-now): Preserve the buffer's 14 * jit-lock.el (jit-lock-fontify-now): Preserve the buffer's
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 201d236f7ac..a7cc1a09022 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -975,7 +975,7 @@ The value of this variable is used when Font Lock mode is turned on."
975;; directives correctly and cleanly. (It is the same problem as fontifying 975;; directives correctly and cleanly. (It is the same problem as fontifying
976;; multi-line strings and comments; regexps are not appropriate for the job.) 976;; multi-line strings and comments; regexps are not appropriate for the job.)
977 977
978(defvar font-lock-extend-region-function nil 978(defvar font-lock-extend-after-change-region-function nil
979 "A function that determines the region to fontify after a change. 979 "A function that determines the region to fontify after a change.
980 980
981This variable is either nil, or is a function that determines the 981This variable is either nil, or is a function that determines the
@@ -986,20 +986,10 @@ Font-lock calls this function after each buffer change.
986The function is given three parameters, the standard BEG, END, and OLD-LEN 986The function is given three parameters, the standard BEG, END, and OLD-LEN
987from `after-change-functions'. It should return either a cons of the beginning 987from `after-change-functions'. It should return either a cons of the beginning
988and end buffer positions \(in that order) of the region to fontify, or nil 988and end buffer positions \(in that order) of the region to fontify, or nil
989\(which directs the caller to fontify a default region). This function 989\(which directs the caller to fontify a default region).
990should preserve point and the match-data. 990This function should preserve the match-data.
991The region it returns may start or end in the middle of a line.") 991The region it returns may start or end in the middle of a line.")
992 992
993(defun font-lock-extend-region (beg end old-len)
994 "Determine the region to fontify after a buffer change.
995
996BEG END and OLD-LEN are the standard parameters from `after-change-functions'.
997The return value is either nil \(which directs the caller to chose the region
998itself), or a cons of the beginning and end \(in that order) of the region.
999The region returned may start or end in the middle of a line."
1000 (if font-lock-extend-region-function
1001 (funcall font-lock-extend-region-function beg end old-len)))
1002
1003(defun font-lock-fontify-buffer () 993(defun font-lock-fontify-buffer ()
1004 "Fontify the current buffer the way the function `font-lock-mode' would." 994 "Fontify the current buffer the way the function `font-lock-mode' would."
1005 (interactive) 995 (interactive)
@@ -1112,47 +1102,54 @@ what properties to clear before refontifying a region.")
1112 1102
1113;; Called when any modification is made to buffer text. 1103;; Called when any modification is made to buffer text.
1114(defun font-lock-after-change-function (beg end old-len) 1104(defun font-lock-after-change-function (beg end old-len)
1115 (let ((inhibit-point-motion-hooks t) 1105 (save-excursion
1116 (inhibit-quit t) 1106 (let ((inhibit-point-motion-hooks t)
1117 (region (font-lock-extend-region beg end old-len))) 1107 (inhibit-quit t)
1118 (save-excursion 1108 (region (if font-lock-extend-after-change-region-function
1109 (funcall font-lock-extend-after-change-region-function
1110 beg end old-len))))
1119 (save-match-data 1111 (save-match-data
1120 (if region 1112 (if region
1121 ;; Fontify the region the major mode has specified. 1113 ;; Fontify the region the major mode has specified.
1122 (setq beg (car region) end (cdr region)) 1114 (setq beg (car region) end (cdr region))
1123 ;; Fontify the whole lines which enclose the region. 1115 ;; Fontify the whole lines which enclose the region.
1124 (setq beg (progn (goto-char beg) (line-beginning-position)) 1116 ;; Actually, this is not needed because
1125 end (progn (goto-char end) (line-beginning-position 2)))) 1117 ;; font-lock-default-fontify-region already rounds up to a whole
1118 ;; number of lines.
1119 ;; (setq beg (progn (goto-char beg) (line-beginning-position))
1120 ;; end (progn (goto-char end) (line-beginning-position 2)))
1121 )
1126 (font-lock-fontify-region beg end))))) 1122 (font-lock-fontify-region beg end)))))
1127 1123
1128(defvar jit-lock-start) (defvar jit-lock-end) 1124(defvar jit-lock-start) (defvar jit-lock-end)
1129(defun font-lock-extend-jit-lock-region-after-change (beg end old-len) 1125(defun font-lock-extend-jit-lock-region-after-change (beg end old-len)
1130 (let ((region (font-lock-extend-region beg end old-len))) 1126 (save-excursion
1131 (if region 1127 ;; First extend the region as font-lock-after-change-function would.
1132 (setq jit-lock-start (min jit-lock-start (car region)) 1128 (let ((region (if font-lock-extend-after-change-region-function
1133 jit-lock-end (max jit-lock-end (cdr region))) 1129 (funcall font-lock-extend-after-change-region-function
1134 (save-excursion 1130 beg end old-len))))
1135 (goto-char beg) 1131 (if region
1136 (forward-line 0) 1132 (setq beg (min jit-lock-start (car region))
1137 (setq jit-lock-start 1133 end (max jit-lock-end (cdr region))))
1138 (min jit-lock-start 1134 ;; Then extend the region obeying font-lock-multiline properties,
1139 (if (and (not (eobp)) 1135 ;; indicating which part of the buffer needs to be refontified.
1140 (get-text-property (point) 'font-lock-multiline)) 1136 (when (and (> beg (point-min))
1141 (or (previous-single-property-change 1137 (get-text-property (1- beg) 'font-lock-multiline))
1142 (point) 'font-lock-multiline) 1138 (setq beg (or (previous-single-property-change
1143 (point-min)) 1139 beg 'font-lock-multiline)
1144 (point)))) 1140 (point-min))))
1145 (goto-char end) 1141 (setq end (or (text-property-any end (point-max)
1146 (forward-line 1) 1142 'font-lock-multiline nil)
1147 (setq jit-lock-end 1143 (point-max)))
1148 (max jit-lock-end 1144 ;; Finally, pre-enlarge the region to a whole number of lines, to try
1149 (if (and (not (bobp)) 1145 ;; and predict what font-lock-default-fontify-region will do, so as to
1150 (get-text-property (1- (point)) 1146 ;; avoid double-redisplay.
1151 'font-lock-multiline)) 1147 (goto-char beg)
1152 (or (next-single-property-change 1148 (forward-line 0)
1153 (1- (point)) 'font-lock-multiline) 1149 (setq jit-lock-start (min jit-lock-start (point)))
1154 (point-max)) 1150 (goto-char end)
1155 (point)))))))) 1151 (forward-line 1)
1152 (setq jit-lock-end (max jit-lock-end (point))))))
1156 1153
1157(defun font-lock-fontify-block (&optional arg) 1154(defun font-lock-fontify-block (&optional arg)
1158 "Fontify some lines the way `font-lock-fontify-buffer' would. 1155 "Fontify some lines the way `font-lock-fontify-buffer' would.
diff --git a/lispref/modes.texi b/lispref/modes.texi
index 8b4188ecff2..7ca8764a0a8 100644
--- a/lispref/modes.texi
+++ b/lispref/modes.texi
@@ -3144,7 +3144,7 @@ earlier line.
3144 You can enlarge (or even reduce) the region to fontify by setting 3144 You can enlarge (or even reduce) the region to fontify by setting
3145one the following variables: 3145one the following variables:
3146 3146
3147@defvar font-lock-extend-region-function 3147@defvar font-lock-extend-after-change-region-function
3148This buffer-local variable is either @code{nil} or a function for 3148This buffer-local variable is either @code{nil} or a function for
3149Font-Lock to call to determine the region to scan and fontify. 3149Font-Lock to call to determine the region to scan and fontify.
3150 3150