emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Replacing buffer contents --- without disturbing markers


From: Daniel Colascione
Subject: Replacing buffer contents --- without disturbing markers
Date: Fri, 10 Sep 2010 16:11:14 -0700

For a mode I'm writing, I have to temporarily replace certain parts of
the buffer with placeholder text. I'm using this function to do it:

(defun ntcmd-inplace-replace (replacement)
  "Replace the characters at point with REPLACEMENT without disturbing markers.

Leave point after replacement. The number of characters replaced
is the length of REPLACEMENT."

  (loop for c across replacement
        ;; Replace the character after point with the next character
        ;; from replacement. We must worry about two kinds
        ;; of marker: those pointing at point (including (point)), and
        ;; those pointing at (1+ (point)).
        ;;
        ;; Mentally run through the code below, and you'll see that
        ;; both kinds of marker are preserved.
        ;;
        do (progn
             (forward-char 1)
             (insert-before-markers c)
             (backward-char 1)
             (delete-char -1)
             (forward-char 1))))

Is it possible to do better? replace-match squashes markers.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]