diff options
| author | Stefan Monnier | 2008-02-13 21:50:37 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2008-02-13 21:50:37 +0000 |
| commit | 2e8195083823ba5ba044343389bd39adc9f48072 (patch) | |
| tree | b8cab3afb029cc7c631bd6367f06233084248c97 | |
| parent | de95cc30ec71235a682f16b7356569620fe947b9 (diff) | |
| download | emacs-2e8195083823ba5ba044343389bd39adc9f48072.tar.gz emacs-2e8195083823ba5ba044343389bd39adc9f48072.zip | |
(highlight-save-buffer-state): New macro.
(highlight-save-buffer-state, hilit-chg-set-face-on-change)
(hilit-chg-clear): Use it to preserve the modified-p flag.
(highlight-changes-rotate-faces): Don't mess with the undo-list.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/hilit-chg.el | 95 |
2 files changed, 62 insertions, 40 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 87141d02ed2..9233db66710 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2008-02-13 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * hilit-chg.el (highlight-save-buffer-state): New macro. | ||
| 4 | (highlight-save-buffer-state, hilit-chg-set-face-on-change) | ||
| 5 | (hilit-chg-clear): Use it to preserve the modified-p flag. | ||
| 6 | (highlight-changes-rotate-faces): Don't mess with the undo-list. | ||
| 7 | |||
| 1 | 2008-02-13 Michael Albinus <michael.albinus@gmx.de> | 8 | 2008-02-13 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 9 | ||
| 3 | * net/ange-ftp.el (ange-ftp-cf1): Quote FILENAME. | 10 | * net/ange-ftp.el (ange-ftp-cf1): Quote FILENAME. |
diff --git a/lisp/hilit-chg.el b/lisp/hilit-chg.el index f75c694175d..73d6c4b91d8 100644 --- a/lisp/hilit-chg.el +++ b/lisp/hilit-chg.el | |||
| @@ -515,12 +515,28 @@ the text properties of type `hilit-chg'." | |||
| 515 | (delete-overlay ov)))))) | 515 | (delete-overlay ov)))))) |
| 516 | (hilit-chg-display-changes beg end))) | 516 | (hilit-chg-display-changes beg end))) |
| 517 | 517 | ||
| 518 | ;; Inspired by font-lock. Something like this should be moved to subr.el. | ||
| 519 | (defmacro highlight-save-buffer-state (&rest body) | ||
| 520 | "Bind variables according to VARLIST and eval BODY restoring buffer state." | ||
| 521 | (declare (indent 0) (debug t)) | ||
| 522 | (let ((modified (make-symbol "modified"))) | ||
| 523 | `(let* ((,modified (buffer-modified-p)) | ||
| 524 | (inhibit-modification-hooks t) | ||
| 525 | deactivate-mark | ||
| 526 | ;; So we don't check the file's mtime. | ||
| 527 | buffer-file-name | ||
| 528 | buffer-file-truename) | ||
| 529 | (progn | ||
| 530 | ,@body) | ||
| 531 | (unless ,modified | ||
| 532 | (restore-buffer-modified-p nil))))) | ||
| 533 | |||
| 518 | ;;;###autoload | 534 | ;;;###autoload |
| 519 | (defun highlight-changes-remove-highlight (beg end) | 535 | (defun highlight-changes-remove-highlight (beg end) |
| 520 | "Remove the change face from the region between BEG and END. | 536 | "Remove the change face from the region between BEG and END. |
| 521 | This allows you to manually remove highlighting from uninteresting changes." | 537 | This allows you to manually remove highlighting from uninteresting changes." |
| 522 | (interactive "r") | 538 | (interactive "r") |
| 523 | (let ((after-change-functions nil)) | 539 | (highlight-save-buffer-state |
| 524 | (remove-text-properties beg end '(hilit-chg nil)) | 540 | (remove-text-properties beg end '(hilit-chg nil)) |
| 525 | (hilit-chg-fixup beg end))) | 541 | (hilit-chg-fixup beg end))) |
| 526 | 542 | ||
| @@ -543,38 +559,39 @@ This allows you to manually remove highlighting from uninteresting changes." | |||
| 543 | (if undo-in-progress | 559 | (if undo-in-progress |
| 544 | (if (eq highlight-changes-mode 'active) | 560 | (if (eq highlight-changes-mode 'active) |
| 545 | (hilit-chg-fixup beg end)) | 561 | (hilit-chg-fixup beg end)) |
| 546 | (if (and (= beg end) (> leng-before 0)) | 562 | (highlight-save-buffer-state |
| 547 | ;; deletion | 563 | (if (and (= beg end) (> leng-before 0)) |
| 548 | (progn | 564 | ;; deletion |
| 549 | ;; The eolp and bolp tests are a kludge! But they prevent | 565 | (progn |
| 550 | ;; rather nasty looking displays when deleting text at the end | 566 | ;; The eolp and bolp tests are a kludge! But they prevent |
| 551 | ;; of line, such as normal corrections as one is typing and | 567 | ;; rather nasty looking displays when deleting text at the end |
| 552 | ;; immediately makes a correction, and when deleting first | 568 | ;; of line, such as normal corrections as one is typing and |
| 553 | ;; character of a line. | 569 | ;; immediately makes a correction, and when deleting first |
| 554 | ;;; (if (= leng-before 1) | 570 | ;; character of a line. |
| 555 | ;;; (if (eolp) | 571 | ;; (if (= leng-before 1) |
| 556 | ;;; (setq beg-decr 0 end-incr 0) | 572 | ;; (if (eolp) |
| 557 | ;;; (if (bolp) | 573 | ;; (setq beg-decr 0 end-incr 0) |
| 558 | ;;; (setq beg-decr 0)))) | 574 | ;; (if (bolp) |
| 559 | ;;; (setq beg (max (- beg beg-decr) (point-min))) | 575 | ;; (setq beg-decr 0)))) |
| 560 | (setq end (min (+ end end-incr) (point-max))) | 576 | ;; (setq beg (max (- beg beg-decr) (point-min))) |
| 561 | (setq type 'hilit-chg-delete)) | 577 | (setq end (min (+ end end-incr) (point-max))) |
| 562 | ;; Not a deletion. | 578 | (setq type 'hilit-chg-delete)) |
| 563 | ;; Most of the time the following is not necessary, but | 579 | ;; Not a deletion. |
| 564 | ;; if the current text was marked as a deletion then | 580 | ;; Most of the time the following is not necessary, but |
| 565 | ;; the old overlay is still in effect, so if we add some | 581 | ;; if the current text was marked as a deletion then |
| 566 | ;; text then remove the deletion marking, but set it to | 582 | ;; the old overlay is still in effect, so if we add some |
| 583 | ;; text then remove the deletion marking, but set it to | ||
| 567 | ;; changed otherwise its highlighting disappears. | 584 | ;; changed otherwise its highlighting disappears. |
| 568 | (if (eq (get-text-property end 'hilit-chg) 'hilit-chg-delete) | 585 | (if (eq (get-text-property end 'hilit-chg) 'hilit-chg-delete) |
| 569 | (progn | 586 | (progn |
| 570 | (remove-text-properties end (+ end 1) '(hilit-chg nil)) | 587 | (remove-text-properties end (+ end 1) '(hilit-chg nil)) |
| 571 | (put-text-property end (+ end 1) 'hilit-chg 'hilit-chg) | 588 | (put-text-property end (+ end 1) 'hilit-chg 'hilit-chg) |
| 572 | (if (eq highlight-changes-mode 'active) | 589 | (if (eq highlight-changes-mode 'active) |
| 573 | (hilit-chg-fixup beg (+ end 1)))))) | 590 | (hilit-chg-fixup beg (+ end 1)))))) |
| 574 | (unless no-property-change | 591 | (unless no-property-change |
| 575 | (put-text-property beg end 'hilit-chg type)) | 592 | (put-text-property beg end 'hilit-chg type)) |
| 576 | (if (or (eq highlight-changes-mode 'active) no-property-change) | 593 | (if (or (eq highlight-changes-mode 'active) no-property-change) |
| 577 | (hilit-chg-make-ov type beg end)))))) | 594 | (hilit-chg-make-ov type beg end))))))) |
| 578 | 595 | ||
| 579 | (defun hilit-chg-set (value) | 596 | (defun hilit-chg-set (value) |
| 580 | "Turn on Highlight Changes mode for this buffer." | 597 | "Turn on Highlight Changes mode for this buffer." |
| @@ -602,12 +619,11 @@ This removes all saved change information." | |||
| 602 | (message "Cannot remove highlighting from read-only mode buffer %s" | 619 | (message "Cannot remove highlighting from read-only mode buffer %s" |
| 603 | (buffer-name)) | 620 | (buffer-name)) |
| 604 | (remove-hook 'after-change-functions 'hilit-chg-set-face-on-change t) | 621 | (remove-hook 'after-change-functions 'hilit-chg-set-face-on-change t) |
| 605 | (let ((after-change-functions nil)) | 622 | (highlight-save-buffer-state |
| 606 | (hilit-chg-hide-changes) | 623 | (hilit-chg-hide-changes) |
| 607 | (hilit-chg-map-changes | 624 | (hilit-chg-map-changes |
| 608 | '(lambda (prop start stop) | 625 | (lambda (prop start stop) |
| 609 | (remove-text-properties start stop '(hilit-chg nil)))) | 626 | (remove-text-properties start stop '(hilit-chg nil))))) |
| 610 | ) | ||
| 611 | (setq highlight-changes-mode nil) | 627 | (setq highlight-changes-mode nil) |
| 612 | (force-mode-line-update) | 628 | (force-mode-line-update) |
| 613 | ;; If we type: C-u -1 M-x highlight-changes-mode | 629 | ;; If we type: C-u -1 M-x highlight-changes-mode |
| @@ -798,11 +814,12 @@ this, eval the following in the buffer to be saved: | |||
| 798 | ;; of the current buffer due to the rotation. We do this by inserting (in | 814 | ;; of the current buffer due to the rotation. We do this by inserting (in |
| 799 | ;; `buffer-undo-list') entries restoring buffer-modified-p to nil before | 815 | ;; `buffer-undo-list') entries restoring buffer-modified-p to nil before |
| 800 | ;; and after the entry for the rotation. | 816 | ;; and after the entry for the rotation. |
| 801 | (unless modified | 817 | ;; FIXME: this is no good: we need to test the `modified' state at the |
| 802 | ;; Install the "before" entry. | 818 | ;; time of the undo, not at the time of the "do", otherwise the undo |
| 803 | (setq buffer-undo-list | 819 | ;; may erroneously clear the modified flag. --Stef |
| 804 | (cons '(apply restore-buffer-modified-p nil) | 820 | ;; (unless modified |
| 805 | buffer-undo-list))) | 821 | ;; ;; Install the "before" entry. |
| 822 | ;; (push '(apply restore-buffer-modified-p nil) buffer-undo-list)) | ||
| 806 | (unwind-protect | 823 | (unwind-protect |
| 807 | (progn | 824 | (progn |
| 808 | ;; ensure hilit-chg-list is made and up to date | 825 | ;; ensure hilit-chg-list is made and up to date |
| @@ -815,10 +832,8 @@ this, eval the following in the buffer to be saved: | |||
| 815 | (if (eq highlight-changes-mode 'active) | 832 | (if (eq highlight-changes-mode 'active) |
| 816 | (hilit-chg-display-changes))) | 833 | (hilit-chg-display-changes))) |
| 817 | (unless modified | 834 | (unless modified |
| 818 | ;; Install the "after" entry. | 835 | ;; Install the "after" entry. FIXME: See above. |
| 819 | (setq buffer-undo-list | 836 | ;; (push '(apply restore-buffer-modified-p nil) buffer-undo-list) |
| 820 | (cons '(apply restore-buffer-modified-p nil) | ||
| 821 | buffer-undo-list)) | ||
| 822 | 837 | ||
| 823 | (restore-buffer-modified-p nil))))) | 838 | (restore-buffer-modified-p nil))))) |
| 824 | ;; This always returns nil so it is safe to use in write-file-functions | 839 | ;; This always returns nil so it is safe to use in write-file-functions |