🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #99387

using set-buffer in a filter.

#99387
From: Scott D Kalter
Date: Tue, 18 Sep 1990 23:29
75 lines
3285 bytes
GNU Emacs 18.55.0 on ata (berkeley-unix)
Sun OS 4.1
Sun4c

The problem seems to be that a process filter that does a set-buffer
will change the selected window for the following character of user
input at which point the selected window will change back again.

Here is an example running from the *scratch* buffer:

----------------------------------------------------------------
(defun foo-filter (proc str) 
   (set-buffer (get-buffer-create "test"))
   (insert str))
foo-filter

(set-process-filter (start-process "test-proc" "test" "csh" "-i") 'foo-filter)
foo-filter
----------------------------------------------------------------

After starting the process if I type 'j' (a single jay) I see nothing
happen.  If I type another one I will see that one appear.  If I
switch to the "test" buffer I will see:

----------------------------------------------------------------
[shadow]sdk> j
----------------------------------------------------------------

The 'j' has appeared in this buffer!

I ***believe*** that the bug is in:

File    : keyboard.c
Function: command_loop_1()

About 30 lines into the page containing this routine, there is a check
to make sure the current window is selected.  Later, at about line 71,
a call is made to read_key_sequence() and starting there the call tree
goes:

read_key_sequence()
get_char()
kbd_buffer_get_char()
wait_reading_process_input()

Here we do a read_process_output() inside a while loop waiting to
timeout or get keyboard input.  I believe this is where the filter is
run which changes the selected window, then keyboard input comes in
which leaves the loop and the input is processed THEN command_loop_1()
gets called again which selects the correct window again.

I have not verified this, I started getting dizzy reading the code.  I
see two possible fixes:

1.  Document that filters should do a save-excursion if the are going
to select different buffers.  I may have missed such documentation but
I glanced at some other standard filters and some of them seem to
set-buffer and not save-excursion.

2.  Verify that the selected buffer is that of the current window
*after* returning from wait_reading_process_input (or maybe after
returning from a process filter?).

I really don't understand the issues well enough to suggest a specific
implementation to (2) above.  I also hope that I am right that (1) is
an effective work-around cause I'm having this problem right now and
don't have another fix.

Some feedback would be greatly appreciated, especially if I'm doing
something wrong or that (1) above is not completely effective.

Thanks,

-Scott D. Kalter  <sdk@twinsun.com>
Technical Details
Message-ID: <9009182329.AA05806@shadow.twinsun.com>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!twinsun.com!sdk

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,a4a0dbdb4374810,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-09-18 16:29:34 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!twinsun.com!sdk
From: sdk@twinsun.com (Scott D Kalter)
Newsgroups: gnu.emacs.bug
Subject: using set-buffer in a filter.
Message-ID: <9009182329.AA05806@shadow.twinsun.com>
Date: 18 Sep 90 23:29:34 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 75
Posted: Wed Sep 19 00:29:34 1990