From: Daniel Colascione <dan.colascione@gmail.com>
To: emacs-devel@gnu.org
Subject: Replacing buffer contents --- without disturbing markers
Date: Fri, 10 Sep 2010 16:11:14 -0700 [thread overview]
Message-ID: <AANLkTinDnb-FJnrjMkYiV53vx8wevMg=Tpg7EVO76Ju2@mail.gmail.com> (raw)
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.
next reply other threads:[~2010-09-10 23:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-10 23:11 Daniel Colascione [this message]
2010-09-11 6:32 ` Replacing buffer contents --- without disturbing markers David Kastrup
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='AANLkTinDnb-FJnrjMkYiV53vx8wevMg=Tpg7EVO76Ju2@mail.gmail.com' \
--to=dan.colascione@gmail.com \
--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.