aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Kastrup2006-09-15 07:19:15 +0000
committerDavid Kastrup2006-09-15 07:19:15 +0000
commitb74e16a384ddbded12eb7e8c7250253614554641 (patch)
tree287d09b973259b6101ae03baec0e0c91c848232a
parent6266eb4a51f75b4e31895cd8d8be1ddd5a18e076 (diff)
downloademacs-b74e16a384ddbded12eb7e8c7250253614554641.tar.gz
emacs-b74e16a384ddbded12eb7e8c7250253614554641.zip
* NEWS: explain new behavior and arguments of `key-binding' and
`command-remapping'. * keymaps.texi (Active Keymaps): Adapt description to use `get-char-property' instead `get-text-property'. Explain how mouse events change this. Explain the new optional argument of `key-binding' and its mouse-dependent lookup. (Searching Keymaps): Adapt description similarly. Explain the new optional argument of `command-remapping'. * Makefile.in (keymap.o): Add "keymap.h" and "window.h" dependencies. * keymap.c: include "window.h". (Fcommand_remapping): New optional POSITION argument. (Fkey_binding): New optional POSITION argument. Completely rework handling of mouse clicks to get the same order of keymaps as `read-key-sequence' and heed POSITION. Also temporarily switch buffers to location of mouse click and back. * keyboard.c (command_loop_1): Adjust call of `Fcommand_remapping' for additional argument. (parse_menu_item): Adjust call of `Fkey_binding' for additional argument. (read_key_sequence): If there are both `local-map' and `keymap' text properties at some buffer position, heed both. * keymap.h: Declare additional optional arguments of `Fcommand_remapping' and `Fkey_binding'.
-rw-r--r--etc/ChangeLog7
-rw-r--r--etc/NEWS6
-rw-r--r--lispref/ChangeLog12
-rw-r--r--lispref/keymaps.texi55
-rw-r--r--src/ChangeLog22
-rw-r--r--src/Makefile.in3
-rw-r--r--src/keyboard.c15
-rw-r--r--src/keymap.c193
-rw-r--r--src/keymap.h4
9 files changed, 240 insertions, 77 deletions
diff --git a/etc/ChangeLog b/etc/ChangeLog
index e236643da10..e1daf63475b 100644
--- a/etc/ChangeLog
+++ b/etc/ChangeLog
@@ -1,3 +1,8 @@
12006-09-15 David Kastrup <dak@gnu.org>
2
3 * NEWS: explain new behavior and arguments of `key-binding' and
4 `command-remapping'.
5
12006-09-11 Paul Eggert <eggert@cs.ucla.edu> 62006-09-11 Paul Eggert <eggert@cs.ucla.edu>
2 7
3 * NEWS: In terminal-oriented subshells, the EMACS environment 8 * NEWS: In terminal-oriented subshells, the EMACS environment
@@ -102,7 +107,7 @@
102 107
103 * PROBLEMS: Emacs now requires ws2_32.dll on Windows. 108 * PROBLEMS: Emacs now requires ws2_32.dll on Windows.
104 109
1052006-07-14 K,Aa(Broly L,Bu(Brentey <lorentey@elte.hu> 1102006-07-14 K,Aa(Broly L$,1 q(Brentey <lorentey@elte.hu>
106 111
107 * HELLO: Update Hungarian sample. 112 * HELLO: Update Hungarian sample.
108 113
diff --git a/etc/NEWS b/etc/NEWS
index 0e19f64720f..59048b8ff8a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -4681,6 +4681,12 @@ over minor mode keymaps.
4681text properties, according to their stickiness. This also means that it 4681text properties, according to their stickiness. This also means that it
4682works with empty overlays. The same hold for the `local-map' property. 4682works with empty overlays. The same hold for the `local-map' property.
4683 4683
4684*** `key-binding' will now look up mouse-specific bindings. The
4685keymaps consulted by `key-binding' will get adapted if the key
4686sequence is started with a mouse event. Instead of letting the click
4687position be determined from the key sequence itself, it is also
4688possible to specify it with an optional argument explicitly.
4689
4684*** Dense keymaps now handle inheritance correctly. 4690*** Dense keymaps now handle inheritance correctly.
4685 4691
4686Previously a dense keymap would hide all of the simple-char key 4692Previously a dense keymap would hide all of the simple-char key
diff --git a/lispref/ChangeLog b/lispref/ChangeLog
index c6c968bdb34..7b32595083f 100644
--- a/lispref/ChangeLog
+++ b/lispref/ChangeLog
@@ -1,3 +1,12 @@
12006-09-15 David Kastrup <dak@gnu.org>
2
3 * keymaps.texi (Active Keymaps): Adapt description to use
4 `get-char-property' instead `get-text-property'. Explain how
5 mouse events change this. Explain the new optional argument of
6 `key-binding' and its mouse-dependent lookup.
7 (Searching Keymaps): Adapt description similarly. Explain the new
8 optional argument of `command-remapping'.
9
12006-09-14 Richard Stallman <rms@gnu.org> 102006-09-14 Richard Stallman <rms@gnu.org>
2 11
3 * keymaps.texi (Searching Keymaps): Clarification. 12 * keymaps.texi (Searching Keymaps): Clarification.
@@ -10,6 +19,7 @@
10 (Basic Char Syntax, General Escape Syntax) 19 (Basic Char Syntax, General Escape Syntax)
11 (Ctl-Char Syntax, Meta-Char Syntax): New subnodes. 20 (Ctl-Char Syntax, Meta-Char Syntax): New subnodes.
12 21
22>>>>>>> 1.751
132006-09-11 Richard Stallman <rms@gnu.org> 232006-09-11 Richard Stallman <rms@gnu.org>
14 24
15 * display.texi (Display Table Format): Wording clarification. 25 * display.texi (Display Table Format): Wording clarification.
@@ -4871,7 +4881,7 @@
4871 (info): Add target. 4881 (info): Add target.
4872 (installall): Target removed. 4882 (installall): Target removed.
4873 4883
48742001-10-31 Pavel Jan,Bm(Bk <Pavel@Janik.cz> 48842001-10-31 Pavel Jan,Am(Bk <Pavel@Janik.cz>
4875 4885
4876 * tips.texi (Coding Conventions): Fix typo. 4886 * tips.texi (Coding Conventions): Fix typo.
4877 4887
diff --git a/lispref/keymaps.texi b/lispref/keymaps.texi
index 2e38514c00d..309664c38dd 100644
--- a/lispref/keymaps.texi
+++ b/lispref/keymaps.texi
@@ -576,6 +576,16 @@ keymap, and the global keymap, in that order. Emacs searches for each
576input key sequence in all these keymaps. @xref{Searching Keymaps}, 576input key sequence in all these keymaps. @xref{Searching Keymaps},
577for more details of this procedure. 577for more details of this procedure.
578 578
579This process is somewhat modified for mouse events: the local modes and
580keymaps of the buffer corresponding to the mouse click position are
581searched instead, text properties are taken from the mouse click
582position in the buffer rather than point, and if the click happens on a
583string embedded with a @code{display}, @code{before-string}, or
584@code{after-string} text property (@pxref{Special Properties}) or
585overlay property (@pxref{Overlay Properties}), any non-@code{nil} maps
586specified with text properties of this string are searched instead of
587those of the buffer.
588
579 The @dfn{global keymap} holds the bindings of keys that are defined 589 The @dfn{global keymap} holds the bindings of keys that are defined
580regardless of the current buffer, such as @kbd{C-f}. The variable 590regardless of the current buffer, such as @kbd{C-f}. The variable
581@code{global-map} holds this keymap, which is always active. 591@code{global-map} holds this keymap, which is always active.
@@ -632,25 +642,27 @@ Normally it ignores @code{overriding-local-map} and
632non-@code{nil} then it pays attention to them. 642non-@code{nil} then it pays attention to them.
633@end defun 643@end defun
634 644
635@defun key-binding key &optional accept-defaults no-remap 645@defun key-binding key &optional accept-defaults no-remap position
636This function returns the binding for @var{key} according to the 646This function returns the binding for @var{key} according to the current
637current active keymaps. The result is @code{nil} if @var{key} is 647active keymaps. The result is @code{nil} if @var{key} is undefined in
638undefined in the keymaps. 648the keymaps. If @var{key} is a key sequence started with the mouse, the
649consulted maps will be changed accordingly.
639 650
640@c Emacs 19 feature 651@c Emacs 19 feature
641The argument @var{accept-defaults} controls checking for default 652The argument @var{accept-defaults} controls checking for default
642bindings, as in @code{lookup-key} (above). 653bindings, as in @code{lookup-key} (above).
643 654
644When @var{key} is a vector containing an input event, such as a mouse
645click, @code{key-binding} first looks for the binding in the keymaps
646that would be active at the position where the click was done.
647
648When commands are remapped (@pxref{Remapping Commands}), 655When commands are remapped (@pxref{Remapping Commands}),
649@code{key-binding} normally processes command remappings so as to 656@code{key-binding} normally processes command remappings so as to
650returns the remapped command that will actually be executed. However, 657returns the remapped command that will actually be executed. However,
651if @var{no-remap} is non-@code{nil}, @code{key-binding} ignores 658if @var{no-remap} is non-@code{nil}, @code{key-binding} ignores
652remappings and returns the binding directly specified for @var{key}. 659remappings and returns the binding directly specified for @var{key}.
653 660
661If @var{position} is non-@code{nil}, it specifies either a buffer
662position or a position like those returned from @code{event-start}. In
663this case, @var{position} instead of @var{key} determines the
664click-specific maps.
665
654An error is signaled if @var{key} is not a string or a vector. 666An error is signaled if @var{key} is not a string or a vector.
655 667
656@example 668@example
@@ -674,21 +686,24 @@ them:
674 (@var{find-in} overriding-terminal-local-map) 686 (@var{find-in} overriding-terminal-local-map)
675 (if overriding-local-map 687 (if overriding-local-map
676 (@var{find-in} overriding-local-map) 688 (@var{find-in} overriding-local-map)
677 (or (@var{find-in} (get-text-property (point) 'keymap)) 689 (or (@var{find-in} (get-char-property (point) 'keymap))
678 (@var{find-in-any} emulation-mode-map-alists) 690 (@var{find-in-any} emulation-mode-map-alists)
679 (@var{find-in-any} minor-mode-overriding-map-alist) 691 (@var{find-in-any} minor-mode-overriding-map-alist)
680 (@var{find-in-any} minor-mode-map-alist) 692 (@var{find-in-any} minor-mode-map-alist)
681 (if (get-text-property (point) 'local-map) 693 (if (get-text-property (point) 'local-map)
682 (@var{find-in} (get-text-property (point) 'local-map)) 694 (@var{find-in} (get-char-property (point) 'local-map))
683 (@var{find-in} (current-local-map)))))) 695 (@var{find-in} (current-local-map))))))
684 (@var{find-in} (current-global-map))) 696 (@var{find-in} (current-global-map)))
685@end lisp 697@end lisp
686 698
687@noindent 699@noindent
688The @var{find-in} and @var{find-in-any} are pseudo functions that 700The @var{find-in} and @var{find-in-any} are pseudo functions that search
689search in one keymap and in an alist of keymaps, respectively. 701in one keymap and in an alist of keymaps, respectively. (Searching a
690(Searching a single keymap for a binding is called @dfn{key lookup}; 702single keymap for a binding is called @dfn{key lookup}; see @ref{Key
691see @ref{Key Lookup}.) 703Lookup}.) Mouse events on strings will use text properties from the
704string if non-@code{nil} instead of the buffer. Also, point and current
705buffer for mouse-based events are switched to correspond to the position
706of the event start while performing the lookup.
692 707
693@enumerate 708@enumerate
694@item 709@item
@@ -1450,11 +1465,13 @@ does not have the effect of remapping @code{kill-line} into
1450if an ordinary binding specifies @code{my-kill-line}, this keymap will 1465if an ordinary binding specifies @code{my-kill-line}, this keymap will
1451remap it to @code{my-other-kill-line}. 1466remap it to @code{my-other-kill-line}.
1452 1467
1453@defun command-remapping command 1468@defun command-remapping command &optional position
1454This function returns the remapping for @var{command} (a symbol), 1469This function returns the remapping for @var{command} (a symbol), given
1455given the current active keymaps. If @var{command} is not remapped 1470the current active keymaps. If @var{command} is not remapped (which is
1456(which is the usual situation), or not a symbol, the function returns 1471the usual situation), or not a symbol, the function returns @code{nil}.
1457@code{nil}. 1472@code{position} can optionally specify a buffer position or a position
1473like those returned from @code{event-start}: in that case, the active
1474maps are changed like they are in @code{key-binding}.
1458@end defun 1475@end defun
1459 1476
1460@node Translation Keymaps 1477@node Translation Keymaps
diff --git a/src/ChangeLog b/src/ChangeLog
index fbd2e8e38be..b6bbcb8401b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,25 @@
12006-09-15 David Kastrup <dak@gnu.org>
2
3 * Makefile.in (keymap.o): Add "keymap.h" and "window.h"
4 dependencies.
5
6 * keymap.c: include "window.h".
7 (Fcommand_remapping): New optional POSITION argument.
8 (Fkey_binding): New optional POSITION argument. Completely rework
9 handling of mouse clicks to get the same order of keymaps as
10 `read-key-sequence' and heed POSITION. Also temporarily switch
11 buffers to location of mouse click and back.
12
13 * keyboard.c (command_loop_1): Adjust call of `Fcommand_remapping'
14 for additional argument.
15 (parse_menu_item): Adjust call of `Fkey_binding' for additional
16 argument.
17 (read_key_sequence): If there are both `local-map' and `keymap'
18 text properties at some buffer position, heed both.
19
20 * keymap.h: Declare additional optional arguments of
21 `Fcommand_remapping' and `Fkey_binding'.
22
12006-09-15 Juanma Barranquero <lekktu@gmail.com> 232006-09-15 Juanma Barranquero <lekktu@gmail.com>
2 24
3 * indent.c (Fcurrent_column, Findent_to): Fix typos in docstring. 25 * indent.c (Fcurrent_column, Findent_to): Fix typos in docstring.
diff --git a/src/Makefile.in b/src/Makefile.in
index 0924e9df52b..af4cb816e18 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1146,7 +1146,8 @@ keyboard.o: keyboard.c termchar.h termhooks.h termopts.h buffer.h charset.h \
1146 systty.h systime.h dispextern.h syntax.h $(INTERVAL_SRC) blockinput.h \ 1146 systty.h systime.h dispextern.h syntax.h $(INTERVAL_SRC) blockinput.h \
1147 atimer.h xterm.h puresize.h msdos.h keymap.h w32term.h macterm.h $(config_h) 1147 atimer.h xterm.h puresize.h msdos.h keymap.h w32term.h macterm.h $(config_h)
1148keymap.o: keymap.c buffer.h commands.h keyboard.h termhooks.h blockinput.h \ 1148keymap.o: keymap.c buffer.h commands.h keyboard.h termhooks.h blockinput.h \
1149 atimer.h systime.h puresize.h charset.h intervals.h $(config_h) 1149 atimer.h systime.h puresize.h charset.h intervals.h keymap.h window.h \
1150 $(config_h)
1150lastfile.o: lastfile.c $(config_h) 1151lastfile.o: lastfile.c $(config_h)
1151macros.o: macros.c window.h buffer.h commands.h macros.h keyboard.h \ 1152macros.o: macros.c window.h buffer.h commands.h macros.h keyboard.h \
1152 dispextern.h $(config_h) 1153 dispextern.h $(config_h)
diff --git a/src/keyboard.c b/src/keyboard.c
index d6a74cf2196..8518bcb98c1 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1674,7 +1674,7 @@ command_loop_1 ()
1674 if (SYMBOLP (cmd)) 1674 if (SYMBOLP (cmd))
1675 { 1675 {
1676 Lisp_Object cmd1; 1676 Lisp_Object cmd1;
1677 if (cmd1 = Fcommand_remapping (cmd), !NILP (cmd1)) 1677 if (cmd1 = Fcommand_remapping (cmd, Qnil), !NILP (cmd1))
1678 cmd = cmd1; 1678 cmd = cmd1;
1679 } 1679 }
1680 1680
@@ -7517,7 +7517,7 @@ parse_menu_item (item, notreal, inmenubar)
7517 Lisp_Object prefix; 7517 Lisp_Object prefix;
7518 7518
7519 if (!NILP (tem)) 7519 if (!NILP (tem))
7520 tem = Fkey_binding (tem, Qnil, Qnil); 7520 tem = Fkey_binding (tem, Qnil, Qnil, Qnil);
7521 7521
7522 prefix = AREF (item_properties, ITEM_PROPERTY_KEYEQ); 7522 prefix = AREF (item_properties, ITEM_PROPERTY_KEYEQ);
7523 if (CONSP (prefix)) 7523 if (CONSP (prefix))
@@ -9134,16 +9134,19 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9134 if (!EQ (map_here, orig_local_map)) 9134 if (!EQ (map_here, orig_local_map))
9135 { 9135 {
9136 orig_local_map = map_here; 9136 orig_local_map = map_here;
9137 keybuf[t] = key; 9137 ++localized_local_map;
9138 mock_input = t + 1;
9139
9140 goto replay_sequence;
9141 } 9138 }
9139
9142 map_here = get_local_map (XINT (pos), 9140 map_here = get_local_map (XINT (pos),
9143 current_buffer, Qkeymap); 9141 current_buffer, Qkeymap);
9144 if (!EQ (map_here, orig_keymap)) 9142 if (!EQ (map_here, orig_keymap))
9145 { 9143 {
9146 orig_keymap = map_here; 9144 orig_keymap = map_here;
9145 ++localized_local_map;
9146 }
9147
9148 if (localized_local_map > 1)
9149 {
9147 keybuf[t] = key; 9150 keybuf[t] = key;
9148 mock_input = t + 1; 9151 mock_input = t + 1;
9149 9152
diff --git a/src/keymap.c b/src/keymap.c
index 8b99231a91d..45bcba9a5fc 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -33,6 +33,7 @@ Boston, MA 02110-1301, USA. */
33#include "puresize.h" 33#include "puresize.h"
34#include "intervals.h" 34#include "intervals.h"
35#include "keymap.h" 35#include "keymap.h"
36#include "window.h"
36 37
37/* The number of elements in keymap vectors. */ 38/* The number of elements in keymap vectors. */
38#define DENSE_TABLE_SIZE (0200) 39#define DENSE_TABLE_SIZE (0200)
@@ -1216,17 +1217,23 @@ binding KEY to DEF is added at the front of KEYMAP. */)
1216 1217
1217/* This function may GC (it calls Fkey_binding). */ 1218/* This function may GC (it calls Fkey_binding). */
1218 1219
1219DEFUN ("command-remapping", Fcommand_remapping, Scommand_remapping, 1, 1, 0, 1220DEFUN ("command-remapping", Fcommand_remapping, Scommand_remapping, 1, 2, 0,
1220 doc: /* Return the remapping for command COMMAND in current keymaps. 1221 doc: /* Return the remapping for command COMMAND in current keymaps.
1221Returns nil if COMMAND is not remapped (or not a symbol). */) 1222Returns nil if COMMAND is not remapped (or not a symbol).
1222 (command) 1223
1223 Lisp_Object command; 1224If the optional argument POSITION is non-nil, it specifies a mouse
1225position as returned by `event-start' and `event-end', and the
1226remapping occurs in the keymaps associated with it. It can also be a
1227number or marker, in which case the keymap properties at the specified
1228buffer position instead of point are used. */)
1229 (command, position)
1230 Lisp_Object command, position;
1224{ 1231{
1225 if (!SYMBOLP (command)) 1232 if (!SYMBOLP (command))
1226 return Qnil; 1233 return Qnil;
1227 1234
1228 ASET (command_remapping_vector, 1, command); 1235 ASET (command_remapping_vector, 1, command);
1229 return Fkey_binding (command_remapping_vector, Qnil, Qt); 1236 return Fkey_binding (command_remapping_vector, Qnil, Qt, position);
1230} 1237}
1231 1238
1232/* Value is number if KEY is too long; nil if valid but has no definition. */ 1239/* Value is number if KEY is too long; nil if valid but has no definition. */
@@ -1552,7 +1559,7 @@ OLP if non-nil indicates that we should obey `overriding-local-map' and
1552 1559
1553/* GC is possible in this function if it autoloads a keymap. */ 1560/* GC is possible in this function if it autoloads a keymap. */
1554 1561
1555DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 3, 0, 1562DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 4, 0,
1556 doc: /* Return the binding for command KEY in current keymaps. 1563 doc: /* Return the binding for command KEY in current keymaps.
1557KEY is a string or vector, a sequence of keystrokes. 1564KEY is a string or vector, a sequence of keystrokes.
1558The binding is probably a symbol with a function definition. 1565The binding is probably a symbol with a function definition.
@@ -1566,55 +1573,86 @@ recognize the default bindings, just as `read-key-sequence' does.
1566Like the normal command loop, `key-binding' will remap the command 1573Like the normal command loop, `key-binding' will remap the command
1567resulting from looking up KEY by looking up the command in the 1574resulting from looking up KEY by looking up the command in the
1568current keymaps. However, if the optional third argument NO-REMAP 1575current keymaps. However, if the optional third argument NO-REMAP
1569is non-nil, `key-binding' returns the unmapped command. */) 1576is non-nil, `key-binding' returns the unmapped command.
1570 (key, accept_default, no_remap) 1577
1571 Lisp_Object key, accept_default, no_remap; 1578If KEY is a key sequence initiated with the mouse, the used keymaps
1579will depend on the clicked mouse position with regard to the buffer
1580and possible local keymaps on strings.
1581
1582If the optional argument POSITION is non-nil, it specifies a mouse
1583position as returned by `event-start' and `event-end', and the lookup
1584occurs in the keymaps associated with it instead of KEY. It can also
1585be a number or marker, in which case the keymap properties at the
1586specified buffer position instead of point are used.
1587 */)
1588 (key, accept_default, no_remap, position)
1589 Lisp_Object key, accept_default, no_remap, position;
1572{ 1590{
1573 Lisp_Object *maps, value; 1591 Lisp_Object *maps, value;
1574 int nmaps, i; 1592 int nmaps, i;
1575 struct gcpro gcpro1; 1593 struct gcpro gcpro1, gcpro2;
1594 int count = SPECPDL_INDEX ();
1576 1595
1577 GCPRO1 (key); 1596 GCPRO2 (key, position);
1578 1597
1579#ifdef HAVE_MOUSE 1598 if (NILP (position))
1580 if (VECTORP (key) && ASIZE (key) > 0)
1581 { 1599 {
1582 Lisp_Object ev, pos; 1600 Lisp_Object event;
1583 if ((ev = AREF (key, 0), CONSP (ev)) 1601 /* mouse events may have a symbolic prefix indicating the
1584 && SYMBOLP (XCAR (ev)) 1602 scrollbar or mode line */
1585 && CONSP (XCDR (ev)) 1603 if (SYMBOLP (AREF (key, 0)) && ASIZE (key) > 1)
1586 && (pos = XCAR (XCDR (ev)), CONSP (pos)) 1604 event = AREF (key, 1);
1587 && XINT (Flength (pos)) == 10 1605 else
1588 && INTEGERP (XCAR (XCDR (pos)))) 1606 event = AREF (key, 0);
1589 {
1590 Lisp_Object map, object;
1591 1607
1592 object = Fnth (make_number(4), pos); 1608 /* We are not interested in locations without event data */
1593 1609
1594 if (CONSP (object)) 1610 if (EVENT_HAS_PARAMETERS (event)) {
1595 map = Fget_char_property (XCDR (object), Qkeymap, XCAR (object)); 1611 Lisp_Object kind;
1596 else
1597 map = Fget_char_property (XCAR (XCDR (pos)), Qkeymap,
1598 Fwindow_buffer (XCAR (pos)));
1599 1612
1600 if (!NILP (Fkeymapp (map))) 1613 kind = EVENT_HEAD_KIND (EVENT_HEAD (event));
1601 { 1614 if (EQ (kind, Qmouse_click))
1602 value = Flookup_key (map, key, accept_default); 1615 position = EVENT_START (event);
1603 if (! NILP (value) && !INTEGERP (value)) 1616 }
1604 goto done;
1605 }
1606 }
1607 } 1617 }
1608#endif /* HAVE_MOUSE */
1609 1618
1610 if (!NILP (current_kboard->Voverriding_terminal_local_map)) 1619 /* Key sequences beginning with mouse clicks
1620 are read using the keymaps of the buffer clicked on, not
1621 the current buffer. So we may have to switch the buffer
1622 here. */
1623
1624 if (CONSP (position))
1625 {
1626 Lisp_Object window;
1627
1628 window = POSN_WINDOW (position);
1629
1630 if (WINDOWP (window)
1631 && BUFFERP (XWINDOW (window)->buffer)
1632 && XBUFFER (XWINDOW (window)->buffer) != current_buffer)
1633 {
1634 /* Arrange to go back to the original buffer once we're done
1635 processing the key sequence. We don't use
1636 save_excursion_{save,restore} here, in analogy to
1637 `read-key-sequence' to avoid saving point. Maybe this
1638 would not be a problem here, but it is easier to keep
1639 things the same.
1640 */
1641
1642 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
1643
1644 set_buffer_internal (XBUFFER (XWINDOW (window)->buffer));
1645 }
1646 }
1647
1648 if (! NILP (current_kboard->Voverriding_terminal_local_map))
1611 { 1649 {
1612 value = Flookup_key (current_kboard->Voverriding_terminal_local_map, 1650 value = Flookup_key (current_kboard->Voverriding_terminal_local_map,
1613 key, accept_default); 1651 key, accept_default);
1614 if (! NILP (value) && !INTEGERP (value)) 1652 if (! NILP (value) && !INTEGERP (value))
1615 goto done; 1653 goto done;
1616 } 1654 }
1617 else if (!NILP (Voverriding_local_map)) 1655 else if (! NILP (Voverriding_local_map))
1618 { 1656 {
1619 value = Flookup_key (Voverriding_local_map, key, accept_default); 1657 value = Flookup_key (Voverriding_local_map, key, accept_default);
1620 if (! NILP (value) && !INTEGERP (value)) 1658 if (! NILP (value) && !INTEGERP (value))
@@ -1622,12 +1660,72 @@ is non-nil, `key-binding' returns the unmapped command. */)
1622 } 1660 }
1623 else 1661 else
1624 { 1662 {
1625 Lisp_Object local; 1663 Lisp_Object keymap, local_map;
1664 EMACS_INT pt;
1626 1665
1627 local = get_local_map (PT, current_buffer, Qkeymap); 1666 pt = INTEGERP (position) ? XINT (position)
1628 if (! NILP (local)) 1667 : MARKERP (position) ? marker_position (position)
1668 : PT;
1669
1670 local_map = get_local_map (pt, current_buffer, Qlocal_map);
1671 keymap = get_local_map (pt, current_buffer, Qkeymap);
1672
1673 if (CONSP (position))
1629 { 1674 {
1630 value = Flookup_key (local, key, accept_default); 1675 Lisp_Object string, window;
1676
1677 window = POSN_WINDOW (position);
1678
1679 /* For a mouse click, get the local text-property keymap
1680 of the place clicked on, rather than point. */
1681
1682 if (POSN_INBUFFER_P (position))
1683 {
1684 Lisp_Object pos;
1685
1686 pos = POSN_BUFFER_POSN (position);
1687 if (INTEGERP (pos)
1688 && XINT (pos) >= BEG && XINT (pos) <= Z)
1689 {
1690 local_map = get_local_map (XINT (pos),
1691 current_buffer, Qlocal_map);
1692
1693 keymap = get_local_map (XINT (pos),
1694 current_buffer, Qkeymap);
1695 }
1696 }
1697
1698 /* If on a mode line string with a local keymap,
1699 or for a click on a string, i.e. overlay string or a
1700 string displayed via the `display' property,
1701 consider `local-map' and `keymap' properties of
1702 that string. */
1703
1704 if (string = POSN_STRING (position),
1705 (CONSP (string) && STRINGP (XCAR (string))))
1706 {
1707 Lisp_Object pos, map;
1708
1709 pos = XCDR (string);
1710 string = XCAR (string);
1711 if (XINT (pos) >= 0
1712 && XINT (pos) < SCHARS (string))
1713 {
1714 map = Fget_text_property (pos, Qlocal_map, string);
1715 if (!NILP (map))
1716 local_map = map;
1717
1718 map = Fget_text_property (pos, Qkeymap, string);
1719 if (!NILP (map))
1720 keymap = map;
1721 }
1722 }
1723
1724 }
1725
1726 if (! NILP (keymap))
1727 {
1728 value = Flookup_key (keymap, key, accept_default);
1631 if (! NILP (value) && !INTEGERP (value)) 1729 if (! NILP (value) && !INTEGERP (value))
1632 goto done; 1730 goto done;
1633 } 1731 }
@@ -1644,10 +1742,9 @@ is non-nil, `key-binding' returns the unmapped command. */)
1644 goto done; 1742 goto done;
1645 } 1743 }
1646 1744
1647 local = get_local_map (PT, current_buffer, Qlocal_map); 1745 if (! NILP (local_map))
1648 if (! NILP (local))
1649 { 1746 {
1650 value = Flookup_key (local, key, accept_default); 1747 value = Flookup_key (local_map, key, accept_default);
1651 if (! NILP (value) && !INTEGERP (value)) 1748 if (! NILP (value) && !INTEGERP (value))
1652 goto done; 1749 goto done;
1653 } 1750 }
@@ -1656,6 +1753,8 @@ is non-nil, `key-binding' returns the unmapped command. */)
1656 value = Flookup_key (current_global_map, key, accept_default); 1753 value = Flookup_key (current_global_map, key, accept_default);
1657 1754
1658 done: 1755 done:
1756 unbind_to (count, Qnil);
1757
1659 UNGCPRO; 1758 UNGCPRO;
1660 if (NILP (value) || INTEGERP (value)) 1759 if (NILP (value) || INTEGERP (value))
1661 return Qnil; 1760 return Qnil;
@@ -1666,7 +1765,7 @@ is non-nil, `key-binding' returns the unmapped command. */)
1666 if (NILP (no_remap) && SYMBOLP (value)) 1765 if (NILP (no_remap) && SYMBOLP (value))
1667 { 1766 {
1668 Lisp_Object value1; 1767 Lisp_Object value1;
1669 if (value1 = Fcommand_remapping (value), !NILP (value1)) 1768 if (value1 = Fcommand_remapping (value, position), !NILP (value1))
1670 value = value1; 1769 value = value1;
1671 } 1770 }
1672 1771
@@ -2467,7 +2566,7 @@ where_is_internal (definition, keymaps, firstonly, noindirect, no_remap)
2467 if (NILP (no_remap) && SYMBOLP (definition)) 2566 if (NILP (no_remap) && SYMBOLP (definition))
2468 { 2567 {
2469 Lisp_Object tem; 2568 Lisp_Object tem;
2470 if (tem = Fcommand_remapping (definition), !NILP (tem)) 2569 if (tem = Fcommand_remapping (definition, Qnil), !NILP (tem))
2471 return Qnil; 2570 return Qnil;
2472 } 2571 }
2473 2572
diff --git a/src/keymap.h b/src/keymap.h
index cbd14cf9ba4..b11f630a1fb 100644
--- a/src/keymap.h
+++ b/src/keymap.h
@@ -29,8 +29,8 @@ EXFUN (Fmake_sparse_keymap, 1);
29EXFUN (Fkeymap_prompt, 1); 29EXFUN (Fkeymap_prompt, 1);
30EXFUN (Fdefine_key, 3); 30EXFUN (Fdefine_key, 3);
31EXFUN (Flookup_key, 3); 31EXFUN (Flookup_key, 3);
32EXFUN (Fcommand_remapping, 1); 32EXFUN (Fcommand_remapping, 2);
33EXFUN (Fkey_binding, 3); 33EXFUN (Fkey_binding, 4);
34EXFUN (Fkey_description, 2); 34EXFUN (Fkey_description, 2);
35EXFUN (Fsingle_key_description, 2); 35EXFUN (Fsingle_key_description, 2);
36EXFUN (Fwhere_is_internal, 5); 36EXFUN (Fwhere_is_internal, 5);