Skip to content

Commit 07b2738

Browse files
committed
Include the project name automatically in the REPL buffer name
1 parent 397272d commit 07b2738

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* [#190](https://github.com/clojure-emacs/inf-clojure/pull/190): Helper function `inf-clojure-set-repl` to select inf-clojure process buffer.
88
* Auto-enable `inf-clojure-minor-mode` after invoking `inf-clojure`. This behaviour is controlled via `inf-clojure-auto-mode`.
9+
* Include the project name automatically in the REPL buffer name.
910

1011
### Bugs fixed
1112

inf-clojure.el

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,11 @@ to suppress the usage of the target buffer discovery logic."
720720
(call-interactively #'inf-clojure)
721721
(rename-buffer target-buffer-name)))
722722

723+
(defun inf-clojure--project-name (dir)
724+
"Extract a project name from a project DIR.
725+
The name is simply the final segment of the path."
726+
(file-name-nondirectory (directory-file-name dir)))
727+
723728
;;;###autoload
724729
(defun inf-clojure (cmd)
725730
"Run an inferior Clojure process, input and output via buffer `*inf-clojure*'.
@@ -744,26 +749,29 @@ process buffer for a list of commands.)"
744749
(mapcar #'cdr inf-clojure-startup-forms)
745750
nil
746751
'confirm-after-completion))))
747-
(if (not (comint-check-proc "*inf-clojure*"))
748-
;; run the new process in the project's root when in a project folder
749-
(let ((default-directory (or (clojure-project-dir) default-directory))
750-
(cmdlist (if (consp cmd)
751-
(list cmd)
752-
(split-string cmd)))
753-
(repl-type (or (unless prefix-arg
754-
inf-clojure-custom-repl-type)
755-
(car (rassoc cmd inf-clojure-startup-forms))
756-
(inf-clojure--prompt-repl-type))))
757-
(message "Starting Clojure REPL via `%s'..." cmd)
758-
(with-current-buffer (apply #'make-comint
759-
"inf-clojure" (car cmdlist) nil (cdr cmdlist))
760-
(inf-clojure-mode)
761-
(setq-local inf-clojure-repl-type repl-type)
762-
(hack-dir-local-variables-non-file-buffer))))
763-
(setq inf-clojure-buffer (get-buffer "*inf-clojure*"))
764-
(if inf-clojure-repl-use-same-window
765-
(pop-to-buffer-same-window "*inf-clojure*")
766-
(pop-to-buffer "*inf-clojure*")))
752+
(let* ((project-dir (clojure-project-dir))
753+
(repl-buffer-name (if project-dir (format "*inf-clojure %s*" (inf-clojure--project-name project-dir)) "*inf-clojure*"))
754+
(comint-name (string-trim repl-buffer-name "*" "*")))
755+
(if (not (comint-check-proc repl-buffer-name))
756+
;; run the new process in the project's root when in a project folder
757+
(let ((default-directory (or project-dir default-directory))
758+
(cmdlist (if (consp cmd)
759+
(list cmd)
760+
(split-string cmd)))
761+
(repl-type (or (unless prefix-arg
762+
inf-clojure-custom-repl-type)
763+
(car (rassoc cmd inf-clojure-startup-forms))
764+
(inf-clojure--prompt-repl-type))))
765+
(message "Starting Clojure REPL via `%s'..." cmd)
766+
(with-current-buffer (apply #'make-comint
767+
comint-name (car cmdlist) nil (cdr cmdlist))
768+
(inf-clojure-mode)
769+
(setq-local inf-clojure-repl-type repl-type)
770+
(hack-dir-local-variables-non-file-buffer))))
771+
(setq inf-clojure-buffer (get-buffer repl-buffer-name))
772+
(if inf-clojure-repl-use-same-window
773+
(pop-to-buffer-same-window repl-buffer-name)
774+
(pop-to-buffer repl-buffer-name))))
767775

768776
;;;###autoload
769777
(defun inf-clojure-connect (host port)
@@ -1436,7 +1444,7 @@ Useful for commands that can invoked outside of an ‘inf-clojure’ buffer
14361444
"Send FORM and apply MATCH-P on the result of sending it to PROC.
14371445
Note that this function will add a \n to the end of the string
14381446
for evaluation, therefore FORM should not include it."
1439-
(funcall match-p (inf-clojure--process-response form proc nil)))
1447+
p (funcall match-p (inf-clojure--process-response form proc nil)))
14401448

14411449
(provide 'inf-clojure)
14421450

0 commit comments

Comments
 (0)