all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Replacing buffer contents --- without disturbing markers
@ 2010-09-10 23:11 Daniel Colascione
  2010-09-11  6:32 ` David Kastrup
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Daniel Colascione @ 2010-09-10 23:11 UTC (permalink / raw
  To: emacs-devel

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.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-09-11 15:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-10 23:11 Replacing buffer contents --- without disturbing markers Daniel Colascione
2010-09-11  6:32 ` David Kastrup
2010-09-11 11:01 ` Stefan Monnier
2010-09-11 15:49 ` Richard Stallman

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.