Skip to content

Commit 862699e

Browse files
committed
[Fix #41] Add a command to quit REPL buffers
For some reason simply killing the REPL buffer didn’t kill the process associated with it. This command handles such situations properly. As an added bonus it can be invoked from non-REPL buffers and can operate on multiple REPLs.
1 parent 872c143 commit 862699e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [#42](https://github.com/clojure-emacs/inf-clojure/issues/42): Add a defcustom controlling the window in which the REPL buffer is displayed (`inf-clojure-repl-use-same-window`).
1111
* Font-lock the code in the REPL.
1212
* Handle properly ANSI color escape sequences in the REPL.
13+
* [#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`).
1314

1415
### Changes
1516

inf-clojure.el

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword
7676
(define-key map "\C-c\C-v" #'inf-clojure-show-var-documentation)
7777
(define-key map "\C-c\C-s" #'inf-clojure-show-var-source)
7878
(define-key map "\C-c\M-o" #'inf-clojure-clear-repl-buffer)
79+
(define-key map "\C-c\C-q" #'inf-clojure-quit)
7980
(easy-menu-define inf-clojure-mode-menu map
8081
"Inferior Clojure REPL Menu"
8182
'("Inf-Clojure REPL"
@@ -88,6 +89,7 @@ mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword
8889
["Show source for var" inf-clojure-show-var-source t]
8990
"--"
9091
["Clear REPL" inf-clojure-clear-repl-buffer]
92+
["Quit" inf-clojure-quit]
9193
"--"
9294
["Version" inf-clojure-display-version]))
9395
map))
@@ -110,6 +112,7 @@ mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword
110112
(define-key map "\C-c\C-v" #'inf-clojure-show-var-documentation)
111113
(define-key map "\C-c\C-s" #'inf-clojure-show-var-source)
112114
(define-key map "\C-c\M-n" #'inf-clojure-set-ns)
115+
(define-key map "\C-c\C-q" #'inf-clojure-quit)
113116
(easy-menu-define inf-clojure-minor-mode-menu map
114117
"Inferior Clojure Minor Mode Menu"
115118
'("Inf-Clojure"
@@ -128,7 +131,9 @@ mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword
128131
["Show source for var" inf-clojure-show-var-source t]
129132
["Show vars in ns" inf-clojure-show-ns-varst]
130133
["Apropos" inf-clojure-apropos t]
131-
["Macroexpand" inf-clojure-macroexpand t]))
134+
["Macroexpand" inf-clojure-macroexpand t]
135+
"--"
136+
["Quit REPL" inf-clojure-quit]))
132137
map))
133138

134139
;;;###autoload
@@ -804,6 +809,31 @@ Return the number of nested sexp the point was over or after."
804809
(interactive)
805810
(message "inf-clojure (version %s)" inf-clojure-version))
806811

812+
(defun inf-clojure-select-target-repl ()
813+
"Find or select an inf-clojure buffer to operate on.
814+
815+
Useful for commands that can invoked outside of an inf-clojure buffer
816+
\\(e.g. from a Clojure buffer\\)."
817+
;; if we're in a inf-clojure buffer we simply return in
818+
(if (eq major-mode 'inf-clojure-mode)
819+
(current-buffer)
820+
;; otherwise we sift through all the inf-clojure buffers that are available
821+
(let ((repl-buffers (cl-remove-if-not (lambda (buf)
822+
(with-current-buffer buf
823+
(eq major-mode 'inf-clojure-mode)))
824+
(buffer-list))))
825+
(cond
826+
((null repl-buffers) (user-error "No inf-clojure buffers found"))
827+
((= (length repl-buffers) 1) (car repl-buffers))
828+
(t (get-buffer (completing-read "Select target inf-clojure buffer: " (mapcar #'buffer-name repl-buffers))))))))
829+
830+
(defun inf-clojure-quit ()
831+
"Kill the REPL buffer and its underlying process."
832+
(interactive)
833+
(let ((target-buffer (inf-clojure-select-target-repl)))
834+
(delete-process target-buffer)
835+
(kill-buffer target-buffer)))
836+
807837
(provide 'inf-clojure)
808838

809839
;;; inf-clojure.el ends here

0 commit comments

Comments
 (0)