Closed agenbite closed 2 years ago
I've tried this:
(link-hint-define-type 'notmuch-show
:next #'link-hint--next-widget-button
:at-point-p #'link-hint--widget-button-at-point-p
:vars '(notmuch-tree-mode)
:open #'widget-button-press
:copy #'link-hint--copy-widget)
(push 'link-hint-notmuch-show link-hint-types)
But it didn't work... :(
I don't use notmuch myself and don't know what these buttons are or how they are implemented. Could you post the result of (text-properties-at (point))
with the point on one of these buttons? Normally buttons have a button
property; there is a generic button handler, so these must be implemented differently. If I have time at some point, I can try to set up notmuch and take a look.
Thanks! This is the result of the text-properties command over an attachment button:
Text content at position 275:
Here is a ‘notmuch-show-part-button-type’ button labeled ‘[ 2021 TRF-RIED_R1_mm.pdf: application/pdf ]’.
There are 4 overlays here:
From 109 to 1055
invisible nil
From 223 to 1055
From 273 to 319
face hl-line
priority -50
window [Show]
From 274 to 318
:base-label "2021 TRF-RIED_R1_mm.pdf: application/pdf"
:notmuch-part-hidden nil
button [Show]
category notmuch-show-part-button-type-button
There are text properties here:
:notmuch-message-extent [Show]
:notmuch-part [Show]
fontified t
front-sticky (:notmuch-part)
rear-nonsticky (:notmuch-part)
[back]
And this is over a part button:
Text content at position 205:
Here is a ‘notmuch-show-part-button-type’ button labeled ‘[ multipart/mixed ]’.
There are 3 overlays here:
From 109 to 1055
invisible nil
From 203 to 222
:base-label "multipart/mixed"
:notmuch-part-hidden nil
button [Show]
category notmuch-show-part-button-type-button
overlay [Show]
From 203 to 223
face hl-line
priority -50
window [Show]
There are text properties here:
:notmuch-message-extent [Show]
:notmuch-part [Show]
fontified t
front-sticky (:notmuch-part)
rear-nonsticky (:notmuch-part)
[back]
If you're so kind as to point me in the right direction I can try to solve the puzzle myself. I thought that the fact that they're buttons should make them work out of the box, but they don't. So I'm at a lost.
Ok, this sort of works:
;; ** notmuch-show links and buttons
(defun link-hint--notmuch-button-at-point-p ()
"Return point of the button at the point or nil."
(when (get-char-property (point) 'button) (point)))
(defun link-hint--notmuch-next-button (&optional bound)
"Return pos of the next button up to BOUND."
(let ((start (point)))
(save-excursion
(forward-button 1)
(while (not (link-hint--notmuch-button-at-point-p))
(forward-button 1))
(when (and (link-hint--notmuch-button-at-point-p)
(> (point) start)
(< (point) bound))
(point)))))
(link-hint-define-type 'notmuch-show
:next #'link-hint--notmuch-next-button
:at-point-p #'link-hint--notmuch-button-at-point-p
:vars '(notmuch-show-mode)
:open #'push-button)
However, it works just once: if I call the same function again, it says "No more buttons!" I believe this has to do with the fact that, somehow, the point gets to the end of the buffer and never comes back. I'm learning elisp, so I don't really know if this is an explanation, because the visible point stays where it should.
Thanks, it looks like these are using overlays. We have a type for this already, it's just not enabled by default since it is slower. Try updating the vars to include whatever modes you want to use:
(link-hint-define-type 'overlay-button
:vars '(woman-mode Man-mode dictionary-mode fanyi-mode notmuch-show-mode))
Thanks for your help, @noctuid! It works great with your suggestion! Do you think that notmuch-show-mode could be added permanently to the overlay-button type?
Yes, are there any other notmuch modes that need to be added?
I believe notmuch-show will be enough for the time being. Selecting messages with hint-link is a different story, I guess.
I'm in love with this package, a life changer. Thanks for it.
However, shoudn't it be able to detect notmuch-show multipart buttons (
notmuch-show-part-button-type
)? These give access to different parts of a message, and it'd be great to be able to hint them. Maybe it's just a matter of adding this new type of link, but I don't know where to start with such an addition.Thanks for any help!