emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org 155dc778e8: * lisp/org.el: (org-get-indirect-buffer


From: ELPA Syncer
Subject: [elpa] externals/org 155dc778e8: * lisp/org.el: (org-get-indirect-buffer) Allow indirect base buffers
Date: Sun, 6 Nov 2022 22:57:51 -0500 (EST)

branch: externals/org
commit 155dc778e8cd12bdfb4c7cac7e03f166ece1059c
Author: Adam Porter <adam@alphapapa.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    * lisp/org.el: (org-get-indirect-buffer) Allow indirect base buffers
    
    Previously, calling this function on an indirect buffer would fail,
    preventing the user from making a new indirect buffer based on an
    indirect buffer (e.g. imagine the user makes an indirect buffer for a
    large subtree, then wants to make another one for a subtree of that).
    Now, the base buffer of the buffer is used, when applicable.
    
    Also, the function is partially rewritten to be clearer, and a
    docstring is added.
    
    Link: 
https://orgmode.org/list/8b2c1814-2c6f-fdca-8ba7-63c415bfca5e@alphapapa.net
---
 lisp/org.el | 35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index d8708f8f25..6c39f351fa 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6160,25 +6160,22 @@ 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 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 "-"
-                          (if heading (concat heading "-" (number-to-string n))
-                            (number-to-string n))))))
-      (setq n (1+ n)))
-    (condition-case nil
-        (let ((indirect-buffer (make-indirect-buffer buffer bname 'clone)))
-          ;; Decouple folding state.  We need to do it manually since
-          ;; `make-indirect-buffer' does not run
-          ;; `clone-indirect-buffer-hook'.
-          (org-fold-core-decouple-indirect-buffer-folds)
-          ;; Return the buffer.
-          indirect-buffer)
-      (error (make-indirect-buffer buffer bname)))))
+(cl-defun org-get-indirect-buffer (&optional (buffer (current-buffer)) heading)
+  "Return an indirect buffer based on BUFFER.
+If HEADING, append it to the name of the new buffer."
+  (let* ((base-buffer (or (buffer-base-buffer buffer) buffer))
+         (buffer-name (generate-new-buffer-name
+                       (format "%s%s"
+                               (buffer-name base-buffer)
+                               (if heading
+                                   (concat "::" heading)
+                                 ""))))
+         (indirect-buffer (make-indirect-buffer base-buffer buffer-name 
'clone)))
+    ;; Decouple folding state.  We need to do it manually since
+    ;; `make-indirect-buffer' does not run
+    ;; `clone-indirect-buffer-hook'.
+    (org-fold-core-decouple-indirect-buffer-folds)
+    indirect-buffer))
 
 (defun org-set-frame-title (title)
   "Set the title of the current frame to the string TITLE."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]