Skip to content

Commit 111d957

Browse files
committed
[Fix #1789] Make it easier to change the connection of the scratch
buffer It wasn't really apparent how one was supposed to change the connection of a scratch buffer, so the relevant command was added to the mode's menu. I've also added another command to quickly toggle a buffer's connection between Clojure and ClojureScript.
1 parent 579a8dd commit 111d957

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ request dispatch.
1212
within the scope of your current Emacs session.
1313
* [#1851](https://github.com/clojure-emacs/cider/issues/1851): Add a command to rerun the last test ran via `cider-test-run-test`. The new command is named `cider-test-rerun-test` and is about to `C-c C-t (C-)g`.
1414
* [#1748](https://github.com/clojure-emacs/cider/issues/1748): Add new interactive command `cider-pprint-eval-last-sexp-to-repl`.
15+
* [#1789](https://github.com/clojure-emacs/cider/issues/1789): Make it easy to change the connection of the cider-scratch buffer from the mode's menu.
16+
* New interactive command `cider-toggle-buffer-connection`.
1517

1618
### Changes
1719

cider-client.el

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ such a link cannot be established automatically."
205205
(when conn
206206
(setq-local cider-connections (list conn)))))
207207

208+
(defun cider-toggle-buffer-connection ()
209+
"Toggles the current buffer's connection between Clojure and ClojureScript."
210+
(interactive)
211+
(cider-ensure-connected)
212+
(let ((other-conn (cider-other-connection)))
213+
(if other-conn
214+
(setq-local cider-connections (list other-conn))
215+
(user-error "No other connection available"))))
216+
208217
(defun cider-clear-buffer-local-connection ()
209218
"Remove association between the current buffer and a connection."
210219
(interactive)

cider-scratch.el

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,23 @@
3232

3333
(require 'cider-interaction)
3434
(require 'clojure-mode)
35+
(require 'easymenu)
3536

3637
(defvar cider-clojure-interaction-mode-map
3738
(let ((map (make-sparse-keymap)))
3839
(set-keymap-parent map clojure-mode-map)
3940
(define-key map (kbd "C-j") #'cider-eval-print-last-sexp)
4041
(define-key map [remap paredit-newline] #'cider-eval-print-last-sexp)
42+
(easy-menu-define cider-clojure-interaction-mode-menu map
43+
"Menu for Clojure Interaction mode"
44+
'("Clojure Interaction"
45+
(["Eval and print last sexp" #'cider-eval-print-last-sexp]
46+
"--"
47+
["Reset" #'cider-scratch-reset]
48+
"--"
49+
["Set buffer connection" #'cider-assoc-buffer-with-connection]
50+
["Toggle buffer connection" #'cider-toggle-buffer-connection]
51+
["Reset buffer connection" #'cider-clear-buffer-local-connection])))
4152
map))
4253

4354
(defconst cider-scratch-buffer-name "*cider-scratch*")
@@ -62,14 +73,24 @@ before point, and prints its value into the buffer, advancing point.
6273
6374
\\{cider-clojure-interaction-mode-map}")
6475

76+
(defun cider--scratch-insert-welcome-message ()
77+
"Insert the welcome message for the scratch buffer."
78+
(insert ";; This buffer is for Clojure experiments and evaluation.\n"
79+
";; Press C-j to evaluate the last expression.\n\n"))
80+
6581
(defun cider-create-scratch-buffer ()
6682
"Create a new scratch buffer."
6783
(with-current-buffer (get-buffer-create cider-scratch-buffer-name)
6884
(cider-clojure-interaction-mode)
69-
(insert ";; This buffer is for Clojure experiments and evaluation.\n"
70-
";; Press C-j to evaluate the last expression.\n\n")
85+
(cider--scratch-insert-welcome-message)
7186
(current-buffer)))
7287

88+
(defun cider-scratch-reset ()
89+
"Reset the current scratch buffer."
90+
(interactive)
91+
(erase-buffer)
92+
(cider--scratch-insert-welcome-message))
93+
7394
(provide 'cider-scratch)
7495

7596
;;; cider-scratch.el ends here

0 commit comments

Comments
 (0)