emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-compat: Allow imenu items without hierarchy
@ 2018-04-12 15:49 Michael Hendricks
  2018-04-15 10:33 ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Hendricks @ 2018-04-12 15:49 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Michael Hendricks

* lisp/org-compat.el (org-imenu-flat): New custom variable.
(org-imenu-get-tree): Skip hierarchical item structure if
org-imenu-flat is true.

Many of my Org files have deep hierarchies, but few total headings.
For those files, I find that navigating a flat menu structure is more
effective than navigating many nested menus.

A flat imenu structure also works well with packages, such as idomenu,
which navigate imenu items via search.
---
 lisp/org-compat.el | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index e7ea4153e..f24396ad8 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -600,6 +600,13 @@ This also applied for speedbar access."
   :group 'org-imenu-and-speedbar
   :type 'integer)
 
+(defcustom org-imenu-flat nil
+  "Non-nil creates all index items at the top level.  Nil creates
+a menu hierarchy that matches the buffer's hierarchy."
+  :group 'org-imenu-and-speedbar
+  :type 'boolean
+  :safe #'booleanp)
+
 ;;;; Imenu
 
 (defvar-local org-imenu-markers nil
@@ -618,6 +625,7 @@ This also applied for speedbar access."
   (setq org-imenu-markers nil)
   (let* ((case-fold-search nil)
 	 (n org-imenu-depth)
+	 (flat org-imenu-flat)
 	 (re (concat "^" (org-get-limited-outline-regexp)))
 	 (subs (make-vector (1+ n) nil))
 	 (last-level 0)
@@ -632,10 +640,12 @@ This also applied for speedbar access."
 	 (setq head (org-link-display-format head0)
 	       m (org-imenu-new-marker))
 	 (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
-	 (if (>= level last-level)
-	     (push (cons head m) (aref subs level))
-	   (push (cons head (aref subs (1+ level))) (aref subs level))
-	   (cl-loop for i from (1+ level) to n do (aset subs i nil)))
+	 (if flat
+	     (push (cons head m) (aref subs 1))
+	   (if (>= level last-level)
+	       (push (cons head m) (aref subs level))
+	     (push (cons head (aref subs (1+ level))) (aref subs level))
+	     (cl-loop for i from (1+ level) to n do (aset subs i nil))))
 	 (setq last-level level))))
     (aref subs 1)))
 
-- 
2.14.2

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

* Re: [PATCH] org-compat: Allow imenu items without hierarchy
  2018-04-12 15:49 [PATCH] org-compat: Allow imenu items without hierarchy Michael Hendricks
@ 2018-04-15 10:33 ` Nicolas Goaziou
  2018-04-17 18:52   ` Michael Hendricks
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2018-04-15 10:33 UTC (permalink / raw)
  To: Michael Hendricks; +Cc: emacs-orgmode

Hello,

Michael Hendricks <michael@ndrix.org> writes:

> * lisp/org-compat.el (org-imenu-flat): New custom variable.
> (org-imenu-get-tree): Skip hierarchical item structure if
> org-imenu-flat is true.
>
> Many of my Org files have deep hierarchies, but few total headings.
> For those files, I find that navigating a flat menu structure is more
> effective than navigating many nested menus.
>
> A flat imenu structure also works well with packages, such as idomenu,
> which navigate imenu items via search.

Thank you. However, you don't need to patch Org to have this. Just set
`imenu-create-index-function' to your liking.

Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] org-compat: Allow imenu items without hierarchy
  2018-04-15 10:33 ` Nicolas Goaziou
@ 2018-04-17 18:52   ` Michael Hendricks
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Hendricks @ 2018-04-17 18:52 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

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

Hi Nicolas,

On Sun, Apr 15, 2018 at 4:33 AM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Thank you. However, you don't need to patch Org to have this. Just set
> `imenu-create-index-function' to your liking.
>

Thanks for the suggestion.   That's how I was doing it before this patch
and it works. I'll keep doing it that way if this patch isn't useful to
anyone.

Since org-imenu-depth and org-imenu-get-tree could also be handled by users
setting imenu-create-index-function to their liking, I assumed that some
pieces of imenu integration were open to patches.  Other modes with
hierarchical structure, like C++ and Java, create imenu items without
hierarchy rather than recreating the class hierarchy in the menu.  That
made me think that users other than myself might prefer a flat imenu in Org
mode too.  For that reason, I'd still like to have this patch included.

I have a couple other patches for imenu integration which clean it up and
make it more consistent with behavior elsewhere.  What's the project's view
on patches like these?  I don't want to waste anyone's time if they're
discouraged by policy.

Thanks for your time.

[-- Attachment #2: Type: text/html, Size: 1679 bytes --]

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

* [PATCH] org-compat: Allow imenu items without hierarchy
@ 2018-04-10 21:46 Michael Hendricks
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Hendricks @ 2018-04-10 21:46 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Michael Hendricks

* lisp/org-compat.el (org-imenu-flat): New custom variable.
(org-imenu-get-tree): Skip hierarchical item structure if
org-imenu-flat is true.

Many of my Org files have deep hierarchies, but few total headings.
For those files, I find that navigating a flat menu structure is more
effective than navigating many nested menus.

A flat imenu structure also works well with packages, such as idomenu,
which navigate imenu items via search.
---
 lisp/org-compat.el | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index e7ea4153e..cb9419857 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -600,6 +600,12 @@ This also applied for speedbar access."
   :group 'org-imenu-and-speedbar
   :type 'integer)
 
+(defcustom org-imenu-flat nil
+  "Non-nil creates index items at the top level.  The default is
+for the index hierarchy to match the buffer's hierarchy."
+  :group 'org-imenu-and-speedbar
+  :type 'boolean)
+
 ;;;; Imenu
 
 (defvar-local org-imenu-markers nil
@@ -618,6 +624,7 @@ This also applied for speedbar access."
   (setq org-imenu-markers nil)
   (let* ((case-fold-search nil)
 	 (n org-imenu-depth)
+	 (flat org-imenu-flat)
 	 (re (concat "^" (org-get-limited-outline-regexp)))
 	 (subs (make-vector (1+ n) nil))
 	 (last-level 0)
@@ -632,10 +639,12 @@ This also applied for speedbar access."
 	 (setq head (org-link-display-format head0)
 	       m (org-imenu-new-marker))
 	 (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
-	 (if (>= level last-level)
-	     (push (cons head m) (aref subs level))
-	   (push (cons head (aref subs (1+ level))) (aref subs level))
-	   (cl-loop for i from (1+ level) to n do (aset subs i nil)))
+	 (if flat
+	     (push (cons head m) (aref subs 1))
+	   (if (>= level last-level)
+	       (push (cons head m) (aref subs level))
+	     (push (cons head (aref subs (1+ level))) (aref subs level))
+	     (cl-loop for i from (1+ level) to n do (aset subs i nil))))
 	 (setq last-level level))))
     (aref subs 1)))
 
-- 
2.14.2

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

end of thread, other threads:[~2018-04-17 18:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-12 15:49 [PATCH] org-compat: Allow imenu items without hierarchy Michael Hendricks
2018-04-15 10:33 ` Nicolas Goaziou
2018-04-17 18:52   ` Michael Hendricks
  -- strict thread matches above, loose matches on Subject: below --
2018-04-10 21:46 Michael Hendricks

Code repositories for project(s) associated with this 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).