Skip to content

Commit

Permalink
racket-{fold unfold}-tests: Lazy load hs-minor-mode
Browse files Browse the repository at this point in the history
No longer eagerly enable hs-minor-mode in racket-mode -- just on first
use of racket-{fold unfold}-tests.

Allow racket-{fold unfold}-tests to work from racket-hash-lang-mode
when sexp lang, as well as racket-mode.
  • Loading branch information
greghendershott committed Nov 18, 2023
1 parent 6574fa5 commit b7e4d62
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
19 changes: 10 additions & 9 deletions racket-edit.el
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
(require 'hideshow)
(require 'xref)

;;; code folding
;;; Show/hide test submodules

(defun racket--for-all-tests (verb f)
(defun racket--fold-tests (fold-p)
;; For this to work in `racket-hash-lang-mode' for all hash-langs,
;; (a) we'd need to learn the test submodule spans from analysis of
;; fully-expanded code (as we can do on the `pdb` branch with a
Expand All @@ -34,27 +34,28 @@
;; regexp flavor, which AFAIK we'd need to implement ourselves.
;;
;; TL;DR: For now require `racket-sexp-edit-mode'.
(racket--assert-sexp-edit-mode)
(unless (bound-and-true-p hs-minor-mode)
(user-error "hs-minor-mode is not enabled"))
(unless hs-minor-mode
(hs-minor-mode))
(save-excursion
(goto-char (point-min))
(let ((n 0))
(while (re-search-forward "^(module[+*]? test" (point-max) t)
(funcall f)
(if fold-p (hs-hide-block) (hs-show-block))
(cl-incf n)
(goto-char (match-end 0)))
(message "%s %d test submodules" verb n))))
(message "%s %d test submodules" (if fold-p "Folded" "Unfolded") n))))

(defun racket-fold-all-tests ()
"Fold (hide) all test submodules."
(interactive)
(racket--for-all-tests "Folded" #'hs-hide-block))
(racket--assert-sexp-edit-mode)
(racket--fold-tests t))

(defun racket-unfold-all-tests ()
"Unfold (show) all test submodules."
(interactive)
(racket--for-all-tests "Unfolded" #'hs-show-block))
(racket--assert-sexp-edit-mode)
(racket--fold-tests nil))

;;; requires

Expand Down
1 change: 0 additions & 1 deletion racket-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@
;; Code folding
(add-to-list 'hs-special-modes-alist
'(racket-mode "(" ")" ";" nil nil))
(hs-minor-mode 1)
;; -----------------------------------------------------------------
;;; Misc
(setq-local local-abbrev-table racket-mode-abbrev-table)
Expand Down

0 comments on commit b7e4d62

Please sign in to comment.