diff options
| author | Stefan Monnier | 2006-08-03 07:14:39 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2006-08-03 07:14:39 +0000 |
| commit | 05a1066ff0521af95b3761376c853d96312ca2f3 (patch) | |
| tree | 93703b07c93c44847892aba80432bcbf59140834 /lisp | |
| parent | ab0dd59ce73e9b13b44ffe52d9937a7a7221e000 (diff) | |
| download | emacs-05a1066ff0521af95b3761376c853d96312ca2f3.tar.gz emacs-05a1066ff0521af95b3761376c853d96312ca2f3.zip | |
(font-lock-beg, font-lock-end, font-lock-extend-region-functions): New vars.
(font-lock-extend-region-multiline)
(font-lock-extend-region-wholelines): New functions.
(font-lock-default-fontify-region): Use them.
(font-lock-extend-jit-lock-region-after-change): Only round up
if font-lock-default-fontify-region will do it as well.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/font-lock.el | 94 |
2 files changed, 78 insertions, 24 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index dd1b63ba4ee..6329e0e699d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,13 @@ | |||
| 1 | 2006-08-03 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2006-08-03 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * font-lock.el (font-lock-beg, font-lock-end) | ||
| 4 | (font-lock-extend-region-functions): New vars. | ||
| 5 | (font-lock-extend-region-multiline) | ||
| 6 | (font-lock-extend-region-wholelines): New functions. | ||
| 7 | (font-lock-default-fontify-region): Use them. | ||
| 8 | (font-lock-extend-jit-lock-region-after-change): Only round up | ||
| 9 | if font-lock-default-fontify-region will do it as well. | ||
| 10 | |||
| 3 | * font-lock.el (font-lock-extend-after-change-region-function): | 11 | * font-lock.el (font-lock-extend-after-change-region-function): |
| 4 | Rename from font-lock-extend-region-function. | 12 | Rename from font-lock-extend-region-function. |
| 5 | (font-lock-extend-region): Remove by inlining at call sites. | 13 | (font-lock-extend-region): Remove by inlining at call sites. |
diff --git a/lisp/font-lock.el b/lisp/font-lock.el index a7cc1a09022..0cad924f201 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el | |||
| @@ -1040,6 +1040,53 @@ The region it returns may start or end in the middle of a line.") | |||
| 1040 | Useful for things like RMAIL and Info where the whole buffer is not | 1040 | Useful for things like RMAIL and Info where the whole buffer is not |
| 1041 | a very meaningful entity to highlight.") | 1041 | a very meaningful entity to highlight.") |
| 1042 | 1042 | ||
| 1043 | |||
| 1044 | (defvar font-lock-beg) (defvar font-lock-end) | ||
| 1045 | (defvar font-lock-extend-region-functions | ||
| 1046 | '(font-lock-extend-region-wholelines | ||
| 1047 | font-lock-extend-region-multiline) | ||
| 1048 | "Special hook run just before proceeding to fontify a region. | ||
| 1049 | This is used to allow major modes to help font-lock find safe buffer positions | ||
| 1050 | as beginning and end of the fontified region. Its most common use is to solve | ||
| 1051 | the problem of /identification/ of multiline elements by providing a function | ||
| 1052 | that tries to find such elements and move the boundaries such that they do | ||
| 1053 | not fall in the middle of one. | ||
| 1054 | Each function is called with no argument; it is expected to adjust the | ||
| 1055 | dynamically bound variables `font-lock-beg' and `font-lock-end'; and return | ||
| 1056 | non-nil iff it did make such an adjustment. | ||
| 1057 | These functions are run in turn repeatedly until they all return nil. | ||
| 1058 | Put first the functions more likely to cause a change and cheaper to compute.") | ||
| 1059 | ;; Mark it as a special hook which doesn't use any global setting | ||
| 1060 | ;; (i.e. doesn't obey the element t in the buffer-local value). | ||
| 1061 | (make-variable-buffer-local 'font-lock-extend-region-functions) | ||
| 1062 | |||
| 1063 | (defun font-lock-extend-region-multiline () | ||
| 1064 | "Move fontification boundaries away from any `font-lock-multiline' property." | ||
| 1065 | (let ((changed nil)) | ||
| 1066 | (when (and (> font-lock-beg (point-min)) | ||
| 1067 | (get-text-property (1- font-lock-beg) 'font-lock-multiline)) | ||
| 1068 | (setq changed t) | ||
| 1069 | (setq font-lock-beg (or (previous-single-property-change | ||
| 1070 | font-lock-beg 'font-lock-multiline) | ||
| 1071 | (point-min)))) | ||
| 1072 | ;; | ||
| 1073 | (when (get-text-property font-lock-end 'font-lock-multiline) | ||
| 1074 | (setq changed t) | ||
| 1075 | (setq font-lock-end (or (text-property-any font-lock-end (point-max) | ||
| 1076 | 'font-lock-multiline nil) | ||
| 1077 | (point-max)))) | ||
| 1078 | changed)) | ||
| 1079 | |||
| 1080 | |||
| 1081 | (defun font-lock-extend-region-wholelines () | ||
| 1082 | "Move fontification boundaries to beginning of lines." | ||
| 1083 | (let ((changed nil)) | ||
| 1084 | (goto-char font-lock-beg) | ||
| 1085 | (unless (bobp) (setq changed t font-lock-beg (line-beginning-position))) | ||
| 1086 | (goto-char font-lock-end) | ||
| 1087 | (unless (bobp) (setq changed t font-lock-end (line-beginning-position 2))) | ||
| 1088 | changed)) | ||
| 1089 | |||
| 1043 | (defun font-lock-default-fontify-region (beg end loudly) | 1090 | (defun font-lock-default-fontify-region (beg end loudly) |
| 1044 | (save-buffer-state | 1091 | (save-buffer-state |
| 1045 | ((parse-sexp-lookup-properties | 1092 | ((parse-sexp-lookup-properties |
| @@ -1051,24 +1098,21 @@ a very meaningful entity to highlight.") | |||
| 1051 | ;; Use the fontification syntax table, if any. | 1098 | ;; Use the fontification syntax table, if any. |
| 1052 | (when font-lock-syntax-table | 1099 | (when font-lock-syntax-table |
| 1053 | (set-syntax-table font-lock-syntax-table)) | 1100 | (set-syntax-table font-lock-syntax-table)) |
| 1054 | (goto-char beg) | 1101 | ;; Extend the region to fontify so that it starts and ends at |
| 1055 | (setq beg (line-beginning-position)) | 1102 | ;; safe places. |
| 1056 | ;; check to see if we should expand the beg/end area for | 1103 | (let ((funs font-lock-extend-region-functions) |
| 1057 | ;; proper multiline matches | 1104 | (font-lock-beg beg) |
| 1058 | (when (and (> beg (point-min)) | 1105 | (font-lock-end end)) |
| 1059 | (get-text-property (1- beg) 'font-lock-multiline)) | 1106 | (while funs |
| 1060 | ;; We are just after or in a multiline match. | 1107 | (setq funs (if (or (not (funcall (car funs))) |
| 1061 | (setq beg (or (previous-single-property-change | 1108 | (eq funs font-lock-extend-region-functions)) |
| 1062 | beg 'font-lock-multiline) | 1109 | (cdr funs) |
| 1063 | (point-min))) | 1110 | ;; If there's been a change, we should go through |
| 1064 | (goto-char beg) | 1111 | ;; the list again since this new position may |
| 1065 | (setq beg (line-beginning-position))) | 1112 | ;; warrant a different answer from one of the fun |
| 1066 | (setq end (or (text-property-any end (point-max) | 1113 | ;; we've already seen. |
| 1067 | 'font-lock-multiline nil) | 1114 | font-lock-extend-region-functions))) |
| 1068 | (point-max))) | 1115 | (setq beg font-lock-beg end font-lock-end)) |
| 1069 | (goto-char end) | ||
| 1070 | ;; Round up to a whole line. | ||
| 1071 | (unless (bolp) (setq end (line-beginning-position 2))) | ||
| 1072 | ;; Now do the fontification. | 1116 | ;; Now do the fontification. |
| 1073 | (font-lock-unfontify-region beg end) | 1117 | (font-lock-unfontify-region beg end) |
| 1074 | (when font-lock-syntactic-keywords | 1118 | (when font-lock-syntactic-keywords |
| @@ -1144,12 +1188,14 @@ what properties to clear before refontifying a region.") | |||
| 1144 | ;; Finally, pre-enlarge the region to a whole number of lines, to try | 1188 | ;; Finally, pre-enlarge the region to a whole number of lines, to try |
| 1145 | ;; and predict what font-lock-default-fontify-region will do, so as to | 1189 | ;; and predict what font-lock-default-fontify-region will do, so as to |
| 1146 | ;; avoid double-redisplay. | 1190 | ;; avoid double-redisplay. |
| 1147 | (goto-char beg) | 1191 | (when (memq 'font-lock-extend-region-wholelines |
| 1148 | (forward-line 0) | 1192 | font-lock-extend-region-functions) |
| 1149 | (setq jit-lock-start (min jit-lock-start (point))) | 1193 | (goto-char beg) |
| 1150 | (goto-char end) | 1194 | (forward-line 0) |
| 1151 | (forward-line 1) | 1195 | (setq jit-lock-start (min jit-lock-start (point))) |
| 1152 | (setq jit-lock-end (max jit-lock-end (point)))))) | 1196 | (goto-char end) |
| 1197 | (forward-line 1) | ||
| 1198 | (setq jit-lock-end (max jit-lock-end (point))))))) | ||
| 1153 | 1199 | ||
| 1154 | (defun font-lock-fontify-block (&optional arg) | 1200 | (defun font-lock-fontify-block (&optional arg) |
| 1155 | "Fontify some lines the way `font-lock-fontify-buffer' would. | 1201 | "Fontify some lines the way `font-lock-fontify-buffer' would. |