aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2012-12-11 13:51:27 -0500
committerStefan Monnier2012-12-11 13:51:27 -0500
commit6ac1f8ca0304a4856fa6223ff6f6b6fa73e0cfd3 (patch)
tree1010079face40e9ef3aa31613e6534e72952e2ac
parent4b0df84832698d8239f8a5e583955cf853b62ace (diff)
downloademacs-6ac1f8ca0304a4856fa6223ff6f6b6fa73e0cfd3.tar.gz
emacs-6ac1f8ca0304a4856fa6223ff6f6b6fa73e0cfd3.zip
* lisp/hilit-chg.el (highlight-save-buffer-state): Delete.
Use with-silent-modifications instead. (hilit-chg-set-face-on-change): Only fixup the text that's modified.
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/hilit-chg.el88
2 files changed, 40 insertions, 52 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index af21ab68606..b78aad8baff 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,9 @@
12012-12-11 Stefan Monnier <monnier@iro.umontreal.ca> 12012-12-11 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * hilit-chg.el (highlight-save-buffer-state): Delete.
4 Use with-silent-modifications instead.
5 (hilit-chg-set-face-on-change): Only fixup the text that's modified.
6
3 * button.el: Handle buttons in display text-properties. 7 * button.el: Handle buttons in display text-properties.
4 (button--area-button-p, button--area-button-string): 8 (button--area-button-p, button--area-button-string):
5 Use (STRING . STRING-POS) representation instead of just STRING. 9 Use (STRING . STRING-POS) representation instead of just STRING.
diff --git a/lisp/hilit-chg.el b/lisp/hilit-chg.el
index 7b5e2b54300..8660f876bfa 100644
--- a/lisp/hilit-chg.el
+++ b/lisp/hilit-chg.el
@@ -523,28 +523,12 @@ the text properties of type `hilit-chg'."
523 (remove-overlays beg end 'hilit-chg t) 523 (remove-overlays beg end 'hilit-chg t)
524 (hilit-chg-display-changes beg end)) 524 (hilit-chg-display-changes beg end))
525 525
526;; Inspired by font-lock. Something like this should be moved to subr.el.
527(defmacro highlight-save-buffer-state (&rest body)
528 "Bind variables according to VARLIST and eval BODY restoring buffer state."
529 (declare (indent 0) (debug t))
530 (let ((modified (make-symbol "modified")))
531 `(let* ((,modified (buffer-modified-p))
532 (inhibit-modification-hooks t)
533 deactivate-mark
534 ;; So we don't check the file's mtime.
535 buffer-file-name
536 buffer-file-truename)
537 (progn
538 ,@body)
539 (unless ,modified
540 (restore-buffer-modified-p nil)))))
541
542;;;###autoload 526;;;###autoload
543(defun highlight-changes-remove-highlight (beg end) 527(defun highlight-changes-remove-highlight (beg end)
544 "Remove the change face from the region between BEG and END. 528 "Remove the change face from the region between BEG and END.
545This allows you to manually remove highlighting from uninteresting changes." 529This allows you to manually remove highlighting from uninteresting changes."
546 (interactive "r") 530 (interactive "r")
547 (highlight-save-buffer-state 531 (with-silent-modifications
548 (remove-text-properties beg end '(hilit-chg nil)) 532 (remove-text-properties beg end '(hilit-chg nil))
549 (hilit-chg-fixup beg end))) 533 (hilit-chg-fixup beg end)))
550 534
@@ -568,40 +552,40 @@ This allows you to manually remove highlighting from uninteresting changes."
568 (if (and highlight-changes-mode 552 (if (and highlight-changes-mode
569 highlight-changes-visible-mode) 553 highlight-changes-visible-mode)
570 (hilit-chg-fixup beg end)) 554 (hilit-chg-fixup beg end))
571 (highlight-save-buffer-state 555 (with-silent-modifications
572 (if (and (= beg end) (> leng-before 0)) 556 (if (and (= beg end) (> leng-before 0))
573 ;; deletion 557 ;; deletion
574 (progn 558 (progn
575 ;; The eolp and bolp tests are a kludge! But they prevent 559 ;; The eolp and bolp tests are a kludge! But they prevent
576 ;; rather nasty looking displays when deleting text at the end 560 ;; rather nasty looking displays when deleting text at the end
577 ;; of line, such as normal corrections as one is typing and 561 ;; of line, such as normal corrections as one is typing and
578 ;; immediately makes a correction, and when deleting first 562 ;; immediately makes a correction, and when deleting first
579 ;; character of a line. 563 ;; character of a line.
580 ;; (if (= leng-before 1) 564 ;; (if (= leng-before 1)
581 ;; (if (eolp) 565 ;; (if (eolp)
582 ;; (setq beg-decr 0 end-incr 0) 566 ;; (setq beg-decr 0 end-incr 0)
583 ;; (if (bolp) 567 ;; (if (bolp)
584 ;; (setq beg-decr 0)))) 568 ;; (setq beg-decr 0))))
585 ;; (setq beg (max (- beg beg-decr) (point-min))) 569 ;; (setq beg (max (- beg beg-decr) (point-min)))
586 (setq end (min (+ end end-incr) (point-max))) 570 (setq end (min (+ end end-incr) (point-max)))
587 (setq type 'hilit-chg-delete)) 571 (setq type 'hilit-chg-delete))
588 ;; Not a deletion. 572 ;; Not a deletion.
589 ;; Most of the time the following is not necessary, but 573 ;; Most of the time the following is not necessary, but
590 ;; if the current text was marked as a deletion then 574 ;; if the current text was marked as a deletion then
591 ;; the old overlay is still in effect. So if the user adds some 575 ;; the old overlay is still in effect. So if the user adds some
592 ;; text where she earlier deleted text, we have to remove the 576 ;; text where she earlier deleted text, we have to remove the
593 ;; deletion marking, and replace it explicitly with a `changed' 577 ;; deletion marking, and replace it explicitly with a `changed'
594 ;; marking, otherwise its highlighting would disappear. 578 ;; marking, otherwise its highlighting would disappear.
595 (if (eq (get-text-property end 'hilit-chg) 'hilit-chg-delete) 579 (if (eq (get-text-property end 'hilit-chg) 'hilit-chg-delete)
596 (save-restriction 580 (save-restriction
597 (widen) 581 (widen)
598 (put-text-property end (+ end 1) 'hilit-chg 'hilit-chg) 582 (put-text-property end (+ end 1) 'hilit-chg 'hilit-chg)
599 (if highlight-changes-visible-mode 583 (if highlight-changes-visible-mode
600 (hilit-chg-fixup beg (+ end 1)))))) 584 (hilit-chg-fixup end (+ end 1))))))
601 (unless no-property-change 585 (unless no-property-change
602 (put-text-property beg end 'hilit-chg type)) 586 (put-text-property beg end 'hilit-chg type))
603 (if (or highlight-changes-visible-mode no-property-change) 587 (if (or highlight-changes-visible-mode no-property-change)
604 (hilit-chg-make-ov type beg end))))))) 588 (hilit-chg-make-ov type beg end)))))))
605 589
606(defun hilit-chg-update () 590(defun hilit-chg-update ()
607 "Update a buffer's highlight changes when visibility changed." 591 "Update a buffer's highlight changes when visibility changed."
@@ -635,7 +619,7 @@ This removes all saved change information."
635 (message "Cannot remove highlighting from read-only mode buffer %s" 619 (message "Cannot remove highlighting from read-only mode buffer %s"
636 (buffer-name)) 620 (buffer-name))
637 (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)
638 (highlight-save-buffer-state 622 (with-silent-modifications
639 (hilit-chg-hide-changes) 623 (hilit-chg-hide-changes)
640 (hilit-chg-map-changes 624 (hilit-chg-map-changes
641 (lambda (_prop start stop) 625 (lambda (_prop start stop)