noctuid / link-hint.el

Pentadactyl-like Link Hinting in Emacs with Avy
GNU General Public License v3.0
160 stars 22 forks source link

Wrong Number of Args, I must be misunderstanding something #202

Closed jsilve24 closed 2 years ago

jsilve24 commented 2 years ago

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.

(defun jds/link-hint-goto-link ()
  "Use link-hint to jump to link but do nothing."
  (interactive)
  (link-hint--one :goto))

Then I added the following for dired

(link-hint-define-type 'dired-filename
    :goto #'dired-goto-file)

I also added the following for mu4e:

(link-hint-define-type 'mu4e-message
    :next #'mu4e-headers-next
    :at-point-p #'(lambda () (interactive) (mu4e-message-at-point t))
    :open #'mu4e-headers-view-message
    :copy #'mu4e-copy-message-path
    :goto #'mu4e-headers-goto-message-id
    :vars '(mu4e-headers-mode))
  (push 'link-hint-mu4e-message link-hint-types)

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

noctuid commented 2 years ago

Some feedback:

jsilve24 commented 2 years ago

Thank you so much!

Justin

jsilve24 commented 2 years ago

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)
jsilve24 commented 2 years ago

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.

jsilve24 commented 2 years ago

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