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)))))