0

I currently have a dired bookmark set to a directory. So in order to access a particular heading, the sequence is as follows:

  1. Bookmarks keybind, type initial letters of directory bookmark.
  2. (Dired fullscreen buffer is open) Use dired file goto, type beginning of filename, press enter twice
  3. Use org-goto within the org buffer.

I'd like instead to be able to go from a keybinding to a find buffer that allows me to type the bookmark for the directory, then the file, then the heading, all of that without changing buffers and with tab completion. For example, after pressing a keybinding for this, I'd write What I'm trying to do is access a file heading by writing something like: <bookmark>/<directory1>/<directory2>/<file>/<heading>, and be at the heading I wanted. Are there ready-made packages or configs that could allow me to do that?

13
  • Are you expecting to type the full (bookmark, filename, heading) without any completion help? If so, that would be easily doable (I think - I haven't tried it), but typing complete names in all cases seems harder to me than using completion at each step.
    – NickD
    Nov 28, 2023 at 18:17
  • @NickD my whole issue is that I'd like to be able to use completion! mixing bookmarks with filepaths with headings
    – shintuku
    Nov 28, 2023 at 18:19
  • That is hard(er) - I think (again I have not tried anything).
    – NickD
    Nov 28, 2023 at 18:28
  • Is this about Org mode's "bookmarks" or about ordinary Emacs bookmarks? I don't really follow what you're asking, FWIW. What are you trying to do: open a Dired buffer by jumping to a bookmark? Open a file (you tagged this find-file)? Please specify the step-by-step recipe you're looking for.
    – Drew
    Nov 28, 2023 at 18:49
  • @Drew The dired directory is reached with Emacs bookmarks. What I'm trying to do is access a file heading by writing something like: <bookmark>/<directory1>/<directory2>/<file>/<heading>, in such a way that tab completion is available. I've tagged this find-file in case there was a way of configuring C-x C-f to do what I wanted. Thanks for the comment!
    – shintuku
    Nov 28, 2023 at 18:53

1 Answer 1

0

Here's a slightly edited ChatGPT-generated script that at least allowed me to use custom "bookmarks" with find-file, using Drew's suggestion. If anyone has ideas of how to extend navigation up to org file headings, please let me know!


(require 'vertico)

(defvar my-choices-alist
  '(("Choice1" . "/path/to/directory1")
    ("Choice2" . "/path/to/directory2")
    ("Choice3" . "/path/to/directory3")
    ("Choice4" . "/path/to/directory4")
    ("Choice5" . "/path/to/directory5")
    ("Choice6" . "/path/to/directory6")
    ("Choice7" . "/path/to/directory7")
    ("Choice8" . "/path/to/directory8")
    ("Choice9" . "/path/to/directory9")
    ("Choice10" . "/path/to/directory10")))

(defun my-find-file-command ()
  "Prompt for input using vertico, open a file, and set `default-directory` to the previous buffer's directory."
  (interactive)
  (let ((choices (mapcar #'car my-choices-alist))
        (selected-choice nil)
        (previous-dir default-directory))

    (setq selected-choice (completing-read "Select a choice: " choices))

    (if (assoc selected-choice my-choices-alist)
        (let* ((directory (cdr (assoc selected-choice my-choices-alist)))
               (file-to-open (read-file-name "Open file: " directory)))
          (find-file file-to-open)
          (setq default-directory previous-dir)
          (message "Opened file and set default directory to the previous buffer's directory: %s" default-directory))
      (message "Invalid choice: %s" selected-choice))))

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.