diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/doc/jao-org-focus.el | 48 |
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." |