comparison src/keymap.c @ 81609:7e640eac2dcb

* keymaps.texi (Active Keymaps): Document new POSITION argument of `current-active-maps'. * keymap.c (Fcurrent_active_maps): Add `position' argument. (Fwhere_is_internal): Adjust call to `current-active-maps' to cater for additional parameter. * keymap.h: Adjust number of parameters to `current-active-maps'. * doc.c (Fsubstitute_command_keys): Adjust call of `current-active-maps'.
author David Kastrup <dak@gnu.org>
date Mon, 25 Jun 2007 20:53:48 +0000
parents 323c37a99c44
children 4ee4f467ca51 988f1edc9674
comparison
equal deleted inserted replaced
81608:75c51005f057 81609:7e640eac2dcb
1539 if (mapptr) *mapptr = cmm_maps; 1539 if (mapptr) *mapptr = cmm_maps;
1540 return i; 1540 return i;
1541 } 1541 }
1542 1542
1543 DEFUN ("current-active-maps", Fcurrent_active_maps, Scurrent_active_maps, 1543 DEFUN ("current-active-maps", Fcurrent_active_maps, Scurrent_active_maps,
1544 0, 1, 0, 1544 0, 2, 0,
1545 doc: /* Return a list of the currently active keymaps. 1545 doc: /* Return a list of the currently active keymaps.
1546 OLP if non-nil indicates that we should obey `overriding-local-map' and 1546 OLP if non-nil indicates that we should obey `overriding-local-map' and
1547 `overriding-terminal-local-map'. */) 1547 `overriding-terminal-local-map'. POSITION can specify a click position
1548 (olp) 1548 like in the respective argument of `key-binding'. */)
1549 Lisp_Object olp; 1549 (olp, position)
1550 { 1550 Lisp_Object olp, position;
1551 Lisp_Object keymaps = Fcons (current_global_map, Qnil); 1551 {
1552 int count = SPECPDL_INDEX ();
1553
1554 Lisp_Object keymaps;
1555
1556 /* If a mouse click position is given, our variables are based on
1557 the buffer clicked on, not the current buffer. So we may have to
1558 switch the buffer here. */
1559
1560 if (CONSP (position))
1561 {
1562 Lisp_Object window;
1563
1564 window = POSN_WINDOW (position);
1565
1566 if (WINDOWP (window)
1567 && BUFFERP (XWINDOW (window)->buffer)
1568 && XBUFFER (XWINDOW (window)->buffer) != current_buffer)
1569 {
1570 /* Arrange to go back to the original buffer once we're done
1571 processing the key sequence. We don't use
1572 save_excursion_{save,restore} here, in analogy to
1573 `read-key-sequence' to avoid saving point. Maybe this
1574 would not be a problem here, but it is easier to keep
1575 things the same.
1576 */
1577
1578 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
1579
1580 set_buffer_internal (XBUFFER (XWINDOW (window)->buffer));
1581 }
1582 }
1583
1584 keymaps = Fcons (current_global_map, Qnil);
1552 1585
1553 if (!NILP (olp)) 1586 if (!NILP (olp))
1554 { 1587 {
1555 if (!NILP (current_kboard->Voverriding_terminal_local_map)) 1588 if (!NILP (current_kboard->Voverriding_terminal_local_map))
1556 keymaps = Fcons (current_kboard->Voverriding_terminal_local_map, keymaps); 1589 keymaps = Fcons (current_kboard->Voverriding_terminal_local_map, keymaps);
1560 else if (!NILP (Voverriding_local_map)) 1593 else if (!NILP (Voverriding_local_map))
1561 keymaps = Fcons (Voverriding_local_map, keymaps); 1594 keymaps = Fcons (Voverriding_local_map, keymaps);
1562 } 1595 }
1563 if (NILP (XCDR (keymaps))) 1596 if (NILP (XCDR (keymaps)))
1564 { 1597 {
1565 Lisp_Object local;
1566 Lisp_Object *maps; 1598 Lisp_Object *maps;
1567 int nmaps, i; 1599 int nmaps, i;
1568 1600
1569 /* This usually returns the buffer's local map, 1601 Lisp_Object keymap, local_map;
1570 but that can be overridden by a `local-map' property. */ 1602 EMACS_INT pt;
1571 local = get_local_map (PT, current_buffer, Qlocal_map); 1603
1572 if (!NILP (local)) 1604 pt = INTEGERP (position) ? XINT (position)
1573 keymaps = Fcons (local, keymaps); 1605 : MARKERP (position) ? marker_position (position)
1606 : PT;
1607
1608 /* Get the buffer local maps, possibly overriden by text or
1609 overlay properties */
1610
1611 local_map = get_local_map (pt, current_buffer, Qlocal_map);
1612 keymap = get_local_map (pt, current_buffer, Qkeymap);
1613
1614 if (CONSP (position))
1615 {
1616 Lisp_Object string;
1617
1618 /* For a mouse click, get the local text-property keymap
1619 of the place clicked on, rather than point. */
1620
1621 if (POSN_INBUFFER_P (position))
1622 {
1623 Lisp_Object pos;
1624
1625 pos = POSN_BUFFER_POSN (position);
1626 if (INTEGERP (pos)
1627 && XINT (pos) >= BEG && XINT (pos) <= Z)
1628 {
1629 local_map = get_local_map (XINT (pos),
1630 current_buffer, Qlocal_map);
1631
1632 keymap = get_local_map (XINT (pos),
1633 current_buffer, Qkeymap);
1634 }
1635 }
1636
1637 /* If on a mode line string with a local keymap,
1638 or for a click on a string, i.e. overlay string or a
1639 string displayed via the `display' property,
1640 consider `local-map' and `keymap' properties of
1641 that string. */
1642
1643 if (string = POSN_STRING (position),
1644 (CONSP (string) && STRINGP (XCAR (string))))
1645 {
1646 Lisp_Object pos, map;
1647
1648 pos = XCDR (string);
1649 string = XCAR (string);
1650 if (INTEGERP (pos)
1651 && XINT (pos) >= 0
1652 && XINT (pos) < SCHARS (string))
1653 {
1654 map = Fget_text_property (pos, Qlocal_map, string);
1655 if (!NILP (map))
1656 local_map = map;
1657
1658 map = Fget_text_property (pos, Qkeymap, string);
1659 if (!NILP (map))
1660 keymap = map;
1661 }
1662 }
1663
1664 }
1665
1666 if (!NILP (local_map))
1667 keymaps = Fcons (local_map, keymaps);
1574 1668
1575 /* Now put all the minor mode keymaps on the list. */ 1669 /* Now put all the minor mode keymaps on the list. */
1576 nmaps = current_minor_maps (0, &maps); 1670 nmaps = current_minor_maps (0, &maps);
1577 1671
1578 for (i = --nmaps; i >= 0; i--) 1672 for (i = --nmaps; i >= 0; i--)
1579 if (!NILP (maps[i])) 1673 if (!NILP (maps[i]))
1580 keymaps = Fcons (maps[i], keymaps); 1674 keymaps = Fcons (maps[i], keymaps);
1581 1675
1582 /* This returns nil unless there is a `keymap' property. */ 1676 if (!NILP (keymap))
1583 local = get_local_map (PT, current_buffer, Qkeymap); 1677 keymaps = Fcons (keymap, keymaps);
1584 if (!NILP (local)) 1678 }
1585 keymaps = Fcons (local, keymaps); 1679
1586 } 1680 unbind_to (count, Qnil);
1587 1681
1588 return keymaps; 1682 return keymaps;
1589 } 1683 }
1590 1684
1591 /* GC is possible in this function if it autoloads a keymap. */ 1685 /* GC is possible in this function if it autoloads a keymap. */
2840 if (CONSP (keymap) && KEYMAPP (XCAR (keymap))) 2934 if (CONSP (keymap) && KEYMAPP (XCAR (keymap)))
2841 keymaps = keymap; 2935 keymaps = keymap;
2842 else if (!NILP (keymap)) 2936 else if (!NILP (keymap))
2843 keymaps = Fcons (keymap, Fcons (current_global_map, Qnil)); 2937 keymaps = Fcons (keymap, Fcons (current_global_map, Qnil));
2844 else 2938 else
2845 keymaps = Fcurrent_active_maps (Qnil); 2939 keymaps = Fcurrent_active_maps (Qnil, Qnil);
2846 2940
2847 /* Only use caching for the menubar (i.e. called with (def nil t nil). 2941 /* Only use caching for the menubar (i.e. called with (def nil t nil).
2848 We don't really need to check `keymap'. */ 2942 We don't really need to check `keymap'. */
2849 if (nomenus && NILP (noindirect) && NILP (keymap)) 2943 if (nomenus && NILP (noindirect) && NILP (keymap))
2850 { 2944 {