From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Hendricks Subject: [PATCH] org-compat: Allow imenu items without hierarchy Date: Thu, 12 Apr 2018 09:49:34 -0600 Message-ID: <20180412154934.58182-1-michael@ndrix.org> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f6eUM-0004Je-PK for emacs-orgmode@gnu.org; Thu, 12 Apr 2018 11:50:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f6eUG-0005sG-PL for emacs-orgmode@gnu.org; Thu, 12 Apr 2018 11:50:18 -0400 Received: from mail8.static.mailgun.info ([104.130.122.8]:48792) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f6eUG-0005re-Kj for emacs-orgmode@gnu.org; Thu, 12 Apr 2018 11:50:12 -0400 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org 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