Skip to content

Commit 1d6260a

Browse files
committed
[Fix #29] Add a command to restart a REPL
This commit also tweaks `inf-clojure-quit' and makes it possible to pass the buffer to quit as an optional parameter.
1 parent d0f0ee8 commit 1d6260a

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Font-lock the code in the REPL.
1212
* Handle properly ANSI color escape sequences in the REPL.
1313
* [#41](https://github.com/clojure-emacs/inf-clojure/issues/41): Add a command to quit the REPL (it's bound to `C-c C-q`).
14+
* [#29](https://github.com/clojure-emacs/inf-clojure/issues/29): Add a command to restart the REPL.
1415

1516
### Changes
1617

inf-clojure.el

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword
9090
["Show source for var" inf-clojure-show-var-source t]
9191
"--"
9292
["Clear REPL" inf-clojure-clear-repl-buffer]
93+
["Restart" inf-clojure-restart]
9394
["Quit" inf-clojure-quit]
9495
"--"
9596
["Version" inf-clojure-display-version]))
@@ -134,6 +135,7 @@ mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword
134135
["Apropos" inf-clojure-apropos t]
135136
["Macroexpand" inf-clojure-macroexpand t]
136137
"--"
138+
["Restart REPL" inf-clojure-restart]
137139
["Quit REPL" inf-clojure-quit]))
138140
map))
139141

@@ -828,13 +830,30 @@ Useful for commands that can invoked outside of an inf-clojure buffer
828830
((= (length repl-buffers) 1) (car repl-buffers))
829831
(t (get-buffer (completing-read "Select target inf-clojure buffer: " (mapcar #'buffer-name repl-buffers))))))))
830832

831-
(defun inf-clojure-quit ()
832-
"Kill the REPL buffer and its underlying process."
833+
(defun inf-clojure-quit (&optional buffer)
834+
"Kill the REPL buffer and its underlying process.
835+
836+
You can pass the target BUFFER as an optional parameter
837+
to suppress the usage of the target buffer discovery logic."
833838
(interactive)
834-
(let ((target-buffer (inf-clojure-select-target-repl)))
835-
(delete-process target-buffer)
839+
(let ((target-buffer (or buffer (inf-clojure-select-target-repl))))
840+
(when (get-buffer-process target-buffer)
841+
(delete-process target-buffer))
836842
(kill-buffer target-buffer)))
837843

844+
(defun inf-clojure-restart (&optional buffer)
845+
"Restart the REPL buffer and its underlying process.
846+
847+
You can pass the target BUFFER as an optional parameter
848+
to suppress the usage of the target buffer discovery logic."
849+
(interactive)
850+
(let* ((target-buffer (or buffer (inf-clojure-select-target-repl)))
851+
(target-buffer-name (buffer-name target-buffer)))
852+
;; TODO: Try to recycle the old buffer instead of killing and recreating it
853+
(inf-clojure-quit target-buffer)
854+
(inf-clojure inf-clojure-program)
855+
(rename-buffer target-buffer-name)))
856+
838857
(provide 'inf-clojure)
839858

840859
;;; inf-clojure.el ends here

0 commit comments

Comments
 (0)