From 34c67ddc3b72f92033ced3f86346f3483f5ba463 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 26 May 2026 19:56:21 -0500 Subject: 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. --- tests/test-pearl-format.el | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/test-pearl-format.el') 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 -- cgit v1.2.3