comparison src/process.c @ 107825:57e2e94dbe55

(read_process_output): Move the save-current-buffer to apply to both the filter and the non-filter branches.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 11 Apr 2010 11:53:13 -0400
parents 912a8c0c9a8a
children 6438b98db9dd
comparison
equal deleted inserted replaced
107824:ffe32691e3ab 107825:57e2e94dbe55
5312 register struct Lisp_Process *p = XPROCESS (proc); 5312 register struct Lisp_Process *p = XPROCESS (proc);
5313 register int opoint; 5313 register int opoint;
5314 struct coding_system *coding = proc_decode_coding_system[channel]; 5314 struct coding_system *coding = proc_decode_coding_system[channel];
5315 int carryover = p->decoding_carryover; 5315 int carryover = p->decoding_carryover;
5316 int readmax = 4096; 5316 int readmax = 4096;
5317 int count = SPECPDL_INDEX ();
5318 Lisp_Object odeactivate;
5317 5319
5318 chars = (char *) alloca (carryover + readmax); 5320 chars = (char *) alloca (carryover + readmax);
5319 if (carryover) 5321 if (carryover)
5320 /* See the comment above. */ 5322 /* See the comment above. */
5321 bcopy (SDATA (p->decoding_buf), chars, carryover); 5323 bcopy (SDATA (p->decoding_buf), chars, carryover);
5384 } 5386 }
5385 5387
5386 /* Now set NBYTES how many bytes we must decode. */ 5388 /* Now set NBYTES how many bytes we must decode. */
5387 nbytes += carryover; 5389 nbytes += carryover;
5388 5390
5391 odeactivate = Vdeactivate_mark;
5392 /* There's no good reason to let process filters change the current
5393 buffer, and many callers of accept-process-output, sit-for, and
5394 friends don't expect current-buffer to be changed from under them. */
5395 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
5396
5389 /* Read and dispose of the process output. */ 5397 /* Read and dispose of the process output. */
5390 outstream = p->filter; 5398 outstream = p->filter;
5391 if (!NILP (outstream)) 5399 if (!NILP (outstream))
5392 { 5400 {
5393 /* We inhibit quit here instead of just catching it so that
5394 hitting ^G when a filter happens to be running won't screw
5395 it up. */
5396 int count = SPECPDL_INDEX ();
5397 Lisp_Object odeactivate;
5398 Lisp_Object obuffer, okeymap; 5401 Lisp_Object obuffer, okeymap;
5399 Lisp_Object text; 5402 Lisp_Object text;
5400 int outer_running_asynch_code = running_asynch_code; 5403 int outer_running_asynch_code = running_asynch_code;
5401 int waiting = waiting_for_user_input_p; 5404 int waiting = waiting_for_user_input_p;
5402 5405
5403 /* No need to gcpro these, because all we do with them later 5406 /* No need to gcpro these, because all we do with them later
5404 is test them for EQness, and none of them should be a string. */ 5407 is test them for EQness, and none of them should be a string. */
5405 odeactivate = Vdeactivate_mark;
5406 XSETBUFFER (obuffer, current_buffer); 5408 XSETBUFFER (obuffer, current_buffer);
5407 okeymap = current_buffer->keymap; 5409 okeymap = current_buffer->keymap;
5408 5410
5411 /* We inhibit quit here instead of just catching it so that
5412 hitting ^G when a filter happens to be running won't screw
5413 it up. */
5409 specbind (Qinhibit_quit, Qt); 5414 specbind (Qinhibit_quit, Qt);
5410 specbind (Qlast_nonmenu_event, Qt); 5415 specbind (Qlast_nonmenu_event, Qt);
5411 5416
5412 /* In case we get recursively called, 5417 /* In case we get recursively called,
5413 and we already saved the match data nonrecursively, 5418 and we already saved the match data nonrecursively,
5472 5477
5473 /* If we saved the match data nonrecursively, restore it now. */ 5478 /* If we saved the match data nonrecursively, restore it now. */
5474 restore_search_regs (); 5479 restore_search_regs ();
5475 running_asynch_code = outer_running_asynch_code; 5480 running_asynch_code = outer_running_asynch_code;
5476 5481
5477 /* Handling the process output should not deactivate the mark. */
5478 Vdeactivate_mark = odeactivate;
5479
5480 /* Restore waiting_for_user_input_p as it was 5482 /* Restore waiting_for_user_input_p as it was
5481 when we were called, in case the filter clobbered it. */ 5483 when we were called, in case the filter clobbered it. */
5482 waiting_for_user_input_p = waiting; 5484 waiting_for_user_input_p = waiting;
5483 5485
5484 #if 0 /* Call record_asynch_buffer_change unconditionally, 5486 #if 0 /* Call record_asynch_buffer_change unconditionally,
5490 /* But do it only if the caller is actually going to read events. 5492 /* But do it only if the caller is actually going to read events.
5491 Otherwise there's no need to make him wake up, and it could 5493 Otherwise there's no need to make him wake up, and it could
5492 cause trouble (for example it would make sit_for return). */ 5494 cause trouble (for example it would make sit_for return). */
5493 if (waiting_for_user_input_p == -1) 5495 if (waiting_for_user_input_p == -1)
5494 record_asynch_buffer_change (); 5496 record_asynch_buffer_change ();
5495
5496 unbind_to (count, Qnil);
5497 return nbytes;
5498 } 5497 }
5499 5498
5500 /* If no filter, write into buffer if it isn't dead. */ 5499 /* If no filter, write into buffer if it isn't dead. */
5501 if (!NILP (p->buffer) && !NILP (XBUFFER (p->buffer)->name)) 5500 else if (!NILP (p->buffer) && !NILP (XBUFFER (p->buffer)->name))
5502 { 5501 {
5503 Lisp_Object old_read_only; 5502 Lisp_Object old_read_only;
5504 int old_begv, old_zv; 5503 int old_begv, old_zv;
5505 int old_begv_byte, old_zv_byte; 5504 int old_begv_byte, old_zv_byte;
5506 Lisp_Object odeactivate;
5507 int before, before_byte; 5505 int before, before_byte;
5508 int opoint_byte; 5506 int opoint_byte;
5509 Lisp_Object text; 5507 Lisp_Object text;
5510 struct buffer *b; 5508 struct buffer *b;
5511 int count = SPECPDL_INDEX (); 5509
5512
5513 odeactivate = Vdeactivate_mark;
5514
5515 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
5516 Fset_buffer (p->buffer); 5510 Fset_buffer (p->buffer);
5517 opoint = PT; 5511 opoint = PT;
5518 opoint_byte = PT_BYTE; 5512 opoint_byte = PT_BYTE;
5519 old_read_only = current_buffer->read_only; 5513 old_read_only = current_buffer->read_only;
5520 old_begv = BEGV; 5514 old_begv = BEGV;
5608 5602
5609 /* If the restriction isn't what it should be, set it. */ 5603 /* If the restriction isn't what it should be, set it. */
5610 if (old_begv != BEGV || old_zv != ZV) 5604 if (old_begv != BEGV || old_zv != ZV)
5611 Fnarrow_to_region (make_number (old_begv), make_number (old_zv)); 5605 Fnarrow_to_region (make_number (old_begv), make_number (old_zv));
5612 5606
5613 /* Handling the process output should not deactivate the mark. */
5614 Vdeactivate_mark = odeactivate;
5615 5607
5616 current_buffer->read_only = old_read_only; 5608 current_buffer->read_only = old_read_only;
5617 SET_PT_BOTH (opoint, opoint_byte); 5609 SET_PT_BOTH (opoint, opoint_byte);
5618 unbind_to (count, Qnil); 5610 }
5619 } 5611 /* Handling the process output should not deactivate the mark. */
5612 Vdeactivate_mark = odeactivate;
5613
5614 unbind_to (count, Qnil);
5620 return nbytes; 5615 return nbytes;
5621 } 5616 }
5622 5617
5623 DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p, Swaiting_for_user_input_p, 5618 DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p, Swaiting_for_user_input_p,
5624 0, 0, 0, 5619 0, 0, 0,