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

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

[elpa] externals/org 68a44ea 04/29: org.el/org-narrow-to-subtree: Suppor


From: ELPA Syncer
Subject: [elpa] externals/org 68a44ea 04/29: org.el/org-narrow-to-subtree: Support cache and passing element arg
Date: Sun, 17 Oct 2021 02:57:25 -0400 (EDT)

branch: externals/org
commit 68a44eadac00d07e2b45b10da60e0e3cd6300d6f
Author: Ihor Radchenko <yantar92@gmail.com>
Commit: Ihor Radchenko <yantar92@gmail.com>

    org.el/org-narrow-to-subtree: Support cache and passing element arg
---
 lisp/org.el | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 23b6bd6..ba3ca1c 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7899,17 +7899,26 @@ If yes, remember the marker and the distance to BEG."
     (move-marker (car x) (+ beg (cdr x))))
   (setq org-markers-to-move nil))
 
-(defun org-narrow-to-subtree ()
+(defun org-narrow-to-subtree (&optional element)
   "Narrow buffer to the current subtree."
   (interactive)
-  (save-excursion
-    (save-match-data
-      (org-with-limited-levels
-       (narrow-to-region
-       (progn (org-back-to-heading t) (point))
-       (progn (org-end-of-subtree t t)
-              (when (and (org-at-heading-p) (not (eobp))) (backward-char 1))
-              (point)))))))
+  (if (org-element--cache-active-p)
+      (if-let* ((heading (org-element-lineage
+                          (or element (org-element-at-point))
+                          '(headline) t))
+                (end (org-element-property :end heading)))
+          (narrow-to-region (org-element-property :begin heading)
+                            (if (= end (point-max))
+                                end (1- end)))
+        (signal 'outline-before-first-heading nil))
+    (save-excursion
+      (save-match-data
+        (org-with-limited-levels
+         (narrow-to-region
+         (progn (org-back-to-heading t) (point))
+         (progn (org-end-of-subtree t t)
+                (when (and (org-at-heading-p) (not (eobp))) (backward-char 1))
+                (point))))))))
 
 (defun org-toggle-narrow-to-subtree ()
   "Narrow to the subtree at point or widen a narrowed buffer."



reply via email to

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