From ee0c0ddab506f33468d926b991e93723e3e102e2 Mon Sep 17 00:00:00 2001 From: jao Date: Wed, 15 Oct 2025 19:22:30 +0100 Subject: org-focus: redisplay children --- lib/doc/jao-org-focus.el | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'lib/doc/jao-org-focus.el') 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." -- cgit v1.2.3