Mercurial > emacs
comparison lisp/jit-lock.el @ 49597:e88404e8f2cf
Trailing whitespace deleted.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 04 Feb 2003 12:29:42 +0000 |
parents | 2cf6194833de |
children | 695cf19ef79e d7ddb3e565de |
comparison
equal
deleted
inserted
replaced
49596:b06535145619 | 49597:e88404e8f2cf |
---|---|
36 `(let ((,modified (buffer-modified-p))) | 36 `(let ((,modified (buffer-modified-p))) |
37 (unwind-protect | 37 (unwind-protect |
38 (progn ,@body) | 38 (progn ,@body) |
39 (unless ,modified | 39 (unless ,modified |
40 (restore-buffer-modified-p nil)))))) | 40 (restore-buffer-modified-p nil)))))) |
41 | 41 |
42 (defmacro with-buffer-prepared-for-jit-lock (&rest body) | 42 (defmacro with-buffer-prepared-for-jit-lock (&rest body) |
43 "Execute BODY in current buffer, overriding several variables. | 43 "Execute BODY in current buffer, overriding several variables. |
44 Preserves the `buffer-modified-p' state of the current buffer." | 44 Preserves the `buffer-modified-p' state of the current buffer." |
45 `(with-buffer-unmodified | 45 `(with-buffer-unmodified |
46 (let ((buffer-undo-list t) | 46 (let ((buffer-undo-list t) |
50 deactivate-mark | 50 deactivate-mark |
51 buffer-file-name | 51 buffer-file-name |
52 buffer-file-truename) | 52 buffer-file-truename) |
53 ,@body)))) | 53 ,@body)))) |
54 | 54 |
55 | 55 |
56 | 56 |
57 ;;; Customization. | 57 ;;; Customization. |
58 | 58 |
59 (defcustom jit-lock-chunk-size 500 | 59 (defcustom jit-lock-chunk-size 500 |
60 "*Jit-lock chunks of this many characters, or smaller." | 60 "*Jit-lock chunks of this many characters, or smaller." |
80 If nil, means stealth fontification is never paused. | 80 If nil, means stealth fontification is never paused. |
81 To reduce machine load during stealth fontification, at the cost of stealth | 81 To reduce machine load during stealth fontification, at the cost of stealth |
82 taking longer to fontify, you could increase the value of this variable. | 82 taking longer to fontify, you could increase the value of this variable. |
83 See also `jit-lock-stealth-load'." | 83 See also `jit-lock-stealth-load'." |
84 :type '(choice (const :tag "never" nil) | 84 :type '(choice (const :tag "never" nil) |
85 (number :tag "seconds")) | 85 (number :tag "seconds")) |
86 :group 'jit-lock) | 86 :group 'jit-lock) |
87 | 87 |
88 | 88 |
89 (defcustom jit-lock-stealth-load | 89 (defcustom jit-lock-stealth-load |
90 (if (condition-case nil (load-average) (error)) 200) | 90 (if (condition-case nil (load-average) (error)) 200) |
91 "*Load in percentage above which stealth fontification is suspended. | 91 "*Load in percentage above which stealth fontification is suspended. |
92 Stealth fontification pauses when the system short-term load average (as | 92 Stealth fontification pauses when the system short-term load average (as |
323 ;; Until someone has a better idea, let's start | 323 ;; Until someone has a better idea, let's start |
324 ;; at the start of the line containing START and | 324 ;; at the start of the line containing START and |
325 ;; stop at the start of the line following NEXT. | 325 ;; stop at the start of the line following NEXT. |
326 (goto-char next) (setq next (line-beginning-position 2)) | 326 (goto-char next) (setq next (line-beginning-position 2)) |
327 (goto-char start) (setq start (line-beginning-position)) | 327 (goto-char start) (setq start (line-beginning-position)) |
328 | 328 |
329 ;; Fontify the chunk, and mark it as fontified. | 329 ;; Fontify the chunk, and mark it as fontified. |
330 ;; We mark it first, to make sure that we don't indefinitely | 330 ;; We mark it first, to make sure that we don't indefinitely |
331 ;; re-execute this fontification if an error occurs. | 331 ;; re-execute this fontification if an error occurs. |
332 (put-text-property start next 'fontified t) | 332 (put-text-property start next 'fontified t) |
333 (run-hook-with-args 'jit-lock-functions start next) | 333 (run-hook-with-args 'jit-lock-functions start next) |
376 (result (cond ((null start) next) | 376 (result (cond ((null start) next) |
377 ((null next) start) | 377 ((null next) start) |
378 ((< (- around start) (- next around)) start) | 378 ((< (- around start) (- next around)) start) |
379 (t next)))) | 379 (t next)))) |
380 result)))) | 380 result)))) |
381 | 381 |
382 | 382 |
383 (defun jit-lock-stealth-fontify () | 383 (defun jit-lock-stealth-fontify () |
384 "Fontify buffers stealthily. | 384 "Fontify buffers stealthily. |
385 This functions is called after Emacs has been idle for | 385 This functions is called after Emacs has been idle for |
386 `jit-lock-stealth-time' seconds." | 386 `jit-lock-stealth-time' seconds." |
391 minibuffer-auto-raise | 391 minibuffer-auto-raise |
392 message-log-max) | 392 message-log-max) |
393 (while (and buffers (not (input-pending-p))) | 393 (while (and buffers (not (input-pending-p))) |
394 (let ((buffer (car buffers))) | 394 (let ((buffer (car buffers))) |
395 (setq buffers (cdr buffers)) | 395 (setq buffers (cdr buffers)) |
396 | 396 |
397 (with-current-buffer buffer | 397 (with-current-buffer buffer |
398 (when jit-lock-mode | 398 (when jit-lock-mode |
399 ;; This is funny. Calling sit-for with 3rd arg non-nil | 399 ;; This is funny. Calling sit-for with 3rd arg non-nil |
400 ;; so that it doesn't redisplay, internally calls | 400 ;; so that it doesn't redisplay, internally calls |
401 ;; wait_reading_process_input also with a parameter | 401 ;; wait_reading_process_input also with a parameter |
445 (nice (or jit-lock-stealth-nice 0)) | 445 (nice (or jit-lock-stealth-nice 0)) |
446 (point (point-min))) | 446 (point (point-min))) |
447 (while (and (setq start | 447 (while (and (setq start |
448 (jit-lock-stealth-chunk-start point)) | 448 (jit-lock-stealth-chunk-start point)) |
449 (sit-for nice)) | 449 (sit-for nice)) |
450 | 450 |
451 ;; fontify a block. | 451 ;; fontify a block. |
452 (jit-lock-fontify-now start (+ start jit-lock-chunk-size)) | 452 (jit-lock-fontify-now start (+ start jit-lock-chunk-size)) |
453 ;; If stealth jit-locking is done backwards, this leads to | 453 ;; If stealth jit-locking is done backwards, this leads to |
454 ;; excessive O(n^2) refontification. -stef | 454 ;; excessive O(n^2) refontification. -stef |
455 ;; (when (>= jit-lock-first-unfontify-pos start) | 455 ;; (when (>= jit-lock-first-unfontify-pos start) |
456 ;; (setq jit-lock-first-unfontify-pos end)) | 456 ;; (setq jit-lock-first-unfontify-pos end)) |
457 | 457 |
458 ;; Wait a little if load is too high. | 458 ;; Wait a little if load is too high. |
459 (when (and jit-lock-stealth-load | 459 (when (and jit-lock-stealth-load |
460 (> (car (load-average)) jit-lock-stealth-load)) | 460 (> (car (load-average)) jit-lock-stealth-load)) |
461 (sit-for (or jit-lock-stealth-time 30))))))))))))) | 461 (sit-for (or jit-lock-stealth-time 30))))))))))))) |
462 | 462 |
487 (let ((jit-lock-defer-time nil)) | 487 (let ((jit-lock-defer-time nil)) |
488 ;; (message "Jit-Defer Now") | 488 ;; (message "Jit-Defer Now") |
489 (sit-for 0) | 489 (sit-for 0) |
490 ;; (message "Jit-Defer Done") | 490 ;; (message "Jit-Defer Done") |
491 ))) | 491 ))) |
492 | 492 |
493 | 493 |
494 (defun jit-lock-after-change (start end old-len) | 494 (defun jit-lock-after-change (start end old-len) |
495 "Mark the rest of the buffer as not fontified after a change. | 495 "Mark the rest of the buffer as not fontified after a change. |
496 Installed on `after-change-functions'. | 496 Installed on `after-change-functions'. |
497 START and END are the start and end of the changed text. OLD-LEN | 497 START and END are the start and end of the changed text. OLD-LEN |
506 ;; beginning of the line, else font-lock will properly change the | 506 ;; beginning of the line, else font-lock will properly change the |
507 ;; text's face, but the display will have been done already and will | 507 ;; text's face, but the display will have been done already and will |
508 ;; be inconsistent with the buffer's content. | 508 ;; be inconsistent with the buffer's content. |
509 (goto-char start) | 509 (goto-char start) |
510 (setq start (line-beginning-position)) | 510 (setq start (line-beginning-position)) |
511 | 511 |
512 ;; If we're in text that matches a multi-line font-lock pattern, | 512 ;; If we're in text that matches a multi-line font-lock pattern, |
513 ;; make sure the whole text will be redisplayed. | 513 ;; make sure the whole text will be redisplayed. |
514 ;; I'm not sure this is ever necessary and/or sufficient. -stef | 514 ;; I'm not sure this is ever necessary and/or sufficient. -stef |
515 (when (get-text-property start 'font-lock-multiline) | 515 (when (get-text-property start 'font-lock-multiline) |
516 (setq start (or (previous-single-property-change | 516 (setq start (or (previous-single-property-change |
517 start 'font-lock-multiline) | 517 start 'font-lock-multiline) |
518 (point-min)))) | 518 (point-min)))) |
519 | 519 |
520 ;; Make sure we change at least one char (in case of deletions). | 520 ;; Make sure we change at least one char (in case of deletions). |
521 (setq end (min (max end (1+ start)) (point-max))) | 521 (setq end (min (max end (1+ start)) (point-max))) |
522 ;; Request refontification. | 522 ;; Request refontification. |
523 (put-text-property start end 'fontified nil)) | 523 (put-text-property start end 'fontified nil)) |
524 ;; Mark the change for deferred contextual refontification. | 524 ;; Mark the change for deferred contextual refontification. |
525 (when jit-lock-first-unfontify-pos | 525 (when jit-lock-first-unfontify-pos |
526 (setq jit-lock-first-unfontify-pos | 526 (setq jit-lock-first-unfontify-pos |
527 (min jit-lock-first-unfontify-pos start)))))) | 527 (min jit-lock-first-unfontify-pos start)))))) |
528 | 528 |
529 (provide 'jit-lock) | 529 (provide 'jit-lock) |
530 | 530 |
531 ;;; jit-lock.el ends here | 531 ;;; jit-lock.el ends here |