diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-26 19:56:21 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-26 19:56:21 -0500 |
| commit | 34c67ddc3b72f92033ced3f86346f3483f5ba463 (patch) | |
| tree | 5df3b8c96266c6f2f6a63930d5d17aaaa32b6f35 | |
| parent | 00571a577e12e4a59b1400e9712e3423e4730643 (diff) | |
| download | pearl-34c67ddc3b72f92033ced3f86346f3483f5ba463.tar.gz pearl-34c67ddc3b72f92033ced3f86346f3483f5ba463.zip | |
feat(refresh): re-tidy drawers via org-tidy when it's active
After a refresh, merge, or comment add, pearl folds property drawers so the page stays scannable. When org-tidy-mode is on, org-tidy owns drawer display with its own compact inline symbol, so a plain native fold doesn't match. Worse, org-tidy's overlays go stale when pearl rewrites the buffer, leaving the new drawers untidied.
I added pearl--hide-or-tidy-drawers, which re-tidies via org-tidy-buffer when org-tidy-mode is active and falls back to the native fold otherwise. I routed the three drawer-hide paths (full render, single-issue refresh, comment add) through it. org-tidy stays an optional soft dependency, guarded by bound-and-true-p and fboundp, so a setup without it behaves exactly as before.
| -rw-r--r-- | pearl.el | 16 | ||||
| -rw-r--r-- | tests/test-pearl-format.el | 24 |
2 files changed, 37 insertions, 3 deletions
@@ -250,13 +250,23 @@ Returns HEADING unchanged when IDENTIFIER is empty or absent from the front." (cond ((fboundp 'org-fold-hide-drawer-all) (org-fold-hide-drawer-all)) ((fboundp 'org-cycle-hide-drawers) (org-cycle-hide-drawers 'all)))) +(defun pearl--hide-or-tidy-drawers () + "Hide property drawers in the accessible buffer, honoring org-tidy if active. +With `org-tidy-mode' on, re-tidy via `org-tidy-buffer' so freshly rendered +drawers pick up org-tidy's compact display instead of a plain fold; otherwise +fold them natively. org-tidy stays an optional soft dependency -- the native +fold is the fallback when it is absent or off." + (if (and (bound-and-true-p org-tidy-mode) (fboundp 'org-tidy-buffer)) + (org-tidy-buffer) + (pearl--hide-all-drawers))) + (defun pearl--hide-drawers-in-region (start end) "Collapse property drawers between START and END. Used after inserting a single subtree (a freshly added comment) so its drawer folds shut like the rest of the page, rather than rendering expanded." (save-restriction (narrow-to-region start end) - (pearl--hide-all-drawers))) + (pearl--hide-or-tidy-drawers))) (defun pearl--restore-page-visibility () "Re-fold the whole current buffer to its `#+STARTUP' visibility and hide drawers. @@ -273,7 +283,7 @@ not sprawl open. A no-op when `pearl-fold-after-update' is nil." (funcall (if (fboundp 'org-cycle-set-startup-visibility) 'org-cycle-set-startup-visibility 'org-set-startup-visibility)) - (pearl--hide-all-drawers))) + (pearl--hide-or-tidy-drawers))) ;; Cache variables @@ -2363,7 +2373,7 @@ matches a first fetch." (goto-char beg) (save-restriction (org-narrow-to-subtree) - (pearl--hide-all-drawers))))))) + (pearl--hide-or-tidy-drawers))))))) ;;;###autoload (defun pearl-refresh-current-issue () diff --git a/tests/test-pearl-format.el b/tests/test-pearl-format.el index 96ec395..1119734 100644 --- a/tests/test-pearl-format.el +++ b/tests/test-pearl-format.el @@ -205,5 +205,29 @@ visible while property drawers fold away." (pearl--restore-page-visibility) (should (test-pearl--line-visible-p "^:LINEAR-ID:")))))) +;;; --hide-or-tidy-drawers (optional org-tidy integration) + +;; org-tidy isn't a test dependency, so declare its mode var special here; the +;; `let' bindings below then bind it dynamically where `bound-and-true-p' reads. +(defvar org-tidy-mode) + +(ert-deftest test-pearl-hide-or-tidy-uses-org-tidy-when-active () + "With org-tidy-mode on, drawer hiding re-tidies via `org-tidy-buffer'." + (let ((tidied nil) (org-tidy-mode t)) + (cl-letf (((symbol-function 'org-tidy-buffer) (lambda () (setq tidied t))) + ((symbol-function 'pearl--hide-all-drawers) + (lambda () (error "should not native-fold when org-tidy is on")))) + (pearl--hide-or-tidy-drawers)) + (should tidied))) + +(ert-deftest test-pearl-hide-or-tidy-folds-natively-when-inactive () + "With org-tidy off, drawer hiding falls back to the native fold." + (let ((folded nil) (org-tidy-mode nil)) + (cl-letf (((symbol-function 'pearl--hide-all-drawers) (lambda () (setq folded t))) + ((symbol-function 'org-tidy-buffer) + (lambda () (error "should not tidy when org-tidy is off")))) + (pearl--hide-or-tidy-drawers)) + (should folded))) + (provide 'test-pearl-format) ;;; test-pearl-format.el ends here |
