From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: Replacing buffer contents --- without disturbing markers Date: Sat, 11 Sep 2010 08:32:35 +0200 Organization: Organization?!? Message-ID: <87tylwpz7g.fsf@lola.goethe.zz> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1284186780 30058 80.91.229.12 (11 Sep 2010 06:33:00 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 11 Sep 2010 06:33:00 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Sep 11 08:32:59 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OuJdw-0001TM-O4 for ged-emacs-devel@m.gmane.org; Sat, 11 Sep 2010 08:32:57 +0200 Original-Received: from localhost ([127.0.0.1]:34327 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OuJdu-000068-Iw for ged-emacs-devel@m.gmane.org; Sat, 11 Sep 2010 02:32:54 -0400 Original-Received: from [140.186.70.92] (port=38024 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OuJdm-0008VS-A0 for emacs-devel@gnu.org; Sat, 11 Sep 2010 02:32:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OuJdl-00025e-4p for emacs-devel@gnu.org; Sat, 11 Sep 2010 02:32:46 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:55663) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OuJdk-00025X-QI for emacs-devel@gnu.org; Sat, 11 Sep 2010 02:32:45 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OuJdj-0001Ro-6q for emacs-devel@gnu.org; Sat, 11 Sep 2010 08:32:43 +0200 Original-Received: from p508eadda.dip.t-dialin.net ([80.142.173.218]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 11 Sep 2010 08:32:43 +0200 Original-Received: from dak by p508eadda.dip.t-dialin.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 11 Sep 2010 08:32:43 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 33 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: p508eadda.dip.t-dialin.net X-Face: 2FEFf>]>q>2iw=B6, xrUubRI>pR&Ml9=ao@P@i)L:\urd*t9M~y1^:+Y]'C0~{mAl`oQuAl \!3KEIp?*w`|bL5qr,H)LFO6Q=qx~iH4DN; i"; /yuIsqbLLCh/!U#X[S~(5eZ41to5f%E@'ELIi$t^ Vc\LWP@J5p^rst0+('>Er0=^1{]M9!p?&:\z]|;&=NP3AhB!B_bi^]Pfkw User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:LFJZ8SOHzhbVPro9C1OQxONuvzA= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:129952 Archived-At: Daniel Colascione 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