summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--elisp/geiser-edit.el28
-rw-r--r--elisp/geiser-racket.el21
3 files changed, 51 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index a97af0a..5f3b250 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@
New features:
+ - Racket: new commands geiser-racket-{show, hide, toggle}-tests,
+ for hiding test modules in code buffers.
- Racket: interaction with submodules (entering them and evaluation
within their scope).
- New commands geiser-eval-buffer (C-c C-b) and
diff --git a/elisp/geiser-edit.el b/elisp/geiser-edit.el
index 5d5cd1b..f75e303 100644
--- a/elisp/geiser-edit.el
+++ b/elisp/geiser-edit.el
@@ -181,6 +181,34 @@ or following links in error buffers.")
(goto-char p)
(error "No %s error" msg))))
+
+;;; Visibility
+(defun geiser-edit--cloak (form)
+ (intern (format "geiser-edit-cloak-%s" form)))
+
+(defun geiser-edit--hide (form)
+ (geiser-edit--show form)
+ (let ((cloak (geiser-edit--cloak form)))
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward (format "(%s\\b" (regexp-quote form)) nil t)
+ (let* ((beg (match-beginning 0))
+ (end (progn (ignore-errors (goto-char beg) (forward-sexp))
+ (point))))
+ (when (> end beg)
+ (overlay-put (make-overlay beg end) 'invisible cloak)))))
+ (add-to-invisibility-spec (cons cloak t))))
+
+(defun geiser-edit--show (form)
+ (let ((cloak (geiser-edit--cloak form)))
+ (remove-overlays nil nil 'invisible cloak)
+ (remove-from-invisibility-spec (cons cloak t))))
+
+(defun geiser-edit--toggle-visibility (form)
+ (if (and (listp buffer-invisibility-spec)
+ (assoc (geiser-edit--cloak form) buffer-invisibility-spec))
+ (geiser-edit--show form)
+ (geiser-edit--hide form)))
;;; Commands:
diff --git a/elisp/geiser-racket.el b/elisp/geiser-racket.el
index 4fbc017..9e00c4d 100644
--- a/elisp/geiser-racket.el
+++ b/elisp/geiser-racket.el
@@ -370,6 +370,27 @@ using start-geiser, a procedure in the geiser/server module."
(setq geiser-image-cache-dir
(geiser-eval--send/result '(:eval (image-cache) geiser/user)))))
+
+;;; Additional commands
+
+(defconst geiser-racket--test-module "module+ test")
+
+(defun geiser-racket-toggle-tests ()
+ "Toggle visibility of test module fragments of the form (module+ test).
+
+When hidden, the test module forms are shown as an ellipsis."
+ (interactive)
+ (geiser-edit--toggle-visibility geiser-racket--test-module))
+
+(defun geiser-racket-show-tests ()
+ "Unconditionally shows all test modules."
+ (interactive)
+ (geiser-edit--show geiser-racket--test-module))
+
+(defun geiser-racket-hide-tests ()
+ "Unconditionally hides all visible test modules."
+ (interactive)
+ (geiser-edit--hide geiser-racket--test-module))
;;; Implementation definition: