Mercurial > hg > xemacs-beta
comparison lisp/packages/lazy-lock.el @ 12:bcdc7deadc19 r19-15b7
Import from CVS: tag r19-15b7
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:48:16 +0200 |
parents | ac2d302a0011 |
children | 4103f0995bd7 |
comparison
equal
deleted
inserted
replaced
11:91ffe8bd52e4 | 12:bcdc7deadc19 |
---|---|
2 | 2 |
3 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Simon Marshall <simon@gnu.ai.mit.edu> | 5 ;; Author: Simon Marshall <simon@gnu.ai.mit.edu> |
6 ;; Keywords: faces files | 6 ;; Keywords: faces files |
7 ;; Version: 1.14 | 7 ;; Version: 1.15 |
8 | 8 |
9 ;; LCD Archive Entry: | 9 ;; LCD Archive Entry: |
10 ;; lazy-lock|Simon Marshall|simon@gnu.ai.mit.edu| | 10 ;; lazy-lock|Simon Marshall|simon@gnu.ai.mit.edu| |
11 ;; Lazy Font Lock mode (with fast demand-driven fontification).| | 11 ;; Lazy Font Lock mode (with fast demand-driven fontification).| |
12 ;; 13-Oct-95|1.14|~/modes/lazy-lock.el.Z| | 12 ;; 13-Nov-95|1.15|~/modes/lazy-lock.el.Z| |
13 | 13 |
14 ;; The archive is archive.cis.ohio-state.edu in /pub/gnu/emacs/elisp-archive. | 14 ;; The archive is archive.cis.ohio-state.edu in /pub/gnu/emacs/elisp-archive. |
15 | 15 |
16 ;;; This file is part of GNU Emacs. | 16 ;;; This file is part of GNU Emacs. |
17 | 17 |
26 ;; GNU General Public License for more details. | 26 ;; GNU General Public License for more details. |
27 | 27 |
28 ;; You should have received a copy of the GNU General Public License | 28 ;; You should have received a copy of the GNU General Public License |
29 ;; along with GNU Emacs; see the file COPYING. If not, write to | 29 ;; along with GNU Emacs; see the file COPYING. If not, write to |
30 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 30 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
31 | |
32 ;;; Synched up with: Not in FSF. (This seems very strange to me.) | |
33 | 31 |
34 ;;; Commentary: | 32 ;;; Commentary: |
35 | 33 |
36 ;; Purpose: | 34 ;; Purpose: |
37 ;; | 35 ;; |
302 ;; - Made `font-lock-beginning-of-syntax-function' wrapped for fontification. | 300 ;; - Made `font-lock-beginning-of-syntax-function' wrapped for fontification. |
303 ;; - Added `lazy-lock-stealth-verbose' (after harassment from Ben Wing). | 301 ;; - Added `lazy-lock-stealth-verbose' (after harassment from Ben Wing). |
304 ;; - XEmacs: Made `font-lock-verbose' wrapped for stealth fontification. | 302 ;; - XEmacs: Made `font-lock-verbose' wrapped for stealth fontification. |
305 ;; 1.13--1.14: | 303 ;; 1.13--1.14: |
306 ;; - Wrap `lazy-lock-colour-invisible' for `set-face-foreground' (Jari Aalto). | 304 ;; - Wrap `lazy-lock-colour-invisible' for `set-face-foreground' (Jari Aalto). |
305 ;; 1.14--1.15: | |
306 ;; - Made `lazy-lock-post-command-setup'; may add to `post-command-idle-hook'. | |
307 | 307 |
308 (require 'font-lock) | 308 (require 'font-lock) |
309 | 309 |
310 (eval-when-compile | 310 (eval-when-compile |
311 ;; Only `require' so `ediff-multiframe-setup-p' is expanded at compile time. | 311 ;; Only `require' so `ediff-multiframe-setup-p' is expanded at compile time. |
318 (defun lazy-lock-submit-bug-report () | 318 (defun lazy-lock-submit-bug-report () |
319 "Submit via mail a bug report on lazy-lock.el." | 319 "Submit via mail a bug report on lazy-lock.el." |
320 (interactive) | 320 (interactive) |
321 (require 'reporter) | 321 (require 'reporter) |
322 (let ((reporter-prompt-for-summary-p t)) | 322 (let ((reporter-prompt-for-summary-p t)) |
323 (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "lazy-lock 1.14" | 323 (reporter-submit-bug-report "simon@gnu.ai.mit.edu" "lazy-lock 1.15" |
324 '(lazy-lock-walk-windows lazy-lock-continuity-time | 324 '(lazy-lock-walk-windows lazy-lock-continuity-time |
325 lazy-lock-stealth-time lazy-lock-stealth-nice | 325 lazy-lock-stealth-time lazy-lock-stealth-nice |
326 lazy-lock-stealth-lines lazy-lock-stealth-verbose | 326 lazy-lock-stealth-lines lazy-lock-stealth-verbose |
327 lazy-lock-hide-invisible lazy-lock-invisible-foreground | 327 lazy-lock-hide-invisible lazy-lock-invisible-foreground |
328 lazy-lock-minimum-size lazy-lock-ignore-commands) | 328 lazy-lock-minimum-size lazy-lock-ignore-commands) |
333 know how to make a clear and unambiguous report. To reproduce the bug: | 333 know how to make a clear and unambiguous report. To reproduce the bug: |
334 | 334 |
335 Start a fresh Emacs via `" invocation-name " -no-init-file -no-site-file'. | 335 Start a fresh Emacs via `" invocation-name " -no-init-file -no-site-file'. |
336 In the `*scratch*' buffer, evaluate:")))) | 336 In the `*scratch*' buffer, evaluate:")))) |
337 | 337 |
338 ;; Let's define `emacs-major-version', `emacs-minor-version', and | 338 ;; Let's define `emacs-minor-version' if no-one else has. |
339 ;; `emacs-version>=' if no-one else has. | |
340 | |
341 (if (not (boundp 'emacs-major-version)) | |
342 (eval-and-compile | |
343 (defconst emacs-major-version | |
344 (progn (or (string-match "^[0-9]+" emacs-version) | |
345 (error "emacs-version unparsable")) | |
346 (string-to-int (match-string 0 emacs-version))) | |
347 "Major version number of this version of Emacs, as an integer. | |
348 Warning, this variable did not exist in Emacs versions earlier than: | |
349 FSF Emacs: 19.23 | |
350 XEmacs: 19.10"))) | |
351 | |
352 (if (not (boundp 'emacs-minor-version)) | 339 (if (not (boundp 'emacs-minor-version)) |
353 (eval-and-compile | 340 (eval-and-compile |
354 (defconst emacs-minor-version | 341 (defconst emacs-minor-version |
355 (progn (or (string-match "^[0-9]+\\.\\([0-9]+\\)" emacs-version) | 342 (save-match-data |
356 (error "emacs-version unparsable")) | 343 (string-match "^[0-9]+\\.\\([0-9]+\\)" emacs-version) |
357 (string-to-int (match-string 1 emacs-version))) | 344 (string-to-int |
358 "Minor version number of this version of Emacs, as an integer. | 345 (substring emacs-version (match-beginning 1) (match-end 1))))))) |
359 Warning, this variable did not exist in Emacs versions earlier than: | |
360 FSF Emacs: 19.23 | |
361 XEmacs: 19.10"))) | |
362 | |
363 (if (not (fboundp 'emacs-version>=)) | |
364 (eval-and-compile | |
365 (defun emacs-version>= (major &optional minor) | |
366 "Return true if the Emacs version is >= to the given MAJOR and MINOR numbers. | |
367 | |
368 The MAJOR version number argument is required, but the MINOR version number | |
369 argument is optional. If the minor version number is not specified (or is the | |
370 symbol `nil') then only the major version numbers are considered in the test." | |
371 (if (null minor) | |
372 (>= emacs-major-version major) | |
373 (or (> emacs-major-version major) | |
374 (and (= emacs-major-version major) | |
375 (>= emacs-minor-version minor)) | |
376 ) | |
377 )))) | |
378 | 346 |
379 ;; Yuck, but we make so much use of this variable it's probably worth it. | 347 ;; Yuck, but we make so much use of this variable it's probably worth it. |
380 (eval-and-compile | 348 (eval-and-compile |
381 (defconst lazy-lock-running-xemacs-p | 349 (defconst lazy-lock-running-xemacs-p |
382 (not (null (save-match-data (string-match "Lucid" emacs-version)))))) | 350 (not (null (save-match-data (string-match "Lucid" emacs-version)))))) |
383 | 351 |
384 (defvar lazy-lock-cache-start nil) ; for window fontifiction | 352 (defvar lazy-lock-cache-start nil) ; for window fontifiction |
385 (defvar lazy-lock-cache-end nil) ; for window fontifiction | 353 (defvar lazy-lock-cache-end nil) ; for window fontifiction |
386 (defvar lazy-lock-cache-continue nil) ; for stealth fontifiction | 354 (defvar lazy-lock-cache-continue nil) ; for stealth fontifiction |
387 | 355 |
356 ;; XEmacs change | |
388 ;;;###autoload | 357 ;;;###autoload |
389 (defvar lazy-lock-mode nil) ; for modeline | 358 (defvar lazy-lock-mode nil) ; for modeline |
390 | 359 |
391 ;; User Variables: | 360 ;; User Variables: |
392 | 361 |
400 If `all-frames', fontify windows even on other frames. | 369 If `all-frames', fontify windows even on other frames. |
401 A non-nil value slows down redisplay.") | 370 A non-nil value slows down redisplay.") |
402 | 371 |
403 ;; XEmacs 19.11 and below exercise a bug in the Xt event loop. | 372 ;; XEmacs 19.11 and below exercise a bug in the Xt event loop. |
404 (defvar lazy-lock-continuity-time | 373 (defvar lazy-lock-continuity-time |
405 (if (or (not lazy-lock-running-xemacs-p) (emacs-version>= 19 12)) | 374 (if (or (not lazy-lock-running-xemacs-p) (> emacs-minor-version 11)) |
406 0 | 375 0 |
407 (if (featurep 'lisp-float-type) 0.001 1)) | 376 (if (featurep 'lisp-float-type) 0.001 1)) |
408 "*Time in seconds to delay before normal window fontification. | 377 "*Time in seconds to delay before normal window fontification. |
409 Window fontification occurs if there is no input within this time.") | 378 Window fontification occurs if there is no input within this time.") |
410 | 379 |
411 ;; `previous-single-property-change' at `point-min' up to Emacs 19.25 is fatal. | 380 ;; `previous-single-property-change' at `point-min' up to Emacs 19.25 is fatal. |
412 ;; `text-property-any', `text-property-not-all' and | 381 ;; `text-property-any', `text-property-not-all' and |
413 ;; `next-single-property-change' up to XEmacs 19.11 are too broke. | 382 ;; `next-single-property-change' up to XEmacs 19.11 are too broke. |
414 (defvar lazy-lock-stealth-time | 383 (defvar lazy-lock-stealth-time |
415 (if (emacs-version>= 19 (if lazy-lock-running-xemacs-p 12 26)) 30) | 384 (if (> emacs-minor-version (if lazy-lock-running-xemacs-p 11 25)) 30) |
416 "*Time in seconds to delay before beginning stealth fontification. | 385 "*Time in seconds to delay before beginning stealth fontification. |
417 Stealth fontification occurs if there is no input within this time. | 386 Stealth fontification occurs if there is no input within this time. |
418 If nil, means no fontification by stealth.") | 387 If nil, means no fontification by stealth.") |
419 | 388 |
420 (defvar lazy-lock-stealth-lines | 389 (defvar lazy-lock-stealth-lines |
494 (if (and lazy-lock-mode (not font-lock-mode)) | 463 (if (and lazy-lock-mode (not font-lock-mode)) |
495 ;; Turned on `lazy-lock-mode' rather than using `font-lock-mode-hook'. | 464 ;; Turned on `lazy-lock-mode' rather than using `font-lock-mode-hook'. |
496 (progn | 465 (progn |
497 (add-hook 'font-lock-mode-hook 'turn-on-lazy-lock) | 466 (add-hook 'font-lock-mode-hook 'turn-on-lazy-lock) |
498 (font-lock-mode 1)) | 467 (font-lock-mode 1)) |
499 (lazy-lock-fixup-hooks) | |
500 ;; Let's get down to business. | 468 ;; Let's get down to business. |
469 (lazy-lock-post-command-setup) | |
501 (if (not lazy-lock-mode) | 470 (if (not lazy-lock-mode) |
502 (let ((modified (buffer-modified-p)) (inhibit-read-only t) | 471 (let ((modified (buffer-modified-p)) (inhibit-read-only t) |
503 (buffer-undo-list t) | 472 (buffer-undo-list t) |
504 deactivate-mark buffer-file-name buffer-file-truename) | 473 deactivate-mark buffer-file-name buffer-file-truename) |
505 (remove-text-properties (point-min) (point-max) '(fontified nil)) | 474 (remove-text-properties (point-min) (point-max) '(fontified nil)) |
513 ;;;###autoload | 482 ;;;###autoload |
514 (defun turn-on-lazy-lock () | 483 (defun turn-on-lazy-lock () |
515 "Unconditionally turn on Lazy Lock mode." | 484 "Unconditionally turn on Lazy Lock mode." |
516 (lazy-lock-mode 1)) | 485 (lazy-lock-mode 1)) |
517 | 486 |
518 (if (not (emacs-version>= 19 (if lazy-lock-running-xemacs-p 12 29))) | 487 (if (< emacs-minor-version (if lazy-lock-running-xemacs-p 12 29)) |
519 ;; We don't need this in Emacs 19.29 or XEmacs 19.12. | 488 ;; We don't need this in Emacs 19.29 or XEmacs 19.12. |
520 (defun lazy-lock-fontify-buffer () | 489 (defun lazy-lock-fontify-buffer () |
521 "Fontify the current buffer where necessary." | 490 "Fontify the current buffer where necessary." |
522 (interactive) | 491 (interactive) |
523 (lazy-lock-fontify-region (point-min) (point-max)))) | 492 (lazy-lock-fontify-region (point-min) (point-max)))) |
524 | 493 |
525 ;; API Functions: | 494 ;; API Functions: |
526 | |
527 (defun lazy-lock-fixup-hooks () | |
528 ;; Make sure our hooks are correct. | |
529 (remove-hook 'pre-idle-hook 'lazy-lock-pre-idle-fontify-windows) | |
530 (remove-hook 'post-command-hook 'lazy-lock-post-command-fontify-stealthily) | |
531 ;; Make sure our hooks are at the end. Font-lock in XEmacs installs | |
532 ;; its own pre-idle-hook to implement deferral (#### something that | |
533 ;; should really be merged with this file; or more likely, lazy-lock | |
534 ;; in its entirety should be merged into font-lock). | |
535 (add-hook 'pre-idle-hook 'lazy-lock-pre-idle-fontify-windows t) | |
536 (add-hook 'post-command-hook 'lazy-lock-post-command-fontify-stealthily t) | |
537 ;; Fascistically remove font-lock's after-change-function and install | |
538 ;; our own. We know better than font-lock what to do. Otherwise, | |
539 ;; revert-buffer, insert-file, etc. cause full refontification of the | |
540 ;; entire changed area. | |
541 (if lazy-lock-mode | |
542 (progn | |
543 (remove-hook 'after-change-functions 'font-lock-after-change-function | |
544 t) | |
545 (make-local-hook 'after-change-functions) | |
546 (add-hook 'after-change-functions 'lazy-lock-after-change-function | |
547 nil t)) | |
548 (remove-hook 'after-change-functions 'lazy-lock-after-change-function t) | |
549 (if font-lock-mode | |
550 (add-hook 'after-change-functions 'font-lock-after-change-function | |
551 nil t))) | |
552 ) | |
553 | |
554 ;; use put-nonduplicable-text-property to avoid unfriendly behavior | |
555 ;; when doing undo, etc. We really don't want syntax-highlighting text | |
556 ;; properties copied into strings or tracked by undo. | |
557 ;; | |
558 ;; #### If start-open and end-open really behaved like they are supposed to, | |
559 ;; we wouldn't really need this. I kind of fixed them up, but there's still | |
560 ;; a bug -- inserting text into the middle of a region of | |
561 ;; (start-open t end-open t) text should cause it not to inherit, but it | |
562 ;; does. | |
563 | |
564 (if lazy-lock-running-xemacs-p | |
565 (defalias 'lazy-lock-put-text-property 'put-nonduplicable-text-property) | |
566 (defalias 'lazy-lock-put-text-property 'put-text-property)) | |
567 | 495 |
568 (defun lazy-lock-fontify-region (start end &optional buffer) | 496 (defun lazy-lock-fontify-region (start end &optional buffer) |
569 "Fontify between START and END in BUFFER where necessary." | 497 "Fontify between START and END in BUFFER where necessary." |
570 (save-excursion | 498 (save-excursion |
571 (and buffer (set-buffer buffer)) | 499 (and buffer (set-buffer buffer)) |
578 (defun lazy-lock-after-fontify-buffer () | 506 (defun lazy-lock-after-fontify-buffer () |
579 ;; Mark the buffer as `fontified'. | 507 ;; Mark the buffer as `fontified'. |
580 (let ((modified (buffer-modified-p)) (inhibit-read-only t) | 508 (let ((modified (buffer-modified-p)) (inhibit-read-only t) |
581 (buffer-undo-list t) | 509 (buffer-undo-list t) |
582 deactivate-mark buffer-file-name buffer-file-truename) | 510 deactivate-mark buffer-file-name buffer-file-truename) |
583 (lazy-lock-put-text-property (point-min) (point-max) 'fontified t) | 511 (put-text-property (point-min) (point-max) 'fontified t) |
584 (or modified (set-buffer-modified-p nil)))) | 512 (or modified (set-buffer-modified-p nil)))) |
585 | 513 |
586 ;; Just a cleaner-looking way of coping with Emacs' and XEmacs' `sit-for'. | 514 ;; Just a cleaner-looking way of coping with Emacs' and XEmacs' `sit-for'. |
587 (defmacro lazy-lock-sit-for (seconds &optional nodisp) | 515 (defmacro lazy-lock-sit-for (seconds &optional nodisp) |
588 (if lazy-lock-running-xemacs-p | 516 (if lazy-lock-running-xemacs-p |
603 (select-window original-window)))))) | 531 (select-window original-window)))))) |
604 (put 'save-selected-window 'lisp-indent-function 0)) | 532 (put 'save-selected-window 'lisp-indent-function 0)) |
605 | 533 |
606 ;; Functions for hooks: | 534 ;; Functions for hooks: |
607 | 535 |
608 ;; lazy-lock optimization: | 536 (defun lazy-lock-post-command-fontify-windows () |
609 ;; | 537 ;; We might not be where we think we are, since `post-command-hook' is run |
610 ;; pre-idle-hook is called an awful lot -- pretty much every time the | 538 ;; before `command_loop_1' makes sure we have the correct buffer selected. |
611 ;; mouse moves or a timeout expires, for example. On Linux (sometimes), | 539 (set-buffer (window-buffer)) |
612 ;; IRIX 5.x, and Solaris 2.something, it happens every 1/4 of a second | 540 ;; Do groovy things if (a) not in a macro, (b) no input pending, (c) got a |
613 ;; due to the 1/4-second timers installed to compensate for various | 541 ;; real command, (d) not in the minibuffer, and (e) no input after waiting |
614 ;; operating system deficiencies in the handling of SIGIO and SIGCHLD. | 542 ;; for `lazy-lock-continuity-time'. |
615 ;; (Those timers cause a cycle of the event loop. They don't necessarily | 543 (if (or executing-kbd-macro |
616 ;; have to, but rewriting to avoid this is fairly tricky and requires | 544 (input-pending-p) |
617 ;; having significant amounts of code called from signal handlers, which | 545 (memq this-command lazy-lock-ignore-commands) |
618 ;; (despite that fact that FSF Emacs reads its X input during a signal | 546 (window-minibuffer-p (selected-window))) |
619 ;; handler ?!), is almost always a bad idea -- it's extremely easy to | |
620 ;; introduce race conditions, which are very hard to track down. | |
621 ;; | |
622 ;; So to improve things, I added `frame-modified-tick'. This is an | |
623 ;; internal counter that gets ticked any time that any internal | |
624 ;; redisplay variable gets ticked. If `frame-modified-tick' is | |
625 ;; the same as the last time we checked, it means that redisplay will | |
626 ;; do absolutely nothing when encountering this frame, and thus we | |
627 ;; can skip out immediately. This happens when the 1/4-second timer | |
628 ;; fires while we're idle, or if we just move the mouse. (Moving | |
629 ;; around in a buffer changes `frame-modified-tick' because the | |
630 ;; internal redisplay variable "point_changed" gets ticked. We could | |
631 ;; easily improve things further by adding more tick counters, mirroring | |
632 ;; more closely the internal redisplay counters -- e.g. if we had | |
633 ;; another counter that didn't get ticked when point moved, we could | |
634 ;; tell if anything was going to happen by seeing if point is within | |
635 ;; window-start and window-end, since we know that redisplay will | |
636 ;; only do a window-scroll if it's not. (If window-start or window-end | |
637 ;; or window-buffer or anything else changed, windows_changed or | |
638 ;; some other variable will get ticked.)) | |
639 ;; | |
640 ;; Also, it's wise to try and avoid things that cons. Avoiding | |
641 ;; `save-window-excursion', as we do, is definitely a major win | |
642 ;; because that's a heavy-duty function as regards consing and such. | |
643 | |
644 (defvar lazy-lock-pre-idle-frame-modified-tick nil) | |
645 (defvar lazy-lock-pre-idle-selected-frame nil) | |
646 | |
647 (defun lazy-lock-pre-idle-fontify-windows () | |
648 ;; Do groovy things always unless we're in one of the ignored commands. | |
649 ;; The old version did the following five checks: | |
650 ;; | |
651 ;; (a) not in a macro, | |
652 ;; (b) no input pending, | |
653 ;; (c) got a real command (i.e. not an ignored command) | |
654 ;; (d) not in the minibuffer | |
655 ;; (e) no input after waiting for `lazy-lock-continuity-time'. | |
656 ;; | |
657 ;; (a), (b), and (e) are automatically taken care of by `pre-idle-hook'. | |
658 ;; I removed (d) because there doesn't seem to be any reason for it. | |
659 ;; | |
660 ;; Also, we do not have to `set-buffer' and in fact it would be | |
661 ;; incorrect to do so, since we may be being called from | |
662 ;; `accept-process-output' or whatever. | |
663 ;; | |
664 (if (memq this-command lazy-lock-ignore-commands) | |
665 (setq lazy-lock-cache-continue nil) | 547 (setq lazy-lock-cache-continue nil) |
666 (setq lazy-lock-cache-continue t) | 548 (setq lazy-lock-cache-continue t) |
667 ;; #### we don't yet handle frame-modified-tick on multiple frames. | 549 (if (lazy-lock-sit-for lazy-lock-continuity-time lazy-lock-hide-invisible) |
668 ;; handling this shouldn't be hard but I just haven't done it yet. | 550 ;; Do the visible parts of the buffer(s), i.e., the window(s). |
669 (if (or (eq 'all-frames lazy-lock-walk-windows) | 551 (if (or (not lazy-lock-walk-windows) |
670 (not (eq lazy-lock-pre-idle-selected-frame (selected-frame))) | 552 (and (eq lazy-lock-walk-windows t) (one-window-p t))) |
671 (not (eq lazy-lock-pre-idle-frame-modified-tick | 553 (if lazy-lock-mode (condition-case nil (lazy-lock-fontify-window))) |
672 (frame-modified-tick (selected-frame))))) | 554 (lazy-lock-fontify-walk-windows))))) |
673 (progn | 555 |
674 ;; Do the visible parts of the buffer(s), i.e., the window(s). | |
675 (if (or (not lazy-lock-walk-windows) | |
676 (and (eq lazy-lock-walk-windows t) (one-window-p t))) | |
677 (if lazy-lock-mode (condition-case nil | |
678 (lazy-lock-fontify-window))) | |
679 (lazy-lock-fontify-walk-windows)) | |
680 (setq lazy-lock-pre-idle-selected-frame (selected-frame)) | |
681 (setq lazy-lock-pre-idle-frame-modified-tick | |
682 (frame-modified-tick (selected-frame))))))) | |
683 | |
684 (defun lazy-lock-after-change-function (beg end old-len) | |
685 (and lazy-lock-mode | |
686 (if (= beg end) | |
687 (font-lock-after-change-function beg end old-len) | |
688 (lazy-lock-put-text-property beg end 'fontified nil)))) | |
689 | |
690 ;; DO NOT put this as a pre-idle hook! The sit-for messes up | |
691 ;; mouse dragging. | |
692 (defun lazy-lock-post-command-fontify-stealthily () | 556 (defun lazy-lock-post-command-fontify-stealthily () |
693 ;; Do groovy things if (a-d) above, (e) not moving the mouse, and (f) no | 557 ;; Do groovy things if (a-d) above, (e) not moving the mouse, and (f) no |
694 ;; input after waiting for `lazy-lock-stealth-time'. | 558 ;; input after after waiting for `lazy-lock-stealth-time'. |
695 (if (and lazy-lock-cache-continue lazy-lock-stealth-time) | 559 (if (and lazy-lock-cache-continue lazy-lock-stealth-time) |
696 (condition-case data | 560 (condition-case data |
697 (if (lazy-lock-sit-for lazy-lock-stealth-time) | 561 (if (lazy-lock-sit-for lazy-lock-stealth-time) |
698 ;; Do the invisible parts of buffers. | 562 ;; Do the invisible parts of buffers. |
699 (lazy-lock-fontify-walk-stealthily)) | 563 (lazy-lock-fontify-walk-stealthily)) |
700 (error (message "Fontifying stealthily... %s" data))))) | 564 (error (message "Fontifying stealthily... %s" data))))) |
701 | 565 |
702 ;; In XEmacs 19.14 with pre-idle-hook we do not have to call this. | |
703 (defun lazy-lock-post-resize-fontify-windows (frame) | 566 (defun lazy-lock-post-resize-fontify-windows (frame) |
704 ;; Fontify all windows in FRAME. | 567 ;; Fontify all windows in FRAME. |
705 (let ((lazy-lock-walk-windows t) executing-kbd-macro this-command) | 568 (let ((lazy-lock-walk-windows t) executing-kbd-macro this-command) |
706 (save-excursion | 569 (save-excursion |
707 (save-selected-window | 570 (save-selected-window |
708 (select-frame frame) | 571 (select-frame frame) |
709 (lazy-lock-pre-idle-fontify-windows))))) | 572 (lazy-lock-post-command-fontify-windows))))) |
710 | 573 |
711 (defun lazy-lock-post-setup-emacs-fontify-windows () | 574 (defun lazy-lock-post-setup-emacs-fontify-windows () |
712 ;; Fontify all windows in all frames. | 575 ;; Fontify all windows in all frames. |
713 (let ((lazy-lock-walk-windows 'all-frames) executing-kbd-macro this-command) | 576 (let ((lazy-lock-walk-windows 'all-frames) executing-kbd-macro this-command) |
714 (lazy-lock-pre-idle-fontify-windows))) | 577 (lazy-lock-post-command-fontify-windows))) |
715 | 578 |
716 (defun lazy-lock-post-setup-ediff-control-frame () | 579 (defun lazy-lock-post-setup-ediff-control-frame () |
717 ;; Fontify all windows in all frames when using the Ediff control frame. | 580 ;; Fontify all windows in all frames when using the Ediff control frame. |
718 (make-local-variable 'lazy-lock-walk-windows) | 581 (make-local-variable 'lazy-lock-walk-windows) |
719 (setq lazy-lock-walk-windows (if (ediff-multiframe-setup-p) 'all-frames t)) | 582 (setq lazy-lock-walk-windows (if (ediff-multiframe-setup-p) 'all-frames t)) |
720 (lazy-lock-fixup-hooks)) | 583 (lazy-lock-post-command-setup)) |
584 | |
585 (defun lazy-lock-post-command-setup () | |
586 ;; Make sure that we're in the correct positions to avoid hassle. | |
587 (remove-hook 'post-command-hook 'lazy-lock-post-command-fontify-windows) | |
588 (remove-hook 'post-command-hook 'lazy-lock-post-command-fontify-stealthily) | |
589 (add-hook 'post-command-hook 'lazy-lock-post-command-fontify-windows) | |
590 (add-hook (if (boundp 'post-command-idle-hook) | |
591 'post-command-idle-hook | |
592 'post-command-hook) | |
593 'lazy-lock-post-command-fontify-stealthily t)) | |
721 | 594 |
722 ;; Functions for fontification: | 595 ;; Functions for fontification: |
723 | 596 |
724 (defun lazy-lock-fontify-window () | 597 (defun lazy-lock-fontify-window () |
725 ;; Fontify the visible part of the buffer where necessary. | 598 ;; Fontify the visible part of the buffer where necessary. |
744 font-lock-beginning-of-syntax-function | 617 font-lock-beginning-of-syntax-function |
745 ;; Prevent XEmacs 19.13 during fontification from messages. | 618 ;; Prevent XEmacs 19.13 during fontification from messages. |
746 font-lock-verbose) | 619 font-lock-verbose) |
747 (while (< start end) | 620 (while (< start end) |
748 ;; Fontify and flag the region as `fontified'. | 621 ;; Fontify and flag the region as `fontified'. |
749 ;; XEmacs: need to bind `font-lock-always-fontify-immediately' | 622 (font-lock-after-change-function start end 0) |
750 ;; or we'll mess up in the presence of deferred font-locking. | 623 (put-text-property start end 'fontified t) |
751 (let ((font-lock-always-fontify-immediately t)) | |
752 (font-lock-after-change-function start end 0)) | |
753 (lazy-lock-put-text-property start end 'fontified t) | |
754 ;; Find the next region. | 624 ;; Find the next region. |
755 (setq start (or (text-property-not-all ws we 'fontified t) ws) | 625 (setq start (or (text-property-not-all ws we 'fontified t) ws) |
756 end (or (text-property-any start we 'fontified t) we))) | 626 end (or (text-property-any start we 'fontified t) we))) |
757 (setq lazy-lock-cache-start ws lazy-lock-cache-end we) | 627 (setq lazy-lock-cache-start ws lazy-lock-cache-end we) |
758 (or modified (set-buffer-modified-p nil)))))) | 628 (or modified (set-buffer-modified-p nil)))))) |
814 ;; Maybe the region is already partially `fontified'. | 684 ;; Maybe the region is already partially `fontified'. |
815 (setq start | 685 (setq start |
816 (or (previous-single-property-change prev 'fontified nil (point)) | 686 (or (previous-single-property-change prev 'fontified nil (point)) |
817 (point))))) | 687 (point))))) |
818 ;; Fontify and flag the region as `fontified'. | 688 ;; Fontify and flag the region as `fontified'. |
819 ;; XEmacs: need to bind `font-lock-always-fontify-immediately' | 689 (font-lock-after-change-function start end 0) |
820 ;; or we'll mess up in the presence of deferred font-locking. | 690 (put-text-property start end 'fontified t) |
821 (let ((font-lock-always-fontify-immediately t)) | |
822 (font-lock-after-change-function start end 0)) | |
823 (lazy-lock-put-text-property start end 'fontified t) | |
824 (or modified (set-buffer-modified-p nil))))) | 691 (or modified (set-buffer-modified-p nil))))) |
825 | 692 |
826 (defun lazy-lock-fontify-walk-stealthily () | 693 (defun lazy-lock-fontify-walk-stealthily () |
827 ;; Fontify regions in all required buffers while there is no input. | 694 ;; Fontify regions in all required buffers while there is no input. |
828 (let ((buffers (buffer-list)) (continue t) fontified message-log-max) | 695 (let ((buffers (buffer-list)) (continue t) fontified message-log-max) |
882 (make-face face) | 749 (make-face face) |
883 (if (not (equal (face-foreground face) fore)) | 750 (if (not (equal (face-foreground face) fore)) |
884 (condition-case nil | 751 (condition-case nil |
885 (set-face-foreground face fore) | 752 (set-face-foreground face fore) |
886 (error (message "Unable to use foreground \"%s\"" fore)))) | 753 (error (message "Unable to use foreground \"%s\"" fore)))) |
887 (lazy-lock-put-text-property (point-min) (point-max) 'face face) | 754 (put-text-property (point-min) (point-max) 'face face) |
888 (lazy-lock-put-text-property (point-min) (point-max) 'fontified nil) | 755 (put-text-property (point-min) (point-max) 'fontified nil) |
889 (or modified (set-buffer-modified-p nil))))) | 756 (or modified (set-buffer-modified-p nil))))) |
890 | 757 |
891 ;; Functions for Emacs: | 758 ;; Functions for Emacs: |
892 | 759 |
893 ;; This fix is for a number of bugs in the function in Emacs 19.28. | 760 ;; This fix is for a number of bugs in the function in Emacs 19.28. |
894 (if (and (not lazy-lock-running-xemacs-p) | 761 (if (and (not lazy-lock-running-xemacs-p) (< emacs-minor-version 29)) |
895 (not (emacs-version>= 19 29))) | |
896 (defun font-lock-fontify-region (start end &optional loudly) | 762 (defun font-lock-fontify-region (start end &optional loudly) |
897 "Put proper face on each string and comment between START and END." | 763 "Put proper face on each string and comment between START and END." |
898 (save-excursion | 764 (save-excursion |
899 (save-restriction | 765 (save-restriction |
900 (widen) | 766 (widen) |
933 (if (nth 3 state) | 799 (if (nth 3 state) |
934 (let ((beg (point))) | 800 (let ((beg (point))) |
935 (while (and (re-search-forward "\\s\"" end 'move) | 801 (while (and (re-search-forward "\\s\"" end 'move) |
936 (nth 3 (parse-partial-sexp beg (point) nil nil | 802 (nth 3 (parse-partial-sexp beg (point) nil nil |
937 state)))) | 803 state)))) |
938 (lazy-lock-put-text-property | 804 (put-text-property beg (point) 'face font-lock-string-face) |
939 beg (point) 'face font-lock-string-face) | |
940 (setq state (parse-partial-sexp beg (point) | 805 (setq state (parse-partial-sexp beg (point) |
941 nil nil state)))) | 806 nil nil state)))) |
942 ;; Likewise for a comment. | 807 ;; Likewise for a comment. |
943 (if (or (nth 4 state) (nth 7 state)) | 808 (if (or (nth 4 state) (nth 7 state)) |
944 (let ((beg (point))) | 809 (let ((beg (point))) |
950 (forward-comment 1) | 815 (forward-comment 1) |
951 ;; forward-comment skips all whitespace, | 816 ;; forward-comment skips all whitespace, |
952 ;; so go back to the real end of the comment. | 817 ;; so go back to the real end of the comment. |
953 (skip-chars-backward " \t")) | 818 (skip-chars-backward " \t")) |
954 (error (goto-char end)))) | 819 (error (goto-char end)))) |
955 (lazy-lock-put-text-property beg (point) 'face | 820 (put-text-property beg (point) 'face |
956 font-lock-comment-face) | 821 font-lock-comment-face) |
957 (setq state (parse-partial-sexp beg (point) | 822 (setq state (parse-partial-sexp beg (point) |
958 nil nil state)))) | 823 nil nil state)))) |
959 ;; Find each interesting place between here and END. | 824 ;; Find each interesting place between here and END. |
960 (while (and (< (point) end) | 825 (while (and (< (point) end) |
961 (setq prev (point) prevstate state) | 826 (setq prev (point) prevstate state) |
979 (forward-comment 1) | 844 (forward-comment 1) |
980 ;; forward-comment skips all whitespace, | 845 ;; forward-comment skips all whitespace, |
981 ;; so go back to the real end of the comment. | 846 ;; so go back to the real end of the comment. |
982 (skip-chars-backward " \t")) | 847 (skip-chars-backward " \t")) |
983 (error (goto-char end)))) | 848 (error (goto-char end)))) |
984 (lazy-lock-put-text-property | 849 (put-text-property beg (point) 'face |
985 beg (point) 'face font-lock-comment-face) | 850 font-lock-comment-face) |
986 (setq state (parse-partial-sexp here (point) | 851 (setq state (parse-partial-sexp here (point) |
987 nil nil state))) | 852 nil nil state))) |
988 (if (nth 3 state) | 853 (if (nth 3 state) |
989 (let ((beg (match-beginning 0))) | 854 (let ((beg (match-beginning 0))) |
990 (while (and (re-search-forward "\\s\"" end 'move) | 855 (while (and (re-search-forward "\\s\"" end 'move) |
991 (nth 3 (parse-partial-sexp | 856 (nth 3 (parse-partial-sexp |
992 here (point) nil nil state)))) | 857 here (point) nil nil state)))) |
993 (lazy-lock-put-text-property | 858 (put-text-property beg (point) 'face |
994 beg (point) 'face font-lock-string-face) | 859 font-lock-string-face) |
995 (setq state (parse-partial-sexp here (point) | 860 (setq state (parse-partial-sexp here (point) |
996 nil nil state)))))) | 861 nil nil state)))))) |
997 ;; Make sure PREV is non-nil after the loop | 862 ;; Make sure PREV is non-nil after the loop |
998 ;; only if it was set on the very last iteration. | 863 ;; only if it was set on the very last iteration. |
999 (setq prev nil))) | 864 (setq prev nil))) |
1007 ;; Functions for XEmacs: | 872 ;; Functions for XEmacs: |
1008 | 873 |
1009 ;; These fix bugs in `text-property-any' and `text-property-not-all'. They may | 874 ;; These fix bugs in `text-property-any' and `text-property-not-all'. They may |
1010 ;; not work perfectly in 19.11 and below because `next-single-property-change' | 875 ;; not work perfectly in 19.11 and below because `next-single-property-change' |
1011 ;; is also broke and not easily fixable in Lisp. | 876 ;; is also broke and not easily fixable in Lisp. |
1012 (if (and lazy-lock-running-xemacs-p | 877 (if (and lazy-lock-running-xemacs-p (< emacs-minor-version 12)) |
1013 (not (emacs-version>= 19 12))) | |
1014 (progn | 878 (progn |
1015 ;; Loop through property changes until found. This fix includes a work | 879 ;; Loop through property changes until found. This fix includes a work |
1016 ;; around which prevents a bug in `window-start' causing a barf here. | 880 ;; around which prevents a bug in `window-start' causing a barf here. |
1017 (defun text-property-any (start end prop value &optional buffer) | 881 (defun text-property-any (start end prop value &optional buffer) |
1018 "Check text from START to END to see if PROP is ever `eq' to VALUE. | 882 "Check text from START to END to see if PROP is ever `eq' to VALUE. |
1038 | 902 |
1039 ;; XEmacs 19.11 function `font-lock-any-extents-p' looks for `text-prop' rather | 903 ;; XEmacs 19.11 function `font-lock-any-extents-p' looks for `text-prop' rather |
1040 ;; than `face'. Since `font-lock-unfontify-region' only removes `face', and we | 904 ;; than `face'. Since `font-lock-unfontify-region' only removes `face', and we |
1041 ;; have non-font-lock properties hanging about, `text-prop' never gets removed. | 905 ;; have non-font-lock properties hanging about, `text-prop' never gets removed. |
1042 ;; Unfortunately `font-lock-any-extents-p' is inlined so we can't redefine it. | 906 ;; Unfortunately `font-lock-any-extents-p' is inlined so we can't redefine it. |
1043 (if (and lazy-lock-running-xemacs-p | 907 (if (and lazy-lock-running-xemacs-p (< emacs-minor-version 12)) |
1044 (not (emacs-version>= 19 12))) | |
1045 (add-hook 'font-lock-mode-hook | 908 (add-hook 'font-lock-mode-hook |
1046 (function (lambda () | 909 (function (lambda () |
1047 (remove-hook 'after-change-functions 'font-lock-after-change-function) | 910 (remove-hook 'after-change-functions 'font-lock-after-change-function) |
1048 (add-hook 'after-change-functions | 911 (add-hook 'after-change-functions |
1049 (function (lambda (beg end old-len) | 912 (function (lambda (beg end old-len) |
1050 (let ((a-c-beg beg) (a-c-end end)) | 913 (let ((a-c-beg beg) (a-c-end end)) |
1051 (save-excursion | 914 (save-excursion |
1052 ;; First set `text-prop' to nil for `font-lock-any-extents-p'. | 915 ;; First set `text-prop' to nil for `font-lock-any-extents-p'. |
1053 (goto-char end) (forward-line 1) (setq end (point)) | 916 (goto-char end) (forward-line 1) (setq end (point)) |
1054 (goto-char beg) (beginning-of-line) (setq beg (point)) | 917 (goto-char beg) (beginning-of-line) (setq beg (point)) |
1055 (lazy-lock-put-text-property beg end 'text-prop nil) | 918 (put-text-property beg end 'text-prop nil) |
1056 ;; Then do the real `font-lock-after-change-function'. | 919 ;; Then do the real `font-lock-after-change-function'. |
1057 (font-lock-after-change-function a-c-beg a-c-end old-len) | 920 (font-lock-after-change-function a-c-beg a-c-end old-len) |
1058 ;; Now set `fontified' to t to stop `lazy-lock-fontify-window'. | 921 ;; Now set `fontified' to t to stop `lazy-lock-fontify-window'. |
1059 (lazy-lock-put-text-property beg end 'fontified t)))))))))) | 922 (put-text-property beg end 'fontified t)))))))))) |
1060 | 923 |
1061 (if (and lazy-lock-running-xemacs-p (emacs-version>= 19 12)) | 924 (if (and lazy-lock-running-xemacs-p (>= emacs-minor-version 12)) |
1062 ;; XEmacs 19.12 font-lock.el's `font-lock-fontify-buffer' runs a hook. | 925 ;; XEmacs 19.12 font-lock.el's `font-lock-fontify-buffer' runs a hook. |
1063 (add-hook 'font-lock-after-fontify-buffer-hook | 926 (add-hook 'font-lock-after-fontify-buffer-hook |
1064 'lazy-lock-after-fontify-buffer)) | 927 'lazy-lock-after-fontify-buffer)) |
1065 | 928 |
1066 ;; Cope with the differences between Emacs and [LX]Emacs. | 929 ;; Cope with the differences between Emacs and [LX]Emacs. |
1070 ;; Install ourselves: | 933 ;; Install ourselves: |
1071 | 934 |
1072 ;; We don't install ourselves on `font-lock-mode-hook' as other packages can be | 935 ;; We don't install ourselves on `font-lock-mode-hook' as other packages can be |
1073 ;; used with font-lock.el, and lazy-lock.el should be dumpable without forcing | 936 ;; used with font-lock.el, and lazy-lock.el should be dumpable without forcing |
1074 ;; people to get lazy or making it difficult for people to use alternatives. | 937 ;; people to get lazy or making it difficult for people to use alternatives. |
1075 ;; make sure we add after font-lock's own pre-idle-hook. | 938 |
939 ;; After a command is run. | |
940 (lazy-lock-post-command-setup) | |
941 | |
942 ;; After some relevant event. | |
1076 (add-hook 'window-setup-hook 'lazy-lock-post-setup-emacs-fontify-windows) | 943 (add-hook 'window-setup-hook 'lazy-lock-post-setup-emacs-fontify-windows) |
1077 ;Not needed in XEmacs 19.14: | 944 ;Not needed in XEmacs 19.15: |
1078 ;(add-hook 'window-size-change-functions 'lazy-lock-post-resize-fontify-windows) | 945 ;(add-hook 'window-size-change-functions 'lazy-lock-post-resize-fontify-windows) |
1079 | 946 |
1080 ;; Package-specific. | 947 ;; Package-specific. |
1081 (add-hook 'ediff-after-setup-control-frame-hooks | 948 (add-hook 'ediff-after-setup-control-frame-hooks |
1082 'lazy-lock-post-setup-ediff-control-frame) | 949 'lazy-lock-post-setup-ediff-control-frame) |