From 0b573c7eba2eedbd57e287288b2cf36a397d73df Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 27 Apr 2022 08:37:11 -0500 Subject: Add functions for org These aren't bound or implemented but they're here in case I want them. --- lisp/+org.el | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'lisp/+org.el') diff --git a/lisp/+org.el b/lisp/+org.el index 400172f..84b0288 100644 --- a/lisp/+org.el +++ b/lisp/+org.el @@ -604,5 +604,50 @@ and POST-PROCESS are passed to `org-export-to-file'." ;;; go forward and backward in the tree, ~ cleanly ~ ;; https://stackoverflow.com/a/25201697/10756297 +(defun +org-show-next-heading-tidily () + "Show next entry, keeping other entries closed." + (interactive) + (if (save-excursion (end-of-line) (outline-invisible-p)) + (progn (org-show-entry) (show-children)) + (outline-next-heading) + (unless (and (bolp) (org-on-heading-p)) + (org-up-heading-safe) + (hide-subtree) + (user-error "Boundary reached")) + (org-overview) + (org-reveal t) + (org-show-entry) + (recenter-top-bottom) + (show-children) + (recenter-top-bottom 1))) + +(defun +org-show-previous-heading-tidily () + "Show previous entry, keeping other entries closed." + (interactive) + (let ((pos (point))) + (outline-previous-heading) + (unless (and (< (point) pos) (bolp) (org-on-heading-p)) + (goto-char pos) + (hide-subtree) + (user-error "Boundary reached")) + (org-overview) + (org-reveal t) + (org-show-entry) + (recenter-top-bottom) + (show-children) + (recenter-top-bottom 1))) + +;;; Make `org-flag-region' (which folds subtrees) recognize +;; [[https://teddit.net/r/orgmode/comments/u3du0v/how_to_make_orgcycle_respect_and_always_show_the/][from u/yantar92]] + +;; (advice-add 'org-flag-region :around #'org-flag-region@unfold-page-breaks) +(defun org-flag-region@unfold-page-breaks (oldfun from to flag &optional spec) + "ADVICE to unfold all the page-break lines inside a folded region." + (funcall oldfun from to flag spec) + (when (and flag (not (eq 'visible spec))) + (org-with-point-at from + (while (re-search-forward "\n\u000c\n" to t) + (org-flag-region (match-beginning 0) (match-end 0) t 'visible))))) + (provide '+org) ;;; +org.el ends here -- cgit 1.4.1-21-gabe81