2

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

Example Example

lawlist
  • 18,826
  • 5
  • 37
  • 118

1 Answers1

1

It doesn't. I did M-x test in a new buffer, and saw hello-world got inserted. There are no text properties on the hyphen.

Perhaps you are not showing all your code or describing the context from the beginning.

And why are you using describe-key? And what key do you hit after RET - that key will be described.

Try C-u C-x = instead, with point before the hyphen.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • Thank you for taking a look at this thread. Even though there are no text properties on the hyphen, pressing the return key on the hyphen is triggering the function `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 using `C-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?) with `follow-link` internally that looks at the preceding or subsequent point? – lawlist Jun 29 '15 at 01:30
  • I edited the question to reflect that my testing included: `M-x describe-key RET RET` – lawlist Jun 29 '15 at 01:38
  • 1
    Looks like a bug, to me. Same thing is true if you insert a char after `world` and you hit `RET` before that char (but not if you insert another and hit `RET` 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:41
  • The same is true in Emacs 22, BTW. Perhaps this is intentional, but in that case the doc should mention it (e.g. specifically for any properties such as `keymap` that it applies to). – Drew Jun 29 '15 at 01:51
  • A workaround may be to place a dummy keymap at that location -- e.g., `(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