teckau22 · 2022-11-27 18:40
I have an org file that has only first-level headings, and the name of each heading is unique. Under each heading is a drawer with some properties.
In a function, I use the following to jump to a specific heading (below, the heading would be named "Example" in the above file):
(re-search-forward (concat "^\\* " "Example" "$") nil t)
And from there I can insert a property with `org-set-property` for that heading.
Everything works very well for my needs, but I kind of feel like there is probably a built-in function that does what my `re-search-forward` line does but in a more elegant way. However, I can't find such a built-in function. Is there one?
Edit: Thanks for your input everyone. As /u/oantolin was pointing out, I was not looking for an interactive solution, and his solution is basically what I was looking for.
[deleted] · 2022-11-27 18:47
[deleted]
thetemp_ · 2022-11-27 19:07
So you're just trying to jump to a specific heading? Try "M-x imenu". A popular custom keybinding for it is "M-i".
akirakom · 2022-11-27 19:56
~~If you want to jump to a specific headline programmatically, you can use org-complex-headline-regexp-format variable to construct the regexp. Or org-find-olp function.~~ Combine org-with-point-at macro with org-find-olp function.
tutux84 · 2022-11-27 21:14
In this regard, `consult-org-heading` is probably more appropriate than `consult-line`.
guerrinha · 2022-11-27 22:25
Will require you to add ID for each heading, but you will be able to use \`org-id-goto\`
oantolin · 2022-11-27 22:26
Several other commenters seem to have misunderstood you, thinking you want to do this interactively, instead of inside a function. In a function I guess you could use:
(org-link-open-from-string "[[*Example]]")
teckau22 · 2022-11-27 23:54
This is exactly it, thanks!
chandergovind · 2022-11-28 11:15
There is an even more direct function: `(org-find-exact-headline-in-buffer "Example")`
teckau22 · 2022-11-28 12:43
Yes, this works even better. So for my needs: `(goto-char (org-find-exact-headline-in-buffer "Example"))`. Thanks!
paretoOptimalDev · 2022-12-02 14:46
I once used these for org-headings.
Now I use consult-imenu for org- headings, in eww, and everywhere I can.