🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #99400

using set-buffer in a filter.

#99400
From: Richard Stallman
Date: Wed, 19 Sep 1990 21:53
32 lines
1989 bytes
My last message on this subject was incorrect.  Here is a corrected
version of the text, now in the manual sources.

======================================================================
  Many filter functions sometimes or always insert the text in the
process's buffer, mimicking the actions of Emacs when there is no
filter.  Such filter functions need to use @code{set-buffer} in order to
be sure to insert in that buffer.  To avoid setting the current buffer
semipermanently, these filter functions must use @code{unwind-protect}
to make sure to restore the previous current buffer.  They should also
update the process marker, and in some cases update the value of point.
Here is how to do these things:

@example
(let ((old-buffer (current-buffer)))
  (unwind-protect
      (let (moving)
        (set-buffer (process-buffer proc))
        (setq moving (= (point) (process-mark proc)))
      	(save-excursion
	  ;; Insert the text, moving the process-marker.
	  (goto-char (process-mark proc))
	  (insert string)
	  (set-marker (process-mark proc) (point)))
        (if moving (goto-char (process-mark proc))))
    (set-buffer old-buffer)))
@end example

@noindent
The reason to use an explicit @code{unwind-protect} rather than letting
@code{save-excursion} restore the current buffer is so as to preserve
the change in point made by @code{goto-char}.
Technical Details
Message-ID: <9009192153.AA28609@pogo>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!AI.MIT.EDU!rms
References: <9009191916.AA05503@life.ai.mit.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,a4a0dbdb4374810
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-09-20 14:52:08 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!AI.MIT.EDU!rms
From: rms@AI.MIT.EDU (Richard Stallman)
Newsgroups: gnu.emacs.bug
Subject: using set-buffer in a filter.
Message-ID: <9009192153.AA28609@pogo>
Date: 19 Sep 90 21:53:38 GMT
References: <9009191916.AA05503@life.ai.mit.edu>
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 32
Posted: Wed Sep 19 22:53:38 1990