Closed jsilve24 closed 2 years ago
Some feedback:
:next
function does not meet the spec. It should not move the point (you should create a new function wrapped in save-excursion
). The :next
function should take one optional argument that is an end bound (mu4e-headers-next's optional argument has different behavior). I will update the documentation to make the arglists for each function more explicit (&optional bound
here):open
works because the function takes no arguments and will therefore operate at the point. mu4e-headers-goto-message-id
takes the message ID as an argument. You either need to create a new function for :goto
that takes no arguments and goes to the message at point, or you need to change your :at-point-p
function to return the message id to pass to mu4e-headers-goto-message-id
. Right now, it first tries to pass the return value of :at-point-p
to mu4e-headers-goto-message-id
, which fails since it is not the message id. Then it tries tries to call mu4e-headers-goto-message-id
without arguments, which fails since one is required.Thank you so much!
Justin
For any others who stumble upon this question. This updated code seems to work for mu4e (still working on dired)
(defun jds/link-hint-goto-link ()
"Use link-hint to jump to link but do nothing."
(interactive)
(link-hint--one :goto))
;; :next function should not move the point
;; it should talk one optional argument that is an end bound
(defun jds~mu4e-headers-next-for-link-hint (&optional bound)
"Function wrapping mu4e-headers-next and mathing spect for link-hint :next function."
(save-excursion
(mu4e-headers-next)
(if (and bound
(> (point) bound))
nil
(point))))
(defun jds~mu4e-at-point-p ()
"Function suitable for :at-point-p in link-hint for mu4e. Return message id to pass to
mu4e-headers-goto-message-id."
(let* ((map (and
(pos-visible-in-window-p)
(mu4e-message-at-point t)))
(msgid (if (not map)
nil
(plist-get map :message-id))))
msgid))
(link-hint-define-type 'mu4e-message
:next #'jds~mu4e-headers-next-for-link-hint
:at-point-p #'jds~mu4e-at-point-p
:open #'mu4e-headers-view-message
:copy #'mu4e-copy-message-path
:goto 'identidy
:vars '(mu4e-headers-mode))
(push 'link-hint-mu4e-message link-hint-types)
Again, thank you for the help. That said, I seem to still be running into an issue with dired.
Note that the following gives no errors but also doesn't move the point.
(defun jds/link-hint-goto-link ()
"Use link-hint to jump to link but do nothing."
(interactive)
(link-hint--one :goto))
(defun jds~jump-to-file (file)
"Move point to file in dired buffer."
(let* ((fullname (expand-file-name
file
(dired-current-directory))))
(message fullname)
(dired-goto-file fullname)))
(link-hint-define-type 'dired-filename
:goto #'jds~jump-to-file)
Looking through the source of link-hint action I am wondering if there is a save-excusion that is keeping this from working. In particular I noticed the following comment in the code and I am wondering if this is topical.
;; when buffer doesn't change but position does (e.g. local org
;; link), do nothing
Thank you again for the help.
So Ultimately, I just found it easy to call avy directly and avoid link-hint for the dired case. Here is the avy code for anyone that is interested (it uses the dired-hacks-utils library)
(require 'dired-hacks-utils)
;;;###autoload
(defun jds~avy-dired-cands ()
(save-excursion
(save-restriction
(narrow-to-region (window-start) (window-end (selected-window) t))
(goto-char (point-min))
(setq pt (point))
(dired-hacks-next-file)
(let ((candidates (list (cons (point) (selected-window)))))
(setq pt (point))
(dired-hacks-next-file)
(while (not (equal (point) pt))
(setq pt (point))
(push (cons (point) (selected-window)) candidates)
(dired-hacks-next-file))
(nreverse candidates)))))
;;;###autoload
(defun jds/avy-dired ()
"Goto a visible file or directory in a dired-buffer."
(interactive)
(avy-action-goto (avy-with jds/avy-dired
(avy-process (jds~avy-dired-cands)))))
First off, my gut here is saying the issue is with me but I just cannot figure it out.
I wanted to define a new type of link action 'goto' that just moves cursor to point but doesn't do much else than that.
Then I added the following for
dired
I also added the following for mu4e:
In both cases I end up with an warning:
link-hint--apply: Wrong number of arguments: (1 . 1), 0
Still the functions work as expected. Where is this warning comming from?
As a final complication, for some reason I notice that the
:goto
action doesn't work if I am trying to jump to the last message in a mu4e headers list (e.g., the message at the bottom of the screen). I have no idea why as each of the component functions works fine. Even the :open works fine so I am confused on that one too.Any advice would be most appreciated.
Thank you, Justin