3

I wan't to be able to programmatically open a file in org mode and scroll to a specific header. the file is quite big, so opening the file at a certain place is qhat I am looking for.

Any idea how to do that from the terminal via Bash?

2 Answers 2

6

Perhaps something along the following lines:

emacs -Q --eval='(progn (find-file "/path/to/file") (goto-char (org-find-exact-headline-in-buffer "org-headline")))'

2
  • 2
    You might want to skip the -Q though: it depends on whether one wants to do something quick and exit, in which case the -Q is useful, since it avoids the potentially long user initialization; or whether one wants to continue working in that emacs session, in which case the user initialization, although long, is useful and amortized over the life of the session. If there is an emacs server running, the emacsclient invocation of the above might be even more useful.
    – NickD
    Jun 2, 2021 at 16:25
  • Great, thanks. It works even with nested headings.
    – kipkipe
    Jun 3, 2021 at 6:43
0

If you have an ID associated with the headline that you are looking for, you could go directly to that headline using org-protocol, as described here:

Jump to org-mode heading from external application

Your Answer

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

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