Function: hilit-chg-set-face-on-change

hilit-chg-set-face-on-change is a byte-compiled function defined in hilit-chg.el.gz.

Signature

(hilit-chg-set-face-on-change BEG END LENG-BEFORE &optional NO-PROPERTY-CHANGE)

Documentation

Record changes and optionally display them in a distinctive face.

hilit-chg-set adds this function to the after-change-functions hook.

Source Code

;; Defined in /usr/src/emacs/lisp/hilit-chg.el.gz
(defun hilit-chg-set-face-on-change (beg end leng-before
					 &optional no-property-change)
  "Record changes and optionally display them in a distinctive face.
`hilit-chg-set' adds this function to the `after-change-functions' hook."
  ;;
  ;; This function is called by the `after-change-functions' hook, which
  ;; is how we are notified when text is changed.
  ;; It is also called from `highlight-compare-with-file'.
  ;;
  ;; We do NOT want to simply do this if this is an undo command, because
  ;; otherwise an undone change shows up as changed.  While the properties
  ;; are automatically restored by undo, we must fix up the overlay.
  (save-match-data
    (let ((end-incr 1)
	  (type 'hilit-chg)
          (property 'hilit-chg))
      (if undo-in-progress
	  (if (and highlight-changes-mode
		   highlight-changes-visible-mode)
	      (hilit-chg-fixup beg end))
        (with-silent-modifications
          (if (and (= beg end) (> leng-before 0))
              ;; deletion
              (progn
                ;; The eolp and bolp tests are a kludge!  But they prevent
                ;; rather nasty looking displays when deleting text at the end
                ;; of line, such as normal corrections as one is typing and
                ;; immediately makes a correction, and when deleting first
                ;; character of a line.
                ;; (if (= leng-before 1)
                ;;     (if (eolp)
                ;;         (setq beg-decr 0 end-incr 0)
                ;;       (if (bolp)
                ;;      (setq beg-decr 0))))
                ;; (setq beg (max (- beg beg-decr) (point-min)))
                (setq end (min (+ end end-incr) (point-max)))
                (setq type 'hilit-chg-delete
                      property 'hilit-chg-delete))
            ;; Not a deletion.
            ;; Most of the time the following is not necessary, but
            ;; if the current text was marked as a deletion then
            ;; the old overlay is still in effect.  So if the user adds some
            ;; text where she earlier deleted text, we have to remove the
            ;; deletion marking, and replace it explicitly with a `changed'
            ;; marking, otherwise its highlighting would disappear.
            (when (eq (get-text-property end 'hilit-chg-delete)
                      'hilit-chg-delete)
              (save-restriction
                (widen)
                (put-text-property end (+ end 1) 'hilit-chg-delete nil)
                (if highlight-changes-visible-mode
                    (hilit-chg-fixup end (+ end 1))))))
          (unless no-property-change
            (put-text-property beg end property type))
          (if (or highlight-changes-visible-mode no-property-change)
              (hilit-chg-make-ov type beg end)))))))