comparison src/event-stream.c @ 173:8eaf7971accc r20-3b13

Import from CVS: tag r20-3b13
author cvs
date Mon, 13 Aug 2007 09:49:09 +0200
parents 15872534500d
children 2d532a89d707
comparison
equal deleted inserted replaced
172:a38aed19690b 173:8eaf7971accc
139 /* The value of point when the last command was executed. */ 139 /* The value of point when the last command was executed. */
140 Bufpos last_point_position; 140 Bufpos last_point_position;
141 141
142 /* The frame that was current when the last command was started. */ 142 /* The frame that was current when the last command was started. */
143 Lisp_Object Vlast_selected_frame; 143 Lisp_Object Vlast_selected_frame;
144 144
145 /* The buffer that was current when the last command was started. */ 145 /* The buffer that was current when the last command was started. */
146 Lisp_Object last_point_position_buffer; 146 Lisp_Object last_point_position_buffer;
147 147
148 /* A (16bit . 16bit) representation of the time of the last-command-event. 148 /* A (16bit . 16bit) representation of the time of the last-command-event.
149 */ 149 */
150 Lisp_Object Vlast_input_time; 150 Lisp_Object Vlast_input_time;
151 151
152 /* Character to recognize as the help char. */ 152 /* Character to recognize as the help char. */
213 builder is for */ 213 builder is for */
214 /* Qnil, or a Lisp_Event representing the first event read 214 /* Qnil, or a Lisp_Event representing the first event read
215 * after the last command completed. Threaded. */ 215 * after the last command completed. Threaded. */
216 /* #### NYI */ 216 /* #### NYI */
217 Lisp_Object prefix_events; 217 Lisp_Object prefix_events;
218 /* Qnil, or a Lisp_Event representing event in the current 218 /* Qnil, or a Lisp_Event representing event in the current
219 * keymap-lookup sequence. Subsequent events are threaded via 219 * keymap-lookup sequence. Subsequent events are threaded via
220 * the event's next slot */ 220 * the event's next slot */
221 Lisp_Object current_events; 221 Lisp_Object current_events;
222 /* Last elt of above */ 222 /* Last elt of above */
223 Lisp_Object most_current_event; 223 Lisp_Object most_current_event;
613 clear_echo_area (selected_frame (), Qnil, 0); 613 clear_echo_area (selected_frame (), Qnil, 0);
614 } 614 }
615 615
616 format_event_object (buf, XEVENT (event), 1); 616 format_event_object (buf, XEVENT (event), 1);
617 len = strlen (buf); 617 len = strlen (buf);
618 618
619 if (len + buf_index + 4 > command_builder->echo_buf_length) 619 if (len + buf_index + 4 > command_builder->echo_buf_length)
620 return; 620 return;
621 e = command_builder->echo_buf + buf_index; 621 e = command_builder->echo_buf + buf_index;
622 memcpy (e, buf, len); 622 memcpy (e, buf, len);
623 e += len; 623 e += len;
649 struct frame *f = selected_frame (); 649 struct frame *f = selected_frame ();
650 /* Message turns off echoing unless more keystrokes turn it on again. */ 650 /* Message turns off echoing unless more keystrokes turn it on again. */
651 if (echo_area_active (f) && !EQ (Qcommand, echo_area_status (f))) 651 if (echo_area_active (f) && !EQ (Qcommand, echo_area_status (f)))
652 return; 652 return;
653 653
654 if (minibuf_level == 0 654 if (minibuf_level == 0
655 && echo_keystrokes > 0) 655 && echo_keystrokes > 0)
656 { 656 {
657 if (!no_snooze) 657 if (!no_snooze)
658 { 658 {
659 /* #### C-g here will cause QUIT. Setting dont_check_for_quit 659 /* #### C-g here will cause QUIT. Setting dont_check_for_quit
760 void 760 void
761 record_auto_save (void) 761 record_auto_save (void)
762 { 762 {
763 keystrokes_since_auto_save = 0; 763 keystrokes_since_auto_save = 0;
764 } 764 }
765 765
766 /* Make an auto save happen as soon as possible at command level. */ 766 /* Make an auto save happen as soon as possible at command level. */
767 767
768 void 768 void
769 force_auto_save_soon (void) 769 force_auto_save_soon (void)
770 { 770 {
872 872
873 EVENT_CHAIN_LOOP (event, command_event_queue) 873 EVENT_CHAIN_LOOP (event, command_event_queue)
874 { 874 {
875 if (XEVENT_TYPE (event) != eval_event 875 if (XEVENT_TYPE (event) != eval_event
876 && XEVENT_TYPE (event) != magic_eval_event) 876 && XEVENT_TYPE (event) != magic_eval_event)
877 return (1); 877 return 1;
878 } 878 }
879 } 879 }
880 return 0; 880 return 0;
881 } 881 }
882 882
884 T if command input is currently available with no waiting. 884 T if command input is currently available with no waiting.
885 Actually, the value is nil only if we can be sure that no input is available. 885 Actually, the value is nil only if we can be sure that no input is available.
886 */ 886 */
887 ()) 887 ())
888 { 888 {
889 return ((detect_input_pending ()) ? Qt : Qnil); 889 return detect_input_pending () ? Qt : Qnil;
890 } 890 }
891 891
892 892
893 /**********************************************************************/ 893 /**********************************************************************/
894 /* timeouts */ 894 /* timeouts */
949 949
950 void 950 void
951 remove_low_level_timeout (struct low_level_timeout **timeout_list, int id) 951 remove_low_level_timeout (struct low_level_timeout **timeout_list, int id)
952 { 952 {
953 struct low_level_timeout *t, *prev; 953 struct low_level_timeout *t, *prev;
954 954
955 /* find it */ 955 /* find it */
956 956
957 for (t = *timeout_list, prev = NULL; t && t->id != id; t = t->next) 957 for (t = *timeout_list, prev = NULL; t && t->id != id; t = t->next)
958 prev = t; 958 prev = t;
959 959
960 if (!t) 960 if (!t)
961 return; /* couldn't find it */ 961 return; /* couldn't find it */
962 962
963 if (!prev) 963 if (!prev)
964 *timeout_list = t->next; 964 *timeout_list = t->next;
978 if (!timeout_list) /* no timer events; block indefinitely */ 978 if (!timeout_list) /* no timer events; block indefinitely */
979 return 0; 979 return 0;
980 else 980 else
981 { 981 {
982 EMACS_TIME current_time; 982 EMACS_TIME current_time;
983 983
984 /* The time to block is the difference between the first 984 /* The time to block is the difference between the first
985 (earliest) timer on the queue and the current time. 985 (earliest) timer on the queue and the current time.
986 If that is negative, then the timer will fire immediately 986 If that is negative, then the timer will fire immediately
987 but we still have to call select(), with a zero-valued 987 but we still have to call select(), with a zero-valued
988 timeout: user events must have precedence over timer events. */ 988 timeout: user events must have precedence over timer events. */
1138 /* We make sure to snarf the data out of the timeout object before 1138 /* We make sure to snarf the data out of the timeout object before
1139 we free it with free_managed_opaque(). */ 1139 we free it with free_managed_opaque(). */
1140 id = timeout->id; 1140 id = timeout->id;
1141 *function = timeout->function; 1141 *function = timeout->function;
1142 *object = timeout->object; 1142 *object = timeout->object;
1143 1143
1144 /* Remove this one from the list of pending timeouts */ 1144 /* Remove this one from the list of pending timeouts */
1145 *timeout_list = delq_no_quit_and_free_cons (op, *timeout_list); 1145 *timeout_list = delq_no_quit_and_free_cons (op, *timeout_list);
1146 1146
1147 /* If this timeout wants to be resignalled, do it now. */ 1147 /* If this timeout wants to be resignalled, do it now. */
1148 if (timeout->resignal_msecs) 1148 if (timeout->resignal_msecs)
1177 list, which is a good thing. */ 1177 list, which is a good thing. */
1178 *timeout_list = noseeum_cons (op, *timeout_list); 1178 *timeout_list = noseeum_cons (op, *timeout_list);
1179 } 1179 }
1180 else 1180 else
1181 free_managed_opaque (Vtimeout_free_list, op); 1181 free_managed_opaque (Vtimeout_free_list, op);
1182 1182
1183 UNGCPRO; 1183 UNGCPRO;
1184 return id; 1184 return id;
1185 } 1185 }
1186 1186
1187 void 1187 void
1759 } 1759 }
1760 } 1760 }
1761 } 1761 }
1762 1762
1763 /* Called from the window-system-specific code when we receive a 1763 /* Called from the window-system-specific code when we receive a
1764 notification that the focus lies on a particular frame. 1764 notification that the focus lies on a particular frame.
1765 Argument is a cons: (frame . (device . in-p)) where in-p is non-nil 1765 Argument is a cons: (frame . (device . in-p)) where in-p is non-nil
1766 for focus-in. 1766 for focus-in.
1767 */ 1767 */
1768 void 1768 void
1769 emacs_handle_focus_change_final (Lisp_Object frame_inp_and_dev) 1769 emacs_handle_focus_change_final (Lisp_Object frame_inp_and_dev)
1846 in_single_console_state (void) 1846 in_single_console_state (void)
1847 { 1847 {
1848 return in_single_console; 1848 return in_single_console;
1849 } 1849 }
1850 1850
1851 /* the number of keyboard characters read. callint.c wants this. 1851 /* the number of keyboard characters read. callint.c wants this.
1852 */ 1852 */
1853 Charcount num_input_chars; 1853 Charcount num_input_chars;
1854 1854
1855 static void 1855 static void
1856 next_event_internal (Lisp_Object target_event, int allow_queued) 1856 next_event_internal (Lisp_Object target_event, int allow_queued)
1861 1861
1862 assert (NILP (XEVENT_NEXT (target_event))); 1862 assert (NILP (XEVENT_NEXT (target_event)));
1863 1863
1864 GCPRO1 (target_event); 1864 GCPRO1 (target_event);
1865 investigate_frame_change (); 1865 investigate_frame_change ();
1866 1866
1867 if (allow_queued && !NILP (command_event_queue)) 1867 if (allow_queued && !NILP (command_event_queue))
1868 { 1868 {
1869 Lisp_Object event = dequeue_command_event (); 1869 Lisp_Object event = dequeue_command_event ();
1870 Fcopy_event (event, target_event); 1870 Fcopy_event (event, target_event);
1871 Fdeallocate_event (event); 1871 Fdeallocate_event (event);
1893 Lisp_Object tristan, isolde; 1893 Lisp_Object tristan, isolde;
1894 1894
1895 e->event.timeout.id_number = 1895 e->event.timeout.id_number =
1896 event_stream_resignal_wakeup (e->event.timeout.interval_id, 0, 1896 event_stream_resignal_wakeup (e->event.timeout.interval_id, 0,
1897 &tristan, &isolde); 1897 &tristan, &isolde);
1898 1898
1899 e->event.timeout.function = tristan; 1899 e->event.timeout.function = tristan;
1900 e->event.timeout.object = isolde; 1900 e->event.timeout.object = isolde;
1901 #ifdef DEBUG_XEMACS 1901 #ifdef DEBUG_XEMACS
1902 /* next_event_internal() doesn't print out timeout events 1902 /* next_event_internal() doesn't print out timeout events
1903 because of the extra info we just set. */ 1903 because of the extra info we just set. */
2081 */ 2081 */
2082 else if (!NILP (Vunread_command_event)) 2082 else if (!NILP (Vunread_command_event))
2083 { 2083 {
2084 Lisp_Object e = Vunread_command_event; 2084 Lisp_Object e = Vunread_command_event;
2085 Vunread_command_event = Qnil; 2085 Vunread_command_event = Qnil;
2086 2086
2087 if (!EVENTP (e) || !command_event_p (e)) 2087 if (!EVENTP (e) || !command_event_p (e))
2088 { 2088 {
2089 signal_error (Qwrong_type_argument, 2089 signal_error (Qwrong_type_argument,
2090 list3 (Qeventp, e, Qunread_command_event)); 2090 list3 (Qeventp, e, Qunread_command_event));
2091 } 2091 }
2100 print_internal (event, Qexternal_debugging_output, 1); 2100 print_internal (event, Qexternal_debugging_output, 1);
2101 write_c_string ("\n", Qexternal_debugging_output); 2101 write_c_string ("\n", Qexternal_debugging_output);
2102 } 2102 }
2103 #endif 2103 #endif
2104 } 2104 }
2105 2105
2106 /* If we're executing a keyboard macro, take the next event from that, 2106 /* If we're executing a keyboard macro, take the next event from that,
2107 and update this-command-keys and recent-keys. 2107 and update this-command-keys and recent-keys.
2108 Note that the unread-command-events take precedence over kbd macros. 2108 Note that the unread-command-events take precedence over kbd macros.
2109 */ 2109 */
2110 else 2110 else
2192 Vlast_input_event = Fmake_event (); 2192 Vlast_input_event = Fmake_event ();
2193 error ("Someone deallocated last-input-event!"); 2193 error ("Someone deallocated last-input-event!");
2194 } 2194 }
2195 if (! EQ (event, Vlast_input_event)) 2195 if (! EQ (event, Vlast_input_event))
2196 Fcopy_event (event, Vlast_input_event); 2196 Fcopy_event (event, Vlast_input_event);
2197 2197
2198 /* last-input-char and last-input-time are derived from 2198 /* last-input-char and last-input-time are derived from
2199 last-input-event. 2199 last-input-event.
2200 Note that last-input-char will never have its high-bit set, in an 2200 Note that last-input-char will never have its high-bit set, in an
2201 effort to sidestep the ambiguity between M-x and oslash. 2201 effort to sidestep the ambiguity between M-x and oslash.
2202 */ 2202 */
2240 event_matches_key_specifier_p (XEVENT (event), Vhelp_char)) 2240 event_matches_key_specifier_p (XEVENT (event), Vhelp_char))
2241 execute_help_form (command_builder, event); 2241 execute_help_form (command_builder, event);
2242 2242
2243 RETURN: 2243 RETURN:
2244 UNGCPRO; 2244 UNGCPRO;
2245 return (event); 2245 return event;
2246 } 2246 }
2247 2247
2248 DEFUN ("next-command-event", Fnext_command_event, 0, 2, 0, /* 2248 DEFUN ("next-command-event", Fnext_command_event, 0, 2, 0, /*
2249 Return the next available \"user\" event. 2249 Return the next available \"user\" event.
2250 Pass this object to `dispatch-event' to handle it. 2250 Pass this object to `dispatch-event' to handle it.
2283 break; 2283 break;
2284 else 2284 else
2285 execute_internal_event (event); 2285 execute_internal_event (event);
2286 } 2286 }
2287 UNGCPRO; 2287 UNGCPRO;
2288 return (event); 2288 return event;
2289 } 2289 }
2290 2290
2291 static void 2291 static void
2292 reset_current_events (struct command_builder *command_builder) 2292 reset_current_events (struct command_builder *command_builder)
2293 { 2293 {
2390 /* This is used in accept-process-output, sleep-for and sit-for. 2390 /* This is used in accept-process-output, sleep-for and sit-for.
2391 Before running any process_events in these routines, we set 2391 Before running any process_events in these routines, we set
2392 recursive_sit_for to Qt, and use this unwind protect to reset it to 2392 recursive_sit_for to Qt, and use this unwind protect to reset it to
2393 Qnil upon exit. When recursive_sit_for is Qt, calling sit-for will 2393 Qnil upon exit. When recursive_sit_for is Qt, calling sit-for will
2394 cause it to return immediately. 2394 cause it to return immediately.
2395 2395
2396 All of these routines install timeouts, so we clear the installed 2396 All of these routines install timeouts, so we clear the installed
2397 timeout as well. 2397 timeout as well.
2398 2398
2399 Note: It's very easy to break the desired behaviours of these 2399 Note: It's very easy to break the desired behaviours of these
2400 3 routines. If you make any changes to anything in this area, run 2400 3 routines. If you make any changes to anything in this area, run
2401 the regression tests at the bottom of the file. -- dmoore */ 2401 the regression tests at the bottom of the file. -- dmoore */
2402 2402
2403 2403
2404 static Lisp_Object 2404 static Lisp_Object
2405 sit_for_unwind (Lisp_Object timeout_id) 2405 sit_for_unwind (Lisp_Object timeout_id)
2406 { 2406 {
2407 if (!NILP(timeout_id)) 2407 if (!NILP(timeout_id))
2432 { 2432 {
2433 /* This function can GC */ 2433 /* This function can GC */
2434 struct gcpro gcpro1, gcpro2; 2434 struct gcpro gcpro1, gcpro2;
2435 Lisp_Object event = Qnil; 2435 Lisp_Object event = Qnil;
2436 Lisp_Object result = Qnil; 2436 Lisp_Object result = Qnil;
2437 int timeout_id; 2437 int timeout_id = -1;
2438 int timeout_enabled = 0; 2438 int timeout_enabled = 0;
2439 int done = 0; 2439 int done = 0;
2440 struct buffer *old_buffer = current_buffer; 2440 struct buffer *old_buffer = current_buffer;
2441 int count; 2441 int count;
2442 2442
2651 if (!NILP (command_event_queue)) 2651 if (!NILP (command_event_queue))
2652 { 2652 {
2653 EVENT_CHAIN_LOOP (event, command_event_queue) 2653 EVENT_CHAIN_LOOP (event, command_event_queue)
2654 { 2654 {
2655 if (command_event_p (event)) 2655 if (command_event_p (event))
2656 return (Qnil); 2656 return Qnil;
2657 } 2657 }
2658 } 2658 }
2659 2659
2660 /* If we're in a macro, or noninteractive, or early in temacs, then 2660 /* If we're in a macro, or noninteractive, or early in temacs, then
2661 don't wait. */ 2661 don't wait. */
2662 if (noninteractive || !NILP (Vexecuting_macro)) 2662 if (noninteractive || !NILP (Vexecuting_macro))
2663 return (Qnil); 2663 return Qnil;
2664 2664
2665 /* Recusive call from a filter function or timeout handler. */ 2665 /* Recusive call from a filter function or timeout handler. */
2666 if (!NILP(recursive_sit_for)) 2666 if (!NILP(recursive_sit_for))
2667 { 2667 {
2668 if (!event_stream_event_pending_p (1) && NILP (nodisplay)) 2668 if (!event_stream_event_pending_p (1) && NILP (nodisplay))
2737 { 2737 {
2738 /* eval-events get delayed until later. */ 2738 /* eval-events get delayed until later. */
2739 enqueue_command_event (Fcopy_event (event, Qnil)); 2739 enqueue_command_event (Fcopy_event (event, Qnil));
2740 break; 2740 break;
2741 } 2741 }
2742 2742
2743 case timeout_event: 2743 case timeout_event:
2744 /* We execute the event even if it's ours, and notice that it's 2744 /* We execute the event even if it's ours, and notice that it's
2745 happened above. */ 2745 happened above. */
2746 default: 2746 default:
2747 { 2747 {
2766 enqueue_command_event (event); 2766 enqueue_command_event (event);
2767 else 2767 else
2768 Fdeallocate_event (event); 2768 Fdeallocate_event (event);
2769 2769
2770 UNGCPRO; 2770 UNGCPRO;
2771 return (result); 2771 return result;
2772 } 2772 }
2773 2773
2774 /* This handy little function is used by xselect.c and energize.c to 2774 /* This handy little function is used by xselect.c and energize.c to
2775 wait for replies from processes that aren't really processes (that is, 2775 wait for replies from processes that aren't really processes (that is,
2776 the X server and the Energize server). 2776 the X server and the Energize server).
2815 /* events on dead channels get silently eaten */ 2815 /* events on dead channels get silently eaten */
2816 if (object_dead_p (XEVENT (event)->channel)) 2816 if (object_dead_p (XEVENT (event)->channel))
2817 return; 2817 return;
2818 2818
2819 /* This function can GC */ 2819 /* This function can GC */
2820 switch (XEVENT_TYPE (event)) 2820 switch (XEVENT_TYPE (event))
2821 { 2821 {
2822 case empty_event: 2822 case empty_event:
2823 return; 2823 return;
2824 2824
2825 case eval_event: 2825 case eval_event:
2826 { 2826 {
2827 call1 (XEVENT (event)->event.eval.function, 2827 call1 (XEVENT (event)->event.eval.function,
2828 XEVENT (event)->event.eval.object); 2828 XEVENT (event)->event.eval.object);
2829 return; 2829 return;
2830 } 2830 }
2831 2831
2832 case magic_eval_event: 2832 case magic_eval_event:
2860 #endif /* EWOULDBLOCK */ 2860 #endif /* EWOULDBLOCK */
2861 #ifdef EAGAIN 2861 #ifdef EAGAIN
2862 else if (readstatus == -1 && errno == EAGAIN) 2862 else if (readstatus == -1 && errno == EAGAIN)
2863 ; 2863 ;
2864 #endif /* EAGAIN */ 2864 #endif /* EAGAIN */
2865 else if ((readstatus == 0 && 2865 else if ((readstatus == 0 &&
2866 /* Note that we cannot distinguish between no input 2866 /* Note that we cannot distinguish between no input
2867 available now and a closed pipe. 2867 available now and a closed pipe.
2868 With luck, a closed pipe will be accompanied by 2868 With luck, a closed pipe will be accompanied by
2869 subprocess termination and SIGCHLD. */ 2869 subprocess termination and SIGCHLD. */
2870 (!network_connection_p (p) || 2870 (!network_connection_p (p) ||
2979 command_builder_find_leaf_1 (struct command_builder *builder) 2979 command_builder_find_leaf_1 (struct command_builder *builder)
2980 { 2980 {
2981 Lisp_Object event0 = builder->current_events; 2981 Lisp_Object event0 = builder->current_events;
2982 2982
2983 if (NILP (event0)) 2983 if (NILP (event0))
2984 return (Qnil); 2984 return Qnil;
2985 2985
2986 return event_binding (event0, 1); 2986 return event_binding (event0, 1);
2987 } 2987 }
2988 2988
2989 /* See if we can do function-key-map or key-translation-map translation 2989 /* See if we can do function-key-map or key-translation-map translation
2994 munge_keymap_translate (struct command_builder *builder, 2994 munge_keymap_translate (struct command_builder *builder,
2995 enum munge_me_out_the_door munge, 2995 enum munge_me_out_the_door munge,
2996 int has_normal_binding_p) 2996 int has_normal_binding_p)
2997 { 2997 {
2998 Lisp_Object suffix; 2998 Lisp_Object suffix;
2999 2999
3000 EVENT_CHAIN_LOOP (suffix, builder->munge_me[munge].first_mungeable_event) 3000 EVENT_CHAIN_LOOP (suffix, builder->munge_me[munge].first_mungeable_event)
3001 { 3001 {
3002 Lisp_Object result = munging_key_map_event_binding (suffix, munge); 3002 Lisp_Object result = munging_key_map_event_binding (suffix, munge);
3003 3003
3004 if (!NILP (result)) 3004 if (!NILP (result))
3005 { 3005 {
3006 if (KEYMAPP (result)) 3006 if (KEYMAPP (result))
3007 { 3007 {
3008 if (NILP (builder->last_non_munged_event) 3008 if (NILP (builder->last_non_munged_event)
3022 UNGCPRO; 3022 UNGCPRO;
3023 } 3023 }
3024 3024
3025 if (KEYMAPP (result)) 3025 if (KEYMAPP (result))
3026 return result; 3026 return result;
3027 3027
3028 if (VECTORP (result) || STRINGP (result)) 3028 if (VECTORP (result) || STRINGP (result))
3029 { 3029 {
3030 Lisp_Object new_chain = 3030 Lisp_Object new_chain =
3031 key_sequence_to_event_chain (result); 3031 key_sequence_to_event_chain (result);
3032 Lisp_Object tempev; 3032 Lisp_Object tempev;
3104 && (NILP (XEVENT_NEXT (evee))) 3104 && (NILP (XEVENT_NEXT (evee)))
3105 && (XEVENT_TYPE (evee) == misc_user_event)) 3105 && (XEVENT_TYPE (evee) == misc_user_event))
3106 { 3106 {
3107 Lisp_Object fn = XEVENT (evee)->event.eval.function; 3107 Lisp_Object fn = XEVENT (evee)->event.eval.function;
3108 Lisp_Object arg = XEVENT (evee)->event.eval.object; 3108 Lisp_Object arg = XEVENT (evee)->event.eval.object;
3109 return (list2 (fn, arg)); 3109 return list2 (fn, arg);
3110 } 3110 }
3111 3111
3112 else if (XEVENT_TYPE (evee) == misc_user_event) 3112 else if (XEVENT_TYPE (evee) == misc_user_event)
3113 return Qnil; 3113 return Qnil;
3114 3114
3143 if (XEVENT_TYPE (builder->most_current_event) == key_press_event 3143 if (XEVENT_TYPE (builder->most_current_event) == key_press_event
3144 && !NILP (Vretry_undefined_key_binding_unshifted)) 3144 && !NILP (Vretry_undefined_key_binding_unshifted))
3145 { 3145 {
3146 Lisp_Object terminal = builder->most_current_event; 3146 Lisp_Object terminal = builder->most_current_event;
3147 struct key_data* key = & XEVENT (terminal)->event.key; 3147 struct key_data* key = & XEVENT (terminal)->event.key;
3148 Emchar c; 3148 Emchar c = 0;
3149 if ((key->modifiers & MOD_SHIFT) 3149 if ((key->modifiers & MOD_SHIFT)
3150 || (CHAR_OR_CHAR_INTP (key->keysym) 3150 || (CHAR_OR_CHAR_INTP (key->keysym)
3151 && ((c = XCHAR_OR_CHAR_INT (key->keysym)), c >= 'A' && c <= 'Z'))) 3151 && ((c = XCHAR_OR_CHAR_INT (key->keysym)), c >= 'A' && c <= 'Z')))
3152 { 3152 {
3153 struct Lisp_Event terminal_copy = *XEVENT (terminal); 3153 struct Lisp_Event terminal_copy = *XEVENT (terminal);
3154 3154
3155 if (key->modifiers & MOD_SHIFT) 3155 if (key->modifiers & MOD_SHIFT)
3156 key->modifiers &= (~ MOD_SHIFT); 3156 key->modifiers &= (~ MOD_SHIFT);
3157 else 3157 else
3158 key->keysym = make_char (c + 'a' - 'A'); 3158 key->keysym = make_char (c + 'a' - 'A');
3159 3159
3171 3171
3172 /* help-char is `auto-bound' in every keymap */ 3172 /* help-char is `auto-bound' in every keymap */
3173 if (!NILP (Vprefix_help_command) && 3173 if (!NILP (Vprefix_help_command) &&
3174 event_matches_key_specifier_p (XEVENT (builder->most_current_event), 3174 event_matches_key_specifier_p (XEVENT (builder->most_current_event),
3175 Vhelp_char)) 3175 Vhelp_char))
3176 return (Vprefix_help_command); 3176 return Vprefix_help_command;
3177 3177
3178 #ifdef HAVE_XIM 3178 #ifdef HAVE_XIM
3179 /* If keysym is a non-ASCII char, bind it to self-insert-char by default. */ 3179 /* If keysym is a non-ASCII char, bind it to self-insert-char by default. */
3180 if (XEVENT_TYPE (builder->most_current_event) == key_press_event 3180 if (XEVENT_TYPE (builder->most_current_event) == key_press_event
3181 && !NILP (Vcomposed_character_default_binding)) 3181 && !NILP (Vcomposed_character_default_binding))
3183 Lisp_Object keysym = XEVENT (builder->most_current_event)->event.key.keysym; 3183 Lisp_Object keysym = XEVENT (builder->most_current_event)->event.key.keysym;
3184 if (CHARP (keysym) && !CHAR_ASCII_P (XCHAR (keysym))) 3184 if (CHARP (keysym) && !CHAR_ASCII_P (XCHAR (keysym)))
3185 return Vcomposed_character_default_binding; 3185 return Vcomposed_character_default_binding;
3186 } 3186 }
3187 #endif /* HAVE_XIM */ 3187 #endif /* HAVE_XIM */
3188 3188
3189 /* If we read extra events attempting to match a function key but end 3189 /* If we read extra events attempting to match a function key but end
3190 up failing, then we release those events back to the command loop 3190 up failing, then we release those events back to the command loop
3191 and fail on the original lookup. The released events will then be 3191 and fail on the original lookup. The released events will then be
3192 reprocessed in the context of the first part having failed. */ 3192 reprocessed in the context of the first part having failed. */
3193 if (!NILP (builder->last_non_munged_event)) 3193 if (!NILP (builder->last_non_munged_event))
3194 { 3194 {
3195 Lisp_Object event0 = builder->last_non_munged_event; 3195 Lisp_Object event0 = builder->last_non_munged_event;
3196 3196
3197 /* Put the commands back on the event queue. */ 3197 /* Put the commands back on the event queue. */
3198 enqueue_event_chain (XEVENT_NEXT (event0), 3198 enqueue_event_chain (XEVENT_NEXT (event0),
3199 &command_event_queue, 3199 &command_event_queue,
3200 &command_event_queue_tail); 3200 &command_event_queue_tail);
3201 3201
3202 /* Then remove them from the command builder. */ 3202 /* Then remove them from the command builder. */
3203 XSET_EVENT_NEXT (event0, Qnil); 3203 XSET_EVENT_NEXT (event0, Qnil);
3204 builder->most_current_event = event0; 3204 builder->most_current_event = event0;
3205 builder->last_non_munged_event = Qnil; 3205 builder->last_non_munged_event = Qnil;
3206 } 3206 }
3216 Every time a command is invoked, Vlast_command_event is set to the last 3216 Every time a command is invoked, Vlast_command_event is set to the last
3217 event in the sequence. 3217 event in the sequence.
3218 3218
3219 This means that Vthis_command_keys is really about "input read since the 3219 This means that Vthis_command_keys is really about "input read since the
3220 last command was executed" rather than about "what keys invoked this 3220 last command was executed" rather than about "what keys invoked this
3221 command." This is a little counterintuitive, but that's the way it 3221 command." This is a little counterintuitive, but that's the way it
3222 has always worked. 3222 has always worked.
3223 3223
3224 As an extra kink, the function read-key-sequence resets/updates the 3224 As an extra kink, the function read-key-sequence resets/updates the
3225 last-command-event and this-command-keys. It doesn't append to the 3225 last-command-event and this-command-keys. It doesn't append to the
3226 command-keys as read-char does. Such are the pitfalls of having to 3226 command-keys as read-char does. Such are the pitfalls of having to
3261 Vrecent_keys_ring = make_vector (recent_keys_ring_size, Qnil); 3261 Vrecent_keys_ring = make_vector (recent_keys_ring_size, Qnil);
3262 /* And return nothing in particular. */ 3262 /* And return nothing in particular. */
3263 return make_vector (0, Qnil); 3263 return make_vector (0, Qnil);
3264 } 3264 }
3265 3265
3266 if (NILP (vector_data (XVECTOR (Vrecent_keys_ring))[recent_keys_ring_index])) 3266 if (NILP (XVECTOR_DATA (Vrecent_keys_ring)[recent_keys_ring_index]))
3267 /* This means the vector has not yet wrapped */ 3267 /* This means the vector has not yet wrapped */
3268 { 3268 {
3269 nkeys = recent_keys_ring_index; 3269 nkeys = recent_keys_ring_index;
3270 start = 0; 3270 start = 0;
3271 } 3271 }
3287 3287
3288 val = make_vector (nwanted, Qnil); 3288 val = make_vector (nwanted, Qnil);
3289 3289
3290 for (i = 0, j = start; i < nkeys; i++) 3290 for (i = 0, j = start; i < nkeys; i++)
3291 { 3291 {
3292 Lisp_Object e = vector_data (XVECTOR (Vrecent_keys_ring))[j]; 3292 Lisp_Object e = XVECTOR_DATA (Vrecent_keys_ring)[j];
3293 3293
3294 if (NILP (e)) 3294 if (NILP (e))
3295 abort (); 3295 abort ();
3296 vector_data (XVECTOR (val))[i] = Fcopy_event (e, Qnil); 3296 XVECTOR_DATA (val)[i] = Fcopy_event (e, Qnil);
3297 if (++j >= recent_keys_ring_size) 3297 if (++j >= recent_keys_ring_size)
3298 j = 0; 3298 j = 0;
3299 } 3299 }
3300 UNGCPRO; 3300 UNGCPRO;
3301 return (val); 3301 return val;
3302 } 3302 }
3303 3303
3304 3304
3305 DEFUN ("recent-keys-ring-size", Frecent_keys_ring_size, 0, 0, 0, /* 3305 DEFUN ("recent-keys-ring-size", Frecent_keys_ring_size, 0, 0, 0, /*
3306 The maximum number of events `recent-keys' can return. 3306 The maximum number of events `recent-keys' can return.
3332 { 3332 {
3333 Vrecent_keys_ring = new_vector; 3333 Vrecent_keys_ring = new_vector;
3334 return size; 3334 return size;
3335 } 3335 }
3336 3336
3337 if (NILP (vector_data (XVECTOR (Vrecent_keys_ring))[recent_keys_ring_index])) 3337 if (NILP (XVECTOR_DATA (Vrecent_keys_ring)[recent_keys_ring_index]))
3338 /* This means the vector has not yet wrapped */ 3338 /* This means the vector has not yet wrapped */
3339 { 3339 {
3340 nkeys = recent_keys_ring_index; 3340 nkeys = recent_keys_ring_index;
3341 start = 0; 3341 start = 0;
3342 } 3342 }
3351 else 3351 else
3352 min = XINT (size); 3352 min = XINT (size);
3353 3353
3354 for (i = 0, j = start; i < min; i++) 3354 for (i = 0, j = start; i < min; i++)
3355 { 3355 {
3356 vector_data (XVECTOR (new_vector))[i] 3356 XVECTOR_DATA (new_vector)[i] = XVECTOR_DATA (Vrecent_keys_ring)[j];
3357 = vector_data (XVECTOR (Vrecent_keys_ring))[j];
3358 if (++j >= recent_keys_ring_size) 3357 if (++j >= recent_keys_ring_size)
3359 j = 0; 3358 j = 0;
3360 } 3359 }
3361 recent_keys_ring_size = XINT (size); 3360 recent_keys_ring_size = XINT (size);
3362 recent_keys_ring_index = (i < recent_keys_ring_size) ? i : 0; 3361 recent_keys_ring_index = (i < recent_keys_ring_size) ? i : 0;
3444 3443
3445 Lisp_Object 3444 Lisp_Object
3446 extract_vector_nth_mouse_event (Lisp_Object vector, int n) 3445 extract_vector_nth_mouse_event (Lisp_Object vector, int n)
3447 { 3446 {
3448 int i; 3447 int i;
3449 3448 int len = XVECTOR_LENGTH (vector);
3450 for (i = 0; i < vector_length (XVECTOR (vector)); i++) 3449
3451 { 3450 for (i = 0; i < len; i++)
3452 Lisp_Object event = vector_data (XVECTOR (vector))[i]; 3451 {
3453 if (EVENTP (event) 3452 Lisp_Object event = XVECTOR_DATA (vector)[i];
3454 && (XEVENT_TYPE (event) == button_press_event 3453 if (EVENTP (event))
3455 || XEVENT_TYPE (event) == button_release_event 3454 switch (XEVENT_TYPE (event))
3456 || XEVENT_TYPE (event) == misc_user_event)) 3455 {
3457 { 3456 case button_press_event :
3458 if (!n) 3457 case button_release_event :
3459 return event; 3458 case misc_user_event :
3460 n--; 3459 if (n == 0)
3461 } 3460 return event;
3461 n--;
3462 break;
3463 default:
3464 continue;
3465 }
3462 } 3466 }
3463 3467
3464 return Qnil; 3468 return Qnil;
3465 } 3469 }
3466 3470
3470 Lisp_Object e; 3474 Lisp_Object e;
3471 3475
3472 if (NILP (Vrecent_keys_ring)) 3476 if (NILP (Vrecent_keys_ring))
3473 Vrecent_keys_ring = make_vector (recent_keys_ring_size, Qnil); 3477 Vrecent_keys_ring = make_vector (recent_keys_ring_size, Qnil);
3474 3478
3475 e = vector_data (XVECTOR (Vrecent_keys_ring)) [recent_keys_ring_index]; 3479 e = XVECTOR_DATA (Vrecent_keys_ring) [recent_keys_ring_index];
3476 3480
3477 if (NILP (e)) 3481 if (NILP (e))
3478 { 3482 {
3479 e = Fmake_event (); 3483 e = Fmake_event ();
3480 vector_data (XVECTOR (Vrecent_keys_ring)) [recent_keys_ring_index] = e; 3484 XVECTOR_DATA (Vrecent_keys_ring) [recent_keys_ring_index] = e;
3481 } 3485 }
3482 Fcopy_event (event, e); 3486 Fcopy_event (event, e);
3483 if (++recent_keys_ring_index == recent_keys_ring_size) 3487 if (++recent_keys_ring_index == recent_keys_ring_size)
3484 recent_keys_ring_index = 0; 3488 recent_keys_ring_index = 0;
3485 } 3489 }
3496 /* No need to copy the events, since they're already copies, and 3500 /* No need to copy the events, since they're already copies, and
3497 nobody other than the command-builder has pointers to them */ 3501 nobody other than the command-builder has pointers to them */
3498 vector = make_vector (n, Qnil); 3502 vector = make_vector (n, Qnil);
3499 n = 0; 3503 n = 0;
3500 EVENT_CHAIN_LOOP (event, command_builder->current_events) 3504 EVENT_CHAIN_LOOP (event, command_builder->current_events)
3501 vector_data (XVECTOR (vector))[n++] = event; 3505 XVECTOR_DATA (vector)[n++] = event;
3502 reset_command_builder_event_chain (command_builder); 3506 reset_command_builder_event_chain (command_builder);
3503 return (vector); 3507 return vector;
3504 } 3508 }
3505 3509
3506 3510
3507 /* 3511 /*
3508 Given the current state of the command builder and a new command event 3512 Given the current state of the command builder and a new command event
3549 */ 3553 */
3550 Fcopy_event (event, recent); 3554 Fcopy_event (event, recent);
3551 e = XEVENT (recent); 3555 e = XEVENT (recent);
3552 if (e->event_type == key_press_event) 3556 if (e->event_type == key_press_event)
3553 e->event.key.modifiers |= MOD_META; 3557 e->event.key.modifiers |= MOD_META;
3554 else if (e->event_type == button_press_event 3558 else if (e->event_type == button_press_event
3555 || e->event_type == button_release_event) 3559 || e->event_type == button_release_event)
3556 e->event.button.modifiers |= MOD_META; 3560 e->event.button.modifiers |= MOD_META;
3557 else 3561 else
3558 abort (); 3562 abort ();
3559 3563
3645 if (XEVENT (Vlast_command_event)->event_type == dead_event) 3649 if (XEVENT (Vlast_command_event)->event_type == dead_event)
3646 { 3650 {
3647 Vlast_command_event = Fmake_event (); 3651 Vlast_command_event = Fmake_event ();
3648 error ("Someone deallocated the last-command-event!"); 3652 error ("Someone deallocated the last-command-event!");
3649 } 3653 }
3650 3654
3651 if (! EQ (event, Vlast_command_event)) 3655 if (! EQ (event, Vlast_command_event))
3652 Fcopy_event (event, Vlast_command_event); 3656 Fcopy_event (event, Vlast_command_event);
3653 3657
3654 /* Note that last-command-char will never have its high-bit set, in 3658 /* Note that last-command-char will never have its high-bit set, in
3655 an effort to sidestep the ambiguity between M-x and oslash. 3659 an effort to sidestep the ambiguity between M-x and oslash.
3682 3686
3683 pre_command_hook (); 3687 pre_command_hook ();
3684 3688
3685 if (XEVENT (event)->event_type == misc_user_event) 3689 if (XEVENT (event)->event_type == misc_user_event)
3686 { 3690 {
3687 call1 (XEVENT (event)->event.eval.function, 3691 call1 (XEVENT (event)->event.eval.function,
3688 XEVENT (event)->event.eval.object); 3692 XEVENT (event)->event.eval.object);
3689 } 3693 }
3690 else 3694 else
3691 { 3695 {
3692 #if 0 3696 #if 0
3764 /* ### This doesn't really fix the problem, 3768 /* ### This doesn't really fix the problem,
3765 if delete-frame is called by some hook */ 3769 if delete-frame is called by some hook */
3766 if (NILP (win)) 3770 if (NILP (win))
3767 return; 3771 return;
3768 #endif 3772 #endif
3769 3773
3770 if (! zmacs_region_stays 3774 if (! zmacs_region_stays
3771 && (!MINI_WINDOW_P (XWINDOW (win)) 3775 && (!MINI_WINDOW_P (XWINDOW (win))
3772 || EQ (zmacs_region_buffer (), WINDOW_BUFFER (XWINDOW (win))))) 3776 || EQ (zmacs_region_buffer (), WINDOW_BUFFER (XWINDOW (win)))))
3773 zmacs_deactivate_region (); 3777 zmacs_deactivate_region ();
3774 else 3778 else
3858 console = Vselected_console; 3862 console = Vselected_console;
3859 else if (!EQ (console, Vselected_console)) 3863 else if (!EQ (console, Vselected_console))
3860 Fselect_console (console); 3864 Fselect_console (console);
3861 3865
3862 command_builder = XCOMMAND_BUILDER (XCONSOLE (console)->command_builder); 3866 command_builder = XCOMMAND_BUILDER (XCONSOLE (console)->command_builder);
3863 switch (XEVENT (event)->event_type) 3867 switch (XEVENT (event)->event_type)
3864 { 3868 {
3865 case button_press_event: 3869 case button_press_event:
3866 case button_release_event: 3870 case button_release_event:
3867 case key_press_event: 3871 case key_press_event:
3868 { 3872 {
3936 kind of sequence that warrants a complaint. 3940 kind of sequence that warrants a complaint.
3937 */ 3941 */
3938 XCONSOLE (console)->defining_kbd_macro = Qnil; 3942 XCONSOLE (console)->defining_kbd_macro = Qnil;
3939 XCONSOLE (console)->prefix_arg = Qnil; 3943 XCONSOLE (console)->prefix_arg = Qnil;
3940 /* Don't complain about undefined button-release events */ 3944 /* Don't complain about undefined button-release events */
3941 if (XEVENT_TYPE (terminal) != button_release_event) 3945 if (XEVENT_TYPE (terminal) != button_release_event)
3942 { 3946 {
3943 Lisp_Object keys = 3947 Lisp_Object keys =
3944 current_events_into_vector (command_builder); 3948 current_events_into_vector (command_builder);
3945 struct gcpro gcpro1; 3949 struct gcpro gcpro1;
3946 3950
4037 { 4041 {
4038 execute_internal_event (event); 4042 execute_internal_event (event);
4039 break; 4043 break;
4040 } 4044 }
4041 } 4045 }
4042 return (Qnil); 4046 return Qnil;
4043 } 4047 }
4044 4048
4045 DEFUN ("read-key-sequence", Fread_key_sequence, 1, 3, 0, /* 4049 DEFUN ("read-key-sequence", Fread_key_sequence, 1, 3, 0, /*
4046 Read a sequence of keystrokes or mouse clicks. 4050 Read a sequence of keystrokes or mouse clicks.
4047 Returns a vector of the event objects read. The vector and the event 4051 Returns a vector of the event objects read. The vector and the event
4142 Lisp_Object event; 4146 Lisp_Object event;
4143 Lisp_Object result; 4147 Lisp_Object result;
4144 int len; 4148 int len;
4145 4149
4146 if (NILP (Vthis_command_keys)) 4150 if (NILP (Vthis_command_keys))
4147 return (make_vector (0, Qnil)); 4151 return make_vector (0, Qnil);
4148 4152
4149 len = event_chain_count (Vthis_command_keys); 4153 len = event_chain_count (Vthis_command_keys);
4150 4154
4151 result = make_vector (len, Qnil); 4155 result = make_vector (len, Qnil);
4152 len = 0; 4156 len = 0;
4153 EVENT_CHAIN_LOOP (event, Vthis_command_keys) 4157 EVENT_CHAIN_LOOP (event, Vthis_command_keys)
4154 vector_data (XVECTOR (result))[len++] = Fcopy_event (event, Qnil); 4158 XVECTOR_DATA (result)[len++] = Fcopy_event (event, Qnil);
4155 return (result); 4159 return result;
4156 } 4160 }
4157 4161
4158 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths, 0, 0, 0, /* 4162 DEFUN ("reset-this-command-lengths", Freset_this_command_lengths, 0, 0, 0, /*
4159 Used for complicated reasons in `universal-argument-other-key'. 4163 Used for complicated reasons in `universal-argument-other-key'.
4160 4164
4189 if (CHARP (XEVENT (event)->event.key.keysym)) 4193 if (CHARP (XEVENT (event)->event.key.keysym))
4190 { 4194 {
4191 Emchar ch = XCHAR (keysym); 4195 Emchar ch = XCHAR (keysym);
4192 Bufbyte str[MAX_EMCHAR_LEN]; 4196 Bufbyte str[MAX_EMCHAR_LEN];
4193 Bytecount len; 4197 Bytecount len;
4194 4198
4195 len = set_charptr_emchar (str, ch); 4199 len = set_charptr_emchar (str, ch);
4196 Lstream_write (XLSTREAM (Vdribble_file), str, len); 4200 Lstream_write (XLSTREAM (Vdribble_file), str, len);
4197 } 4201 }
4198 else if (string_char_length (XSYMBOL (keysym)->name) == 1) 4202 else if (string_char_length (XSYMBOL (keysym)->name) == 1)
4199 /* one-char key events are printed with just the key name */ 4203 /* one-char key events are printed with just the key name */
4315 Vthis_command_keys = Qnil; 4319 Vthis_command_keys = Qnil;
4316 staticpro (&Vthis_command_keys); 4320 staticpro (&Vthis_command_keys);
4317 Vthis_command_keys_tail = Qnil; 4321 Vthis_command_keys_tail = Qnil;
4318 4322
4319 num_input_chars = 0; 4323 num_input_chars = 0;
4320 4324
4321 command_event_queue = Qnil; 4325 command_event_queue = Qnil;
4322 staticpro (&command_event_queue); 4326 staticpro (&command_event_queue);
4323 command_event_queue_tail = Qnil; 4327 command_event_queue_tail = Qnil;
4324 4328
4325 Vlast_selected_frame = Qnil; 4329 Vlast_selected_frame = Qnil;
4557 */ ); 4561 */ );
4558 Vretry_undefined_key_binding_unshifted = Qt; 4562 Vretry_undefined_key_binding_unshifted = Qt;
4559 4563
4560 #ifdef HAVE_XIM 4564 #ifdef HAVE_XIM
4561 DEFVAR_LISP ("Vcomposed_character_default_binding", 4565 DEFVAR_LISP ("Vcomposed_character_default_binding",
4562 &Vretry_undefined_key_binding_unshifted /* 4566 &Vretry_undefined_key_binding_unshifted /*
4563 The default keybinding to use for key events from composed input. 4567 The default keybinding to use for key events from composed input.
4564 Window systems frequently have ways to allow the user to compose 4568 Window systems frequently have ways to allow the user to compose
4565 single characters in a language using multiple keystrokes. 4569 single characters in a language using multiple keystrokes.
4566 XEmacs sees these as single character keypress events. 4570 XEmacs sees these as single character keypress events.
4567 */ ); 4571 */ );