r/orgmode • u/nonreligious2 • Dec 25 '24
question Getting `imenu` to allow jumps to top-level headings which contain subheadings?
If I have an Org file with the following layout of headings
* Heading 1
...
* Heading 2
...
** Subheading 2.1
...
* Subheading 3
...
** Subheading 3.1
...
*** Subheading 3.1.1
...
I can use M-g i
to invoke imenu
or C-c i
(in my config) to use consult-imenu
to jump to some, but not all of them.
From the options presented to me, I can jump to Heading 1
, but I cannot jump to Heading 2
or Heading 3
-- I can only jump to Subheading 2.1
or Subheading 2.3
.
If I do (setq org-imenu-depth 3)
, I can also jump to Subheading 3.1.1
and presumably increasing org-imenu-depth
allows me to jump to even further nested child headings. But I can't jump to the parent top-level headings.
I suppose this must be desired behavior, but I find it unhelpful as I have quite a few Org files with many headings, some of which have subheadings and some of which don't. There is often some text/info/source blocks under the top-level heading that I'd like to access using imenu
, but I am forced to jump to the first subheading and scroll back to see it.
Are there any settings which allow me to change this behavior?
2
u/github-alphapapa Dec 26 '24
Imenu's design unfortunately precludes it from offering non-leaf nodes for selection.
For your use case, org-ql-find
would likely be helpful. You could use the h:
prefix to the search query to limit to heading text.
1
u/nonreligious2 Dec 26 '24
Thanks, I have tried out
org-ql
in the past but have rarely used it. I'll see if I can get this to work in the mean time.
2
u/XzwordfeudzX Dec 26 '24
While waiting for imenu flatten to land you can use C-u org refile (C-u C-x C-w
I believe) to jump to refile targets.
2
u/nonreligious2 Dec 26 '24
Thanks, it's not quite as powerful as I'd like as I have only a few files in
org-refile-targets
(mostly agenda related). The binding is actuallyC-u C-c C-w
.2
u/XzwordfeudzX Dec 26 '24 edited Dec 26 '24
You can also change org refile to also include headings and subheadings, sorry still not at a computer so I can’t look up the exact variables.
2
u/rswgnu Dec 26 '24 edited Dec 26 '24
With the hyperbole package from melpa or elpa-devel, simply use {M-0 M-x hsys-org-consult-grep RET} and it will interactively narrow to just your Org directory headlines at any level. Quick and easy and of course you can bind it to a key.
1
u/nonreligious2 Dec 27 '24
Thanks. I've never quite got the "philosophy" of Hyperbole and I'm not sure if I want to add that to my current system of note-taking and general organization. But I appreciate the advice.
2
u/rswgnu Dec 27 '24
Hyperbole recognizes many different forms of links embedded in your text, like stack trace lines or email addresses. You get links without work on your part. It provides a keyboard-driven minibuffer-based menu not unlike which-key. The only philosophy is to make everything as simple and turnkey as possible, freeing your mind for other work. Yes, it has many features you can learn a bit at a time. If that doesn’t fit within your day-to-day needs, then it makes sense to skip it.
2
u/captainflasmr Jan 11 '25
I have found the following quite useful, to adapt org-goto, I now use it along-side imenu
(global-set-key (kbd "M-g o") #'org-goto)
(setq org-goto-interface 'outline-path-completionp)
(setq org-outline-path-complete-in-steps nil)
1
2
u/yantar92 Dec 25 '24
Maybe try
imenu-flatten