comparison src/keymap.c @ 90602:b5c13d1564a9

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 437-446) - Update from CVS - lisp/url/url-methods.el: Fix format error when http_proxy is empty string - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 137-140) - Update from CVS Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-111
author Miles Bader <miles@gnu.org>
date Wed, 20 Sep 2006 06:04:23 +0000
parents a1a25ac6c88a f9742f561ed9
children bb0e318b7c53
comparison
equal deleted inserted replaced
90601:a1a25ac6c88a 90602:b5c13d1564a9
21 Boston, MA 02110-1301, USA. */ 21 Boston, MA 02110-1301, USA. */
22 22
23 23
24 #include <config.h> 24 #include <config.h>
25 #include <stdio.h> 25 #include <stdio.h>
26 #if HAVE_ALLOCA_H
27 # include <alloca.h>
28 #endif
26 #include "lisp.h" 29 #include "lisp.h"
27 #include "commands.h" 30 #include "commands.h"
28 #include "buffer.h" 31 #include "buffer.h"
29 #include "character.h" 32 #include "character.h"
30 #include "charset.h" 33 #include "charset.h"
32 #include "termhooks.h" 35 #include "termhooks.h"
33 #include "blockinput.h" 36 #include "blockinput.h"
34 #include "puresize.h" 37 #include "puresize.h"
35 #include "intervals.h" 38 #include "intervals.h"
36 #include "keymap.h" 39 #include "keymap.h"
40 #include "window.h"
37 41
38 /* The number of elements in keymap vectors. */ 42 /* The number of elements in keymap vectors. */
39 #define DENSE_TABLE_SIZE (0200) 43 #define DENSE_TABLE_SIZE (0200)
40 44
41 /* Actually allocate storage for these variables */ 45 /* Actually allocate storage for these variables */
1247 } 1251 }
1248 } 1252 }
1249 1253
1250 /* This function may GC (it calls Fkey_binding). */ 1254 /* This function may GC (it calls Fkey_binding). */
1251 1255
1252 DEFUN ("command-remapping", Fcommand_remapping, Scommand_remapping, 1, 1, 0, 1256 DEFUN ("command-remapping", Fcommand_remapping, Scommand_remapping, 1, 2, 0,
1253 doc: /* Return the remapping for command COMMAND in current keymaps. 1257 doc: /* Return the remapping for command COMMAND in current keymaps.
1254 Returns nil if COMMAND is not remapped (or not a symbol). */) 1258 Returns nil if COMMAND is not remapped (or not a symbol).
1255 (command) 1259
1256 Lisp_Object command; 1260 If the optional argument POSITION is non-nil, it specifies a mouse
1261 position as returned by `event-start' and `event-end', and the
1262 remapping occurs in the keymaps associated with it. It can also be a
1263 number or marker, in which case the keymap properties at the specified
1264 buffer position instead of point are used. */)
1265 (command, position)
1266 Lisp_Object command, position;
1257 { 1267 {
1258 if (!SYMBOLP (command)) 1268 if (!SYMBOLP (command))
1259 return Qnil; 1269 return Qnil;
1260 1270
1261 ASET (command_remapping_vector, 1, command); 1271 ASET (command_remapping_vector, 1, command);
1262 return Fkey_binding (command_remapping_vector, Qnil, Qt); 1272 return Fkey_binding (command_remapping_vector, Qnil, Qt, position);
1263 } 1273 }
1264 1274
1265 /* Value is number if KEY is too long; nil if valid but has no definition. */ 1275 /* Value is number if KEY is too long; nil if valid but has no definition. */
1266 /* GC is possible in this function if it autoloads a keymap. */ 1276 /* GC is possible in this function if it autoloads a keymap. */
1267 1277
1583 return keymaps; 1593 return keymaps;
1584 } 1594 }
1585 1595
1586 /* GC is possible in this function if it autoloads a keymap. */ 1596 /* GC is possible in this function if it autoloads a keymap. */
1587 1597
1588 DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 3, 0, 1598 DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 4, 0,
1589 doc: /* Return the binding for command KEY in current keymaps. 1599 doc: /* Return the binding for command KEY in current keymaps.
1590 KEY is a string or vector, a sequence of keystrokes. 1600 KEY is a string or vector, a sequence of keystrokes.
1591 The binding is probably a symbol with a function definition. 1601 The binding is probably a symbol with a function definition.
1592 1602
1593 Normally, `key-binding' ignores bindings for t, which act as default 1603 Normally, `key-binding' ignores bindings for t, which act as default
1597 recognize the default bindings, just as `read-key-sequence' does. 1607 recognize the default bindings, just as `read-key-sequence' does.
1598 1608
1599 Like the normal command loop, `key-binding' will remap the command 1609 Like the normal command loop, `key-binding' will remap the command
1600 resulting from looking up KEY by looking up the command in the 1610 resulting from looking up KEY by looking up the command in the
1601 current keymaps. However, if the optional third argument NO-REMAP 1611 current keymaps. However, if the optional third argument NO-REMAP
1602 is non-nil, `key-binding' returns the unmapped command. */) 1612 is non-nil, `key-binding' returns the unmapped command.
1603 (key, accept_default, no_remap) 1613
1604 Lisp_Object key, accept_default, no_remap; 1614 If KEY is a key sequence initiated with the mouse, the used keymaps
1615 will depend on the clicked mouse position with regard to the buffer
1616 and possible local keymaps on strings.
1617
1618 If the optional argument POSITION is non-nil, it specifies a mouse
1619 position as returned by `event-start' and `event-end', and the lookup
1620 occurs in the keymaps associated with it instead of KEY. It can also
1621 be a number or marker, in which case the keymap properties at the
1622 specified buffer position instead of point are used.
1623 */)
1624 (key, accept_default, no_remap, position)
1625 Lisp_Object key, accept_default, no_remap, position;
1605 { 1626 {
1606 Lisp_Object *maps, value; 1627 Lisp_Object *maps, value;
1607 int nmaps, i; 1628 int nmaps, i;
1608 struct gcpro gcpro1; 1629 struct gcpro gcpro1, gcpro2;
1609 1630 int count = SPECPDL_INDEX ();
1610 GCPRO1 (key); 1631
1611 1632 GCPRO2 (key, position);
1612 #ifdef HAVE_MOUSE 1633
1613 if (VECTORP (key) && ASIZE (key) > 0) 1634 if (NILP (position) && VECTORP (key))
1614 { 1635 {
1615 Lisp_Object ev, pos; 1636 Lisp_Object event
1616 if ((ev = AREF (key, 0), CONSP (ev)) 1637 /* mouse events may have a symbolic prefix indicating the
1617 && SYMBOLP (XCAR (ev)) 1638 scrollbar or mode line */
1618 && CONSP (XCDR (ev)) 1639 = AREF (key, SYMBOLP (AREF (key, 0)) && ASIZE (key) > 1 ? 1 : 0);
1619 && (pos = XCAR (XCDR (ev)), CONSP (pos)) 1640
1620 && XINT (Flength (pos)) == 10 1641 /* We are not interested in locations without event data */
1621 && INTEGERP (XCAR (XCDR (pos)))) 1642
1622 { 1643 if (EVENT_HAS_PARAMETERS (event)) {
1623 Lisp_Object map, object; 1644 Lisp_Object kind;
1624 1645
1625 object = Fnth (make_number(4), pos); 1646 kind = EVENT_HEAD_KIND (EVENT_HEAD (event));
1626 1647 if (EQ (kind, Qmouse_click))
1627 if (CONSP (object)) 1648 position = EVENT_START (event);
1628 map = Fget_char_property (XCDR (object), Qkeymap, XCAR (object)); 1649 }
1629 else 1650 }
1630 map = Fget_char_property (XCAR (XCDR (pos)), Qkeymap, 1651
1631 Fwindow_buffer (XCAR (pos))); 1652 /* Key sequences beginning with mouse clicks
1632 1653 are read using the keymaps of the buffer clicked on, not
1633 if (!NILP (Fkeymapp (map))) 1654 the current buffer. So we may have to switch the buffer
1634 { 1655 here. */
1635 value = Flookup_key (map, key, accept_default); 1656
1636 if (! NILP (value) && !INTEGERP (value)) 1657 if (CONSP (position))
1637 goto done; 1658 {
1638 } 1659 Lisp_Object window;
1639 } 1660
1640 } 1661 window = POSN_WINDOW (position);
1641 #endif /* HAVE_MOUSE */ 1662
1642 1663 if (WINDOWP (window)
1643 if (!NILP (current_kboard->Voverriding_terminal_local_map)) 1664 && BUFFERP (XWINDOW (window)->buffer)
1665 && XBUFFER (XWINDOW (window)->buffer) != current_buffer)
1666 {
1667 /* Arrange to go back to the original buffer once we're done
1668 processing the key sequence. We don't use
1669 save_excursion_{save,restore} here, in analogy to
1670 `read-key-sequence' to avoid saving point. Maybe this
1671 would not be a problem here, but it is easier to keep
1672 things the same.
1673 */
1674
1675 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
1676
1677 set_buffer_internal (XBUFFER (XWINDOW (window)->buffer));
1678 }
1679 }
1680
1681 if (! NILP (current_kboard->Voverriding_terminal_local_map))
1644 { 1682 {
1645 value = Flookup_key (current_kboard->Voverriding_terminal_local_map, 1683 value = Flookup_key (current_kboard->Voverriding_terminal_local_map,
1646 key, accept_default); 1684 key, accept_default);
1647 if (! NILP (value) && !INTEGERP (value)) 1685 if (! NILP (value) && !INTEGERP (value))
1648 goto done; 1686 goto done;
1649 } 1687 }
1650 else if (!NILP (Voverriding_local_map)) 1688 else if (! NILP (Voverriding_local_map))
1651 { 1689 {
1652 value = Flookup_key (Voverriding_local_map, key, accept_default); 1690 value = Flookup_key (Voverriding_local_map, key, accept_default);
1653 if (! NILP (value) && !INTEGERP (value)) 1691 if (! NILP (value) && !INTEGERP (value))
1654 goto done; 1692 goto done;
1655 } 1693 }
1656 else 1694 else
1657 { 1695 {
1658 Lisp_Object local; 1696 Lisp_Object keymap, local_map;
1659 1697 EMACS_INT pt;
1660 local = get_local_map (PT, current_buffer, Qkeymap); 1698
1661 if (! NILP (local)) 1699 pt = INTEGERP (position) ? XINT (position)
1662 { 1700 : MARKERP (position) ? marker_position (position)
1663 value = Flookup_key (local, key, accept_default); 1701 : PT;
1702
1703 local_map = get_local_map (pt, current_buffer, Qlocal_map);
1704 keymap = get_local_map (pt, current_buffer, Qkeymap);
1705
1706 if (CONSP (position))
1707 {
1708 Lisp_Object string;
1709
1710 /* For a mouse click, get the local text-property keymap
1711 of the place clicked on, rather than point. */
1712
1713 if (POSN_INBUFFER_P (position))
1714 {
1715 Lisp_Object pos;
1716
1717 pos = POSN_BUFFER_POSN (position);
1718 if (INTEGERP (pos)
1719 && XINT (pos) >= BEG && XINT (pos) <= Z)
1720 {
1721 local_map = get_local_map (XINT (pos),
1722 current_buffer, Qlocal_map);
1723
1724 keymap = get_local_map (XINT (pos),
1725 current_buffer, Qkeymap);
1726 }
1727 }
1728
1729 /* If on a mode line string with a local keymap,
1730 or for a click on a string, i.e. overlay string or a
1731 string displayed via the `display' property,
1732 consider `local-map' and `keymap' properties of
1733 that string. */
1734
1735 if (string = POSN_STRING (position),
1736 (CONSP (string) && STRINGP (XCAR (string))))
1737 {
1738 Lisp_Object pos, map;
1739
1740 pos = XCDR (string);
1741 string = XCAR (string);
1742 if (XINT (pos) >= 0
1743 && XINT (pos) < SCHARS (string))
1744 {
1745 map = Fget_text_property (pos, Qlocal_map, string);
1746 if (!NILP (map))
1747 local_map = map;
1748
1749 map = Fget_text_property (pos, Qkeymap, string);
1750 if (!NILP (map))
1751 keymap = map;
1752 }
1753 }
1754
1755 }
1756
1757 if (! NILP (keymap))
1758 {
1759 value = Flookup_key (keymap, key, accept_default);
1664 if (! NILP (value) && !INTEGERP (value)) 1760 if (! NILP (value) && !INTEGERP (value))
1665 goto done; 1761 goto done;
1666 } 1762 }
1667 1763
1668 nmaps = current_minor_maps (0, &maps); 1764 nmaps = current_minor_maps (0, &maps);
1675 value = Flookup_key (maps[i], key, accept_default); 1771 value = Flookup_key (maps[i], key, accept_default);
1676 if (! NILP (value) && !INTEGERP (value)) 1772 if (! NILP (value) && !INTEGERP (value))
1677 goto done; 1773 goto done;
1678 } 1774 }
1679 1775
1680 local = get_local_map (PT, current_buffer, Qlocal_map); 1776 if (! NILP (local_map))
1681 if (! NILP (local)) 1777 {
1682 { 1778 value = Flookup_key (local_map, key, accept_default);
1683 value = Flookup_key (local, key, accept_default);
1684 if (! NILP (value) && !INTEGERP (value)) 1779 if (! NILP (value) && !INTEGERP (value))
1685 goto done; 1780 goto done;
1686 } 1781 }
1687 } 1782 }
1688 1783
1689 value = Flookup_key (current_global_map, key, accept_default); 1784 value = Flookup_key (current_global_map, key, accept_default);
1690 1785
1691 done: 1786 done:
1787 unbind_to (count, Qnil);
1788
1692 UNGCPRO; 1789 UNGCPRO;
1693 if (NILP (value) || INTEGERP (value)) 1790 if (NILP (value) || INTEGERP (value))
1694 return Qnil; 1791 return Qnil;
1695 1792
1696 /* If the result of the ordinary keymap lookup is an interactive 1793 /* If the result of the ordinary keymap lookup is an interactive
1697 command, look for a key binding (ie. remapping) for that command. */ 1794 command, look for a key binding (ie. remapping) for that command. */
1698 1795
1699 if (NILP (no_remap) && SYMBOLP (value)) 1796 if (NILP (no_remap) && SYMBOLP (value))
1700 { 1797 {
1701 Lisp_Object value1; 1798 Lisp_Object value1;
1702 if (value1 = Fcommand_remapping (value), !NILP (value1)) 1799 if (value1 = Fcommand_remapping (value, position), !NILP (value1))
1703 value = value1; 1800 value = value1;
1704 } 1801 }
1705 1802
1706 return value; 1803 return value;
1707 } 1804 }
2447 /* If this command is remapped, then it has no key bindings 2544 /* If this command is remapped, then it has no key bindings
2448 of its own. */ 2545 of its own. */
2449 if (NILP (no_remap) && SYMBOLP (definition)) 2546 if (NILP (no_remap) && SYMBOLP (definition))
2450 { 2547 {
2451 Lisp_Object tem; 2548 Lisp_Object tem;
2452 if (tem = Fcommand_remapping (definition), !NILP (tem)) 2549 if (tem = Fcommand_remapping (definition, Qnil), !NILP (tem))
2453 return Qnil; 2550 return Qnil;
2454 } 2551 }
2455 2552
2456 found = keymaps; 2553 found = keymaps;
2457 while (CONSP (found)) 2554 while (CONSP (found))