aboutsummaryrefslogtreecommitdiffstats
path: root/src/keymap.c
diff options
context:
space:
mode:
authorSpencer Baugh2025-09-26 18:13:30 -0400
committerEli Zaretskii2025-10-18 12:48:41 +0300
commitbea16dfe69fba7d3bbb7a67bcf60b3c4739aad7c (patch)
tree3d3ae3d45ee090ecdab3167d72f0b7c9f82156a2 /src/keymap.c
parent59da5020da703aae784ec8afeaa32348c6b6bfd5 (diff)
downloademacs-bea16dfe69fba7d3bbb7a67bcf60b3c4739aad7c.tar.gz
emacs-bea16dfe69fba7d3bbb7a67bcf60b3c4739aad7c.zip
Respect keymaps in buffer text for clicks on displayed strings
When clicking on a string displayed by a display property, also look at the text properties of the underlying buffer text for keymaps, not just the displayed string. The displayed string takes precedence over the buffer text, but it doesn't replace it. Also, we should use the buffer's local map even for clicks on the mode line. (Otherwise, what's the point of the <mode-line> event?) * src/keymap.c (Fcurrent_active_maps): Consider displayed string, then buffer text, then fall back to local map. (Bug#79505) * test/src/keymap-tests.el (keymap-test-keymaps-for-non-buffer-positions): Add more tests.
Diffstat (limited to 'src/keymap.c')
-rw-r--r--src/keymap.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/src/keymap.c b/src/keymap.c
index 295b209f06b..a01dee1476b 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -1721,33 +1721,12 @@ means to return the active maps for that window's buffer. */)
1721 /* For a mouse click, get the local text-property keymap 1721 /* For a mouse click, get the local text-property keymap
1722 of the place clicked on, rather than point. */ 1722 of the place clicked on, rather than point. */
1723 1723
1724 if (POSN_INBUFFER_P (position)) 1724 local_map = Qnil;
1725 { 1725 keymap = Qnil;
1726 Lisp_Object pos = POSN_BUFFER_POSN (position);
1727 if (FIXNUMP (pos)
1728 && XFIXNUM (pos) >= BEG && XFIXNUM (pos) <= Z)
1729 {
1730 local_map = get_local_map (XFIXNUM (pos),
1731 current_buffer, Qlocal_map);
1732
1733 keymap = get_local_map (XFIXNUM (pos),
1734 current_buffer, Qkeymap);
1735 }
1736 }
1737
1738 Lisp_Object pos_area = POSN_POSN (position);
1739 if (EQ (pos_area, Qmode_line) || EQ (pos_area, Qheader_line))
1740 {
1741 /* For clicks on mode line or header line, ignore the maps
1742 we found at POSITION, because properties at point are
1743 not relevant in that case. */
1744 local_map = Qnil;
1745 keymap = Qnil;
1746 }
1747 1726
1748 /* If on a mode line string with a local keymap, or for a 1727 /* If on a mode line string with a local keymap, or for a
1749 click on a string, i.e. overlay string or a string 1728 click on a string, i.e. overlay string or a string
1750 displayed via the `display' property, consider only the 1729 displayed via the `display' property, first consider the
1751 `local-map' and `keymap' properties of that string. */ 1730 `local-map' and `keymap' properties of that string. */
1752 1731
1753 if (CONSP (string) && STRINGP (XCAR (string))) 1732 if (CONSP (string) && STRINGP (XCAR (string)))
@@ -1763,6 +1742,26 @@ means to return the active maps for that window's buffer. */)
1763 } 1742 }
1764 } 1743 }
1765 1744
1745 Lisp_Object buffer_posn = POSN_BUFFER_POSN (position);
1746 /* Then, if the click was in the buffer, get the local
1747 text-property keymap of the place clicked on. */
1748
1749 if (FIXNUMP (buffer_posn)
1750 && XFIXNUM (buffer_posn) >= BEG && XFIXNUM (buffer_posn) <= Z)
1751 {
1752 /* The properties in POSN_STRING take precedence, if set. */
1753 if (NILP (local_map))
1754 local_map = get_local_map (XFIXNUM (buffer_posn),
1755 current_buffer, Qlocal_map);
1756
1757 if (NILP (keymap))
1758 keymap = get_local_map (XFIXNUM (buffer_posn),
1759 current_buffer, Qkeymap);
1760 }
1761
1762 /* Finally, fall back on the buffer's local map. */
1763 if (NILP (local_map))
1764 local_map = BVAR (current_buffer, keymap);
1766 } 1765 }
1767 1766
1768 if (!NILP (local_map)) 1767 if (!NILP (local_map))