aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKarl Heuer1995-01-28 03:05:45 +0000
committerKarl Heuer1995-01-28 03:05:45 +0000
commitba72822c1d15f496b5cf3e250398fb9fc1ebdec6 (patch)
tree54b3d7e4e41d1ea3dda9b86cdbf7f98242279041 /src
parent329d527986b6c6ed0117fa09fcc39d176ebb03ab (diff)
downloademacs-ba72822c1d15f496b5cf3e250398fb9fc1ebdec6.tar.gz
emacs-ba72822c1d15f496b5cf3e250398fb9fc1ebdec6.zip
* keyboard.c (kbd_buffer_frame_or_window): Delete; now in perdisplay.
(immediate_echo, echobuf, echoptr, echo_after_prompt): Likewise. (echo_prompt, echo_char, echo_dash): use perdisplay and ECHOBUFSIZE. (echo, cancel_echoing, echo_length, echo_truncate): Likewise. (read_char, kbd_buffer_store_event, kbd_buffer_get_event): Likewise. (Fdiscard_input, stuff_buffered_input): Likewise. (init_keyboard, syms_of_keyboard): Likewise.
Diffstat (limited to 'src')
-rw-r--r--src/keyboard.c160
1 files changed, 66 insertions, 94 deletions
diff --git a/src/keyboard.c b/src/keyboard.c
index 4b55cb03303..7039437a76f 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -95,7 +95,7 @@ struct backtrace
95 char evalargs; 95 char evalargs;
96 }; 96 };
97 97
98PERD the_only_perd; 98PERDISPLAY the_only_perdisplay;
99 99
100/* Non-nil disable property on a command means 100/* Non-nil disable property on a command means
101 do not execute it; call disabled-command-hook's value instead. */ 101 do not execute it; call disabled-command-hook's value instead. */
@@ -327,34 +327,6 @@ int meta_key;
327 327
328extern char *pending_malloc_warning; 328extern char *pending_malloc_warning;
329 329
330/* Vector to GCPRO the frames and windows mentioned in kbd_buffer.
331
332 The interrupt-level event handlers will never enqueue an event on a
333 frame which is not in Vframe_list, and once an event is dequeued,
334 internal_last_event_frame or the event itself points to the frame.
335 So that's all fine.
336
337 But while the event is sitting in the queue, it's completely
338 unprotected. Suppose the user types one command which will run for
339 a while and then delete a frame, and then types another event at
340 the frame that will be deleted, before the command gets around to
341 it. Suppose there are no references to this frame elsewhere in
342 Emacs, and a GC occurs before the second event is dequeued. Now we
343 have an event referring to a freed frame, which will crash Emacs
344 when it is dequeued.
345
346 Similar things happen when an event on a scroll bar is enqueued; the
347 window may be deleted while the event is in the queue.
348
349 So, we use this vector to protect the frame_or_window field in the
350 event queue. That way, they'll be dequeued as dead frames or
351 windows, but still valid lisp objects.
352
353 If perd->kbd_buffer[i].kind != no_event, then
354 (XVECTOR (kbd_buffer_frame_or_window)->contents[i]
355 == perd->kbd_buffer[i].frame_or_window. */
356static Lisp_Object kbd_buffer_frame_or_window;
357
358#ifdef HAVE_MOUSE 330#ifdef HAVE_MOUSE
359/* If this flag is a frame, we check mouse_moved to see when the 331/* If this flag is a frame, we check mouse_moved to see when the
360 mouse moves, and motion events will appear in the input stream. 332 mouse moves, and motion events will appear in the input stream.
@@ -470,20 +442,6 @@ static Lisp_Object make_lispy_switch_frame ();
470/* > 0 if we are to echo keystrokes. */ 442/* > 0 if we are to echo keystrokes. */
471static int echo_keystrokes; 443static int echo_keystrokes;
472 444
473/* Nonzero means echo each character as typed. */
474static int immediate_echo;
475
476/* The text we're echoing in the modeline - partial key sequences,
477 usually. '\0'-terminated. This really shouldn't have a fixed size. */
478static char echobuf[300];
479
480/* Where to append more text to echobuf if we want to. */
481static char *echoptr;
482
483/* If we have echoed a prompt string specified by the user,
484 this is its length. Otherwise this is -1. */
485static int echo_after_prompt;
486
487/* Nonzero means don't try to suspend even if the operating system seems 445/* Nonzero means don't try to suspend even if the operating system seems
488 to support it. */ 446 to support it. */
489static int cannot_suspend; 447static int cannot_suspend;
@@ -498,15 +456,16 @@ static int cannot_suspend;
498echo_prompt (str) 456echo_prompt (str)
499 char *str; 457 char *str;
500{ 458{
459 PERDISPLAY *perd = get_perdisplay (selected_frame);
501 int len = strlen (str); 460 int len = strlen (str);
502 461
503 if (len > sizeof echobuf - 4) 462 if (len > ECHOBUFSIZE - 4)
504 len = sizeof echobuf - 4; 463 len = ECHOBUFSIZE - 4;
505 bcopy (str, echobuf, len); 464 bcopy (str, perd->echobuf, len);
506 echoptr = echobuf + len; 465 perd->echoptr = perd->echobuf + len;
507 *echoptr = '\0'; 466 *perd->echoptr = '\0';
508 467
509 echo_after_prompt = len; 468 perd->echo_after_prompt = len;
510 469
511 echo (); 470 echo ();
512} 471}
@@ -519,12 +478,13 @@ echo_char (c)
519 Lisp_Object c; 478 Lisp_Object c;
520{ 479{
521 extern char *push_key_description (); 480 extern char *push_key_description ();
481 PERDISPLAY *perd = get_perdisplay (selected_frame);
522 482
523 if (immediate_echo) 483 if (perd->immediate_echo)
524 { 484 {
525 char *ptr = echoptr; 485 char *ptr = perd->echoptr;
526 486
527 if (ptr != echobuf) 487 if (ptr != perd->echobuf)
528 *ptr++ = ' '; 488 *ptr++ = ' ';
529 489
530 /* If someone has passed us a composite event, use its head symbol. */ 490 /* If someone has passed us a composite event, use its head symbol. */
@@ -532,7 +492,7 @@ echo_char (c)
532 492
533 if (INTEGERP (c)) 493 if (INTEGERP (c))
534 { 494 {
535 if (ptr - echobuf > sizeof echobuf - 6) 495 if (ptr - perd->echobuf > ECHOBUFSIZE - 6)
536 return; 496 return;
537 497
538 ptr = push_key_description (XINT (c), ptr); 498 ptr = push_key_description (XINT (c), ptr);
@@ -540,20 +500,20 @@ echo_char (c)
540 else if (SYMBOLP (c)) 500 else if (SYMBOLP (c))
541 { 501 {
542 struct Lisp_String *name = XSYMBOL (c)->name; 502 struct Lisp_String *name = XSYMBOL (c)->name;
543 if (((ptr - echobuf) + name->size + 4) > sizeof echobuf) 503 if (((ptr - perd->echobuf) + name->size + 4) > ECHOBUFSIZE)
544 return; 504 return;
545 bcopy (name->data, ptr, name->size); 505 bcopy (name->data, ptr, name->size);
546 ptr += name->size; 506 ptr += name->size;
547 } 507 }
548 508
549 if (echoptr == echobuf && EQ (c, Vhelp_char)) 509 if (perd->echoptr == perd->echobuf && EQ (c, Vhelp_char))
550 { 510 {
551 strcpy (ptr, " (Type ? for further options)"); 511 strcpy (ptr, " (Type ? for further options)");
552 ptr += strlen (ptr); 512 ptr += strlen (ptr);
553 } 513 }
554 514
555 *ptr = 0; 515 *ptr = 0;
556 echoptr = ptr; 516 perd->echoptr = ptr;
557 517
558 echo (); 518 echo ();
559 } 519 }
@@ -564,19 +524,20 @@ echo_char (c)
564 524
565echo_dash () 525echo_dash ()
566{ 526{
567 if (!immediate_echo && echoptr == echobuf) 527 PERDISPLAY *perd = get_perdisplay (selected_frame);
528 if (!perd->immediate_echo && perd->echoptr == perd->echobuf)
568 return; 529 return;
569 /* Do nothing if we just printed a prompt. */ 530 /* Do nothing if we just printed a prompt. */
570 if (echo_after_prompt == echoptr - echobuf) 531 if (perd->echo_after_prompt == perd->echoptr - perd->echobuf)
571 return; 532 return;
572 /* Do nothing if not echoing at all. */ 533 /* Do nothing if not echoing at all. */
573 if (echoptr == 0) 534 if (perd->echoptr == 0)
574 return; 535 return;
575 536
576 /* Put a dash at the end of the buffer temporarily, 537 /* Put a dash at the end of the buffer temporarily,
577 but make it go away when the next character is added. */ 538 but make it go away when the next character is added. */
578 echoptr[0] = '-'; 539 perd->echoptr[0] = '-';
579 echoptr[1] = 0; 540 perd->echoptr[1] = 0;
580 541
581 echo (); 542 echo ();
582} 543}
@@ -586,10 +547,11 @@ echo_dash ()
586 547
587echo () 548echo ()
588{ 549{
589 if (!immediate_echo) 550 PERDISPLAY *perd = get_perdisplay (selected_frame);
551 if (!perd->immediate_echo)
590 { 552 {
591 int i; 553 int i;
592 immediate_echo = 1; 554 perd->immediate_echo = 1;
593 555
594 for (i = 0; i < this_command_key_count; i++) 556 for (i = 0; i < this_command_key_count; i++)
595 { 557 {
@@ -603,7 +565,7 @@ echo ()
603 } 565 }
604 566
605 echoing = 1; 567 echoing = 1;
606 message2_nolog (echobuf, strlen (echobuf)); 568 message2_nolog (perd->echobuf, strlen (perd->echobuf));
607 echoing = 0; 569 echoing = 0;
608 570
609 if (waiting_for_input && !NILP (Vquit_flag)) 571 if (waiting_for_input && !NILP (Vquit_flag))
@@ -614,9 +576,10 @@ echo ()
614 576
615cancel_echoing () 577cancel_echoing ()
616{ 578{
617 immediate_echo = 0; 579 PERDISPLAY *perd = get_perdisplay (selected_frame);
618 echoptr = echobuf; 580 perd->immediate_echo = 0;
619 echo_after_prompt = -1; 581 perd->echoptr = perd->echobuf;
582 perd->echo_after_prompt = -1;
620} 583}
621 584
622/* Return the length of the current echo string. */ 585/* Return the length of the current echo string. */
@@ -624,7 +587,8 @@ cancel_echoing ()
624static int 587static int
625echo_length () 588echo_length ()
626{ 589{
627 return echoptr - echobuf; 590 PERDISPLAY *perd = get_perdisplay (selected_frame);
591 return perd->echoptr - perd->echobuf;
628} 592}
629 593
630/* Truncate the current echo message to its first LEN chars. 594/* Truncate the current echo message to its first LEN chars.
@@ -635,8 +599,9 @@ static void
635echo_truncate (len) 599echo_truncate (len)
636 int len; 600 int len;
637{ 601{
638 echobuf[len] = '\0'; 602 PERDISPLAY *perd = get_perdisplay (selected_frame);
639 echoptr = echobuf + len; 603 perd->echobuf[len] = '\0';
604 perd->echoptr = perd->echobuf + len;
640 truncate_echo_area (len); 605 truncate_echo_area (len);
641} 606}
642 607
@@ -1473,6 +1438,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
1473 int count; 1438 int count;
1474 jmp_buf save_jump; 1439 jmp_buf save_jump;
1475 int key_already_recorded = 0; 1440 int key_already_recorded = 0;
1441 PERDISPLAY *perd = get_perdisplay (selected_frame);
1476 Lisp_Object also_record; 1442 Lisp_Object also_record;
1477 also_record = Qnil; 1443 also_record = Qnil;
1478 1444
@@ -1574,7 +1540,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
1574 } 1540 }
1575 1541
1576 /* Message turns off echoing unless more keystrokes turn it on again. */ 1542 /* Message turns off echoing unless more keystrokes turn it on again. */
1577 if (echo_area_glyphs && *echo_area_glyphs && echo_area_glyphs != echobuf) 1543 if (echo_area_glyphs && *echo_area_glyphs && echo_area_glyphs != perd->echobuf)
1578 cancel_echoing (); 1544 cancel_echoing ();
1579 else 1545 else
1580 /* If already echoing, continue. */ 1546 /* If already echoing, continue. */
@@ -1603,7 +1569,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
1603 1569
1604 /* If in middle of key sequence and minibuffer not active, 1570 /* If in middle of key sequence and minibuffer not active,
1605 start echoing if enough time elapses. */ 1571 start echoing if enough time elapses. */
1606 if (minibuf_level == 0 && !immediate_echo && this_command_key_count > 0 1572 if (minibuf_level == 0 && !perd->immediate_echo && this_command_key_count > 0
1607 && ! noninteractive 1573 && ! noninteractive
1608 && echo_keystrokes > 0 1574 && echo_keystrokes > 0
1609 && (echo_area_glyphs == 0 || *echo_area_glyphs == 0)) 1575 && (echo_area_glyphs == 0 || *echo_area_glyphs == 0))
@@ -1972,12 +1938,12 @@ Normally, mouse motion is ignored.")
1972 mouse_moved indicates when the mouse has moved again, and 1938 mouse_moved indicates when the mouse has moved again, and
1973 *mouse_position_hook provides the mouse position. */ 1939 *mouse_position_hook provides the mouse position. */
1974 1940
1975static PERD * 1941static PERDISPLAY *
1976find_active_event_queue () 1942find_active_event_queue ()
1977{ 1943{
1978 PERD *perd; 1944 PERDISPLAY *perd;
1979 perd = &the_only_perd; 1945 perd = &the_only_perdisplay;
1980 /* FOR_ALL_PERDS (perd) */ 1946 /* FOR_ALL_PERDISPLAYS (perd) */
1981 { 1947 {
1982 if (perd->kbd_fetch_ptr != perd->kbd_store_ptr) 1948 if (perd->kbd_fetch_ptr != perd->kbd_store_ptr)
1983 return perd; 1949 return perd;
@@ -2002,7 +1968,7 @@ void
2002kbd_buffer_store_event (event) 1968kbd_buffer_store_event (event)
2003 register struct input_event *event; 1969 register struct input_event *event;
2004{ 1970{
2005 PERD *perd = get_perd (XFRAME (event->frame_or_window)); 1971 PERDISPLAY *perd = get_perdisplay (XFRAME (event->frame_or_window));
2006 1972
2007 if (event->kind == no_event) 1973 if (event->kind == no_event)
2008 abort (); 1974 abort ();
@@ -2079,8 +2045,8 @@ kbd_buffer_store_event (event)
2079 sp->y = event->y; 2045 sp->y = event->y;
2080 sp->timestamp = event->timestamp; 2046 sp->timestamp = event->timestamp;
2081 } 2047 }
2082 (XVECTOR (kbd_buffer_frame_or_window)->contents[perd->kbd_store_ptr 2048 (XVECTOR (perd->kbd_buffer_frame_or_window)->contents[perd->kbd_store_ptr
2083 - perd->kbd_buffer] 2049 - perd->kbd_buffer]
2084 = event->frame_or_window); 2050 = event->frame_or_window);
2085 2051
2086 perd->kbd_store_ptr++; 2052 perd->kbd_store_ptr++;
@@ -2096,7 +2062,7 @@ kbd_buffer_store_event (event)
2096static Lisp_Object 2062static Lisp_Object
2097kbd_buffer_get_event () 2063kbd_buffer_get_event ()
2098{ 2064{
2099 PERD *perd; 2065 PERDISPLAY *perd;
2100 register int c; 2066 register int c;
2101 Lisp_Object obj; 2067 Lisp_Object obj;
2102 2068
@@ -2257,8 +2223,7 @@ kbd_buffer_get_event ()
2257 2223
2258 /* Wipe out this event, to catch bugs. */ 2224 /* Wipe out this event, to catch bugs. */
2259 event->kind = no_event; 2225 event->kind = no_event;
2260 (XVECTOR (kbd_buffer_frame_or_window)->contents[event - perd->kbd_buffer] 2226 XVECTOR (perd->kbd_buffer_frame_or_window)->contents[event - perd->kbd_buffer] = Qnil;
2261 = Qnil);
2262 2227
2263 perd->kbd_fetch_ptr = event + 1; 2228 perd->kbd_fetch_ptr = event + 1;
2264 } 2229 }
@@ -2327,7 +2292,7 @@ kbd_buffer_get_event ()
2327void 2292void
2328swallow_events () 2293swallow_events ()
2329{ 2294{
2330 PERD *perd; 2295 PERDISPLAY *perd;
2331 while ((perd = find_active_event_queue ()) != NULL) 2296 while ((perd = find_active_event_queue ()) != NULL)
2332 { 2297 {
2333 struct input_event *event; 2298 struct input_event *event;
@@ -5668,7 +5633,7 @@ DEFUN ("discard-input", Fdiscard_input, Sdiscard_input, 0, 0, 0,
5668Also cancel any kbd macro being defined.") 5633Also cancel any kbd macro being defined.")
5669 () 5634 ()
5670{ 5635{
5671 PERD *perd = &the_only_perd; 5636 PERDISPLAY *perd = &the_only_perdisplay;
5672 defining_kbd_macro = 0; 5637 defining_kbd_macro = 0;
5673 update_mode_lines++; 5638 update_mode_lines++;
5674 5639
@@ -5681,7 +5646,7 @@ Also cancel any kbd macro being defined.")
5681 volatile qualifier of kbd_store_ptr. Is there anything wrong 5646 volatile qualifier of kbd_store_ptr. Is there anything wrong
5682 with that? */ 5647 with that? */
5683 perd->kbd_fetch_ptr = (struct input_event *) perd->kbd_store_ptr; 5648 perd->kbd_fetch_ptr = (struct input_event *) perd->kbd_store_ptr;
5684 Ffillarray (kbd_buffer_frame_or_window, Qnil); 5649 Ffillarray (perd->kbd_buffer_frame_or_window, Qnil);
5685 input_pending = 0; 5650 input_pending = 0;
5686 5651
5687 return Qnil; 5652 return Qnil;
@@ -5754,7 +5719,7 @@ stuff_buffered_input (stuffstring)
5754#ifdef BSD 5719#ifdef BSD
5755#ifndef BSD4_1 5720#ifndef BSD4_1
5756 register unsigned char *p; 5721 register unsigned char *p;
5757 PERD *perd = &the_only_perd; /* We really want the primary display's perd */ 5722 PERDISPLAY *perd = &the_only_perdisplay; /* We really want the primary display's perd */
5758 5723
5759 if (STRINGP (stuffstring)) 5724 if (STRINGP (stuffstring))
5760 { 5725 {
@@ -5774,8 +5739,8 @@ stuff_buffered_input (stuffstring)
5774 if (perd->kbd_fetch_ptr->kind == ascii_keystroke) 5739 if (perd->kbd_fetch_ptr->kind == ascii_keystroke)
5775 stuff_char (perd->kbd_fetch_ptr->code); 5740 stuff_char (perd->kbd_fetch_ptr->code);
5776 perd->kbd_fetch_ptr->kind = no_event; 5741 perd->kbd_fetch_ptr->kind = no_event;
5777 (XVECTOR (kbd_buffer_frame_or_window)->contents[perd->kbd_fetch_ptr 5742 (XVECTOR (perd->kbd_buffer_frame_or_window)->contents[perd->kbd_fetch_ptr
5778 - perd->kbd_buffer] 5743 - perd->kbd_buffer]
5779 = Qnil); 5744 = Qnil);
5780 perd->kbd_fetch_ptr++; 5745 perd->kbd_fetch_ptr++;
5781 } 5746 }
@@ -6047,11 +6012,11 @@ init_keyboard ()
6047 unread_command_char = -1; 6012 unread_command_char = -1;
6048 total_keys = 0; 6013 total_keys = 0;
6049 recent_keys_index = 0; 6014 recent_keys_index = 0;
6050 the_only_perd.kbd_buffer 6015 the_only_perdisplay.kbd_buffer
6051 = (struct input_event *)xmalloc (KBD_BUFFER_SIZE 6016 = (struct input_event *)xmalloc (KBD_BUFFER_SIZE
6052 * sizeof (struct input_event)); 6017 * sizeof (struct input_event));
6053 the_only_perd.kbd_fetch_ptr = the_only_perd.kbd_buffer; 6018 the_only_perdisplay.kbd_fetch_ptr = the_only_perdisplay.kbd_buffer;
6054 the_only_perd.kbd_store_ptr = the_only_perd.kbd_buffer; 6019 the_only_perdisplay.kbd_store_ptr = the_only_perdisplay.kbd_buffer;
6055#ifdef HAVE_MOUSE 6020#ifdef HAVE_MOUSE
6056 do_mouse_tracking = Qnil; 6021 do_mouse_tracking = Qnil;
6057#endif 6022#endif
@@ -6071,7 +6036,14 @@ init_keyboard ()
6071 If we're running an undumped Emacs, it hasn't been initialized by 6036 If we're running an undumped Emacs, it hasn't been initialized by
6072 syms_of_keyboard yet. */ 6037 syms_of_keyboard yet. */
6073 if (initialized) 6038 if (initialized)
6074 Ffillarray (kbd_buffer_frame_or_window, Qnil); 6039 {
6040 PERDISPLAY *perd;
6041 perd = &the_only_perdisplay;
6042 /* FOR_ALL_PERDISPLAYS (perd) */
6043 {
6044 Ffillarray (perd->kbd_buffer_frame_or_window, Qnil);
6045 }
6046 }
6075 6047
6076 if (!noninteractive && !read_socket_hook && NILP (Vwindow_system)) 6048 if (!noninteractive && !read_socket_hook && NILP (Vwindow_system))
6077 { 6049 {
@@ -6242,9 +6214,9 @@ syms_of_keyboard ()
6242 Fset (Qextended_command_history, Qnil); 6214 Fset (Qextended_command_history, Qnil);
6243 staticpro (&Qextended_command_history); 6215 staticpro (&Qextended_command_history);
6244 6216
6245 kbd_buffer_frame_or_window 6217 the_only_perdisplay.kbd_buffer_frame_or_window
6246 = Fmake_vector (make_number (KBD_BUFFER_SIZE), Qnil); 6218 = Fmake_vector (make_number (KBD_BUFFER_SIZE), Qnil);
6247 staticpro (&kbd_buffer_frame_or_window); 6219 staticpro (&the_only_perdisplay.kbd_buffer_frame_or_window);
6248 6220
6249 accent_key_syms = Qnil; 6221 accent_key_syms = Qnil;
6250 staticpro (&accent_key_syms); 6222 staticpro (&accent_key_syms);