comparison src/event-stream.c @ 5923:61d7d7bcbe76 cygwin

merged heads after pull -u
author Henry Thompson <ht@markup.co.uk>
date Thu, 05 Feb 2015 17:19:05 +0000
parents b3824b7f5627
children 6ec4964c1687
comparison
equal deleted inserted replaced
5921:68639fb08af8 5923:61d7d7bcbe76
79 #include "buffer.h" 79 #include "buffer.h"
80 #include "commands.h" 80 #include "commands.h"
81 #include "device-impl.h" 81 #include "device-impl.h"
82 #include "elhash.h" 82 #include "elhash.h"
83 #include "events.h" 83 #include "events.h"
84 #include "extents.h"
84 #include "frame-impl.h" 85 #include "frame-impl.h"
85 #include "insdel.h" /* for buffer_reset_changes */ 86 #include "insdel.h" /* for buffer_reset_changes */
86 #include "keymap.h" 87 #include "keymap.h"
87 #include "lstream.h" 88 #include "lstream.h"
88 #include "macros.h" /* for defining_keyboard_macro */ 89 #include "macros.h" /* for defining_keyboard_macro */
334 { XD_LISP_OBJECT, offsetof (struct command_builder, current_events) }, 335 { XD_LISP_OBJECT, offsetof (struct command_builder, current_events) },
335 { XD_LISP_OBJECT, offsetof (struct command_builder, most_current_event) }, 336 { XD_LISP_OBJECT, offsetof (struct command_builder, most_current_event) },
336 { XD_LISP_OBJECT, offsetof (struct command_builder, last_non_munged_event) }, 337 { XD_LISP_OBJECT, offsetof (struct command_builder, last_non_munged_event) },
337 { XD_LISP_OBJECT, offsetof (struct command_builder, console) }, 338 { XD_LISP_OBJECT, offsetof (struct command_builder, console) },
338 { XD_LISP_OBJECT_ARRAY, offsetof (struct command_builder, first_mungeable_event), 2 }, 339 { XD_LISP_OBJECT_ARRAY, offsetof (struct command_builder, first_mungeable_event), 2 },
340 { XD_LISP_OBJECT, offsetof (struct command_builder, echo_buf) },
339 { XD_END } 341 { XD_END }
340 }; 342 };
341 343
342 static Lisp_Object 344 static Lisp_Object
343 mark_command_builder (Lisp_Object obj) 345 mark_command_builder (Lisp_Object obj)
346 mark_object (builder->current_events); 348 mark_object (builder->current_events);
347 mark_object (builder->most_current_event); 349 mark_object (builder->most_current_event);
348 mark_object (builder->last_non_munged_event); 350 mark_object (builder->last_non_munged_event);
349 mark_object (builder->first_mungeable_event[0]); 351 mark_object (builder->first_mungeable_event[0]);
350 mark_object (builder->first_mungeable_event[1]); 352 mark_object (builder->first_mungeable_event[1]);
353 mark_object (builder->echo_buf);
351 return builder->console; 354 return builder->console;
352 }
353
354 static void
355 finalize_command_builder (Lisp_Object obj)
356 {
357 struct command_builder *b = XCOMMAND_BUILDER (obj);
358 if (b->echo_buf)
359 {
360 xfree (b->echo_buf);
361 b->echo_buf = 0;
362 }
363 } 355 }
364 356
365 DEFINE_NODUMP_LISP_OBJECT ("command-builder", command_builder, 357 DEFINE_NODUMP_LISP_OBJECT ("command-builder", command_builder,
366 mark_command_builder, 358 mark_command_builder,
367 internal_object_printer, 359 internal_object_printer, 0, 0, 0,
368 finalize_command_builder, 0, 0,
369 command_builder_description, 360 command_builder_description,
370 struct command_builder); 361 struct command_builder);
371 362
372 static void 363 static void
373 reset_command_builder_event_chain (struct command_builder *builder) 364 reset_command_builder_event_chain (struct command_builder *builder)
387 378
388 builder->console = console; 379 builder->console = console;
389 reset_command_builder_event_chain (builder); 380 reset_command_builder_event_chain (builder);
390 if (with_echo_buf) 381 if (with_echo_buf)
391 { 382 {
392 /* #### This badly needs to be turned into a Dynarr */ 383 builder->echo_buf = Fmake_string (make_fixnum (300 * MAX_ICHAR_LEN),
393 builder->echo_buf_length = 300; /* #### Kludge */ 384 make_char (0));
394 builder->echo_buf = xnew_array (Ibyte, builder->echo_buf_length);
395 builder->echo_buf[0] = 0;
396 } 385 }
397 else 386 else
398 { 387 {
399 builder->echo_buf_length = 0; 388 builder->echo_buf = Qnil;
400 builder->echo_buf = NULL; 389 }
401 } 390 builder->echo_buf_fill_pointer = builder->echo_buf_end = -1;
402 builder->echo_buf_index = -1;
403 builder->self_insert_countdown = 0; 391 builder->self_insert_countdown = 0;
404 392
405 return builder_obj; 393 return builder_obj;
406 } 394 }
407 395
444 432
445 return wrap_command_builder (new_buildings); 433 return wrap_command_builder (new_buildings);
446 } 434 }
447 435
448 static void 436 static void
449 free_command_builder (struct command_builder *builder)
450 {
451 if (builder->echo_buf)
452 {
453 xfree (builder->echo_buf);
454 builder->echo_buf = NULL;
455 }
456 free_normal_lisp_object (wrap_command_builder (builder));
457 }
458
459 static void
460 command_builder_append_event (struct command_builder *builder, 437 command_builder_append_event (struct command_builder *builder,
461 Lisp_Object event) 438 Lisp_Object event)
462 { 439 {
463 assert (EVENTP (event)); 440 assert (EVENTP (event));
464 441
658 echo_key_event (struct command_builder *command_builder, 635 echo_key_event (struct command_builder *command_builder,
659 Lisp_Object event) 636 Lisp_Object event)
660 { 637 {
661 /* This function can GC */ 638 /* This function can GC */
662 DECLARE_EISTRING_MALLOC (buf); 639 DECLARE_EISTRING_MALLOC (buf);
663 Bytecount buf_index = command_builder->echo_buf_index; 640 Bytecount buf_fill_pointer = command_builder->echo_buf_fill_pointer;
664 Ibyte *e;
665 Bytecount len; 641 Bytecount len;
666 642
667 if (buf_index < 0) 643 if (buf_fill_pointer < 0)
668 { 644 {
669 buf_index = 0; /* We're echoing now */ 645 buf_fill_pointer = 0;
670 clear_echo_area (selected_frame (), Qnil, 0); 646 clear_echo_area (selected_frame (), Qnil, 0);
671 } 647 }
672 648
673 format_event_object (buf, event, 1); 649 format_event_object (buf, event, 1);
674 len = eilen (buf); 650 len = eilen (buf);
675 651
676 if (len + buf_index + 4 > command_builder->echo_buf_length) 652 if (NILP (command_builder->echo_buf) ||
653 (len + buf_fill_pointer + 4 > XSTRING_LENGTH (command_builder->echo_buf)))
677 { 654 {
678 eifree (buf); 655 eifree (buf);
679 return; 656 return;
680 } 657 }
681 e = command_builder->echo_buf + buf_index; 658
682 memcpy (e, eidata (buf), len); 659 eicat_ascii (buf, " - ");
683 e += len; 660
661 memcpy (XSTRING_DATA (command_builder->echo_buf) + buf_fill_pointer,
662 eidata (buf), eilen (buf));
663 init_string_ascii_begin (command_builder->echo_buf);
664 bump_string_modiff (command_builder->echo_buf);
665 sledgehammer_check_ascii_begin (command_builder->echo_buf);
666
667 command_builder->echo_buf_end = buf_fill_pointer + eilen (buf);
668 /* *Not* including the trailing " - ". */
669 command_builder->echo_buf_fill_pointer = buf_fill_pointer + len + 1;
684 eifree (buf); 670 eifree (buf);
685
686 e[0] = ' ';
687 e[1] = '-';
688 e[2] = ' ';
689 e[3] = 0;
690
691 command_builder->echo_buf_index = buf_index + len + 1;
692 } 671 }
693 672
694 static void 673 static void
695 regenerate_echo_keys_from_this_command_keys (struct command_builder * 674 regenerate_echo_keys_from_this_command_keys (struct command_builder *
696 builder) 675 builder)
697 { 676 {
698 Lisp_Object event; 677 Lisp_Object event;
699 678
700 builder->echo_buf_index = 0; 679 builder->echo_buf_fill_pointer = builder->echo_buf_end = 0;
680 if (STRINGP (builder->echo_buf))
681 {
682 detach_all_extents (builder->echo_buf);
683 }
701 684
702 EVENT_CHAIN_LOOP (event, Vthis_command_keys) 685 EVENT_CHAIN_LOOP (event, Vthis_command_keys)
703 echo_key_event (builder, event); 686 echo_key_event (builder, event);
704 } 687 }
705 688
732 if (NILP (Fsit_for (Vecho_keystrokes, Qnil))) 715 if (NILP (Fsit_for (Vecho_keystrokes, Qnil)))
733 /* input came in, so don't echo. */ 716 /* input came in, so don't echo. */
734 goto done; 717 goto done;
735 } 718 }
736 719
737 echo_area_message (f, command_builder->echo_buf, Qnil, 0, 720 echo_area_message (f, NULL, command_builder->echo_buf, 0,
738 /* not echo_buf_index. That doesn't include 721 command_builder->echo_buf_end, Qcommand);
739 the terminating " - ". */
740 strlen ((char *) command_builder->echo_buf),
741 Qcommand);
742 } 722 }
743 723
744 done: 724 done:
745 Vquit_flag = Qnil; /* see begin_dont_check_for_quit() */ 725 Vquit_flag = Qnil; /* see begin_dont_check_for_quit() */
746 unbind_to (depth); 726 unbind_to (depth);
752 { 732 {
753 /* This function can GC */ 733 /* This function can GC */
754 struct frame *f = selected_frame (); 734 struct frame *f = selected_frame ();
755 735
756 if (command_builder) 736 if (command_builder)
757 command_builder->echo_buf_index = -1; 737 {
738 command_builder->echo_buf_fill_pointer =
739 command_builder->echo_buf_end = -1;
740 }
758 741
759 if (remove_echo_area_echo) 742 if (remove_echo_area_echo)
760 clear_echo_area (f, Qcommand, 0); 743 clear_echo_area (f, Qcommand, 0);
761 } 744 }
762 745
812 Lisp_Object event) 795 Lisp_Object event)
813 { 796 {
814 /* This function can GC */ 797 /* This function can GC */
815 Lisp_Object help = Qnil; 798 Lisp_Object help = Qnil;
816 int speccount = specpdl_depth (); 799 int speccount = specpdl_depth ();
817 Bytecount buf_index = command_builder->echo_buf_index; 800 Bytecount buf_fill_pointer = command_builder->echo_buf_fill_pointer;
818 Lisp_Object echo = ((buf_index <= 0) 801 Bytecount buf_end = command_builder->echo_buf_end;
819 ? Qnil 802 Lisp_Object echo = ((buf_fill_pointer <= 0) ? Qnil
820 : make_string (command_builder->echo_buf, 803 : Fcopy_sequence (command_builder->echo_buf));
821 buf_index)); 804
822 struct gcpro gcpro1, gcpro2; 805 struct gcpro gcpro1, gcpro2;
823 GCPRO2 (echo, help); 806 GCPRO2 (echo, help);
824 807
825 record_unwind_protect (Feval, 808 record_unwind_protect (Feval,
826 list2 (Qset_window_configuration, 809 list2 (Qset_window_configuration,
854 /* Discard next key if it is a space */ 837 /* Discard next key if it is a space */
855 reset_key_echo (command_builder, 1); 838 reset_key_echo (command_builder, 1);
856 Fnext_command_event (event, Qnil); 839 Fnext_command_event (event, Qnil);
857 } 840 }
858 841
859 command_builder->echo_buf_index = buf_index; 842 command_builder->echo_buf_fill_pointer = buf_fill_pointer;
860 if (buf_index > 0) 843 command_builder->echo_buf_end = buf_end;
861 memcpy (command_builder->echo_buf, 844
862 XSTRING_DATA (echo), buf_index + 1); /* terminating 0 */ 845 if (buf_fill_pointer > 0)
846 {
847 command_builder->echo_buf = echo;
848 }
863 UNGCPRO; 849 UNGCPRO;
864 } 850 }
865 851
866 852
867 /**********************************************************************/ 853 /**********************************************************************/
2180 CHECK_LIVE_EVENT (event); 2166 CHECK_LIVE_EVENT (event);
2181 2167
2182 if (!NILP (prompt)) 2168 if (!NILP (prompt))
2183 { 2169 {
2184 Bytecount len; 2170 Bytecount len;
2171 Lisp_Object args[] = { Qnil, prompt };
2185 CHECK_STRING (prompt); 2172 CHECK_STRING (prompt);
2186 2173
2187 len = XSTRING_LENGTH (prompt); 2174 len = XSTRING_LENGTH (prompt);
2188 if (command_builder->echo_buf_length < len) 2175
2189 len = command_builder->echo_buf_length - 1; 2176 detach_all_extents (command_builder->echo_buf);
2190 memcpy (command_builder->echo_buf, XSTRING_DATA (prompt), len); 2177 if (XSTRING_LENGTH (command_builder->echo_buf) < len)
2191 command_builder->echo_buf[len] = 0; 2178 {
2192 command_builder->echo_buf_index = len; 2179 command_builder->echo_buf
2193 echo_area_message (XFRAME (CONSOLE_SELECTED_FRAME (con)), 2180 = Fmake_string (make_fixnum (len + 300 * MAX_ICHAR_LEN),
2194 command_builder->echo_buf, 2181 make_char (0));
2195 Qnil, 0, 2182 }
2196 command_builder->echo_buf_index, 2183
2197 Qcommand); 2184 args[0] = command_builder->echo_buf;
2185 Freplace (countof (args), args);
2186 copy_string_extents (command_builder->echo_buf, prompt, 0, 0,
2187 XSTRING_LENGTH (prompt));
2188 command_builder->echo_buf_fill_pointer
2189 = command_builder->echo_buf_end = len;
2190
2191 echo_area_message (XFRAME (CONSOLE_SELECTED_FRAME (con)), NULL,
2192 command_builder->echo_buf, 0,
2193 command_builder->echo_buf_end, Qcommand);
2198 } 2194 }
2199 2195
2200 start_over_and_avoid_hosage: 2196 start_over_and_avoid_hosage:
2201 2197
2202 /* If there is something in unread-command-events, simply return it. 2198 /* If there is something in unread-command-events, simply return it.
2434 struct gcpro gcpro1; 2430 struct gcpro gcpro1;
2435 GCPRO1 (event); 2431 GCPRO1 (event);
2436 2432
2437 maybe_echo_keys (XCOMMAND_BUILDER 2433 maybe_echo_keys (XCOMMAND_BUILDER
2438 (XCONSOLE (Vselected_console)-> 2434 (XCONSOLE (Vselected_console)->
2439 command_builder), 0); /* #### This sucks bigtime */ 2435 command_builder),
2436 /* Only snooze displaying keystrokes if we don't have a
2437 prompt. (If we have a prompt, our callers want us to
2438 show it!) */
2439 !NILP (prompt));
2440 2440
2441 for (;;) 2441 for (;;)
2442 { 2442 {
2443 event = Fnext_event (event, prompt); 2443 event = Fnext_event (event, prompt);
2444 if (command_event_p (event)) 2444 if (command_event_p (event))
3386 if (!NILP (result)) 3386 if (!NILP (result))
3387 { 3387 {
3388 copy_command_builder (neub, builder); 3388 copy_command_builder (neub, builder);
3389 *did_munge = 1; 3389 *did_munge = 1;
3390 } 3390 }
3391 free_command_builder (neub); 3391 free_normal_lisp_object (wrap_command_builder (neub));
3392 UNGCPRO; 3392 UNGCPRO;
3393 if (!NILP (result)) 3393 if (!NILP (result))
3394 return result; 3394 return result;
3395 } 3395 }
3396 } 3396 }
3598 make_char(tolower(this_alternative))); 3598 make_char(tolower(this_alternative)));
3599 result = command_builder_find_leaf_no_jit_binding 3599 result = command_builder_find_leaf_no_jit_binding
3600 (newb, allow_misc_user_events_p, did_munge); 3600 (newb, allow_misc_user_events_p, did_munge);
3601 } 3601 }
3602 3602
3603 free_command_builder (newb); 3603 free_normal_lisp_object (wrap_command_builder (newb));
3604 UNGCPRO; 3604 UNGCPRO;
3605 3605
3606 if (!NILP (result)) 3606 if (!NILP (result))
3607 return result; 3607 return result;
3608 } 3608 }
4068 { 4068 {
4069 Lisp_Object prompt = Fkeymap_prompt (leaf, Qt); 4069 Lisp_Object prompt = Fkeymap_prompt (leaf, Qt);
4070 if (STRINGP (prompt)) 4070 if (STRINGP (prompt))
4071 { 4071 {
4072 /* Append keymap prompt to key echo buffer */ 4072 /* Append keymap prompt to key echo buffer */
4073 int buf_index = command_builder->echo_buf_index; 4073 int buf_fill_pointer = command_builder->echo_buf_fill_pointer;
4074 Bytecount len = XSTRING_LENGTH (prompt); 4074 Bytecount len = XSTRING_LENGTH (prompt);
4075 4075
4076 if (len + buf_index + 1 <= command_builder->echo_buf_length) 4076 if (len + buf_fill_pointer + 1
4077 <= XSTRING_LENGTH (command_builder->echo_buf))
4077 { 4078 {
4078 Ibyte *echo = command_builder->echo_buf + buf_index; 4079 memcpy (XSTRING_DATA (command_builder->echo_buf)
4079 memcpy (echo, XSTRING_DATA (prompt), len); 4080 + buf_fill_pointer,
4080 echo[len] = 0; 4081 XSTRING_DATA (prompt),
4082 len);
4083 copy_string_extents (command_builder->echo_buf, prompt,
4084 buf_fill_pointer, 0, len);
4085
4086 init_string_ascii_begin (command_builder->echo_buf);
4087 bump_string_modiff (command_builder->echo_buf);
4088 sledgehammer_check_ascii_begin (command_builder->echo_buf);
4089
4090 /* Show the keymap prompt, but don't adjust the fill
4091 pointer to reflect it. */
4092 command_builder->echo_buf_end
4093 = command_builder->echo_buf_fill_pointer + len;
4081 } 4094 }
4082 maybe_echo_keys (command_builder, 1); 4095 maybe_echo_keys (command_builder, 1);
4083 } 4096 }
4084 else 4097 else
4085 maybe_echo_keys (command_builder, 0); 4098 maybe_echo_keys (command_builder, 0);
4098 #endif 4111 #endif
4099 } 4112 }
4100 else if (!NILP (leaf)) 4113 else if (!NILP (leaf))
4101 { 4114 {
4102 if (EQ (Qcommand, echo_area_status (f)) 4115 if (EQ (Qcommand, echo_area_status (f))
4103 && command_builder->echo_buf_index > 0) 4116 && command_builder->echo_buf_fill_pointer > 0)
4104 { 4117 {
4105 /* If we had been echoing keys, echo the last one (without 4118 /* If we had been echoing keys, echo the last one (without
4106 the trailing dash) and redisplay before executing the 4119 the trailing dash) and redisplay before executing the
4107 command. */ 4120 command. */
4108 command_builder->echo_buf[command_builder->echo_buf_index] = 0; 4121 command_builder->echo_buf_end =
4122 command_builder->echo_buf_fill_pointer;
4109 maybe_echo_keys (command_builder, 1); 4123 maybe_echo_keys (command_builder, 1);
4110 Fsit_for (Qzero, Qt); 4124 Fsit_for (Qzero, Qt);
4111 } 4125 }
4112 } 4126 }
4113 RETURN_UNGCPRO (leaf); 4127 RETURN_UNGCPRO (leaf);
4810 } 4824 }
4811 else if (string_char_length (XSYMBOL (keysym)->name) == 1) 4825 else if (string_char_length (XSYMBOL (keysym)->name) == 1)
4812 /* one-char key events are printed with just the key name */ 4826 /* one-char key events are printed with just the key name */
4813 Fprinc (keysym, Vdribble_file); 4827 Fprinc (keysym, Vdribble_file);
4814 else if (EQ (keysym, Qreturn)) 4828 else if (EQ (keysym, Qreturn))
4815 Lstream_putc (XLSTREAM (Vdribble_file), '\n'); 4829 (void) Lstream_putc (XLSTREAM (Vdribble_file), '\n');
4816 else if (EQ (keysym, Qspace)) 4830 else if (EQ (keysym, Qspace))
4817 Lstream_putc (XLSTREAM (Vdribble_file), ' '); 4831 (void) Lstream_putc (XLSTREAM (Vdribble_file), ' ');
4818 else 4832 else
4819 Fprinc (event, Vdribble_file); 4833 Fprinc (event, Vdribble_file);
4820 } 4834 }
4821 else 4835 else
4822 Fprinc (event, Vdribble_file); 4836 Fprinc (event, Vdribble_file);
4846 fd = qxe_open (XSTRING_DATA (filename), 4860 fd = qxe_open (XSTRING_DATA (filename),
4847 O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY, 4861 O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY,
4848 CREAT_MODE); 4862 CREAT_MODE);
4849 if (fd < 0) 4863 if (fd < 0)
4850 report_file_error ("Unable to create dribble file", filename); 4864 report_file_error ("Unable to create dribble file", filename);
4851 Vdribble_file = make_filedesc_output_stream (fd, 0, 0, LSTR_CLOSING); 4865 Vdribble_file = make_filedesc_output_stream (fd, 0, 0, LSTR_CLOSING,
4866 NULL);
4852 #ifdef MULE 4867 #ifdef MULE
4853 Vdribble_file = 4868 Vdribble_file =
4854 make_coding_output_stream 4869 make_coding_output_stream
4855 (XLSTREAM (Vdribble_file), 4870 (XLSTREAM (Vdribble_file),
4856 Qescape_quoted, CODING_ENCODE, 0); 4871 Qescape_quoted, CODING_ENCODE, 0);