2

I am trying to insert propertized text that is clickable like this:

(let ((buf (get-buffer-create "*test*")))
  (with-current-buffer buf
    (read-only-mode -1)
    (erase-buffer)
    (org-mode)
    (insert 
     (propertize "clickable"
         'font-lock-face '(:foreground "red")
         'keymap (let ((map (make-sparse-keymap)))
               (define-key map (kbd "<mouse-1>")
                 (lambda ()
                   (interactive)
                   (message-box "clicked")))
               map)
         'mouse-face 'highlight
         'help-echo "Bad key, click to replace."))
    (read-only-mode +1))

  (display-buffer-in-side-window buf '((side . right))))

However, The keymap and mouse-face properties seem to be lost and I only see these properties:

There are text properties here:
  font-lock-face       (:foreground "red")
  fontified            t
  help-echo            [Show]

[back]

Am I missing some critical thing that causes these to be stripped out?

2
  • Indeed, org-mode is the culprit. Thanks. Jul 26 at 19:03
  • I moved the comment to an answer.
    – Drew
    Jul 26 at 22:29
0

(Changing my comment to a (partial) answer, as comments can be deleted at any time.)

If you comment out the sexp (org-mode) then your initial code works (except for the red text, for which you'd need to use property face, not font-lock-face, or else define font-locking for your buffer).

Maybe check which part of Org mode is interfering.

0

This is a solution that works to make clickable text like I wanted.

(let ((buf (get-buffer-create "*test*")))
  (with-current-buffer buf
    (read-only-mode -1)
    (erase-buffer)
    (org-mode)
    (insert-button "clickable" 'face '(:foreground "red")
           'keymap (let ((map (make-sparse-keymap)))
                 (define-key map (kbd "<mouse-1>")
                   (lambda ()
                 (interactive)
                 (message-box "clicked")))
                 map)
           'mouse-face 'highlight
           'help-echo "Bad key, click to replace.")

    (read-only-mode +1))
  (add-text-properties (point-min) (point-max) '(mouse-face highlight))
  (display-buffer-in-side-window buf '((side . right))))

I am still not sure why the keymap and mouse-face properties get stripped in the original question though.

I guess the difference is this uses an overlay. If I use insert-text-button it also does not work as desired.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.