Mercurial > hg > xemacs-beta
comparison lisp/font-lock.el @ 462:0784d089fdc9 r21-2-46
Import from CVS: tag r21-2-46
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:44:37 +0200 |
parents | 223736d75acb |
children | 7039e6323819 |
comparison
equal
deleted
inserted
replaced
461:120ed4009e51 | 462:0784d089fdc9 |
---|---|
1184 "Set this to non-nil to disable font-lock deferral. | 1184 "Set this to non-nil to disable font-lock deferral. |
1185 Otherwise, changes to existing text will not be processed until the | 1185 Otherwise, changes to existing text will not be processed until the |
1186 next redisplay cycle, avoiding excessive fontification when many | 1186 next redisplay cycle, avoiding excessive fontification when many |
1187 buffer modifications are performed or a buffer is reverted.") | 1187 buffer modifications are performed or a buffer is reverted.") |
1188 | 1188 |
1189 (defvar font-lock-pending-extent-table (make-hash-table :weakness 'key)) | 1189 ;; list of buffers in which there is a pending change. |
1190 (defvar font-lock-pending-buffer-table (make-hash-table :weakness 'key)) | |
1191 ;; table used to keep track of ranges needing fontification. | |
1190 (defvar font-lock-range-table (make-range-table)) | 1192 (defvar font-lock-range-table (make-range-table)) |
1191 | 1193 |
1192 (defun font-lock-pre-idle-hook () | 1194 (defun font-lock-pre-idle-hook () |
1193 (condition-case font-lock-error | 1195 (condition-case font-lock-error |
1194 (if (> (hash-table-count font-lock-pending-extent-table) 0) | 1196 (if (> (hash-table-count font-lock-pending-buffer-table) 0) |
1195 (font-lock-fontify-pending-extents)) | 1197 (font-lock-fontify-pending-extents)) |
1196 (error (warn "Error caught in `font-lock-pre-idle-hook': %s" | 1198 (error (warn "Error caught in `font-lock-pre-idle-hook': %s" |
1197 font-lock-error)))) | 1199 font-lock-error)))) |
1198 | 1200 |
1199 ;;; called when any modification is made to buffer text. This function | 1201 ;;; called when any modification is made to buffer text. This function |
1201 ;;; the extents are merged and pruned, and the resulting ranges fontified. | 1203 ;;; the extents are merged and pruned, and the resulting ranges fontified. |
1202 ;;; This function could easily be adapted to other after-change-functions. | 1204 ;;; This function could easily be adapted to other after-change-functions. |
1203 | 1205 |
1204 (defun font-lock-after-change-function (beg end old-len) | 1206 (defun font-lock-after-change-function (beg end old-len) |
1205 (when font-lock-mode | 1207 (when font-lock-mode |
1206 (let ((ex (make-extent beg end))) | 1208 ;; treat deletions as if the following character (or previous, if |
1207 (set-extent-property ex 'detachable nil) | 1209 ;; there is no following) were inserted. this is a bit of a hack |
1208 (set-extent-property ex 'end-open nil) | 1210 ;; but allows us to use text properties for everything. |
1209 (let ((exs (gethash (current-buffer) font-lock-pending-extent-table))) | 1211 (if (= beg end) |
1210 (push ex exs) | 1212 (cond ((/= end (point-max)) (setq end (1+ end))) |
1211 (puthash (current-buffer) exs font-lock-pending-extent-table))) | 1213 ((/= beg (point-min)) (setq beg (1- beg))) |
1214 (t nil))) | |
1215 (put-text-property beg end 'font-lock-pending t) | |
1216 (puthash (current-buffer) t font-lock-pending-buffer-table) | |
1212 (if font-lock-always-fontify-immediately | 1217 (if font-lock-always-fontify-immediately |
1213 (font-lock-fontify-pending-extents)))) | 1218 (font-lock-fontify-pending-extents)))) |
1214 | 1219 |
1215 (defun font-lock-fontify-pending-extents () | 1220 (defun font-lock-fontify-pending-extents () |
1216 ;; ah, the beauty of mapping functions. | 1221 ;; ah, the beauty of mapping functions. |
1217 ;; this function is actually shorter than the old version, which handled | 1222 ;; this function is actually shorter than the old version, which handled |
1218 ;; only one buffer and one contiguous region! | 1223 ;; only one buffer and one contiguous region! |
1219 (save-match-data | 1224 (save-match-data |
1220 (maphash | 1225 (maphash |
1221 #'(lambda (buffer exs) | 1226 #'(lambda (buffer dummy) |
1222 ;; remove first, to avoid infinite reprocessing if error | 1227 ;; remove first, to avoid infinite reprocessing if error |
1223 (remhash buffer font-lock-pending-extent-table) | 1228 (remhash buffer font-lock-pending-buffer-table) |
1224 (when (buffer-live-p buffer) | 1229 (when (buffer-live-p buffer) |
1225 (clear-range-table font-lock-range-table) | 1230 (clear-range-table font-lock-range-table) |
1226 (with-current-buffer buffer | 1231 (with-current-buffer buffer |
1227 (save-excursion | 1232 (save-excursion |
1228 (save-restriction | 1233 (save-restriction |
1229 ;; if we don't widen, then the C code will fail to | 1234 ;; if we don't widen, then the C code in |
1230 ;; realize that we're inside a comment. | 1235 ;; syntactically-sectionize will fail to realize that |
1236 ;; we're inside a comment. #### We don't actually use | |
1237 ;; syntactically-sectionize any more. Do we still | |
1238 ;; need the widen? | |
1231 (widen) | 1239 (widen) |
1232 (let ((zmacs-region-stays | 1240 (let ((zmacs-region-stays |
1233 zmacs-region-stays)) ; protect from change! | 1241 zmacs-region-stays)) ; protect from change! |
1234 (mapc | 1242 (map-extents |
1235 #'(lambda (ex) | 1243 #'(lambda (ex dummy-maparg) |
1236 ;; paranoia. | 1244 ;; first expand the ranges to full lines, |
1237 (when (and (extent-live-p ex) | 1245 ;; because that is what will be fontified; |
1238 (not (extent-detached-p ex))) | 1246 ;; then use a range table to merge the |
1239 ;; first expand the ranges to full lines, because | 1247 ;; ranges. (we could also do this simply using |
1240 ;; that is what will be fontified; then use a | 1248 ;; text properties. the range table code was |
1241 ;; range table to merge the ranges. | 1249 ;; here from a previous version of this code |
1242 (let* ((beg (extent-start-position ex)) | 1250 ;; and works just as well.) |
1243 (end (extent-end-position ex)) | 1251 (let* ((beg (extent-start-position ex)) |
1244 (beg (progn (goto-char beg) | 1252 (end (extent-end-position ex)) |
1245 (beginning-of-line) | 1253 (beg (progn (goto-char beg) |
1246 (point))) | 1254 (beginning-of-line) |
1247 (end (progn (goto-char end) | 1255 (point))) |
1248 (forward-line 1) | 1256 (end (progn (goto-char end) |
1249 (point)))) | 1257 (forward-line 1) |
1250 (detach-extent ex) | 1258 (point)))) |
1251 (put-range-table beg end t | 1259 (put-range-table beg end t |
1252 font-lock-range-table)))) | 1260 font-lock-range-table))) |
1253 exs) | 1261 nil nil nil nil nil 'font-lock-pending t) |
1262 ;; clear all pending extents first in case of error below. | |
1263 (put-text-property (point-min) (point-max) | |
1264 'font-lock-pending nil) | |
1254 (map-range-table | 1265 (map-range-table |
1255 #'(lambda (beg end val) | 1266 #'(lambda (beg end val) |
1256 ;; Maybe flush the internal cache used by | 1267 ;; This creates some unnecessary progress gauges. |
1257 ;; syntactically-sectionize. (It'd be nice if this | |
1258 ;; was more automatic.) Any deletions mean the | |
1259 ;; cache is invalid, and insertions at beginning or | |
1260 ;; end of line mean that the bol cache might be | |
1261 ;; invalid. | |
1262 ;; #### This code has been commented out for some time | |
1263 ;; now and is bit-rotting. Someone should look into | |
1264 ;; this. | |
1265 ;; (if (or change-was-deletion (bobp) | |
1266 ;; (= (preceding-char) ?\n)) | |
1267 ;; (buffer-syntactic-context-flush-cache)) | |
1268 ;; #### This creates some unnecessary progress gauges. | |
1269 ;; (if (and (= beg (point-min)) | 1268 ;; (if (and (= beg (point-min)) |
1270 ;; (= end (point-max))) | 1269 ;; (= end (point-max))) |
1271 ;; (font-lock-fontify-buffer) | 1270 ;; (font-lock-fontify-buffer) |
1272 ;; (font-lock-fontify-region beg end))) | 1271 ;; (font-lock-fontify-region beg end))) |
1273 (font-lock-fontify-region beg end)) | 1272 (font-lock-fontify-region beg end)) |
1274 font-lock-range-table))))))) | 1273 font-lock-range-table))))))) |
1275 font-lock-pending-extent-table))) | 1274 font-lock-pending-buffer-table))) |
1276 | 1275 |
1277 ;; Syntactic fontification functions. | 1276 ;; Syntactic fontification functions. |
1278 | 1277 |
1279 (defun font-lock-lisp-like (mode) | 1278 (defun font-lock-lisp-like (mode) |
1280 ;; Note: (or (get mode 'font-lock-lisp-like) (string-match ...)) is | 1279 ;; Note: (or (get mode 'font-lock-lisp-like) (string-match ...)) is |