comparison src/event-stream.c @ 853:2b6fa2618f76

[xemacs-hg @ 2002-05-28 08:44:22 by ben] merge my stderr-proc ws make-docfile.c: Fix places where we forget to check for EOF. code-init.el: Don't use CRLF conversion by default on process output. CMD.EXE and friends work both ways but Cygwin programs don't like the CRs. code-process.el, multicast.el, process.el: Removed. Improvements to call-process-internal: -- allows a buffer to be specified for input and stderr output -- use it on all systems -- implement C-g as documented -- clean up and comment call-process-region uses new call-process facilities; no temp file. remove duplicate funs in process.el. comment exactly how coding systems work and fix various problems. open-multicast-group now does similar coding-system frobbing to open-network-stream. dumped-lisp.el, faces.el, msw-faces.el: Fix some hidden errors due to code not being defined at the right time. xemacs.mak: Add -DSTRICT. ================================================================ ALLOW SEPARATION OF STDOUT AND STDERR IN PROCESSES ================================================================ Standard output and standard error can be processed separately in a process. Each can have its own buffer, its own mark in that buffer, and its filter function. You can specify a separate buffer for stderr in `start-process' to get things started, or use the new primitives: set-process-stderr-buffer process-stderr-buffer process-stderr-mark set-process-stderr-filter process-stderr-filter Also, process-send-region takes a 4th optional arg, a buffer. Currently always uses a pipe() under Unix to read the error output. (#### Would a PTY be better?) sysdep.h, sysproc.h, unexfreebsd.c, unexsunos4.c, nt.c, emacs.c, callproc.c, symsinit.h, sysdep.c, Makefile.in.in, process-unix.c: Delete callproc.c. Move child_setup() to process-unix.c. wait_for_termination() now only needed on a few really old systems. console-msw.h, event-Xt.c, event-msw.c, event-stream.c, event-tty.c, event-unixoid.c, events.h, process-nt.c, process-unix.c, process.c, process.h, procimpl.h: Rewrite the process methods to handle a separate channel for error input. Create Lstreams for reading in the error channel. Many process methods need change. In general the changes are fairly clear as they involve duplicating what's used for reading the normal stdout and changing for stderr -- although tedious, as such changes are required throughout the entire process code. Rewrote the code that reads process output to do two loops, one for stdout and one for stderr. gpmevent.c, tooltalk.c: set_process_filter takes an argument for stderr. ================================================================ NEW ERROR-TRAPPING MECHANISM ================================================================ Totally rewrite error trapping code to be unified and support more features. Basic function is call_trapping_problems(), which lets you specify, by means of flags, what sorts of problems you want trapped. these can include -- quit -- errors -- throws past the function -- creation of "display objects" (e.g. buffers) -- deletion of already-existing "display objects" (e.g. buffers) -- modification of already-existing buffers -- entering the debugger -- gc -- errors->warnings (ala suspended errors) etc. All other error funs rewritten in terms of this one. Various older mechanisms removed or rewritten. window.c, insdel.c, console.c, buffer.c, device.c, frame.c: When creating a display object, added call to note_object_created(), for use with trapping_problems mechanism. When deleting, call check_allowed_operation() and note_object deleted(). The trapping-problems code records the objects created since the call-trapping-problems began. Those objects can be deleted, but none others (i.e. previously existing ones). bytecode.c, cmdloop.c: internal_catch takes another arg. eval.c: Add long comments describing the "five lists" used to maintain state (backtrace, gcpro, specbind, etc.) in the Lisp engine. backtrace.h, eval.c: Implement trapping-problems mechanism, eliminate old mechanisms or redo in terms of new one. frame.c, gutter.c: Flush out the concept of "critical display section", defined by the in_display() var. Use an internal_bind() to get it reset, rather than just doing it at end, because there may be a non-local exit. event-msw.c, event-stream.c, console-msw.h, device.c, dialog-msw.c, frame.c, frame.h, intl.c, toolbar.c, menubar-msw.c, redisplay.c, alloc.c, menubar-x.c: Make use of new trapping-errors stuff and rewrite code based on old mechanisms. glyphs-widget.c, redisplay.h: Protect calling Lisp in redisplay. insdel.c: Protect hooks against deleting existing buffers. frame-msw.c: Use EQ, not EQUAL in hash tables whose keys are just numbers. Otherwise we run into stickiness in redisplay because internal_equal() can QUIT. ================================================================ SIGNAL, C-G CHANGES ================================================================ Here we change the way that C-g interacts with event reading. The idea is that a C-g occurring while we're reading a user event should be read as C-g, but elsewhere should be a QUIT. The former code did all sorts of bizarreness -- requiring that no QUIT occurs anywhere in event-reading code (impossible to enforce given the stuff called or Lisp code invoked), and having some weird system involving enqueue/dequeue of a C-g and interaction with Vquit_flag -- and it didn't work. Now, we simply enclose all code where we want C-g read as an event with {begin/end}_dont_check_for_quit(). This completely turns off the mechanism that checks (and may remove or alter) C-g in the read-ahead queues, so we just get the C-g normal. Signal.c documents this very carefully. cmdloop.c: Correct use of dont_check_for_quit to new scheme, remove old out-of-date comments. event-stream.c: Fix C-g handling to actually work. device-x.c: Disable quit checking when err out. signal.c: Cleanup. Add large descriptive comment. process-unix.c, process-nt.c, sysdep.c: Use QUIT instead of REALLY_QUIT. It's not necessary to use REALLY_QUIT and just confuses the issue. lisp.h: Comment quit handlers. ================================================================ CONS CHANGES ================================================================ free_cons() now takes a Lisp_Object not the result of XCONS(). car and cdr have been renamed so that they don't get used directly; go through XCAR(), XCDR() instead. alloc.c, dired.c, editfns.c, emodules.c, fns.c, glyphs-msw.c, glyphs-x.c, glyphs.c, keymap.c, minibuf.c, search.c, eval.c, lread.c, lisp.h: Correct free_cons calling convention: now takes Lisp_Object, not Lisp_Cons chartab.c: Eliminate direct use of ->car, ->cdr, should be black box. callint.c: Rewrote using EXTERNAL_LIST_LOOP to avoid use of Lisp_Cons. ================================================================ USE INTERNAL-BIND-* ================================================================ eval.c: Cleanups of these funs. alloc.c, fileio.c, undo.c, specifier.c, text.c, profile.c, lread.c, redisplay.c, menubar-x.c, macros.c: Rewrote to use internal_bind_int() and internal_bind_lisp_object() in place of whatever varied and cumbersome mechanisms were formerly there. ================================================================ SPECBIND SANITY ================================================================ backtrace.h: - Improved comments backtrace.h, bytecode.c, eval.c: Add new mechanism check_specbind_stack_sanity() for sanity checking code each time the catchlist or specbind stack change. Removed older prototype of same mechanism. ================================================================ MISC ================================================================ lisp.h, insdel.c, window.c, device.c, console.c, buffer.c: Fleshed out authorship. device-msw.c: Correct bad Unicode-ization. print.c: Be more careful when not initialized or in fatal error handling. search.c: Eliminate running_asynch_code, an FSF holdover. alloc.c: Added comments about gc-cons-threshold. dialog-x.c: Use begin_gc_forbidden() around code to build up a widget value tree, like in menubar-x.c. gui.c: Use Qunbound not Qnil as the default for gethash. lisp-disunion.h, lisp-union.h: Added warnings on use of VOID_TO_LISP(). lisp.h: Use ERROR_CHECK_STRUCTURES to turn on ERROR_CHECK_TRAPPING_PROBLEMS and ERROR_CHECK_TYPECHECK lisp.h: Add assert_with_message. lisp.h: Add macros for gcproing entire arrays. (You could do this before but it required manual twiddling the gcpro structure.) lisp.h: Add prototypes for new functions defined elsewhere.
author ben
date Tue, 28 May 2002 08:45:36 +0000
parents e7ee5f8bde58
children 804517e16990
comparison
equal deleted inserted replaced
852:d83885ef293b 853:2b6fa2618f76
518 return 1; 518 return 1;
519 } 519 }
520 return 0; 520 return 0;
521 } 521 }
522 522
523 void 523 static void
524 event_stream_next_event (Lisp_Event *event) 524 event_stream_next_event (Lisp_Event *event)
525 { 525 {
526 Lisp_Object event_obj; 526 Lisp_Object event_obj;
527 527
528 check_event_stream_ok (EVENT_STREAM_READ); 528 check_event_stream_ok (EVENT_STREAM_READ);
529 529
530 event_obj = wrap_event (event); 530 event_obj = wrap_event (event);
531 zero_event (event); 531 zero_event (event);
532 /* If C-g was pressed, treat it as a character to be read. 532 /* SIGINT occurs when C-g was pressed on a TTY. (SIGINT might have
533 Note that if C-g was pressed while we were blocking, 533 been sent manually by the user, but we don't care; we treat it
534 the SIGINT signal handler will be called. It will 534 the same.)
535 set Vquit_flag and write a byte on our "fake pipe", 535
536 which will unblock us. */ 536 The SIGINT signal handler sets Vquit_flag as well as sigint_happened
537 and write a byte on our "fake pipe", which unblocks us when we are
538 waiting for an event. */
539
540 /* If SIGINT was received after we disabled quit checking (because
541 we want to read C-g's as characters), but before we got a chance
542 to start reading, notice it now and treat it as a character to be
543 read. If above callers wanted this to be QUIT, they can
544 determine this by comparing the event against quit-char. */
545
537 if (maybe_read_quit_event (event)) 546 if (maybe_read_quit_event (event))
538 { 547 {
539 DEBUG_PRINT_EMACS_EVENT ("SIGINT", event_obj); 548 DEBUG_PRINT_EMACS_EVENT ("SIGINT", event_obj);
540 return; 549 return;
541 } 550 }
544 Let's hope it doesn't. I think the code here is fairly 553 Let's hope it doesn't. I think the code here is fairly
545 clean and doesn't do this. */ 554 clean and doesn't do this. */
546 emacs_is_blocking = 1; 555 emacs_is_blocking = 1;
547 event_stream->next_event_cb (event); 556 event_stream->next_event_cb (event);
548 emacs_is_blocking = 0; 557 emacs_is_blocking = 0;
558
559 /* Now check to see if C-g was pressed while we were blocking.
560 We treat it as an event, just like above. */
561 if (maybe_read_quit_event (event))
562 {
563 DEBUG_PRINT_EMACS_EVENT ("SIGINT", event_obj);
564 return;
565 }
549 566
550 #ifdef DEBUG_XEMACS 567 #ifdef DEBUG_XEMACS
551 /* timeout events have more info set later, so 568 /* timeout events have more info set later, so
552 print the event out in next_event_internal(). */ 569 print the event out in next_event_internal(). */
553 if (event->event_type != timeout_event) 570 if (event->event_type != timeout_event)
619 con->input_enabled = 0; 636 con->input_enabled = 0;
620 } 637 }
621 } 638 }
622 639
623 void 640 void
624 event_stream_select_process (Lisp_Process *proc) 641 event_stream_select_process (Lisp_Process *proc, int doin, int doerr)
625 { 642 {
643 int cur_in, cur_err;
644
626 check_event_stream_ok (EVENT_STREAM_PROCESS); 645 check_event_stream_ok (EVENT_STREAM_PROCESS);
627 if (!get_process_selected_p (proc)) 646
628 { 647 cur_in = get_process_selected_p (proc, 0);
629 event_stream->select_process_cb (proc); 648 if (cur_in)
630 set_process_selected_p (proc, 1); 649 doin = 0;
650
651 if (!process_has_separate_stderr (wrap_process (proc)))
652 {
653 doerr = 0;
654 cur_err = 0;
655 }
656 else
657 {
658 cur_err = get_process_selected_p (proc, 1);
659 if (cur_err)
660 doerr = 0;
661 }
662
663 if (doin || doerr)
664 {
665 event_stream->select_process_cb (proc, doin, doerr);
666 set_process_selected_p (proc, cur_in || doin, cur_err || doerr);
631 } 667 }
632 } 668 }
633 669
634 void 670 void
635 event_stream_unselect_process (Lisp_Process *proc) 671 event_stream_unselect_process (Lisp_Process *proc, int doin, int doerr)
636 { 672 {
673 int cur_in, cur_err;
674
637 check_event_stream_ok (EVENT_STREAM_PROCESS); 675 check_event_stream_ok (EVENT_STREAM_PROCESS);
638 if (get_process_selected_p (proc)) 676
639 { 677 cur_in = get_process_selected_p (proc, 0);
640 event_stream->unselect_process_cb (proc); 678 if (!cur_in)
641 set_process_selected_p (proc, 0); 679 doin = 0;
642 } 680
643 } 681 if (!process_has_separate_stderr (wrap_process (proc)))
644 682 {
645 USID 683 doerr = 0;
646 event_stream_create_stream_pair (void *inhandle, void *outhandle, 684 cur_err = 0;
647 Lisp_Object *instream, Lisp_Object *outstream, int flags) 685 }
686 else
687 {
688 cur_err = get_process_selected_p (proc, 1);
689 if (!cur_err)
690 doerr = 0;
691 }
692
693 if (doin || doerr)
694 {
695 event_stream->unselect_process_cb (proc, doin, doerr);
696 set_process_selected_p (proc, cur_in && !doin, cur_err && !doerr);
697 }
698 }
699
700 void
701 event_stream_create_io_streams (void *inhandle, void *outhandle,
702 void *errhandle, Lisp_Object *instream,
703 Lisp_Object *outstream,
704 Lisp_Object *errstream,
705 USID *in_usid,
706 USID *err_usid,
707 int flags)
648 { 708 {
649 check_event_stream_ok (EVENT_STREAM_PROCESS); 709 check_event_stream_ok (EVENT_STREAM_PROCESS);
650 return event_stream->create_stream_pair_cb 710 event_stream->create_io_streams_cb
651 (inhandle, outhandle, instream, outstream, flags); 711 (inhandle, outhandle, errhandle, instream, outstream, errstream,
652 } 712 in_usid, err_usid, flags);
653 713 }
654 USID 714
655 event_stream_delete_stream_pair (Lisp_Object instream, Lisp_Object outstream) 715 void
716 event_stream_delete_io_streams (Lisp_Object instream,
717 Lisp_Object outstream,
718 Lisp_Object errstream,
719 USID *in_usid,
720 USID *err_usid)
656 { 721 {
657 check_event_stream_ok (EVENT_STREAM_PROCESS); 722 check_event_stream_ok (EVENT_STREAM_PROCESS);
658 return event_stream->delete_stream_pair_cb (instream, outstream); 723 event_stream->delete_io_streams_cb (instream, outstream, errstream,
724 in_usid, err_usid);
659 } 725 }
660 726
661 void 727 void
662 event_stream_quit_p (void) 728 event_stream_quit_p (void)
663 { 729 {
732 maybe_echo_keys (struct command_builder *command_builder, int no_snooze) 798 maybe_echo_keys (struct command_builder *command_builder, int no_snooze)
733 { 799 {
734 /* This function can GC */ 800 /* This function can GC */
735 double echo_keystrokes; 801 double echo_keystrokes;
736 struct frame *f = selected_frame (); 802 struct frame *f = selected_frame ();
803 int depth = begin_dont_check_for_quit ();
804
737 /* Message turns off echoing unless more keystrokes turn it on again. */ 805 /* Message turns off echoing unless more keystrokes turn it on again. */
738 if (echo_area_active (f) && !EQ (Qcommand, echo_area_status (f))) 806 if (echo_area_active (f) && !EQ (Qcommand, echo_area_status (f)))
739 return; 807 goto done;
740 808
741 if (INTP (Vecho_keystrokes) || FLOATP (Vecho_keystrokes)) 809 if (INTP (Vecho_keystrokes) || FLOATP (Vecho_keystrokes))
742 echo_keystrokes = extract_float (Vecho_keystrokes); 810 echo_keystrokes = extract_float (Vecho_keystrokes);
743 else 811 else
744 echo_keystrokes = 0; 812 echo_keystrokes = 0;
750 #endif 818 #endif
751 ) 819 )
752 { 820 {
753 if (!no_snooze) 821 if (!no_snooze)
754 { 822 {
755 /* #### C-g here will cause QUIT. Setting dont_check_for_quit
756 doesn't work. See check_quit. */
757 if (NILP (Fsit_for (Vecho_keystrokes, Qnil))) 823 if (NILP (Fsit_for (Vecho_keystrokes, Qnil)))
758 /* input came in, so don't echo. */ 824 /* input came in, so don't echo. */
759 return; 825 goto done;
760 } 826 }
761 827
762 echo_area_message (f, command_builder->echo_buf, Qnil, 0, 828 echo_area_message (f, command_builder->echo_buf, Qnil, 0,
763 /* not echo_buf_index. That doesn't include 829 /* not echo_buf_index. That doesn't include
764 the terminating " - ". */ 830 the terminating " - ". */
765 strlen ((char *) command_builder->echo_buf), 831 strlen ((char *) command_builder->echo_buf),
766 Qcommand); 832 Qcommand);
767 } 833 }
834
835 done:
836 Vquit_flag = Qnil; /* see begin_dont_check_for_quit() */
837 unbind_to (depth);
768 } 838 }
769 839
770 static void 840 static void
771 reset_key_echo (struct command_builder *command_builder, 841 reset_key_echo (struct command_builder *command_builder,
772 int remove_echo_area_echo) 842 int remove_echo_area_echo)
1546 dequeue_command_event (void) 1616 dequeue_command_event (void)
1547 { 1617 {
1548 return dequeue_event (&command_event_queue, &command_event_queue_tail); 1618 return dequeue_event (&command_event_queue, &command_event_queue_tail);
1549 } 1619 }
1550 1620
1551 /* put the event on the typeahead queue, unless
1552 the event is the quit char, in which case the `QUIT'
1553 which will occur on the next trip through this loop is
1554 all the processing we should do - leaving it on the queue
1555 would cause the quit to be processed twice.
1556 */
1557 static void 1621 static void
1558 enqueue_command_event_1 (Lisp_Object event_to_copy) 1622 enqueue_command_event_1 (Lisp_Object event_to_copy)
1559 { 1623 {
1560 /* do not call check_quit() here. Vquit_flag was set in 1624 enqueue_command_event (Fcopy_event (event_to_copy, Qnil));
1561 next_event_internal. */
1562 if (NILP (Vquit_flag))
1563 enqueue_command_event (Fcopy_event (event_to_copy, Qnil));
1564 } 1625 }
1565 1626
1566 void 1627 void
1567 enqueue_magic_eval_event (void (*fun) (Lisp_Object), Lisp_Object object) 1628 enqueue_magic_eval_event (void (*fun) (Lisp_Object), Lisp_Object object)
1568 { 1629 {
1967 } 2028 }
1968 2029
1969 /* the number of keyboard characters read. callint.c wants this. */ 2030 /* the number of keyboard characters read. callint.c wants this. */
1970 Charcount num_input_chars; 2031 Charcount num_input_chars;
1971 2032
2033 /* Read an event from the window system (or tty). If ALLOW_QUEUED is
2034 non-zero, read from the command-event queue first.
2035
2036 If C-g was pressed, this function will attempt to QUIT. If you want
2037 to read C-g as an event, wrap this function with a call to
2038 begin_dont_check_for_quit(), and set Vquit_flag to Qnil just before
2039 you unbind. In this case, TARGET_EVENT will contain a C-g.
2040
2041 Note that even if you are interested in C-g doing QUIT, a caller of you
2042 might not be.
2043 */
2044
1972 static void 2045 static void
1973 next_event_internal (Lisp_Object target_event, int allow_queued) 2046 next_event_internal (Lisp_Object target_event, int allow_queued)
1974 { 2047 {
1975 struct gcpro gcpro1; 2048 struct gcpro gcpro1;
1976 /* QUIT; This is incorrect - the caller must do this because some 2049 QUIT;
1977 callers (ie, Fnext_event()) do not want to QUIT. */
1978 2050
1979 assert (NILP (XEVENT_NEXT (target_event))); 2051 assert (NILP (XEVENT_NEXT (target_event)));
1980 2052
1981 GCPRO1 (target_event); 2053 GCPRO1 (target_event);
1982 2054
2015 /* next_event_internal() doesn't print out timeout events 2087 /* next_event_internal() doesn't print out timeout events
2016 because of the extra info we just set. */ 2088 because of the extra info we just set. */
2017 DEBUG_PRINT_EMACS_EVENT ("real, timeout", target_event); 2089 DEBUG_PRINT_EMACS_EVENT ("real, timeout", target_event);
2018 } 2090 }
2019 2091
2020 /* If we read a ^G, then set quit-flag but do not discard the ^G. 2092 /* If we read a ^G, then set quit-flag and try to QUIT.
2021 The callers of next_event_internal() will do one of two things: 2093 This may be blocked (see above).
2022
2023 -- set Vquit_flag to Qnil. (next-event does this.) This will
2024 cause the ^G to be treated as a normal keystroke.
2025 -- not change Vquit_flag but attempt to enqueue the ^G, at
2026 which point it will be discarded. The next time QUIT is
2027 called, it will notice that Vquit_flag was set.
2028
2029 */ 2094 */
2030 if (e->event_type == key_press_event && 2095 if (e->event_type == key_press_event &&
2031 event_matches_key_specifier_p 2096 event_matches_key_specifier_p
2032 (e, make_char (CONSOLE_QUIT_CHAR (XCONSOLE (EVENT_CHANNEL (e)))))) 2097 (e, make_char (CONSOLE_QUIT_CHAR (XCONSOLE (EVENT_CHANNEL (e))))))
2033 { 2098 {
2034 Vquit_flag = Qt; 2099 Vquit_flag = Qt;
2100 QUIT;
2035 } 2101 }
2036 } 2102 }
2037 2103
2038 UNGCPRO; 2104 UNGCPRO;
2039 } 2105 }
2040 2106
2041 static void 2107 void
2042 run_pre_idle_hook (void) 2108 run_pre_idle_hook (void)
2043 { 2109 {
2044 if (!NILP (Vpre_idle_hook) 2110 if (!NILP (Vpre_idle_hook)
2045 && !detect_input_pending ()) 2111 && !detect_input_pending ())
2046 safe_run_hook_trapping_errors 2112 safe_run_hook_trapping_problems
2047 ("Error in `pre-idle-hook' (setting hook to nil)", 2113 ("Error in `pre-idle-hook' (setting hook to nil)",
2048 Qpre_idle_hook, 1); 2114 Qpre_idle_hook, INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION);
2049 } 2115 }
2050 2116
2051 static void push_this_command_keys (Lisp_Object event); 2117 static void push_this_command_keys (Lisp_Object event);
2052 static void push_recent_keys (Lisp_Object event); 2118 static void push_recent_keys (Lisp_Object event);
2053 static void dribble_out_event (Lisp_Object event); 2119 static void dribble_out_event (Lisp_Object event);
2106 struct console *con = XCONSOLE (Vselected_console); 2172 struct console *con = XCONSOLE (Vselected_console);
2107 struct command_builder *command_builder = 2173 struct command_builder *command_builder =
2108 XCOMMAND_BUILDER (con->command_builder); 2174 XCOMMAND_BUILDER (con->command_builder);
2109 int store_this_key = 0; 2175 int store_this_key = 0;
2110 struct gcpro gcpro1; 2176 struct gcpro gcpro1;
2177 int depth;
2111 2178
2112 GCPRO1 (event); 2179 GCPRO1 (event);
2113 /* DO NOT do QUIT anywhere within this function or the functions it calls. 2180
2114 We want to read the ^G as an event. */ 2181 depth = begin_dont_check_for_quit ();
2115 2182
2116 #ifdef LWLIB_MENUBARS_LUCID 2183 #ifdef LWLIB_MENUBARS_LUCID
2117 /* 2184 /*
2118 * #### Fix the menu code so this isn't necessary. 2185 * #### Fix the menu code so this isn't necessary.
2119 * 2186 *
2172 Lisp_Object e = XCAR (Vunread_command_events); 2239 Lisp_Object e = XCAR (Vunread_command_events);
2173 Vunread_command_events = XCDR (Vunread_command_events); 2240 Vunread_command_events = XCDR (Vunread_command_events);
2174 if (!EVENTP (e) || !command_event_p (e)) 2241 if (!EVENTP (e) || !command_event_p (e))
2175 signal_error_1 (Qwrong_type_argument, 2242 signal_error_1 (Qwrong_type_argument,
2176 list3 (Qcommand_event_p, e, Qunread_command_events)); 2243 list3 (Qcommand_event_p, e, Qunread_command_events));
2177 redisplay (); 2244 redisplay_no_pre_idle_hook ();
2178 if (!EQ (e, event)) 2245 if (!EQ (e, event))
2179 Fcopy_event (e, event); 2246 Fcopy_event (e, event);
2180 DEBUG_PRINT_EMACS_EVENT ("unread-command-events", event); 2247 DEBUG_PRINT_EMACS_EVENT ("unread-command-events", event);
2181 } 2248 }
2182 } 2249 }
2192 signal_error_1 (Qwrong_type_argument, 2259 signal_error_1 (Qwrong_type_argument,
2193 list3 (Qeventp, e, Qunread_command_event)); 2260 list3 (Qeventp, e, Qunread_command_event));
2194 } 2261 }
2195 if (!EQ (e, event)) 2262 if (!EQ (e, event))
2196 Fcopy_event (e, event); 2263 Fcopy_event (e, event);
2197 redisplay (); 2264 redisplay_no_pre_idle_hook ();
2198 DEBUG_PRINT_EMACS_EVENT ("unread-command-event", event); 2265 DEBUG_PRINT_EMACS_EVENT ("unread-command-event", event);
2199 } 2266 }
2200 2267
2201 /* If we're executing a keyboard macro, take the next event from that, 2268 /* If we're executing a keyboard macro, take the next event from that,
2202 and update this-command-keys and recent-keys. 2269 and update this-command-keys and recent-keys.
2204 */ 2271 */
2205 else 2272 else
2206 { 2273 {
2207 if (!NILP (Vexecuting_macro)) 2274 if (!NILP (Vexecuting_macro))
2208 { 2275 {
2209 redisplay (); 2276 redisplay_no_pre_idle_hook ();
2210 pop_kbd_macro_event (event); /* This throws past us at 2277 pop_kbd_macro_event (event); /* This throws past us at
2211 end-of-macro. */ 2278 end-of-macro. */
2212 store_this_key = 1; 2279 store_this_key = 1;
2213 DEBUG_PRINT_EMACS_EVENT ("keyboard macro", event); 2280 DEBUG_PRINT_EMACS_EVENT ("keyboard macro", event);
2214 } 2281 }
2215 /* Otherwise, read a real event, possibly from the 2282 /* Otherwise, read a real event, possibly from the
2216 command_event_queue, and update this-command-keys and 2283 command_event_queue, and update this-command-keys and
2217 recent-keys. */ 2284 recent-keys. */
2218 else 2285 else
2219 { 2286 {
2220 run_pre_idle_hook ();
2221 redisplay (); 2287 redisplay ();
2222 next_event_internal (event, 1); 2288 next_event_internal (event, 1);
2223 Vquit_flag = Qnil; /* Read C-g as an event. */
2224 store_this_key = 1; 2289 store_this_key = 1;
2225 } 2290 }
2226 } 2291 }
2227 2292
2293 /* temporarily reenable quit checking here, because arbitrary lisp
2294 is executed */
2295 Vquit_flag = Qnil; /* see begin_dont_check_for_quit() */
2296 unbind_to (depth);
2228 status_notify (); /* Notice process change */ 2297 status_notify (); /* Notice process change */
2298 depth = begin_dont_check_for_quit ();
2229 2299
2230 /* Since we can free the most stuff here 2300 /* Since we can free the most stuff here
2231 * (since this is typically called from 2301 * (since this is typically called from
2232 * the command-loop top-level). */ 2302 * the command-loop top-level). */
2233 if (need_to_check_c_alloca) 2303 if (need_to_check_c_alloca)
2256 goto STORE_AND_EXECUTE_KEY; 2326 goto STORE_AND_EXECUTE_KEY;
2257 case key_press_event: /* any key input can trigger autosave */ 2327 case key_press_event: /* any key input can trigger autosave */
2258 break; 2328 break;
2259 } 2329 }
2260 2330
2331 /* temporarily reenable quit checking here, because we could get stuck */
2332 Vquit_flag = Qnil; /* see begin_dont_check_for_quit() */
2333 unbind_to (depth);
2261 maybe_do_auto_save (); 2334 maybe_do_auto_save ();
2335 depth = begin_dont_check_for_quit ();
2336
2262 num_input_chars++; 2337 num_input_chars++;
2263 STORE_AND_EXECUTE_KEY: 2338 STORE_AND_EXECUTE_KEY:
2264 if (store_this_key) 2339 if (store_this_key)
2265 { 2340 {
2266 echo_key_event (command_builder, event); 2341 echo_key_event (command_builder, event);
2324 if (!EVENTP (command_builder->current_events)) 2399 if (!EVENTP (command_builder->current_events))
2325 finalize_kbd_macro_chars (con); 2400 finalize_kbd_macro_chars (con);
2326 store_kbd_macro_event (event); 2401 store_kbd_macro_event (event);
2327 } 2402 }
2328 } 2403 }
2329 /* If this is the help char and there is a help form, then execute the 2404 /* If this is the help char and there is a help form, then execute
2330 help form and swallow this character. This is the only place where 2405 the help form and swallow this character. Note that
2331 calling Fnext_event() can cause arbitrary lisp code to run. Note 2406 execute_help_form() calls Fnext_command_event(), which calls this
2332 that execute_help_form() calls Fnext_command_event(), which calls 2407 function, as well as Fdispatch_event. */
2333 this function, as well as Fdispatch_event.
2334 */
2335 if (!NILP (Vhelp_form) && 2408 if (!NILP (Vhelp_form) &&
2336 event_matches_key_specifier_p (XEVENT (event), Vhelp_char)) 2409 event_matches_key_specifier_p (XEVENT (event), Vhelp_char))
2337 execute_help_form (command_builder, event); 2410 {
2411 /* temporarily reenable quit checking here, because we could get stuck */
2412 Vquit_flag = Qnil; /* see begin_dont_check_for_quit() */
2413 unbind_to (depth);
2414 execute_help_form (command_builder, event);
2415 depth = begin_dont_check_for_quit ();
2416 }
2338 2417
2339 RETURN: 2418 RETURN:
2419 Vquit_flag = Qnil; /* see begin_dont_check_for_quit() */
2420 unbind_to (depth);
2421
2340 UNGCPRO; 2422 UNGCPRO;
2423
2341 return event; 2424 return event;
2342 } 2425 }
2343 2426
2344 DEFUN ("next-command-event", Fnext_command_event, 0, 2, 0, /* 2427 DEFUN ("next-command-event", Fnext_command_event, 0, 2, 0, /*
2345 Return the next available "user" event. 2428 Return the next available "user" event.
2368 (event, prompt)) 2451 (event, prompt))
2369 { 2452 {
2370 /* This function can GC */ 2453 /* This function can GC */
2371 struct gcpro gcpro1; 2454 struct gcpro gcpro1;
2372 GCPRO1 (event); 2455 GCPRO1 (event);
2456
2373 maybe_echo_keys (XCOMMAND_BUILDER 2457 maybe_echo_keys (XCOMMAND_BUILDER
2374 (XCONSOLE (Vselected_console)-> 2458 (XCONSOLE (Vselected_console)->
2375 command_builder), 0); /* #### This sucks bigtime */ 2459 command_builder), 0); /* #### This sucks bigtime */
2460
2376 for (;;) 2461 for (;;)
2377 { 2462 {
2378 event = Fnext_event (event, prompt); 2463 event = Fnext_event (event, prompt);
2379 if (command_event_p (event)) 2464 if (command_event_p (event))
2380 break; 2465 break;
2407 time. */ 2492 time. */
2408 event_stream_force_event_pending (selected_frame ()); 2493 event_stream_force_event_pending (selected_frame ());
2409 2494
2410 while (event_stream_event_pending_p (0)) 2495 while (event_stream_event_pending_p (0))
2411 { 2496 {
2412 QUIT; /* next_event_internal() does not QUIT. */
2413
2414 /* We're a generator of the command_event_queue, so we can't be a 2497 /* We're a generator of the command_event_queue, so we can't be a
2415 consumer as well. Also, we have no reason to consult the 2498 consumer as well. Also, we have no reason to consult the
2416 command_event_queue; there are only user and eval-events there, 2499 command_event_queue; there are only user and eval-events there,
2417 and we'd just have to put them back anyway. 2500 and we'd just have to put them back anyway.
2418 */ 2501 */
2419 next_event_internal (event, 0); /* blocks */ 2502 next_event_internal (event, 0); /* blocks */
2420 /* See the comment in accept-process-output about Vquit_flag */
2421 if (XEVENT_TYPE (event) == magic_event || 2503 if (XEVENT_TYPE (event) == magic_event ||
2422 XEVENT_TYPE (event) == timeout_event || 2504 XEVENT_TYPE (event) == timeout_event ||
2423 XEVENT_TYPE (event) == process_event || 2505 XEVENT_TYPE (event) == process_event ||
2424 XEVENT_TYPE (event) == pointer_motion_event) 2506 XEVENT_TYPE (event) == pointer_motion_event)
2425 execute_internal_event (event); 2507 execute_internal_event (event);
2455 /* This throws away user-input on the queue, but doesn't process any 2537 /* This throws away user-input on the queue, but doesn't process any
2456 events. Calling dispatch_event() here leads to a race condition. 2538 events. Calling dispatch_event() here leads to a race condition.
2457 */ 2539 */
2458 Lisp_Object event = Fmake_event (Qnil, Qnil); 2540 Lisp_Object event = Fmake_event (Qnil, Qnil);
2459 Lisp_Object head = Qnil, tail = Qnil; 2541 Lisp_Object head = Qnil, tail = Qnil;
2460 Lisp_Object oiq = Vinhibit_quit; 2542 struct gcpro gcpro1;
2461 struct gcpro gcpro1, gcpro2;
2462 /* #### not correct here with Vselected_console? Should 2543 /* #### not correct here with Vselected_console? Should
2463 discard-input take a console argument, or maybe map over 2544 discard-input take a console argument, or maybe map over
2464 all consoles? */ 2545 all consoles? */
2465 struct console *con = XCONSOLE (Vselected_console); 2546 struct console *con = XCONSOLE (Vselected_console);
2466 2547
2467 /* next_event_internal() can cause arbitrary Lisp code to be evalled */ 2548 /* next_event_internal() can cause arbitrary Lisp code to be evalled */
2468 GCPRO2 (event, oiq); 2549 GCPRO1 (event);
2469 Vinhibit_quit = Qt;
2470 /* If a macro was being defined then we have to mark the modeline 2550 /* If a macro was being defined then we have to mark the modeline
2471 has changed to ensure that it gets updated correctly. */ 2551 has changed to ensure that it gets updated correctly. */
2472 if (!NILP (con->defining_kbd_macro)) 2552 if (!NILP (con->defining_kbd_macro))
2473 MARK_MODELINE_CHANGED; 2553 MARK_MODELINE_CHANGED;
2474 con->defining_kbd_macro = Qnil; 2554 con->defining_kbd_macro = Qnil;
2475 reset_current_events (XCOMMAND_BUILDER (con->command_builder)); 2555 reset_current_events (XCOMMAND_BUILDER (con->command_builder));
2476 2556
2477 while (!NILP (command_event_queue) 2557 while (!NILP (command_event_queue)
2478 || event_stream_event_pending_p (1)) 2558 || event_stream_event_pending_p (1))
2479 { 2559 {
2560 /* We want to ignore C-g's along with all other keypresses. */
2561 int depth = begin_dont_check_for_quit ();
2480 /* This will take stuff off the command_event_queue, or read it 2562 /* This will take stuff off the command_event_queue, or read it
2481 from the event_stream, but it will not block. 2563 from the event_stream, but it will not block.
2482 */ 2564 */
2483 next_event_internal (event, 1); 2565 next_event_internal (event, 1);
2484 Vquit_flag = Qnil; /* Treat C-g as a user event (ignore it). 2566 /* The following comment used to be here:
2485 It is vitally important that we reset 2567
2486 Vquit_flag here. Otherwise, if we're 2568 [[Treat C-g as a user event (ignore it). It is vitally
2487 reading from a TTY console, 2569 important that we reset Vquit_flag here. Otherwise, if we're
2488 maybe_read_quit_event() will notice 2570 reading from a TTY console, maybe_read_quit_event() will
2489 that C-g has been set and send us 2571 notice that C-g has been set and send us another C-g. That
2490 another C-g. That will cause us 2572 will cause us to get right back here, and read another C-g,
2491 to get right back here, and read 2573 ad infinitum ...]]
2492 another C-g, ad infinitum ... */ 2574
2575 but I don't think this is correct; maybe_read_quit_event()
2576 checks and resets sigint_happened. It shouldn't matter if we
2577 reset here or outside of the while loop. --ben */
2578 Vquit_flag = Qnil; /* see begin_dont_check_for_quit() */
2579
2580 unbind_to (depth);
2493 2581
2494 /* If the event is a user event, ignore it. */ 2582 /* If the event is a user event, ignore it. */
2495 if (!command_event_p (event)) 2583 if (!command_event_p (event))
2496 { 2584 {
2497 /* Otherwise, chain the event onto our list of events not to ignore, 2585 /* Otherwise, chain the event onto our list of events not to ignore,
2523 command_event_queue_tail = tail; 2611 command_event_queue_tail = tail;
2524 2612
2525 Fdeallocate_event (event); 2613 Fdeallocate_event (event);
2526 UNGCPRO; 2614 UNGCPRO;
2527 2615
2528 Vinhibit_quit = oiq;
2529 return Qnil; 2616 return Qnil;
2530 } 2617 }
2531 2618
2532 2619
2533 /**********************************************************************/ 2620 /**********************************************************************/
2646 timeout_enabled = 0; 2733 timeout_enabled = 0;
2647 done = 1; /* We're done. */ 2734 done = 1; /* We're done. */
2648 continue; /* Don't call next_event_internal */ 2735 continue; /* Don't call next_event_internal */
2649 } 2736 }
2650 2737
2651 QUIT; /* next_event_internal() does not QUIT, so check for ^G
2652 before reading output from the process - this makes it
2653 less likely that the filter will actually be aborted.
2654 */
2655
2656 next_event_internal (event, 0); 2738 next_event_internal (event, 0);
2657 /* If C-g was pressed while we were waiting, Vquit_flag got
2658 set and next_event_internal() also returns C-g. When
2659 we enqueue the C-g below, it will get discarded. The
2660 next time through, QUIT will be called and will signal a quit. */
2661 switch (XEVENT_TYPE (event)) 2739 switch (XEVENT_TYPE (event))
2662 { 2740 {
2663 case process_event: 2741 case process_event:
2664 { 2742 {
2665 if (NILP (process) || 2743 if (NILP (process) ||
2692 } 2770 }
2693 2771
2694 unbind_to_1 (count, timeout_enabled ? make_int (timeout_id) : Qnil); 2772 unbind_to_1 (count, timeout_enabled ? make_int (timeout_id) : Qnil);
2695 2773
2696 Fdeallocate_event (event); 2774 Fdeallocate_event (event);
2775
2776 status_notify ();
2777
2697 UNGCPRO; 2778 UNGCPRO;
2698 current_buffer = old_buffer; 2779 current_buffer = old_buffer;
2699 return result; 2780 return result;
2700 } 2781 }
2701 2782
2728 { 2809 {
2729 /* If our timeout has arrived, we move along. */ 2810 /* If our timeout has arrived, we move along. */
2730 if (!event_stream_wakeup_pending_p (id, 0)) 2811 if (!event_stream_wakeup_pending_p (id, 0))
2731 goto DONE_LABEL; 2812 goto DONE_LABEL;
2732 2813
2733 QUIT; /* next_event_internal() does not QUIT, so check for ^G
2734 before reading output from the process - this makes it
2735 less likely that the filter will actually be aborted.
2736 */
2737 /* We're a generator of the command_event_queue, so we can't be a 2814 /* We're a generator of the command_event_queue, so we can't be a
2738 consumer as well. We don't care about command and eval-events 2815 consumer as well. We don't care about command and eval-events
2739 anyway. 2816 anyway.
2740 */ 2817 */
2741 next_event_internal (event, 0); /* blocks */ 2818 next_event_internal (event, 0); /* blocks */
2742 /* See the comment in accept-process-output about Vquit_flag */
2743 switch (XEVENT_TYPE (event)) 2819 switch (XEVENT_TYPE (event))
2744 { 2820 {
2745 case timeout_event: 2821 case timeout_event:
2746 /* We execute the event even if it's ours, and notice that it's 2822 /* We execute the event even if it's ours, and notice that it's
2747 happened above. */ 2823 happened above. */
2806 don't wait. */ 2882 don't wait. */
2807 if (noninteractive || !NILP (Vexecuting_macro)) 2883 if (noninteractive || !NILP (Vexecuting_macro))
2808 return Qnil; 2884 return Qnil;
2809 2885
2810 /* Recursive call from a filter function or timeout handler. */ 2886 /* Recursive call from a filter function or timeout handler. */
2811 if (!NILP(recursive_sit_for)) 2887 if (!NILP (recursive_sit_for))
2812 { 2888 {
2813 if (!event_stream_event_pending_p (1) && NILP (nodisplay)) 2889 if (!event_stream_event_pending_p (1) && NILP (nodisplay))
2814 {
2815 run_pre_idle_hook ();
2816 redisplay (); 2890 redisplay ();
2817 }
2818 return Qnil; 2891 return Qnil;
2819 } 2892 }
2820 2893
2821 2894
2822 /* Otherwise, start reading events from the event_stream. 2895 /* Otherwise, start reading events from the event_stream.
2841 while (1) 2914 while (1)
2842 { 2915 {
2843 /* If there is no user input pending, then redisplay. 2916 /* If there is no user input pending, then redisplay.
2844 */ 2917 */
2845 if (!event_stream_event_pending_p (1) && NILP (nodisplay)) 2918 if (!event_stream_event_pending_p (1) && NILP (nodisplay))
2846 {
2847 run_pre_idle_hook ();
2848 redisplay (); 2919 redisplay ();
2849 }
2850 2920
2851 /* If our timeout has arrived, we move along. */ 2921 /* If our timeout has arrived, we move along. */
2852 if (!event_stream_wakeup_pending_p (id, 0)) 2922 if (!event_stream_wakeup_pending_p (id, 0))
2853 { 2923 {
2854 result = Qt; 2924 result = Qt;
2855 goto DONE_LABEL; 2925 goto DONE_LABEL;
2856 } 2926 }
2857 2927
2858 QUIT; /* next_event_internal() does not QUIT, so check for ^G
2859 before reading output from the process - this makes it
2860 less likely that the filter will actually be aborted.
2861 */
2862 /* We're a generator of the command_event_queue, so we can't be a 2928 /* We're a generator of the command_event_queue, so we can't be a
2863 consumer as well. In fact, we know there's nothing on the 2929 consumer as well. In fact, we know there's nothing on the
2864 command_event_queue that we didn't just put there. 2930 command_event_queue that we didn't just put there.
2865 */ 2931 */
2866 next_event_internal (event, 0); /* blocks */ 2932 next_event_internal (event, 0); /* blocks */
2867 /* See the comment in accept-process-output about Vquit_flag */
2868 2933
2869 if (command_event_p (event)) 2934 if (command_event_p (event))
2870 { 2935 {
2871 QUIT; /* If the command was C-g check it here
2872 so that we abort out of the sit-for,
2873 not the next command. sleep-for and
2874 accept-process-output continue looping
2875 so they check QUIT again implicitly.*/
2876 result = Qnil; 2936 result = Qnil;
2877 goto DONE_LABEL; 2937 goto DONE_LABEL;
2878 } 2938 }
2879 switch (XEVENT_TYPE (event)) 2939 switch (XEVENT_TYPE (event))
2880 { 2940 {
2925 struct gcpro gcpro1; 2985 struct gcpro gcpro1;
2926 GCPRO1 (event); 2986 GCPRO1 (event);
2927 2987
2928 while (!(*predicate) (predicate_arg)) 2988 while (!(*predicate) (predicate_arg))
2929 { 2989 {
2930 QUIT; /* next_event_internal() does not QUIT. */
2931
2932 /* We're a generator of the command_event_queue, so we can't be a 2990 /* We're a generator of the command_event_queue, so we can't be a
2933 consumer as well. Also, we have no reason to consult the 2991 consumer as well. Also, we have no reason to consult the
2934 command_event_queue; there are only user and eval-events there, 2992 command_event_queue; there are only user and eval-events there,
2935 and we'd just have to put them back anyway. 2993 and we'd just have to put them back anyway.
2936 */ 2994 */
2937 next_event_internal (event, 0); 2995 next_event_internal (event, 0);
2938 /* See the comment in accept-process-output about Vquit_flag */
2939 if (command_event_p (event) 2996 if (command_event_p (event)
2940 || (XEVENT_TYPE (event) == eval_event) 2997 || (XEVENT_TYPE (event) == eval_event)
2941 || (XEVENT_TYPE (event) == magic_eval_event)) 2998 || (XEVENT_TYPE (event) == magic_eval_event))
2942 enqueue_command_event_1 (event); 2999 enqueue_command_event_1 (event);
2943 else 3000 else
2987 3044
2988 case process_event: 3045 case process_event:
2989 { 3046 {
2990 Lisp_Object p = XEVENT (event)->event.process.process; 3047 Lisp_Object p = XEVENT (event)->event.process.process;
2991 Charcount readstatus; 3048 Charcount readstatus;
2992 3049 int iter;
2993 assert (PROCESSP (p)); 3050
2994 while ((readstatus = read_process_output (p)) > 0) 3051 assert (PROCESSP (p));
2995 ; 3052 for (iter = 0; iter < 2; iter++)
2996 if (readstatus > 0) 3053 {
2997 ; /* this clauses never gets executed but allows the #ifdefs 3054 if (iter == 1 && !process_has_separate_stderr (p))
2998 to work cleanly. */ 3055 break;
3056 while ((readstatus = read_process_output (p, iter)) > 0)
3057 ;
3058 if (readstatus > 0)
3059 ; /* this clauses never gets executed but
3060 allows the #ifdefs to work cleanly. */
2999 #ifdef EWOULDBLOCK 3061 #ifdef EWOULDBLOCK
3000 else if (readstatus == -1 && errno == EWOULDBLOCK) 3062 else if (readstatus == -1 && errno == EWOULDBLOCK)
3001 ; 3063 ;
3002 #endif /* EWOULDBLOCK */ 3064 #endif /* EWOULDBLOCK */
3003 #ifdef EAGAIN 3065 #ifdef EAGAIN
3004 else if (readstatus == -1 && errno == EAGAIN) 3066 else if (readstatus == -1 && errno == EAGAIN)
3005 ; 3067 ;
3006 #endif /* EAGAIN */ 3068 #endif /* EAGAIN */
3007 else if ((readstatus == 0 && 3069 else if ((readstatus == 0 &&
3008 /* Note that we cannot distinguish between no input 3070 /* Note that we cannot distinguish between no input
3009 available now and a closed pipe. 3071 available now and a closed pipe.
3010 With luck, a closed pipe will be accompanied by 3072 With luck, a closed pipe will be accompanied by
3011 subprocess termination and SIGCHLD. */ 3073 subprocess termination and SIGCHLD. */
3012 (!network_connection_p (p) || 3074 (!network_connection_p (p) ||
3013 /* 3075 /*
3014 When connected to ToolTalk (i.e. 3076 When connected to ToolTalk (i.e.
3015 connected_via_filedesc_p()), it's not possible to 3077 connected_via_filedesc_p()), it's not possible to
3016 reliably determine whether there is a message 3078 reliably determine whether there is a message
3017 waiting for ToolTalk to receive. ToolTalk expects 3079 waiting for ToolTalk to receive. ToolTalk expects
3018 to have tt_message_receive() called exactly once 3080 to have tt_message_receive() called exactly once
3019 every time the file descriptor becomes active, so 3081 every time the file descriptor becomes active, so
3020 the filter function forces this by returning 0. 3082 the filter function forces this by returning 0.
3021 Emacs must not interpret this as a closed pipe. */ 3083 Emacs must not interpret this as a closed pipe. */
3022 connected_via_filedesc_p (XPROCESS (p)))) 3084 connected_via_filedesc_p (XPROCESS (p))))
3023 3085
3024 /* On some OSs with ptys, when the process on one end of 3086 /* On some OSs with ptys, when the process on one end of
3025 a pty exits, the other end gets an error reading with 3087 a pty exits, the other end gets an error reading with
3026 errno = EIO instead of getting an EOF (0 bytes read). 3088 errno = EIO instead of getting an EOF (0 bytes read).
3027 Therefore, if we get an error reading and errno = 3089 Therefore, if we get an error reading and errno =
3028 EIO, just continue, because the child process has 3090 EIO, just continue, because the child process has
3029 exited and should clean itself up soon (e.g. when we 3091 exited and should clean itself up soon (e.g. when we
3030 get a SIGCHLD). */ 3092 get a SIGCHLD). */
3031 #ifdef EIO 3093 #ifdef EIO
3032 || (readstatus == -1 && errno == EIO) 3094 || (readstatus == -1 && errno == EIO)
3033 #endif 3095 #endif
3034 3096
3035 ) 3097 )
3036 { 3098 {
3037 /* Currently, we rely on SIGCHLD to indicate that the 3099 /* Currently, we rely on SIGCHLD to indicate that the
3038 process has terminated. Unfortunately, on some systems 3100 process has terminated. Unfortunately, on some systems
3039 the SIGCHLD gets missed some of the time. So we put an 3101 the SIGCHLD gets missed some of the time. So we put an
3040 additional check in status_notify() to see whether a 3102 additional check in status_notify() to see whether a
3041 process has terminated. We must tell status_notify() 3103 process has terminated. We must tell status_notify()
3042 to enable that check, and we do so now. */ 3104 to enable that check, and we do so now. */
3043 kick_status_notify (); 3105 kick_status_notify ();
3106 }
3107
3108 /* We must call status_notify here to allow the
3109 event_stream->unselect_process_cb to be run if appropriate.
3110 Otherwise, dead fds may be selected for, and we will get a
3111 continuous stream of process events for them. Since we don't
3112 return until all process events have been flushed, we would
3113 get stuck here, processing events on a process whose status
3114 was 'exit. Call this after dispatch-event, or the fds will
3115 have been closed before we read the last data from them.
3116 It's safe for the filter to signal an error because
3117 status_notify() will be called on return to top-level.
3118 */
3119 status_notify ();
3120 return;
3044 } 3121 }
3045 else
3046 {
3047 /* Deactivate network connection */
3048 Lisp_Object status = Fprocess_status (p);
3049 if (EQ (status, Qopen)
3050 /* In case somebody changes the theory of whether to
3051 return open as opposed to run for network connection
3052 "processes"... */
3053 || EQ (status, Qrun))
3054 update_process_status (p, Qexit, 256, 0);
3055 deactivate_process (p);
3056 }
3057
3058 /* We must call status_notify here to allow the
3059 event_stream->unselect_process_cb to be run if appropriate.
3060 Otherwise, dead fds may be selected for, and we will get a
3061 continuous stream of process events for them. Since we don't
3062 return until all process events have been flushed, we would
3063 get stuck here, processing events on a process whose status
3064 was 'exit. Call this after dispatch-event, or the fds will
3065 have been closed before we read the last data from them.
3066 It's safe for the filter to signal an error because
3067 status_notify() will be called on return to top-level.
3068 */
3069 status_notify ();
3070 return;
3071 } 3122 }
3072 3123
3073 case timeout_event: 3124 case timeout_event:
3074 { 3125 {
3075 Lisp_Event *e = XEVENT (event); 3126 Lisp_Event *e = XEVENT (event);
3858 maybe_echo_keys (command_builder, 1); 3909 maybe_echo_keys (command_builder, 1);
3859 } 3910 }
3860 else 3911 else
3861 maybe_echo_keys (command_builder, 0); 3912 maybe_echo_keys (command_builder, 0);
3862 } 3913 }
3914 /* #### i don't trust this at all. --ben */
3915 #if 0
3863 else if (!NILP (Vquit_flag)) 3916 else if (!NILP (Vquit_flag))
3864 { 3917 {
3865 Lisp_Object quit_event = Fmake_event (Qnil, Qnil); 3918 Lisp_Object quit_event = Fmake_event (Qnil, Qnil);
3866 Lisp_Event *e = XEVENT (quit_event); 3919 Lisp_Event *e = XEVENT (quit_event);
3867 /* if quit happened during menu acceleration, pretend we read it */ 3920 /* if quit happened during menu acceleration, pretend we read it */
3872 e->channel = wrap_console (con); 3925 e->channel = wrap_console (con);
3873 3926
3874 enqueue_command_event (quit_event); 3927 enqueue_command_event (quit_event);
3875 Vquit_flag = Qnil; 3928 Vquit_flag = Qnil;
3876 } 3929 }
3930 #endif
3877 } 3931 }
3878 else if (!NILP (leaf)) 3932 else if (!NILP (leaf))
3879 { 3933 {
3880 if (EQ (Qcommand, echo_area_status (f)) 3934 if (EQ (Qcommand, echo_area_status (f))
3881 && command_builder->echo_buf_index > 0) 3935 && command_builder->echo_buf_index > 0)
4093 pre_command_hook (void) 4147 pre_command_hook (void)
4094 { 4148 {
4095 last_point_position = BUF_PT (current_buffer); 4149 last_point_position = BUF_PT (current_buffer);
4096 last_point_position_buffer = wrap_buffer (current_buffer); 4150 last_point_position_buffer = wrap_buffer (current_buffer);
4097 /* This function can GC */ 4151 /* This function can GC */
4098 safe_run_hook_trapping_errors 4152 safe_run_hook_trapping_problems
4099 ("Error in `pre-command-hook' (setting hook to nil)", 4153 ("Error in `pre-command-hook' (setting hook to nil)",
4100 Qpre_command_hook, 1); 4154 Qpre_command_hook, INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION);
4101 4155
4102 /* This is a kludge, but necessary; see simple.el */ 4156 /* This is a kludge, but necessary; see simple.el */
4103 call0 (Qhandle_pre_motion_command); 4157 call0 (Qhandle_pre_motion_command);
4104 } 4158 }
4105 4159
4138 || EQ (zmacs_region_buffer (), WINDOW_BUFFER (XWINDOW (win))))) 4192 || EQ (zmacs_region_buffer (), WINDOW_BUFFER (XWINDOW (win)))))
4139 zmacs_deactivate_region (); 4193 zmacs_deactivate_region ();
4140 else 4194 else
4141 zmacs_update_region (); 4195 zmacs_update_region ();
4142 4196
4143 safe_run_hook_trapping_errors 4197 safe_run_hook_trapping_problems
4144 ("Error in `post-command-hook' (setting hook to nil)", 4198 ("Error in `post-command-hook' (setting hook to nil)",
4145 Qpost_command_hook, 1); 4199 Qpost_command_hook, INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION);
4200
4201 #if 0 /* FSF Emacs crap */
4202 if (!NILP (Vdeferred_action_list))
4203 call0 (Vdeferred_action_function);
4204
4205 if (NILP (Vunread_command_events)
4206 && NILP (Vexecuting_macro)
4207 && !NILP (Vpost_command_idle_hook)
4208 && !NILP (Fsit_for (make_float ((double) post_command_idle_delay
4209 / 1000000), Qnil)))
4210 safe_run_hook_trapping_problems
4211 ("Error in `post-command-idle-hook' (setting hook to nil)",
4212 Qpost_command_idle_hook,
4213 INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION);
4214 #endif /* FSF Emacs crap */
4215
4216 #if 0 /* FSF Emacs */
4217 if (!NILP (current_buffer->mark_active))
4218 {
4219 if (!NILP (Vdeactivate_mark) && !NILP (Vtransient_mark_mode))
4220 {
4221 current_buffer->mark_active = Qnil;
4222 run_hook (intern ("deactivate-mark-hook"));
4223 }
4224 else if (current_buffer != prev_buffer ||
4225 BUF_MODIFF (current_buffer) != prev_modiff)
4226 run_hook (intern ("activate-mark-hook"));
4227 }
4228 #endif /* FSF Emacs */
4146 4229
4147 /* #### Kludge!!! This is necessary to make sure that things 4230 /* #### Kludge!!! This is necessary to make sure that things
4148 are properly positioned even if post-command-hook moves point. 4231 are properly positioned even if post-command-hook moves point.
4149 #### There should be a cleaner way of handling this. */ 4232 #### There should be a cleaner way of handling this. */
4150 call0 (Qauto_show_make_point_visible); 4233 call0 (Qauto_show_make_point_visible);
4445 QUIT; 4528 QUIT;
4446 4529
4447 if (NILP (continue_echo)) 4530 if (NILP (continue_echo))
4448 reset_this_command_keys (wrap_console (con), 1); 4531 reset_this_command_keys (wrap_console (con), 1);
4449 4532
4450 specbind (Qinhibit_quit, Qt);
4451
4452 if (!NILP (dont_downcase_last)) 4533 if (!NILP (dont_downcase_last))
4453 specbind (Qretry_undefined_key_binding_unshifted, Qnil); 4534 specbind (Qretry_undefined_key_binding_unshifted, Qnil);
4454 4535
4455 for (;;) 4536 for (;;)
4456 { 4537 {
4473 } 4554 }
4474 prompt = Qnil; 4555 prompt = Qnil;
4475 } 4556 }
4476 } 4557 }
4477 4558
4478 Vquit_flag = Qnil; /* In case we read a ^G; do not call check_quit() here */
4479 Fdeallocate_event (event); 4559 Fdeallocate_event (event);
4480 RETURN_UNGCPRO (unbind_to_1 (speccount, result)); 4560 RETURN_UNGCPRO (unbind_to_1 (speccount, result));
4481 } 4561 }
4482 4562
4483 DEFUN ("this-command-keys", Fthis_command_keys, 0, 0, 0, /* 4563 DEFUN ("this-command-keys", Fthis_command_keys, 0, 0, 0, /*
4725 4805
4726 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook /* 4806 DEFVAR_LISP ("pre-command-hook", &Vpre_command_hook /*
4727 Function or functions to run before every command. 4807 Function or functions to run before every command.
4728 This may examine the `this-command' variable to find out what command 4808 This may examine the `this-command' variable to find out what command
4729 is about to be run, or may change it to cause a different command to run. 4809 is about to be run, or may change it to cause a different command to run.
4730 Function on this hook must be careful to avoid signalling errors! 4810 Errors while running the hook are caught and turned into warnings.
4731 */ ); 4811 */ );
4732 Vpre_command_hook = Qnil; 4812 Vpre_command_hook = Qnil;
4733 4813
4734 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook /* 4814 DEFVAR_LISP ("post-command-hook", &Vpost_command_hook /*
4735 Function or functions to run after every command. 4815 Function or functions to run after every command.
4741 DEFVAR_LISP ("pre-idle-hook", &Vpre_idle_hook /* 4821 DEFVAR_LISP ("pre-idle-hook", &Vpre_idle_hook /*
4742 Normal hook run when XEmacs it about to be idle. 4822 Normal hook run when XEmacs it about to be idle.
4743 This occurs whenever it is going to block, waiting for an event. 4823 This occurs whenever it is going to block, waiting for an event.
4744 This generally happens as a result of a call to `next-event', 4824 This generally happens as a result of a call to `next-event',
4745 `next-command-event', `sit-for', `sleep-for', `accept-process-output', 4825 `next-command-event', `sit-for', `sleep-for', `accept-process-output',
4746 or `x-get-selection'. 4826 or `get-selection'. Errors while running the hook are caught and
4747 Errors running the hook are caught and ignored. 4827 turned into warnings.
4748 */ ); 4828 */ );
4749 Vpre_idle_hook = Qnil; 4829 Vpre_idle_hook = Qnil;
4750 4830
4751 DEFVAR_BOOL ("focus-follows-mouse", &focus_follows_mouse /* 4831 DEFVAR_BOOL ("focus-follows-mouse", &focus_follows_mouse /*
4752 *Variable to control XEmacs behavior with respect to focus changing. 4832 *Variable to control XEmacs behavior with respect to focus changing.
5061 } 5141 }
5062 } 5142 }
5063 5143
5064 5144
5065 /* 5145 /*
5146 #### this comment is at least 8 years old and some may no longer apply.
5147
5066 useful testcases for v18/v19 compatibility: 5148 useful testcases for v18/v19 compatibility:
5067 5149
5068 (defun foo () 5150 (defun foo ()
5069 (interactive) 5151 (interactive)
5070 (setq unread-command-event (character-to-event ?A (allocate-event))) 5152 (setq unread-command-event (character-to-event ?A (allocate-event)))