Q: Why does there appear to be a keymap
on the hyphen of hello-world in the following example?
GOAL: Place text properties before the hyphen and after the hyphen -- without any keymap being placed on the hyphen itself.
Background: The following example has been constructed to place text properties only on the word "hello" and the word "world". As far as I can tell, the hyphen between "hello" and "world" should not have any text properties. Yet when I place the cursor at the hyphen and type M-x describe-key RET RET
, I see that it is linked to my-follow-link
from my-mouse-map
.
(defvar my-mouse-map
(let ((map (make-sparse-keymap)))
(define-key map [mouse-2] 'my-follow-link)
(define-key map [return] 'my-follow-link)
(define-key map [follow-link] 'mouse-face)
map)
"Keymap for mouse when in `my-mode'.")
;; Author: Drew Adams -- http://emacs.stackexchange.com/a/13411/2287
;; Modified by @lawlist for purposes of testing different scenarios.
(defun my-follow-link (event)
"Doc-string."
(interactive (list last-nonmenu-event))
(run-hooks 'mouse-leave-buffer-hook)
(with-current-buffer (window-buffer (posn-window (event-start event)))
(let ((foo (get-text-property (posn-point (event-start event)) 'test)))
(message "%s" foo))))
(defun test ()
(interactive)
(fundamental-mode)
(let* (beg end)
(save-excursion
(goto-char (point-min))
(setq beg (point))
(insert "hello")
(setq end (point))
(add-text-properties beg end (list
'test "This is my first half of the test."
'face '(:foreground "cyan" :weight bold)
'mouse-face '(:foreground "red" :weight bold)
'help-echo "mouse-2, RET: My first message."
'keymap my-mouse-map))
(insert "-")
(setq beg (point))
(insert "world")
(setq end (point))
(add-text-properties beg end (list
'test "This is my seond half of the test."
'face '(:foreground "orange" :weight bold)
'mouse-face '(:foreground "blue" :weight bold)
'help-echo "mouse-2, RET: My second message."
'keymap my-mouse-map)))))
my-follow-link
. As far as I can tell it should not be triggering that function, yet it is. All of the code is included. The second screen shot was made usingC-u C-x =
-- it shows there are no text properties, yet Emacs treats that point as having a keymap at that location. Perhaps there is something wrong (a bug?) withfollow-link
internally that looks at the preceding or subsequent point? – lawlist Jun 29 '15 at 01:30M-x describe-key RET RET
– lawlist Jun 29 '15 at 01:38world
and you hitRET
before that char (but not if you insert another and hitRET
before it).insert
is supposed not to have properties inherit, so rear stickiness should not be a problem. Unless someone gives you a good explanation, consider reporting this as a bug. – Drew Jun 29 '15 at 01:41keymap
that it applies to). – Drew Jun 29 '15 at 01:51(put-text-property (point) (1+ (point)) 'keymap 'dummy)
-- so that the buffer default (global or buffer-local keymaps) work again. – lawlist Jun 29 '15 at 02:11