38 |
(progn ,@body) |
(progn ,@body) |
39 |
(unless ,modified |
(unless ,modified |
40 |
(restore-buffer-modified-p nil)))))) |
(restore-buffer-modified-p nil)))))) |
41 |
|
|
42 |
(defmacro with-buffer-prepared-for-jit-lock (&rest body) |
(defmacro with-buffer-prepared-for-jit-lock (&rest body) |
43 |
"Execute BODY in current buffer, overriding several variables. |
"Execute BODY in current buffer, overriding several variables. |
44 |
Preserves the `buffer-modified-p' state of the current buffer." |
Preserves the `buffer-modified-p' state of the current buffer." |
52 |
buffer-file-truename) |
buffer-file-truename) |
53 |
,@body)))) |
,@body)))) |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
;;; Customization. |
;;; Customization. |
58 |
|
|
82 |
taking longer to fontify, you could increase the value of this variable. |
taking longer to fontify, you could increase the value of this variable. |
83 |
See also `jit-lock-stealth-load'." |
See also `jit-lock-stealth-load'." |
84 |
:type '(choice (const :tag "never" nil) |
:type '(choice (const :tag "never" nil) |
85 |
(number :tag "seconds")) |
(number :tag "seconds")) |
86 |
:group 'jit-lock) |
:group 'jit-lock) |
87 |
|
|
88 |
|
|
89 |
(defcustom jit-lock-stealth-load |
(defcustom jit-lock-stealth-load |
90 |
(if (condition-case nil (load-average) (error)) 200) |
(if (condition-case nil (load-average) (error)) 200) |
325 |
;; stop at the start of the line following NEXT. |
;; stop at the start of the line following NEXT. |
326 |
(goto-char next) (setq next (line-beginning-position 2)) |
(goto-char next) (setq next (line-beginning-position 2)) |
327 |
(goto-char start) (setq start (line-beginning-position)) |
(goto-char start) (setq start (line-beginning-position)) |
328 |
|
|
329 |
;; Fontify the chunk, and mark it as fontified. |
;; Fontify the chunk, and mark it as fontified. |
330 |
;; We mark it first, to make sure that we don't indefinitely |
;; We mark it first, to make sure that we don't indefinitely |
331 |
;; re-execute this fontification if an error occurs. |
;; re-execute this fontification if an error occurs. |
378 |
((< (- around start) (- next around)) start) |
((< (- around start) (- next around)) start) |
379 |
(t next)))) |
(t next)))) |
380 |
result)))) |
result)))) |
381 |
|
|
382 |
|
|
383 |
(defun jit-lock-stealth-fontify () |
(defun jit-lock-stealth-fontify () |
384 |
"Fontify buffers stealthily. |
"Fontify buffers stealthily. |
393 |
(while (and buffers (not (input-pending-p))) |
(while (and buffers (not (input-pending-p))) |
394 |
(let ((buffer (car buffers))) |
(let ((buffer (car buffers))) |
395 |
(setq buffers (cdr buffers)) |
(setq buffers (cdr buffers)) |
396 |
|
|
397 |
(with-current-buffer buffer |
(with-current-buffer buffer |
398 |
(when jit-lock-mode |
(when jit-lock-mode |
399 |
;; This is funny. Calling sit-for with 3rd arg non-nil |
;; This is funny. Calling sit-for with 3rd arg non-nil |
447 |
(while (and (setq start |
(while (and (setq start |
448 |
(jit-lock-stealth-chunk-start point)) |
(jit-lock-stealth-chunk-start point)) |
449 |
(sit-for nice)) |
(sit-for nice)) |
450 |
|
|
451 |
;; fontify a block. |
;; fontify a block. |
452 |
(jit-lock-fontify-now start (+ start jit-lock-chunk-size)) |
(jit-lock-fontify-now start (+ start jit-lock-chunk-size)) |
453 |
;; If stealth jit-locking is done backwards, this leads to |
;; If stealth jit-locking is done backwards, this leads to |
454 |
;; excessive O(n^2) refontification. -stef |
;; excessive O(n^2) refontification. -stef |
455 |
;; (when (>= jit-lock-first-unfontify-pos start) |
;; (when (>= jit-lock-first-unfontify-pos start) |
456 |
;; (setq jit-lock-first-unfontify-pos end)) |
;; (setq jit-lock-first-unfontify-pos end)) |
457 |
|
|
458 |
;; Wait a little if load is too high. |
;; Wait a little if load is too high. |
459 |
(when (and jit-lock-stealth-load |
(when (and jit-lock-stealth-load |
460 |
(> (car (load-average)) jit-lock-stealth-load)) |
(> (car (load-average)) jit-lock-stealth-load)) |
489 |
(sit-for 0) |
(sit-for 0) |
490 |
;; (message "Jit-Defer Done") |
;; (message "Jit-Defer Done") |
491 |
))) |
))) |
492 |
|
|
493 |
|
|
494 |
(defun jit-lock-after-change (start end old-len) |
(defun jit-lock-after-change (start end old-len) |
495 |
"Mark the rest of the buffer as not fontified after a change. |
"Mark the rest of the buffer as not fontified after a change. |
508 |
;; be inconsistent with the buffer's content. |
;; be inconsistent with the buffer's content. |
509 |
(goto-char start) |
(goto-char start) |
510 |
(setq start (line-beginning-position)) |
(setq start (line-beginning-position)) |
511 |
|
|
512 |
;; If we're in text that matches a multi-line font-lock pattern, |
;; If we're in text that matches a multi-line font-lock pattern, |
513 |
;; make sure the whole text will be redisplayed. |
;; make sure the whole text will be redisplayed. |
514 |
;; I'm not sure this is ever necessary and/or sufficient. -stef |
;; I'm not sure this is ever necessary and/or sufficient. -stef |
516 |
(setq start (or (previous-single-property-change |
(setq start (or (previous-single-property-change |
517 |
start 'font-lock-multiline) |
start 'font-lock-multiline) |
518 |
(point-min)))) |
(point-min)))) |
519 |
|
|
520 |
;; Make sure we change at least one char (in case of deletions). |
;; Make sure we change at least one char (in case of deletions). |
521 |
(setq end (min (max end (1+ start)) (point-max))) |
(setq end (min (max end (1+ start)) (point-max))) |
522 |
;; Request refontification. |
;; Request refontification. |
525 |
(when jit-lock-first-unfontify-pos |
(when jit-lock-first-unfontify-pos |
526 |
(setq jit-lock-first-unfontify-pos |
(setq jit-lock-first-unfontify-pos |
527 |
(min jit-lock-first-unfontify-pos start)))))) |
(min jit-lock-first-unfontify-pos start)))))) |
528 |
|
|
529 |
(provide 'jit-lock) |
(provide 'jit-lock) |
530 |
|
|
531 |
;;; jit-lock.el ends here |
;;; jit-lock.el ends here |