summaryrefslogtreecommitdiffhomepage
path: root/lib/doc
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2025-10-15 19:22:30 +0100
committerjao <jao@gnu.org>2025-10-15 19:22:30 +0100
commitee0c0ddab506f33468d926b991e93723e3e102e2 (patch)
treeb1405c456733f99cab3f10ae03cb33c1d83e2a17 /lib/doc
parent7ea6f4969c2dea09ff8f2c26b5309da6c22d9b8e (diff)
downloadelibs-ee0c0ddab506f33468d926b991e93723e3e102e2.tar.gz
elibs-ee0c0ddab506f33468d926b991e93723e3e102e2.tar.bz2
org-focus: redisplay children
Diffstat (limited to 'lib/doc')
-rw-r--r--lib/doc/jao-org-focus.el48
1 files changed, 35 insertions, 13 deletions
diff --git a/lib/doc/jao-org-focus.el b/lib/doc/jao-org-focus.el
index 8f3138e..ac33df9 100644
--- a/lib/doc/jao-org-focus.el
+++ b/lib/doc/jao-org-focus.el
@@ -26,6 +26,7 @@
;;; focus on subtree
(defvar-local jao-org-focus--parent nil)
+(defvar-local jao-org-focus--section nil)
(defun jao-org-focus ()
"Pop creatingly to an indirect buffer focused on the encloing subtree.
@@ -34,19 +35,40 @@ When invoked on an indirect buffer, pops back to its base."
(interactive)
(if-let* ((b (get-buffer (or jao-org-focus--parent ""))))
(pop-to-buffer b)
- (when-let* ((elem (org-element-at-point))
- (header (if (eq 'headline (org-element-type elem))
- elem
- (org-previous-visible-heading 1)
- (org-element-at-point)))
- (title (org-element-property :title header))
- (parent (buffer-name))
- (bname (format "%s [%s]" title parent)))
- (if-let* ((b (get-buffer bname)))
- (pop-to-buffer b)
- (clone-indirect-buffer bname t)
- (setq jao-org-focus--parent parent)
- (org-narrow-to-subtree)))))
+ (when-let* ((elem (org-element-at-point))
+ (header (if (eq 'headline (org-element-type elem))
+ elem
+ (org-previous-visible-heading 1)
+ (org-element-at-point)))
+ (title (org-element-property :title header))
+ (parent (buffer-name))
+ (bname (format "%s [%s]" title parent)))
+ (if-let* ((b (get-buffer bname)))
+ (pop-to-buffer b)
+ (clone-indirect-buffer bname t)
+ (setq jao-org-focus--parent parent
+ jao-org-focus--section title)
+ (org-narrow-to-subtree)
+ (show-subtree)))))
+
+(defun jao-org-focus-redisplay ()
+ "Redisplay a focused buffer.
+
+Useful when its parent has been reorganised and the narrowing is out of
+sync."
+ (interactive)
+ (when-let* ((title jao-org-focus--section))
+ (widen)
+ (goto-char (point-min))
+ (when (re-search-forward (format "\\*+ %s" title) nil t)
+ (org-narrow-to-subtree)
+ (beginning-of-line))))
+
+(defun jao-org-focus-redisplay-children ()
+ "Find focused children and redisplay them."
+ (interactive)
+ (dolist (b (jao-org-focus-list))
+ (with-current-buffer b (jao-org-focus-redisplay))))
(defun jao-org-focus-list (&optional any-parent)
"List of buffers that are focusing on a subtree of this one or its parent."