emacs-devel
[Top][All Lists]
Advanced

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

Re: Replacing buffer contents --- without disturbing markers


From: David Kastrup
Subject: Re: Replacing buffer contents --- without disturbing markers
Date: Sat, 11 Sep 2010 08:32:35 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Daniel Colascione <address@hidden> writes:

> 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.

Not sure whether make-indirect-buffer would keep the markers in piece.

-- 
David Kastrup




reply via email to

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