Skip to content

Commit c8f83e0

Browse files
committed
Add refresh-mode flags to the namespace transient menu
Expose cider-ns-refresh's modes as explicit toggles on cider-ns-menu (--all, --clear, --inhibit-fns), instead of the undiscoverable single/ double/negative prefix arguments. cider-ns-refresh now also accepts a list of mode symbols (backward compatible with the scalar symbol/prefix forms), so the orthogonal inhibit-fns can combine with reload-all or clear.
1 parent 76eff25 commit c8f83e0

3 files changed

Lines changed: 43 additions & 7 deletions

File tree

lisp/cider-mode.el

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,31 @@ If invoked with a prefix ARG eval the expression after inserting it."
522522
"CIDER NS keymap.")
523523

524524
;;;###autoload (autoload 'cider-ns-menu "cider-mode" "Menu for CIDER's namespace commands." t)
525+
(transient-define-suffix cider-ns-menu--refresh (args)
526+
"Refresh namespaces, applying the menu's refresh ARGS.
527+
`--all', `--clear' and `--inhibit-fns' map to the corresponding
528+
`cider-ns-refresh' modes; with none set it does a smart reload."
529+
(interactive (list (transient-args 'cider-ns-menu)))
530+
(cider-ns-refresh
531+
(delq nil (list (and (member "--all" args) 'refresh-all)
532+
(and (member "--clear" args) 'clear)
533+
(and (member "--inhibit-fns" args) 'inhibit-fns)))))
534+
525535
(transient-define-prefix cider-ns-menu ()
526-
"Transient menu for CIDER's namespace commands."
536+
"Transient menu for CIDER's namespace commands.
537+
The refresh arguments make `cider-ns-refresh's modes (otherwise reached
538+
via prefix arguments) explicit toggles."
539+
["Refresh arguments"
540+
("-a" "Reload all (unconditionally)" "--all")
541+
("-c" "Clear the tracker first" "--clear")
542+
("-i" "Inhibit refresh functions" "--inhibit-fns")]
527543
[["Namespace"
528544
("b" "Browse namespace" cider-browse-ns)
529545
("f" "Find namespace" cider-find-ns)
530546
("n" "Set REPL namespace" cider-repl-set-ns)
531547
("e" "Eval namespace form" cider-eval-ns-form)]
532548
["Reload"
533-
("r" "Refresh (smart reload)" cider-ns-refresh)
549+
("r" "Refresh (smart reload)" cider-ns-menu--refresh)
534550
("l" "Require and reload" cider-ns-reload)
535551
("L" "Require and reload all" cider-ns-reload-all)]]
536552
;; Meta-variant duplicates, hidden from the menu, preserving muscle memory.
@@ -539,7 +555,7 @@ If invoked with a prefix ARG eval the expression after inserting it."
539555
("M-f" "Find namespace" cider-find-ns)
540556
("M-n" "Set REPL namespace" cider-repl-set-ns)
541557
("M-e" "Eval namespace form" cider-eval-ns-form)
542-
("M-r" "Refresh (smart reload)" cider-ns-refresh)
558+
("M-r" "Refresh (smart reload)" cider-ns-menu--refresh)
543559
("M-l" "Require and reload all" cider-ns-reload-all)])
544560

545561
;;;###autoload (autoload 'cider-menu "cider-mode" "Top-level transient menu for CIDER." t)

lisp/cider-ns.el

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,15 @@ unloaded.
359359
360360
With a negative prefix argument, or if MODE is `inhibit-fns', prevent any
361361
refresh functions (defined in `cider-ns-refresh-before-fn' and
362-
`cider-ns-refresh-after-fn') from being invoked."
362+
`cider-ns-refresh-after-fn') from being invoked.
363+
364+
MODE may also be a list combining these symbols (e.g. \\='(refresh-all
365+
inhibit-fns)), which is how `cider-ns-menu' passes its arguments."
363366
(interactive "p")
364-
(let ((clear? (member mode '(clear 16)))
365-
(all? (member mode '(refresh-all 4)))
366-
(inhibit-refresh-fns (member mode '(inhibit-fns -1))))
367+
(let* ((modes (if (listp mode) mode (list mode)))
368+
(clear? (or (memq 'clear modes) (memq 16 modes)))
369+
(all? (or (memq 'refresh-all modes) (memq 4 modes)))
370+
(inhibit-refresh-fns (or (memq 'inhibit-fns modes) (memq -1 modes))))
367371
(cider-map-repls '(:clj "cider/refresh" "cider.clj-reload/reload")
368372
(lambda (conn)
369373
(cider-ns-refresh--save-modified-buffers conn)

test/cider-ns-tests.el

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
(require 'buttercup)
2929
(require 'cider-ns)
30+
(require 'cider-mode) ; for `cider-ns-menu--refresh'
3031
(require 'cider-test-utils "test/utils/cider-test-utils")
3132

3233
;; Please, for each `describe', ensure there's an `it' block, so that its execution is visible in CI.
@@ -250,3 +251,18 @@
250251
:to-equal 'cider-ns-refresh))
251252
(it "provides a menu (#2798)"
252253
(expect (lookup-key cider-ns-refresh-log-mode-map [menu-bar]) :to-be-truthy)))
254+
255+
(describe "cider-ns-menu--refresh"
256+
(before-each (spy-on 'cider-ns-refresh))
257+
258+
(it "translates the menu switches into a list of refresh modes"
259+
(cider-ns-menu--refresh '("--all" "--inhibit-fns"))
260+
(expect 'cider-ns-refresh :to-have-been-called-with '(refresh-all inhibit-fns)))
261+
262+
(it "passes clear on its own"
263+
(cider-ns-menu--refresh '("--clear"))
264+
(expect 'cider-ns-refresh :to-have-been-called-with '(clear)))
265+
266+
(it "passes nil for a plain smart reload when no switches are set"
267+
(cider-ns-menu--refresh nil)
268+
(expect 'cider-ns-refresh :to-have-been-called-with nil)))

0 commit comments

Comments
 (0)