comparison src/keyboard.c @ 83067:b44978264e1d

Merged in changes from CVS HEAD Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-118 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-119 src/keyboard.c (adjust_point_for_property): #ifdef-out dodgy xassert * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-120 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-107
author Karoly Lorentey <lorentey@elte.hu>
date Sat, 28 Feb 2004 04:52:40 +0000
parents 887bb2eb4a89 6c578d781772
children 40fd42596e17
comparison
equal deleted inserted replaced
83066:887bb2eb4a89 83067:b44978264e1d
1914 was already in the range: we don't get to choose 1914 was already in the range: we don't get to choose
1915 which end of the range we have to go to. */ 1915 which end of the range we have to go to. */
1916 : (PT < last_pt ? beg : end)); 1916 : (PT < last_pt ? beg : end));
1917 check_composition = check_display = 1; 1917 check_composition = check_display = 1;
1918 } 1918 }
1919 #if 0 /* This assertion isn't correct, because SET_PT may end up setting
1920 the point to something other than its argument, due to
1921 point-motion hooks, intangibility, etc. */
1919 xassert (PT == beg || PT == end); 1922 xassert (PT == beg || PT == end);
1923 #endif
1924
1920 /* Pretend the area doesn't exist if the buffer is not 1925 /* Pretend the area doesn't exist if the buffer is not
1921 modified. */ 1926 modified. */
1922 if (!modified && !ellipsis && beg < end) 1927 if (!modified && !ellipsis && beg < end)
1923 { 1928 {
1924 if (last_pt == beg && PT == end && end < ZV) 1929 if (last_pt == beg && PT == end && end < ZV)
3514 3519
3515 void 3520 void
3516 kbd_buffer_store_event (event) 3521 kbd_buffer_store_event (event)
3517 register struct input_event *event; 3522 register struct input_event *event;
3518 { 3523 {
3524 kbd_buffer_store_event_hold (event, 0);
3525 }
3526
3527 /* Store EVENT obtained at interrupt level into kbd_buffer, fifo.
3528
3529 If HOLD_QUIT is 0, just stuff EVENT into the fifo.
3530 Else, if HOLD_QUIT.kind != NO_EVENT, discard EVENT.
3531 Else, if EVENT is a quit event, store the quit event
3532 in HOLD_QUIT, and return (thus ignoring further events).
3533
3534 This is used in read_avail_input to postpone the processing
3535 of the quit event until all subsequent input events have been
3536 parsed (and discarded).
3537 */
3538
3539 void
3540 kbd_buffer_store_event_hold (event, hold_quit)
3541 register struct input_event *event;
3542 struct input_event *hold_quit;
3543 {
3519 if (event->kind == NO_EVENT) 3544 if (event->kind == NO_EVENT)
3520 abort (); 3545 abort ();
3546
3547 if (hold_quit && hold_quit->kind != NO_EVENT)
3548 return;
3521 3549
3522 if (event->kind == ASCII_KEYSTROKE_EVENT) 3550 if (event->kind == ASCII_KEYSTROKE_EVENT)
3523 { 3551 {
3524 register int c = event->code & 0377; 3552 register int c = event->code & 0377;
3525 3553
3558 } 3586 }
3559 return; 3587 return;
3560 } 3588 }
3561 #endif 3589 #endif
3562 3590
3591 if (hold_quit)
3592 {
3593 bcopy (event, (char *) hold_quit, sizeof (*event));
3594 return;
3595 }
3596
3563 /* If this results in a quit_char being returned to Emacs as 3597 /* If this results in a quit_char being returned to Emacs as
3564 input, set Vlast_event_frame properly. If this doesn't 3598 input, set Vlast_event_frame properly. If this doesn't
3565 get returned to Emacs as an event, the next event read 3599 get returned to Emacs as an event, the next event read
3566 will set Vlast_event_frame again, so this is safe to do. */ 3600 will set Vlast_event_frame again, so this is safe to do. */
3567 { 3601 {
3587 } 3621 }
3588 /* Don't insert two BUFFER_SWITCH_EVENT's in a row. 3622 /* Don't insert two BUFFER_SWITCH_EVENT's in a row.
3589 Just ignore the second one. */ 3623 Just ignore the second one. */
3590 else if (event->kind == BUFFER_SWITCH_EVENT 3624 else if (event->kind == BUFFER_SWITCH_EVENT
3591 && kbd_fetch_ptr != kbd_store_ptr 3625 && kbd_fetch_ptr != kbd_store_ptr
3592 && kbd_store_ptr->kind == BUFFER_SWITCH_EVENT) 3626 && ((kbd_store_ptr == kbd_buffer
3627 ? kbd_buffer + KBD_BUFFER_SIZE - 1
3628 : kbd_store_ptr - 1)->kind) == BUFFER_SWITCH_EVENT)
3593 return; 3629 return;
3594 3630
3595 if (kbd_store_ptr - kbd_buffer == KBD_BUFFER_SIZE) 3631 if (kbd_store_ptr - kbd_buffer == KBD_BUFFER_SIZE)
3596 kbd_store_ptr = kbd_buffer; 3632 kbd_store_ptr = kbd_buffer;
3597 3633
3646 overlay, or nil if neither from a string nor from a buffer. POS is 3682 overlay, or nil if neither from a string nor from a buffer. POS is
3647 the position within OBJECT where the help was found. 3683 the position within OBJECT where the help was found.
3648 3684
3649 Value is the number of input_events generated. */ 3685 Value is the number of input_events generated. */
3650 3686
3651 int 3687 void
3652 gen_help_event (bufp, size, help, frame, window, object, pos) 3688 gen_help_event (help, frame, window, object, pos)
3653 struct input_event *bufp;
3654 int size;
3655 Lisp_Object help, frame, object, window; 3689 Lisp_Object help, frame, object, window;
3656 int pos; 3690 int pos;
3657 { 3691 {
3658 if (size >= 1) 3692 struct input_event event;
3659 { 3693
3660 bufp->kind = HELP_EVENT; 3694 EVENT_INIT (event);
3661 bufp->frame_or_window = frame; 3695
3662 bufp->arg = object; 3696 event.kind = HELP_EVENT;
3663 bufp->x = WINDOWP (window) ? window : frame; 3697 event.frame_or_window = frame;
3664 bufp->y = help; 3698 event.arg = object;
3665 bufp->code = pos; 3699 event.x = WINDOWP (window) ? window : frame;
3666 return 1; 3700 event.y = help;
3667 } 3701 event.code = pos;
3668 return 0; 3702 kbd_buffer_store_event (&event);
3669 } 3703 }
3670 3704
3671 3705
3672 /* Store HELP_EVENTs for HELP on FRAME in the input queue. */ 3706 /* Store HELP_EVENTs for HELP on FRAME in the input queue. */
3673 3707
6568 Except on VMS, all input is read by this function. 6602 Except on VMS, all input is read by this function.
6569 If interrupt_input is nonzero, this function MUST be called 6603 If interrupt_input is nonzero, this function MUST be called
6570 only when SIGIO is blocked. 6604 only when SIGIO is blocked.
6571 6605
6572 Returns the number of keyboard chars read, or -1 meaning 6606 Returns the number of keyboard chars read, or -1 meaning
6573 this is a bad time to try to read input. 6607 this is a bad time to try to read input. */
6574
6575 Typically, there are just a few available input events to be read
6576 here, so we really don't need to allocate and initialize a big
6577 buffer of input_events as we used to do. Instead, we just allocate
6578 a small buffer of input events -- and then poll for more input if we
6579 read a full buffer of input events. */
6580
6581 #define NREAD_INPUT_EVENTS 512
6582 6608
6583 static int 6609 static int
6584 read_avail_input (expected) 6610 read_avail_input (expected)
6585 int expected; 6611 int expected;
6586 { 6612 {
6598 if (d->read_socket_hook) 6624 if (d->read_socket_hook)
6599 { 6625 {
6600 int discard = 0; 6626 int discard = 0;
6601 int nr; 6627 int nr;
6602 6628
6603 do { 6629 struct input_event hold_quit;
6604 struct input_event buf[NREAD_INPUT_EVENTS]; 6630
6605 6631 EVENT_INIT (hold_quit);
6606 for (i = 0; i < NREAD_INPUT_EVENTS; i++) 6632 hold_quit.kind = NO_EVENT;
6607 EVENT_INIT (buf[i]); 6633
6608 6634 /* No need for FIONREAD or fcntl; just say don't wait. */
6609 /* No need for FIONREAD or fcntl; just say don't wait. */ 6635 while (nr = (*d->read_socket_hook) (d, expected, &hold_quit), nr > 0)
6610 nr = (*d->read_socket_hook) (d, buf, NREAD_INPUT_EVENTS, expected); 6636 {
6611 6637 nread += nr;
6612 if (nr > 0) 6638 expected = 0;
6613 { 6639 }
6614 /* We've got input. */ 6640
6615 nread += nr; 6641 if (nr == -1) /* Not OK to read input now. */
6616 expected = 0; 6642 {
6617 6643 err = 1;
6618 /* Scan the chars for C-g and store them in kbd_buffer. */ 6644 }
6619 for (i = 0; !discard && i < nr; i++) 6645 else if (nr == -2) /* Non-transient error. */
6620 { 6646 {
6621 kbd_buffer_store_event (&buf[i]); 6647 /* The display device terminated; it should be closed. */
6622 /* Don't look at input that follows a C-g too closely. 6648
6623 This reduces lossage due to autorepeat on C-g. */ 6649 /* Kill Emacs if this was our last display. */
6624 if (buf[i].kind == ASCII_KEYSTROKE_EVENT 6650 if (! display_list->next_display)
6625 && buf[i].code == quit_char) 6651 /* Formerly simply reported no input, but that
6626 discard = 1; 6652 sometimes led to a failure of Emacs to terminate.
6627 } 6653 SIGHUP seems appropriate if we can't reach the
6628 } 6654 terminal. */
6629 else if (nr == -1) /* Not OK to read input now. */ 6655 /* ??? Is it really right to send the signal just to
6630 { 6656 this process rather than to the whole process
6631 err = 1; 6657 group? Perhaps on systems with FIONREAD Emacs is
6632 } 6658 alone in its group. */
6633 else if (nr == -2) /* Non-transient error. */ 6659 kill (getpid (), SIGHUP);
6634 { 6660
6635 /* The display device terminated; it should be closed. */ 6661 /* XXX Is calling delete_display safe here? It calls Fdelete_frame. */
6636 6662 if (d->delete_display_hook)
6637 /* Kill Emacs if this was our last display. */ 6663 (*d->delete_display_hook) (d);
6638 if (! display_list->next_display) 6664 else
6639 /* Formerly simply reported no input, but that 6665 delete_display (d);
6640 sometimes led to a failure of Emacs to terminate. 6666 }
6641 SIGHUP seems appropriate if we can't reach the 6667
6642 terminal. */ 6668 if (hold_quit.kind != NO_EVENT)
6643 /* ??? Is it really right to send the signal just to 6669 kbd_buffer_store_event (&hold_quit);
6644 this process rather than to the whole process
6645 group? Perhaps on systems with FIONREAD Emacs is
6646 alone in its group. */
6647 kill (getpid (), SIGHUP);
6648
6649 /* XXX Is calling delete_display safe here? It calls Fdelete_frame. */
6650 if (d->delete_display_hook)
6651 (*d->delete_display_hook) (d);
6652 else
6653 delete_display (d);
6654 }
6655 } while (nr == NREAD_INPUT_EVENTS);
6656 } 6670 }
6657 6671
6658 d = next; 6672 d = next;
6659 } 6673 }
6660 6674
6670 and so this function is called once for each individual termcap 6684 and so this function is called once for each individual termcap
6671 display. The first parameter indicates which device to read from. */ 6685 display. The first parameter indicates which device to read from. */
6672 6686
6673 int 6687 int
6674 tty_read_avail_input (struct display *display, 6688 tty_read_avail_input (struct display *display,
6675 struct input_event *buf, 6689 int expected,
6676 int numchars, int expected) 6690 struct input_event *hold_quit)
6677 { 6691 {
6678 /* Using numchars here avoids reading more than the buf can 6692 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
6679 really hold. That may prevent loss of characters on some systems 6693 the kbd_buffer can really hold. That may prevent loss
6680 when input is stuffed at us. */ 6694 of characters on some systems when input is stuffed at us. */
6681 unsigned char cbuf[numchars]; 6695 unsigned char cbuf[KBD_BUFFER_SIZE - 1];
6682 int n_to_read, i; 6696 int n_to_read, i;
6683 struct tty_display_info *tty = display->display_info.tty; 6697 struct tty_display_info *tty = display->display_info.tty;
6684 int nread = 0; 6698 int nread = 0;
6685 6699
6686 if (display->type != output_termcap) 6700 if (display->type != output_termcap)
6783 #endif /* not MSDOS */ 6797 #endif /* not MSDOS */
6784 #endif /* not WINDOWSNT */ 6798 #endif /* not WINDOWSNT */
6785 6799
6786 for (i = 0; i < nread; i++) 6800 for (i = 0; i < nread; i++)
6787 { 6801 {
6788 buf[i].kind = ASCII_KEYSTROKE_EVENT; 6802 struct input_event buf;
6789 buf[i].modifiers = 0; 6803 EVENT_INIT (buf);
6804 buf.kind = ASCII_KEYSTROKE_EVENT;
6805 buf.modifiers = 0;
6790 if (tty->meta_key == 1 && (cbuf[i] & 0x80)) 6806 if (tty->meta_key == 1 && (cbuf[i] & 0x80))
6791 buf[i].modifiers = meta_modifier; 6807 buf.modifiers = meta_modifier;
6792 if (tty->meta_key != 2) 6808 if (tty->meta_key != 2)
6793 cbuf[i] &= ~0x80; 6809 cbuf[i] &= ~0x80;
6794 6810
6795 buf[i].code = cbuf[i]; 6811 buf.code = cbuf[i];
6796 /* Set the frame corresponding to the active tty. Note that the 6812 /* Set the frame corresponding to the active tty. Note that the
6797 value of selected_frame is not reliable here, redisplay tends 6813 value of selected_frame is not reliable here, redisplay tends
6798 to temporarily change it. */ 6814 to temporarily change it. */
6799 buf[i].frame_or_window = tty->top_frame; 6815 buf.frame_or_window = tty->top_frame;
6800 buf[i].arg = Qnil; 6816 buf.arg = Qnil;
6817
6818 kbd_buffer_store_event (&buf);
6819 /* Don't look at input that follows a C-g too closely.
6820 This reduces lossage due to autorepeat on C-g. */
6821 if (buf.kind == ASCII_KEYSTROKE_EVENT
6822 && buf.code == quit_char)
6823 break;
6801 } 6824 }
6802 6825
6803 return nread; 6826 return nread;
6804 } 6827 }
6805 #endif /* not VMS */ 6828 #endif /* not VMS */