noctuid/link-hint.el

Feature: detecting dired file names

Closed this issue · 8 comments

The file text has text property dired-filename set to t.

I'm not sure I really consider files in dired to be links. This package is more focused on links that are in some part of the buffer (whereas every line in dired is a file). You might as well just use avy-goto-line (possibly combined with whatever action) or counsel-find-file.

That said, adding support for new link types is very easy. You could put this in your config:

(defun link-hint--next-dired-filename (&optional bound)
  (link-hint--next-property 'dired-filename bound))

(defun link-hint--dired-mode-p ()
  (memq major-mode '(dired-mode ranger-mode)))

(defun link-hint--dired-filename-at-point-p ()
  (when (get-text-property (point) 'dired-filename)
    (link-hint--property-text 'dired-filename)))

(link-hint-define-type 'dired-filename
  :next #'link-hint--next-dired-filename
  :at-point-p #'link-hint--dired-filename-at-point-p
  :predicates (list #'link-hint--dired-mode-p)
  :open #'dired-find-file
  :copy #'kill-new)

(push 'link-hint-dired-filename link-hint-types)

I'll think more about whether or not to add this by default. I think at some point, most of the helper functionality that exists in link hint will probably be moved to things.el as actions like opening/copying/etc. make sense on things in general not just "links." At that point, link-hint would just be a wrapper that implements the required functions for various link things.

Thanks, it works great! I will follow your example and I will implement similar handling for eshells list/find which would require some more coding since there are no text properties indicating that the file name is a file.

You may consider also (dired-copy-filename-as-kill 0) instead of kill-new which will copy the full path to the file.

Thanks for the suggestion. I'll leave this issue open until this code makes its way into some package.

Hey, I'm creating link-hint-extras package, where I intend to put everything that is not suitable for link-hint package. Maybe you are interested. There is already support for: xref, dired, completion buffer and man.

@noctuid if any of those modes are suitable for link-hint, I can send PRs

I think they all seem reasonable. I guess dired files are reasonable since I don't know what other behavior it would have in dired buffers. There might be some actual other links for org agenda, but I think it would be fine to use for entries too (the user can always disable if they don't want it). I will accept PRs.

Should I make a PR per type? Also, on readme the user must be notified about the link-hint-completion-list-candidate issue.