From: David Kastrup <dak@gnu.org>
To: emacs-devel@gnu.org
Subject: Re: Replacing buffer contents --- without disturbing markers
Date: Sat, 11 Sep 2010 08:32:35 +0200 [thread overview]
Message-ID: <87tylwpz7g.fsf@lola.goethe.zz> (raw)
In-Reply-To: AANLkTinDnb-FJnrjMkYiV53vx8wevMg=Tpg7EVO76Ju2@mail.gmail.com
Daniel Colascione <dan.colascione@gmail.com> 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
next prev parent reply other threads:[~2010-09-11 6:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-10 23:11 Replacing buffer contents --- without disturbing markers Daniel Colascione
2010-09-11 6:32 ` David Kastrup [this message]
2010-09-11 11:01 ` Stefan Monnier
2010-09-11 15:49 ` Richard Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87tylwpz7g.fsf@lola.goethe.zz \
--to=dak@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.