Function: epa-file--replace-text

epa-file--replace-text is a byte-compiled function defined in epa-file.el.gz.

Signature

(epa-file--replace-text STRING FILE VISIT BEG END)

Source Code

;; Defined in /usr/src/emacs/lisp/epa-file.el.gz
(defun epa-file--replace-text (string file visit beg end)
  ;; The idea here is that we want to replace the text in the buffer
  ;; (for instance, for a `revert-buffer'), but we want to touch as
  ;; little of the text as possible.  So we compare the new and the
  ;; old text and only starts replacing when the text changes.
  (let ((orig-point (point))
        new-start length)
    (goto-char (point-max))
    (setq new-start (point))
    (setq length
	  (epa-file-decode-and-insert
           string file visit beg end t))
    (if (equal (buffer-substring (point-min) new-start)
               (buffer-substring new-start (point-max)))
        ;; The new text is equal to the old, so just keep the old.
        (delete-region new-start (point-max))
      ;; Compute the region the hard way.
      (let ((p1 (point-min))
            (p2 new-start))
        (while (and (< p1 new-start)
                    (< p2 (point-max))
                    (eql (char-after p1) (char-after p2)))
          (incf p1)
          (incf p2))
        (delete-region new-start p2)
        (delete-region p1 new-start)))
    ;; Restore point, if possible.
    (if (< orig-point (point-max))
        (goto-char orig-point)
      (goto-char (point-max)))
    length))