emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-imenu-get-tree: Allow parent headings to be selected themselves
@ 2022-05-30  8:07 Adam Porter
  2022-05-30 12:22 ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Adam Porter @ 2022-05-30  8:07 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 122 bytes --]

Hi,

Please see the attached patch that remedies a longstanding, simple 
shortcoming in Org's Imenu support.

Thanks,
Adam

[-- Attachment #2: 0001-org-imenu-get-tree-Allow-parent-headings-to-be-selec.patch --]
[-- Type: text/x-patch, Size: 1538 bytes --]

From 00104b2b9246b19cdb02bbce993d120581dc9f0e Mon Sep 17 00:00:00 2001
From: Adam Porter <adam@alphapapa.net>
Date: Mon, 30 May 2022 02:59:06 -0500
Subject: [PATCH] org-imenu-get-tree: Allow parent headings to be selected
 themselves

Imenu only allows leaf nodes to be chosen.  In programming language
buffers, non-leaf nodes are "virtual" nodes, i.e. categories like
"functions" or "variables" rather than actual locations in the buffer.
But in Org buffers, non-leaf nodes are headings, which the user may
want to select with Imenu.

So now, for a non-leaf node (i.e. headings that have children), we
push an extra item to the result, without including its children, so
that it can be listed and selected in Imenu as a leaf node.
---
 lisp/org-compat.el | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 7041976..e9c53cf 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -1053,6 +1053,11 @@ This also applied for speedbar access."
 	   (let* ((m (point-marker))
 		  (item (propertize headline 'org-imenu-marker m 'org-imenu t)))
 	     (push m org-imenu-markers)
+             (when (save-excursion (org-goto-first-child))
+               ;; Entry has children: push an extra item for entry
+               ;; itself so it can be selected (Imenu only allows
+               ;; selection of leaf nodes).
+               (push (cons item m) (aref subs level)))
 	     (if (>= level last-level)
 		 (push (cons item m) (aref subs level))
 	       (push (cons item
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] org-imenu-get-tree: Allow parent headings to be selected themselves
  2022-05-30  8:07 [PATCH] org-imenu-get-tree: Allow parent headings to be selected themselves Adam Porter
@ 2022-05-30 12:22 ` Ihor Radchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2022-05-30 12:22 UTC (permalink / raw)
  To: Adam Porter; +Cc: emacs-orgmode

Adam Porter <adam@alphapapa.net> writes:

> Please see the attached patch that remedies a longstanding, simple 
> shortcoming in Org's Imenu support.

I tried to test your patch starting from emacs -Q and I am unable to
select parent headings. Could you provide a detailed example
demonstrating the difference before/after the patch?

Best,
Ihor


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-30 12:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-30  8:07 [PATCH] org-imenu-get-tree: Allow parent headings to be selected themselves Adam Porter
2022-05-30 12:22 ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).