aboutsummaryrefslogtreecommitdiffstats
path: root/src/keyboard.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/keyboard.c')
-rw-r--r--src/keyboard.c245
1 files changed, 155 insertions, 90 deletions
diff --git a/src/keyboard.c b/src/keyboard.c
index f1bfea0f18c..681018bbab9 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1458,6 +1458,72 @@ DEFUN ("abort-recursive-edit", Fabort_recursive_edit, Sabort_recursive_edit, 0,
1458 return Qnil; 1458 return Qnil;
1459} 1459}
1460 1460
1461#ifdef HAVE_MOUSE
1462
1463/* Restore mouse tracking enablement. See Ftrack_mouse for the only use
1464 of this function. */
1465
1466static Lisp_Object
1467tracking_off (old_value)
1468 Lisp_Object old_value;
1469{
1470 do_mouse_tracking = old_value;
1471 if (NILP (old_value))
1472 {
1473 /* Redisplay may have been preempted because there was input
1474 available, and it assumes it will be called again after the
1475 input has been processed. If the only input available was
1476 the sort that we have just disabled, then we need to call
1477 redisplay. */
1478 if (!readable_events (READABLE_EVENTS_DO_TIMERS_NOW))
1479 {
1480 redisplay_preserve_echo_area (6);
1481 get_input_pending (&input_pending,
1482 READABLE_EVENTS_DO_TIMERS_NOW);
1483 }
1484 }
1485 return Qnil;
1486}
1487
1488DEFUN ("track-mouse", Ftrack_mouse, Strack_mouse, 0, UNEVALLED, 0,
1489 doc: /* Evaluate BODY with mouse movement events enabled.
1490Within a `track-mouse' form, mouse motion generates input events that
1491you can read with `read-event'.
1492Normally, mouse motion is ignored.
1493usage: (track-mouse BODY ...) */)
1494 (args)
1495 Lisp_Object args;
1496{
1497 int count = SPECPDL_INDEX ();
1498 Lisp_Object val;
1499
1500 record_unwind_protect (tracking_off, do_mouse_tracking);
1501
1502 do_mouse_tracking = Qt;
1503
1504 val = Fprogn (args);
1505 return unbind_to (count, val);
1506}
1507
1508/* If mouse has moved on some frame, return one of those frames.
1509 Return 0 otherwise. */
1510
1511static FRAME_PTR
1512some_mouse_moved ()
1513{
1514 Lisp_Object tail, frame;
1515
1516 FOR_EACH_FRAME (tail, frame)
1517 {
1518 if (XFRAME (frame)->mouse_moved)
1519 return XFRAME (frame);
1520 }
1521
1522 return 0;
1523}
1524
1525#endif /* HAVE_MOUSE */
1526
1461/* This is the actual command reading loop, 1527/* This is the actual command reading loop,
1462 sans error-handling encapsulation. */ 1528 sans error-handling encapsulation. */
1463 1529
@@ -2106,6 +2172,8 @@ static Lisp_Object
2106safe_run_hooks_1 (hook) 2172safe_run_hooks_1 (hook)
2107 Lisp_Object hook; 2173 Lisp_Object hook;
2108{ 2174{
2175 if (NILP (Vrun_hooks))
2176 return Qnil;
2109 return call1 (Vrun_hooks, Vinhibit_quit); 2177 return call1 (Vrun_hooks, Vinhibit_quit);
2110} 2178}
2111 2179
@@ -2388,7 +2456,17 @@ show_help_echo (help, window, object, pos, ok_to_overwrite_keystroke_echo)
2388 2456
2389#ifdef HAVE_MOUSE 2457#ifdef HAVE_MOUSE
2390 if (!noninteractive && STRINGP (help)) 2458 if (!noninteractive && STRINGP (help))
2391 help = call1 (Qmouse_fixup_help_message, help); 2459 {
2460 /* The mouse-fixup-help-message Lisp function can call
2461 mouse_position_hook, which resets the mouse_moved flags.
2462 This causes trouble if we are trying to read a mouse motion
2463 event (i.e., if we are inside a `track-mouse' form), so we
2464 restore the mouse_moved flag. */
2465 FRAME_PTR f = NILP (do_mouse_tracking) ? NULL : some_mouse_moved ();
2466 help = call1 (Qmouse_fixup_help_message, help);
2467 if (f)
2468 f->mouse_moved = 1;
2469 }
2392#endif 2470#endif
2393 2471
2394 if (STRINGP (help) || NILP (help)) 2472 if (STRINGP (help) || NILP (help))
@@ -2483,7 +2561,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2483 EMACS_TIME *end_time; 2561 EMACS_TIME *end_time;
2484{ 2562{
2485 volatile Lisp_Object c; 2563 volatile Lisp_Object c;
2486 int count; 2564 int count, jmpcount;
2487 jmp_buf local_getcjmp; 2565 jmp_buf local_getcjmp;
2488 jmp_buf save_jump; 2566 jmp_buf save_jump;
2489 volatile int key_already_recorded = 0; 2567 volatile int key_already_recorded = 0;
@@ -2714,12 +2792,14 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2714 around any call to sit_for or kbd_buffer_get_event; 2792 around any call to sit_for or kbd_buffer_get_event;
2715 it *must not* be in effect when we call redisplay. */ 2793 it *must not* be in effect when we call redisplay. */
2716 2794
2795 jmpcount = SPECPDL_INDEX ();
2717 if (_setjmp (local_getcjmp)) 2796 if (_setjmp (local_getcjmp))
2718 { 2797 {
2719 /* Handle quits while reading the keyboard. */ 2798 /* Handle quits while reading the keyboard. */
2720 /* We must have saved the outer value of getcjmp here, 2799 /* We must have saved the outer value of getcjmp here,
2721 so restore it now. */ 2800 so restore it now. */
2722 restore_getcjmp (save_jump); 2801 restore_getcjmp (save_jump);
2802 unbind_to (jmpcount, Qnil);
2723 XSETINT (c, quit_char); 2803 XSETINT (c, quit_char);
2724 internal_last_event_frame = selected_frame; 2804 internal_last_event_frame = selected_frame;
2725 Vlast_event_frame = internal_last_event_frame; 2805 Vlast_event_frame = internal_last_event_frame;
@@ -2760,7 +2840,12 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2760 goto non_reread; 2840 goto non_reread;
2761 } 2841 }
2762 2842
2763 timer_start_idle (); 2843 /* Start idle timers if no time limit is supplied. We don't do it
2844 if a time limit is supplied to avoid an infinite recursion in the
2845 situation where an idle timer calls `sit-for'. */
2846
2847 if (!end_time)
2848 timer_start_idle ();
2764 2849
2765 /* If in middle of key sequence and minibuffer not active, 2850 /* If in middle of key sequence and minibuffer not active,
2766 start echoing if enough time elapses. */ 2851 start echoing if enough time elapses. */
@@ -2830,7 +2915,8 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2830 c = read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu); 2915 c = read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu);
2831 2916
2832 /* Now that we have read an event, Emacs is not idle. */ 2917 /* Now that we have read an event, Emacs is not idle. */
2833 timer_stop_idle (); 2918 if (!end_time)
2919 timer_stop_idle ();
2834 2920
2835 goto exit; 2921 goto exit;
2836 } 2922 }
@@ -2973,7 +3059,8 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2973 /* Actually read a character, waiting if necessary. */ 3059 /* Actually read a character, waiting if necessary. */
2974 save_getcjmp (save_jump); 3060 save_getcjmp (save_jump);
2975 restore_getcjmp (local_getcjmp); 3061 restore_getcjmp (local_getcjmp);
2976 timer_start_idle (); 3062 if (!end_time)
3063 timer_start_idle ();
2977 c = kbd_buffer_get_event (&kb, used_mouse_menu, end_time); 3064 c = kbd_buffer_get_event (&kb, used_mouse_menu, end_time);
2978 restore_getcjmp (save_jump); 3065 restore_getcjmp (save_jump);
2979 3066
@@ -3025,7 +3112,8 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3025 3112
3026 non_reread: 3113 non_reread:
3027 3114
3028 timer_stop_idle (); 3115 if (!end_time)
3116 timer_stop_idle ();
3029 RESUME_POLLING; 3117 RESUME_POLLING;
3030 3118
3031 if (NILP (c)) 3119 if (NILP (c))
@@ -3063,7 +3151,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3063 last_input_char = c; 3151 last_input_char = c;
3064 Fcommand_execute (tem, Qnil, Fvector (1, &last_input_char), Qt); 3152 Fcommand_execute (tem, Qnil, Fvector (1, &last_input_char), Qt);
3065 3153
3066 if (CONSP (c) && EQ (XCAR (c), Qselect_window)) 3154 if (CONSP (c) && EQ (XCAR (c), Qselect_window) && !end_time)
3067 /* We stopped being idle for this event; undo that. This 3155 /* We stopped being idle for this event; undo that. This
3068 prevents automatic window selection (under 3156 prevents automatic window selection (under
3069 mouse_autoselect_window from acting as a real input event, for 3157 mouse_autoselect_window from acting as a real input event, for
@@ -3272,7 +3360,8 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3272 show_help_echo (help, window, object, position, 0); 3360 show_help_echo (help, window, object, position, 0);
3273 3361
3274 /* We stopped being idle for this event; undo that. */ 3362 /* We stopped being idle for this event; undo that. */
3275 timer_resume_idle (); 3363 if (!end_time)
3364 timer_resume_idle ();
3276 goto retry; 3365 goto retry;
3277 } 3366 }
3278 3367
@@ -3556,72 +3645,6 @@ restore_getcjmp (temp)
3556 bcopy (temp, getcjmp, sizeof getcjmp); 3645 bcopy (temp, getcjmp, sizeof getcjmp);
3557} 3646}
3558 3647
3559#ifdef HAVE_MOUSE
3560
3561/* Restore mouse tracking enablement. See Ftrack_mouse for the only use
3562 of this function. */
3563
3564static Lisp_Object
3565tracking_off (old_value)
3566 Lisp_Object old_value;
3567{
3568 do_mouse_tracking = old_value;
3569 if (NILP (old_value))
3570 {
3571 /* Redisplay may have been preempted because there was input
3572 available, and it assumes it will be called again after the
3573 input has been processed. If the only input available was
3574 the sort that we have just disabled, then we need to call
3575 redisplay. */
3576 if (!readable_events (READABLE_EVENTS_DO_TIMERS_NOW))
3577 {
3578 redisplay_preserve_echo_area (6);
3579 get_input_pending (&input_pending,
3580 READABLE_EVENTS_DO_TIMERS_NOW);
3581 }
3582 }
3583 return Qnil;
3584}
3585
3586DEFUN ("track-mouse", Ftrack_mouse, Strack_mouse, 0, UNEVALLED, 0,
3587 doc: /* Evaluate BODY with mouse movement events enabled.
3588Within a `track-mouse' form, mouse motion generates input events that
3589you can read with `read-event'.
3590Normally, mouse motion is ignored.
3591usage: (track-mouse BODY ...) */)
3592 (args)
3593 Lisp_Object args;
3594{
3595 int count = SPECPDL_INDEX ();
3596 Lisp_Object val;
3597
3598 record_unwind_protect (tracking_off, do_mouse_tracking);
3599
3600 do_mouse_tracking = Qt;
3601
3602 val = Fprogn (args);
3603 return unbind_to (count, val);
3604}
3605
3606/* If mouse has moved on some frame, return one of those frames.
3607 Return 0 otherwise. */
3608
3609static FRAME_PTR
3610some_mouse_moved ()
3611{
3612 Lisp_Object tail, frame;
3613
3614 FOR_EACH_FRAME (tail, frame)
3615 {
3616 if (XFRAME (frame)->mouse_moved)
3617 return XFRAME (frame);
3618 }
3619
3620 return 0;
3621}
3622
3623#endif /* HAVE_MOUSE */
3624
3625/* Low level keyboard/mouse input. 3648/* Low level keyboard/mouse input.
3626 kbd_buffer_store_event places events in kbd_buffer, and 3649 kbd_buffer_store_event places events in kbd_buffer, and
3627 kbd_buffer_get_event retrieves them. */ 3650 kbd_buffer_get_event retrieves them. */
@@ -4056,13 +4079,15 @@ kbd_buffer_get_event (kbp, used_mouse_menu, end_time)
4056 { 4079 {
4057 EMACS_TIME duration; 4080 EMACS_TIME duration;
4058 EMACS_GET_TIME (duration); 4081 EMACS_GET_TIME (duration);
4059 EMACS_SUB_TIME (duration, *end_time, duration); 4082 if (EMACS_TIME_GE (duration, *end_time))
4060 if (EMACS_TIME_NEG_P (duration)) 4083 return Qnil; /* finished waiting */
4061 return Qnil;
4062 else 4084 else
4063 wait_reading_process_output (EMACS_SECS (duration), 4085 {
4064 EMACS_USECS (duration), 4086 EMACS_SUB_TIME (duration, *end_time, duration);
4065 -1, 1, Qnil, NULL, 0); 4087 wait_reading_process_output (EMACS_SECS (duration),
4088 EMACS_USECS (duration),
4089 -1, 1, Qnil, NULL, 0);
4090 }
4066 } 4091 }
4067 else 4092 else
4068 wait_reading_process_output (0, 0, -1, 1, Qnil, NULL, 0); 4093 wait_reading_process_output (0, 0, -1, 1, Qnil, NULL, 0);
@@ -4635,6 +4660,32 @@ timer_check (do_it_now)
4635 UNGCPRO; 4660 UNGCPRO;
4636 return nexttime; 4661 return nexttime;
4637} 4662}
4663
4664DEFUN ("current-idle-time", Fcurrent_idle_time, Scurrent_idle_time, 0, 0, 0,
4665 doc: /* Return the current length of Emacs idleness.
4666The value is returned as a list of three integers. The first has the
4667most significant 16 bits of the seconds, while the second has the
4668least significant 16 bits. The third integer gives the microsecond
4669count.
4670
4671The microsecond count is zero on systems that do not provide
4672resolution finer than a second. */)
4673 ()
4674{
4675 if (! EMACS_TIME_NEG_P (timer_idleness_start_time))
4676 {
4677 EMACS_TIME now, idleness_now;
4678
4679 EMACS_GET_TIME (now);
4680 EMACS_SUB_TIME (idleness_now, now, timer_idleness_start_time);
4681
4682 return list3 (make_number ((EMACS_SECS (idleness_now) >> 16) & 0xffff),
4683 make_number ((EMACS_SECS (idleness_now) >> 0) & 0xffff),
4684 make_number (EMACS_USECS (idleness_now)));
4685 }
4686
4687 return Qnil;
4688}
4638 4689
4639/* Caches for modify_event_symbol. */ 4690/* Caches for modify_event_symbol. */
4640static Lisp_Object accent_key_syms; 4691static Lisp_Object accent_key_syms;
@@ -8565,7 +8616,15 @@ follow_key (key, nmaps, current, defs, next)
8565 such as Vfunction_key_map and Vkey_translation_map. */ 8616 such as Vfunction_key_map and Vkey_translation_map. */
8566typedef struct keyremap 8617typedef struct keyremap
8567{ 8618{
8568 Lisp_Object map, parent; 8619 /* This is the map originally specified for this use. */
8620 Lisp_Object parent;
8621 /* This is a submap reached by looking up, in PARENT,
8622 the events from START to END. */
8623 Lisp_Object map;
8624 /* Positions [START, END) in the key sequence buffer
8625 are the key that we have scanned so far.
8626 Those events are the ones that we will replace
8627 if PAREHT maps them into a key sequence. */
8569 int start, end; 8628 int start, end;
8570} keyremap; 8629} keyremap;
8571 8630
@@ -8638,7 +8697,11 @@ keyremap_step (keybuf, bufsize, fkey, input, doit, diff, prompt)
8638 Lisp_Object next, key; 8697 Lisp_Object next, key;
8639 8698
8640 key = keybuf[fkey->end++]; 8699 key = keybuf[fkey->end++];
8641 next = access_keymap_keyremap (fkey->map, key, prompt, doit); 8700
8701 if (KEYMAPP (fkey->parent))
8702 next = access_keymap_keyremap (fkey->map, key, prompt, doit);
8703 else
8704 next = Qnil;
8642 8705
8643 /* If keybuf[fkey->start..fkey->end] is bound in the 8706 /* If keybuf[fkey->start..fkey->end] is bound in the
8644 map and we're in a position to do the key remapping, replace it with 8707 map and we're in a position to do the key remapping, replace it with
@@ -8878,9 +8941,8 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
8878 reinitialize fkey and keytran before each replay. */ 8941 reinitialize fkey and keytran before each replay. */
8879 fkey.map = fkey.parent = current_kboard->Vlocal_function_key_map; 8942 fkey.map = fkey.parent = current_kboard->Vlocal_function_key_map;
8880 keytran.map = keytran.parent = current_kboard->Vlocal_key_translation_map; 8943 keytran.map = keytran.parent = current_kboard->Vlocal_key_translation_map;
8881 /* If there is no translation map, turn off scanning. */ 8944 fkey.start = fkey.end = 0;
8882 fkey.start = fkey.end = KEYMAPP (fkey.map) ? 0 : bufsize + 1; 8945 keytran.start = keytran.end = 0;
8883 keytran.start = keytran.end = KEYMAPP (keytran.map) ? 0 : bufsize + 1;
8884 8946
8885 starting_buffer = current_buffer; 8947 starting_buffer = current_buffer;
8886 first_unbound = bufsize + 1; 8948 first_unbound = bufsize + 1;
@@ -9687,8 +9749,8 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9687 9749
9688 keybuf[t - 1] = new_key; 9750 keybuf[t - 1] = new_key;
9689 mock_input = max (t, mock_input); 9751 mock_input = max (t, mock_input);
9690 fkey.start = fkey.end = KEYMAPP (fkey.map) ? 0 : bufsize + 1; 9752 fkey.start = fkey.end = 0;
9691 keytran.start = keytran.end = KEYMAPP (keytran.map) ? 0 : bufsize + 1; 9753 keytran.start = keytran.end = 0;
9692 9754
9693 goto replay_sequence; 9755 goto replay_sequence;
9694 } 9756 }
@@ -11494,6 +11556,7 @@ syms_of_keyboard ()
11494 menu_bar_items_vector = Qnil; 11556 menu_bar_items_vector = Qnil;
11495 staticpro (&menu_bar_items_vector); 11557 staticpro (&menu_bar_items_vector);
11496 11558
11559 defsubr (&Scurrent_idle_time);
11497 defsubr (&Sevent_convert_list); 11560 defsubr (&Sevent_convert_list);
11498 defsubr (&Sread_key_sequence); 11561 defsubr (&Sread_key_sequence);
11499 defsubr (&Sread_key_sequence_vector); 11562 defsubr (&Sread_key_sequence_vector);
@@ -11555,14 +11618,16 @@ These events are processed first, before actual keyboard input. */);
11555 11618
11556 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events, 11619 DEFVAR_LISP ("unread-post-input-method-events", &Vunread_post_input_method_events,
11557 doc: /* List of events to be processed as input by input methods. 11620 doc: /* List of events to be processed as input by input methods.
11558These events are processed after `unread-command-events', but 11621These events are processed before `unread-command-events'
11559before actual keyboard input. */); 11622and actual keyboard input without given to `input-method-function'. */);
11560 Vunread_post_input_method_events = Qnil; 11623 Vunread_post_input_method_events = Qnil;
11561 11624
11562 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events, 11625 DEFVAR_LISP ("unread-input-method-events", &Vunread_input_method_events,
11563 doc: /* List of events to be processed as input by input methods. 11626 doc: /* List of events to be processed as input by input methods.
11564These events are processed after `unread-command-events', but 11627These events are processed after `unread-command-events', but
11565before actual keyboard input. */); 11628before actual keyboard input.
11629If there's an active input method, the events are given to
11630`input-method-function'. */);
11566 Vunread_input_method_events = Qnil; 11631 Vunread_input_method_events = Qnil;
11567 11632
11568 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char, 11633 DEFVAR_LISP ("meta-prefix-char", &meta_prefix_char,