emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Michael Hendricks <michael@ndrix.org>
To: emacs-orgmode@gnu.org
Cc: Michael Hendricks <michael@ndrix.org>
Subject: [PATCH] org-compat: Allow imenu items without hierarchy
Date: Thu, 12 Apr 2018 09:49:34 -0600	[thread overview]
Message-ID: <20180412154934.58182-1-michael@ndrix.org> (raw)

* 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

             reply	other threads:[~2018-04-12 15:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-12 15:49 Michael Hendricks [this message]
2018-04-15 10:33 ` [PATCH] org-compat: Allow imenu items without hierarchy 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180412154934.58182-1-michael@ndrix.org \
    --to=michael@ndrix.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).