What I'm trying to do is use org-attach-dired-to-subtree when I find something I'm looking for with M-x locate.

That doesn't work, cause M-x locate results is not a dired buffer.

1 Answer 1


C-h m in the *Locate* buffer says:

V visits the directory of the file on the current line.
This function runs ‘locate-mode-hook’ before returning.

so you could (possibly - I have not tried it) even do the org-attach-dired-to-subtree from the hook. No, this is nonsense: I misinterpeted this function in the last sentence: it does not refer to locate-find-directory (which is bound to V), it refers to locate-mode itself.

EDIT: Here's a simple function that wraps the relevant pieces to org-attach a single file from the *Locate* buffer:

(defun my/locate-org-attach-file ()
  (let ((file (locate-get-filename)))
    (org-attach-dired-to-subtree (list file))))
  • Thanks for this one. It opens the Dired buffer, but it's not jumping to the file, so I have to search for it anew, inside the Dired buffer. Anyways, it does solve the problem, so thanks;) Jan 31 at 9:43
  • See edited answer for a single-file function. You could probably implement a bulk function by looping over marked files in the *Locate* buffer but there are a couple of complications (possilbe non-uniqueness of file names is one).
    – NickD
    Jan 31 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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