From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Colascione Newsgroups: gmane.emacs.devel Subject: Replacing buffer contents --- without disturbing markers Date: Fri, 10 Sep 2010 16:11:14 -0700 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: dough.gmane.org 1284160340 28042 80.91.229.12 (10 Sep 2010 23:12:20 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 10 Sep 2010 23:12:20 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Sep 11 01:12:19 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 1OuClW-0005pW-EG for ged-emacs-devel@m.gmane.org; Sat, 11 Sep 2010 01:12:18 +0200 Original-Received: from localhost ([127.0.0.1]:54273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OuClV-0006eS-JP for ged-emacs-devel@m.gmane.org; Fri, 10 Sep 2010 19:12:17 -0400 Original-Received: from [140.186.70.92] (port=37699 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OuClJ-0006N9-Uo for emacs-devel@gnu.org; Fri, 10 Sep 2010 19:12:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OuCkW-0000bG-0D for emacs-devel@gnu.org; Fri, 10 Sep 2010 19:11:16 -0400 Original-Received: from mail-wy0-f169.google.com ([74.125.82.169]:59747) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OuCkV-0000bA-SP for emacs-devel@gnu.org; Fri, 10 Sep 2010 19:11:15 -0400 Original-Received: by wyb36 with SMTP id 36so3968919wyb.0 for ; Fri, 10 Sep 2010 16:11:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=HJzONWXizNpSBxedkN2W9ImTms5Mv5I6UeA+OSroMeg=; b=TtNmj3BxZvD/Fz0KLIW+oo6whcyAYtFbXTC92uOdDq2mgRWmjwj4u1ZcpsbcxFNqSS LBfKmedpUidewUFV0gE6FCygz2xMpgqdzqz3QlFsKHmHAEeXcPTITkBE1eka8q6XacoF a3MO4txyXIdibK7t7Fp1h/sf7f7KjQ1+Jj+84= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=queOEXjK9KXpyxr9NEVrQOqy/lTl3M74UAyJUjtdOB+aWc/w5pL9MqVcM30xxv5pGC BYZG+JzTmS9ltBI7PpNpUIM0s/kFNMFEZQxhNnOYg2/F+iUNlAitNAycTz/mmq+635XM q66PSi9P0hiIaC1KdF7l5jXZ7peGT88YkPe+Y= Original-Received: by 10.227.138.141 with SMTP id a13mr732774wbu.208.1284160274481; Fri, 10 Sep 2010 16:11:14 -0700 (PDT) Original-Received: by 10.216.136.2 with HTTP; Fri, 10 Sep 2010 16:11:14 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) 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:129936 Archived-At: 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.