Hi Karl,

Karl Voit <devn...@karl-voit.at> writes:

> How about using IDs of the sub-tree headings (if found) in order to
> name the buffer? In case someone is using custom IDs (like me), the
> list would look like:
>
> - myorgmode.org-1              (-> no ID found for this sub-heading)
> - myorgmode.org-project-foobar              (-> :ID: project-foobar)
> - myorgmode.org-2013-10-25-customerX  (-> :ID: 2013-10-25-customerX)

The attached patch does name indirect buffers after the current tree
heading -- thanks for this idea.

Would anyone else find this useful?

>From b5da8fa8ad7c9dc7b4f3c2d177c1aada685e520c Mon Sep 17 00:00:00 2001
From: Bastien Guerry <b...@altern.org>
Date: Wed, 6 Nov 2013 13:50:39 +0100
Subject: [PATCH] org.el (org-get-indirect-buffer): New argument `heading'

* org.el (org-get-indirect-buffer): New argument `heading'
to name the buffer after the current tree heading.
(org-tree-to-indirect-buffer): Use `org-get-indirect-buffer'
with a `heading' argument.

Thanks to Karl Voit for suggesting this.
---
 lisp/org.el | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 7c2a316..7e47891 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7466,7 +7466,7 @@ frame is not changed."
 	     (not (eq org-indirect-buffer-display 'new-frame))
 	     (not arg))
 	(kill-buffer org-last-indirect-buffer))
-    (setq ibuf (org-get-indirect-buffer cbuf)
+    (setq ibuf (org-get-indirect-buffer cbuf heading)
 	  org-last-indirect-buffer ibuf)
     (cond
      ((or (eq org-indirect-buffer-display 'new-frame)
@@ -7497,11 +7497,11 @@ frame is not changed."
     (run-hook-with-args 'org-cycle-hook 'all)
     (and (window-live-p cwin) (select-window cwin))))
 
-(defun org-get-indirect-buffer (&optional buffer)
+(defun org-get-indirect-buffer (&optional buffer heading)
   (setq buffer (or buffer (current-buffer)))
   (let ((n 1) (base (buffer-name buffer)) bname)
     (while (buffer-live-p
-	    (get-buffer (setq bname (concat base "-" (number-to-string n)))))
+	    (get-buffer (setq bname (concat base "-" (or heading (number-to-string n))))))
       (setq n (1+ n)))
     (condition-case nil
         (make-indirect-buffer buffer bname 'clone)
-- 
1.8.4.2

-- 
 Bastien

Reply via email to