comparison lisp/font-lock.el @ 5349:239193591765

Unbreak font-lock during `revert-buffer. 2011-01-30 Mike Sperber <mike@xemacs.org> * font-lock.el (font-lock-fontify-pending-extents): Don't fail if `font-lock-mode' is unset, which can happen in the middle of `revert-buffer'. This fixes Issue622.
author Mike Sperber <sperber@deinprogramm.de>
date Sun, 30 Jan 2011 14:27:31 +0100
parents 77907bd57d25
children 0af042a0c116
comparison
equal deleted inserted replaced
5348:39304a35b6b3 5349:239193591765
1475 ;; this function is actually shorter than the old version, which handled 1475 ;; this function is actually shorter than the old version, which handled
1476 ;; only one buffer and one contiguous region! 1476 ;; only one buffer and one contiguous region!
1477 (save-match-data 1477 (save-match-data
1478 (maphash 1478 (maphash
1479 #'(lambda (buffer dummy) 1479 #'(lambda (buffer dummy)
1480 ;; remove first, to avoid infinite reprocessing if error 1480 (catch 'exit
1481 (remhash buffer font-lock-pending-buffer-table) 1481 ;; font-lock-mode may be temporarily unset during `revert-buffer'
1482 (when (buffer-live-p buffer) 1482 (if (not font-lock-mode)
1483 (clear-range-table font-lock-range-table) 1483 (throw 'exit nil))
1484 (with-current-buffer buffer 1484 ;; remove first, to avoid infinite reprocessing if error
1485 (save-excursion 1485 (remhash buffer font-lock-pending-buffer-table)
1486 (save-restriction 1486 (when (buffer-live-p buffer)
1487 ;; if we don't widen, then the C code in 1487 (clear-range-table font-lock-range-table)
1488 ;; syntactically-sectionize will fail to realize that 1488 (with-current-buffer buffer
1489 ;; we're inside a comment. #### We don't actually use 1489 (save-excursion
1490 ;; syntactically-sectionize any more. Do we still 1490 (save-restriction
1491 ;; need the widen? 1491 ;; if we don't widen, then the C code in
1492 (widen) 1492 ;; syntactically-sectionize will fail to realize that
1493 (map-extents 1493 ;; we're inside a comment. #### We don't actually use
1494 #'(lambda (ex dummy-maparg) 1494 ;; syntactically-sectionize any more. Do we still
1495 ;; first expand the ranges to full lines, 1495 ;; need the widen?
1496 ;; because that is what will be fontified; 1496 (widen)
1497 ;; then use a range table to merge the 1497 (map-extents
1498 ;; ranges. (we could also do this simply using 1498 #'(lambda (ex dummy-maparg)
1499 ;; text properties. the range table code was 1499 ;; first expand the ranges to full lines,
1500 ;; here from a previous version of this code 1500 ;; because that is what will be fontified;
1501 ;; and works just as well.) 1501 ;; then use a range table to merge the
1502 (let* ((beg (extent-start-position ex)) 1502 ;; ranges. (we could also do this simply using
1503 (end (extent-end-position ex)) 1503 ;; text properties. the range table code was
1504 (beg (progn (goto-char beg) 1504 ;; here from a previous version of this code
1505 (beginning-of-line) 1505 ;; and works just as well.)
1506 (point))) 1506 (let* ((beg (extent-start-position ex))
1507 (end (progn (goto-char end) 1507 (end (extent-end-position ex))
1508 (forward-line 1) 1508 (beg (progn (goto-char beg)
1509 (point)))) 1509 (beginning-of-line)
1510 (put-range-table beg end t 1510 (point)))
1511 font-lock-range-table))) 1511 (end (progn (goto-char end)
1512 nil nil nil nil nil 'font-lock-pending t) 1512 (forward-line 1)
1513 ;; clear all pending extents first in case of error below. 1513 (point))))
1514 (put-text-property (point-min) (point-max) 1514 (put-range-table beg end t
1515 'font-lock-pending nil) 1515 font-lock-range-table)))
1516 (map-range-table 1516 nil nil nil nil nil 'font-lock-pending t)
1517 #'(lambda (beg end val) 1517 ;; clear all pending extents first in case of error below.
1518 (put-text-property (point-min) (point-max)
1519 'font-lock-pending nil)
1520 (map-range-table
1521 #'(lambda (beg end val)
1518 ;; This creates some unnecessary progress gauges. 1522 ;; This creates some unnecessary progress gauges.
1519 ;; (if (and (= beg (point-min)) 1523 ;; (if (and (= beg (point-min))
1520 ;; (= end (point-max))) 1524 ;; (= end (point-max)))
1521 ;; (font-lock-fontify-buffer) 1525 ;; (font-lock-fontify-buffer)
1522 ;; (font-lock-fontify-region beg end))) 1526 ;; (font-lock-fontify-region beg end)))
1523 (font-lock-fontify-region beg end)) 1527 (font-lock-fontify-region beg end))
1524 font-lock-range-table)))))) 1528 font-lock-range-table)))))))
1525 font-lock-pending-buffer-table))) 1529 font-lock-pending-buffer-table)))
1526 1530
1527 ;; Syntactic fontification functions. 1531 ;; Syntactic fontification functions.
1528 1532
1529 (defun font-lock-lisp-like (mode) 1533 (defun font-lock-lisp-like (mode)