comparison src/keymap.c @ 771:943eaba38521

[xemacs-hg @ 2002-03-13 08:51:24 by ben] The big ben-mule-21-5 check-in! Various files were added and deleted. See CHANGES-ben-mule. There are still some test suite failures. No crashes, though. Many of the failures have to do with problems in the test suite itself rather than in the actual code. I'll be addressing these in the next day or so -- none of the test suite failures are at all critical. Meanwhile I'll be trying to address the biggest issues -- i.e. build or run failures, which will almost certainly happen on various platforms. All comments should be sent to ben@xemacs.org -- use a Cc: if necessary when sending to mailing lists. There will be pre- and post- tags, something like pre-ben-mule-21-5-merge-in, and post-ben-mule-21-5-merge-in.
author ben
date Wed, 13 Mar 2002 08:54:06 +0000
parents 218e3d55692e
children e38acbeb1cae
comparison
equal deleted inserted replaced
770:336a418893b5 771:943eaba38521
1 /* Manipulation of keymaps 1 /* Manipulation of keymaps
2 Copyright (C) 1985, 1991-1995 Free Software Foundation, Inc. 2 Copyright (C) 1985, 1991-1995 Free Software Foundation, Inc.
3 Copyright (C) 1995 Board of Trustees, University of Illinois. 3 Copyright (C) 1995 Board of Trustees, University of Illinois.
4 Copyright (C) 1995 Sun Microsystems, Inc. 4 Copyright (C) 1995 Sun Microsystems, Inc.
5 Copyright (C) 2001 Ben Wing.
5 Totally redesigned by jwz in 1991. 6 Totally redesigned by jwz in 1991.
6 7
7 This file is part of XEmacs. 8 This file is part of XEmacs.
8 9
9 XEmacs is free software; you can redistribute it and/or modify it 10 XEmacs is free software; you can redistribute it and/or modify it
170 171
171 172
172 /* Actually allocate storage for these variables */ 173 /* Actually allocate storage for these variables */
173 174
174 Lisp_Object Vcurrent_global_map; /* Always a keymap */ 175 Lisp_Object Vcurrent_global_map; /* Always a keymap */
176
177 static Lisp_Object Vglobal_tty_map, Vglobal_window_system_map;
175 178
176 static Lisp_Object Vmouse_grabbed_buffer; 179 static Lisp_Object Vmouse_grabbed_buffer;
177 180
178 /* Alist of minor mode variables and keymaps. */ 181 /* Alist of minor mode variables and keymaps. */
179 static Lisp_Object Qminor_mode_map_alist; 182 static Lisp_Object Qminor_mode_map_alist;
441 */ 444 */
442 /* !!#### I'm not sure how correct this is. */ 445 /* !!#### I'm not sure how correct this is. */
443 Intbyte str [1 + MAX_EMCHAR_LEN]; 446 Intbyte str [1 + MAX_EMCHAR_LEN];
444 Bytecount count = set_charptr_emchar (str, XCHAR (keysym)); 447 Bytecount count = set_charptr_emchar (str, XCHAR (keysym));
445 str[count] = 0; 448 str[count] = 0;
446 keysym = intern ((char *) str); 449 keysym = intern_int (str);
447 } 450 }
448 return control_meta_superify (keysym, modifiers); 451 return control_meta_superify (keysym, modifiers);
449 } 452 }
450 453
451 454
1753 a cons (STRING . DEFN), meaning that DEFN is the definition 1756 a cons (STRING . DEFN), meaning that DEFN is the definition
1754 (DEFN should be a valid definition in its own right); 1757 (DEFN should be a valid definition in its own right);
1755 or a cons (KEYMAP . CHAR), meaning use definition of CHAR in map KEYMAP. 1758 or a cons (KEYMAP . CHAR), meaning use definition of CHAR in map KEYMAP.
1756 1759
1757 Contrary to popular belief, the world is not ASCII. When running under a 1760 Contrary to popular belief, the world is not ASCII. When running under a
1758 window manager, XEmacs can tell the difference between, for example, the 1761 window system, XEmacs can tell the difference between, for example, the
1759 keystrokes control-h, control-shift-h, and backspace. You can, in fact, 1762 keystrokes control-h, control-shift-h, and backspace. You can, in fact,
1760 bind different commands to each of these. 1763 bind different commands to each of these.
1761 1764
1762 A `key sequence' is a set of keystrokes. A `keystroke' is a keysym and some 1765 A `key sequence' is a set of keystrokes. A `keystroke' is a keysym and some
1763 set of modifiers (such as control and meta). A `keysym' is what is printed 1766 set of modifiers (such as control and meta). A `keysym' is what is printed
1836 (define-key global-map [(control x) tab] \'command-3) 1839 (define-key global-map [(control x) tab] \'command-3)
1837 1840
1838 Of course, all of this applies only when running under a window system. If 1841 Of course, all of this applies only when running under a window system. If
1839 you're talking to XEmacs through a TTY connection, you don't get any of 1842 you're talking to XEmacs through a TTY connection, you don't get any of
1840 these features. 1843 these features.
1844
1845 To find out programmatically what a key is bound to, use `key-binding' to
1846 check all applicable keymaps, or `lookup-key' to check a specific keymap.
1847 The documentation for `key-binding' also contains a description of which
1848 keymaps are applicable in various situations. `where-is-internal' does
1849 the opposite of `key-binding', i.e. searches keymaps for the keys that
1850 map to a particular binding.
1851
1852 If you are confused about why a particular key sequence is generating a
1853 particular binding, and looking through the keymaps doesn't help, setting
1854 the variable `debug-emacs-events' may help. If not, try checking
1855 what's in `function-key-map' and `key-translation-map'.
1841 */ 1856 */
1842 (keymap, keys, def)) 1857 (keymap, keys, def))
1843 { 1858 {
1844 /* This function can GC */ 1859 /* This function can GC */
1845 int idx; 1860 int idx;
2320 XSETBUFFER (tem, current_buffer); 2335 XSETBUFFER (tem, current_buffer);
2321 /* It's not a mouse event; order of keymaps searched is: 2336 /* It's not a mouse event; order of keymaps searched is:
2322 o keymap of any/all extents under the mouse 2337 o keymap of any/all extents under the mouse
2323 o minor-mode maps 2338 o minor-mode maps
2324 o local-map of current-buffer 2339 o local-map of current-buffer
2340 o global-tty-map or global-window-system-map
2325 o global-map 2341 o global-map
2326 */ 2342 */
2327 /* The terminal element of the lookup may be nil or a keysym. 2343 /* The terminal element of the lookup may be nil or a keysym.
2328 In those cases we don't want to check for an extent 2344 In those cases we don't want to check for an extent
2329 keymap. */ 2345 keymap. */
2348 if the mouse is over a modeline: 2364 if the mouse is over a modeline:
2349 o modeline-map of buffer corresponding to that modeline 2365 o modeline-map of buffer corresponding to that modeline
2350 o else, local-map of buffer under the mouse 2366 o else, local-map of buffer under the mouse
2351 o minor-mode maps 2367 o minor-mode maps
2352 o local-map of current-buffer 2368 o local-map of current-buffer
2369 o global-tty-map or global-window-system-map
2353 o global-map 2370 o global-map
2354 */ 2371 */
2355 Lisp_Object window = Fevent_window (terminal); 2372 Lisp_Object window = Fevent_window (terminal);
2356 2373
2357 if (!NILP (Fevent_over_vertical_divider_p (terminal))) 2374 if (!NILP (Fevent_over_vertical_divider_p (terminal)))
2413 relevant_map_push (map, &closure); 2430 relevant_map_push (map, &closure);
2414 } 2431 }
2415 } 2432 }
2416 #endif /* HAVE_WINDOW_SYSTEM */ 2433 #endif /* HAVE_WINDOW_SYSTEM */
2417 2434
2435 if (CONSOLE_TTY_P (con))
2436 relevant_map_push (Vglobal_tty_map, &closure);
2437 else
2438 relevant_map_push (Vglobal_window_system_map, &closure);
2439
2418 { 2440 {
2419 int nmaps = closure.nmaps; 2441 int nmaps = closure.nmaps;
2420 /* Silently truncate at 100 keymaps to prevent infinite lossage */ 2442 /* Silently truncate at 100 keymaps to prevent infinite lossage */
2421 if (nmaps >= max_maps && max_maps > 0) 2443 if (nmaps >= max_maps && max_maps > 0)
2422 maps[max_maps - 1] = Vcurrent_global_map; 2444 maps[max_maps - 1] = Vcurrent_global_map;
2513 but does not list the parents of those keymaps. 2535 but does not list the parents of those keymaps.
2514 EVENT-OR-KEYS controls which keymaps will be listed. 2536 EVENT-OR-KEYS controls which keymaps will be listed.
2515 If EVENT-OR-KEYS is a mouse event (or a vector whose last element is a 2537 If EVENT-OR-KEYS is a mouse event (or a vector whose last element is a
2516 mouse event), the keymaps for that mouse event will be listed (see 2538 mouse event), the keymaps for that mouse event will be listed (see
2517 `key-binding'). Otherwise, the keymaps for key presses will be listed. 2539 `key-binding'). Otherwise, the keymaps for key presses will be listed.
2540 See `key-binding' for a description of which keymaps are searched in
2541 various situations.
2518 */ 2542 */
2519 (event_or_keys)) 2543 (event_or_keys))
2520 { 2544 {
2521 /* This function can GC */ 2545 /* This function can GC */
2522 struct gcpro gcpro1; 2546 struct gcpro gcpro1;
2545 2569
2546 For key-presses, the order of keymaps searched is: 2570 For key-presses, the order of keymaps searched is:
2547 - the `keymap' property of any extent(s) at point; 2571 - the `keymap' property of any extent(s) at point;
2548 - any applicable minor-mode maps; 2572 - any applicable minor-mode maps;
2549 - the current local map of the current-buffer; 2573 - the current local map of the current-buffer;
2574 - either `global-tty-map' or `global-window-system-map', depending on
2575 whether the current console is a TTY or non-TTY console;
2550 - the current global map. 2576 - the current global map.
2551 2577
2552 For mouse-clicks, the order of keymaps searched is: 2578 For mouse-clicks, the order of keymaps searched is:
2553 - the current-local-map of the `mouse-grabbed-buffer' if any; 2579 - the current-local-map of the `mouse-grabbed-buffer' if any;
2554 - vertical-divider-map, if the event happened over a vertical divider 2580 - vertical-divider-map, if the event happened over a vertical divider
2559 - the value of `toolbar-map' in the current-buffer (if the click 2585 - the value of `toolbar-map' in the current-buffer (if the click
2560 happened over a toolbar); 2586 happened over a toolbar);
2561 - the current local map of the buffer under the mouse (does not 2587 - the current local map of the buffer under the mouse (does not
2562 apply to toolbar clicks); 2588 apply to toolbar clicks);
2563 - any applicable minor-mode maps; 2589 - any applicable minor-mode maps;
2590 - either `global-tty-map' or `global-window-system-map', depending on
2591 whether the current console is a TTY or non-TTY console;
2564 - the current global map. 2592 - the current global map.
2565 2593
2566 Note that if `overriding-local-map' or `overriding-terminal-local-map' 2594 Note that if `overriding-local-map' or `overriding-terminal-local-map'
2567 is non-nil, *only* those two maps and the current global map are searched. 2595 is non-nil, *only* those two maps and the current global map are searched.
2596
2597 Note also that key sequences actually received from the keyboard driver
2598 may be processed in various ways to generate the key sequence that is
2599 actually looked up in the keymaps. In particular:
2600
2601 -- Keysyms are individually passed through `keyboard-translate-table' before
2602 any other processing.
2603 -- After this, key sequences as a whole are passed through
2604 `key-translation-map'.
2605 -- The resulting key sequence is actually looked up in the keymaps.
2606 -- If there's no binding found, the key sequence is passed through
2607 `function-key-map' and looked up again.
2608 -- If no binding is found and `retry-undefined-key-binding-unshifted' is
2609 set (it usually is) and the final keysym is an uppercase character,
2610 we lowercase it and start over from the `key-translation-map' stage.
2611 -- If no binding is found and we're on MS Windows and have international
2612 support, we successively remap the key sequence using the keyboard layouts
2613 of various default locales (current language environment, user default,
2614 system default, US ASCII) and try again. This makes (e.g.) sequences
2615 such as `C-x b' work in a Russian locale, where the alphabetic keys are
2616 actually generating Russian characters and not the Roman letters written
2617 on the keycaps. (Not yet implemented)
2618 -- Finally, if the last keystroke matches `help-char', we automatically
2619 generate and display a list of possible key sequences and bindings
2620 given the prefix so far generated.
2568 */ 2621 */
2569 (keys, accept_default)) 2622 (keys, accept_default))
2570 { 2623 {
2571 /* This function can GC */ 2624 /* This function can GC */
2572 int i; 2625 int i;
2875 2928
2876 /* otherwise, string-sort them. */ 2929 /* otherwise, string-sort them. */
2877 { 2930 {
2878 char *s1 = (char *) string_data (XSYMBOL (obj1)->name); 2931 char *s1 = (char *) string_data (XSYMBOL (obj1)->name);
2879 char *s2 = (char *) string_data (XSYMBOL (obj2)->name); 2932 char *s2 = (char *) string_data (XSYMBOL (obj2)->name);
2880 #ifdef I18N2
2881 return 0 > strcoll (s1, s2) ? 1 : -1;
2882 #else
2883 return 0 > strcmp (s1, s2) ? 1 : -1; 2933 return 0 > strcmp (s1, s2) ? 1 : -1;
2884 #endif
2885 } 2934 }
2886 } 2935 }
2887 2936
2888 2937
2889 /* used by map_keymap() */ 2938 /* used by map_keymap() */
4348 This keymap works like `function-key-map', but comes after that, 4397 This keymap works like `function-key-map', but comes after that,
4349 and applies even for keys that have ordinary bindings. 4398 and applies even for keys that have ordinary bindings.
4350 */ ); 4399 */ );
4351 Vkey_translation_map = Qnil; 4400 Vkey_translation_map = Qnil;
4352 4401
4402 DEFVAR_LISP ("global-tty-map", &Vglobal_tty_map /*
4403 Global keymap that applies only to TTY's.
4404 Key bindings are looked up in this map just before looking in the global map,
4405 but only when the current console is a TTY console. See also
4406 `global-window-system-map'.
4407 */ );
4408 Vglobal_tty_map = Qnil;
4409
4410 DEFVAR_LISP ("global-window-system-map", &Vglobal_window_system_map /*
4411 Global keymap that applies only to window systems.
4412 Key bindings are looked up in this map just before looking in the global map,
4413 but only when the current console is not a TTY console. See also
4414 `global-tty-map'.
4415 */ );
4416 Vglobal_window_system_map = Qnil;
4417
4353 DEFVAR_LISP ("vertical-divider-map", &Vvertical_divider_map /* 4418 DEFVAR_LISP ("vertical-divider-map", &Vvertical_divider_map /*
4354 Keymap which handles mouse clicks over vertical dividers. 4419 Keymap which handles mouse clicks over vertical dividers.
4355 */ ); 4420 */ );
4356 Vvertical_divider_map = Qnil; 4421 Vvertical_divider_map = Qnil;
4357 4422
4372 /* This function can GC */ 4437 /* This function can GC */
4373 Lisp_Object ESC_prefix = intern ("ESC-prefix"); 4438 Lisp_Object ESC_prefix = intern ("ESC-prefix");
4374 Lisp_Object meta_disgustitute; 4439 Lisp_Object meta_disgustitute;
4375 4440
4376 Vcurrent_global_map = Fmake_keymap (Qnil); 4441 Vcurrent_global_map = Fmake_keymap (Qnil);
4442 Vglobal_tty_map = Fmake_keymap (intern ("global-tty-map"));
4443 Vglobal_window_system_map =
4444 Fmake_keymap (intern ("global-window-system-map"));
4377 4445
4378 meta_disgustitute = Fmake_keymap (Qnil); 4446 meta_disgustitute = Fmake_keymap (Qnil);
4379 Ffset (ESC_prefix, meta_disgustitute); 4447 Ffset (ESC_prefix, meta_disgustitute);
4380 /* no need to protect meta_disgustitute, though */ 4448 /* no need to protect meta_disgustitute, though */
4381 keymap_store_internal (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META), 4449 keymap_store_internal (MAKE_MODIFIER_HASH_KEY (XEMACS_MOD_META),