Skip to content

Commit 09b7ea8

Browse files
committed
Merge pull request #504 from jonpither/nil-designation
[Fix #501] Nil appearing in nrepl-server buffer name when no project dir...
2 parents 35c8429 + 60003a0 commit 09b7ea8

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ visually distinctive from `cider-repl-output-face` (used for STDOUT output).
2929

3030
### Bugs fixed
3131

32+
* [#501](https://github.com/clojure-emacs/cider/issues/501) Fix
33+
nil appearing in nrepl-server buffer name when no project directory.
3234
* [#493](https://github.com/clojure-emacs/cider/issues/493) Fix rotate connection to handle no
3335
nREPL connection.
3436
* [#468](https://github.com/clojure-emacs/cider/issues/468) Fix

nrepl-client.el

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ buffer will be hidden.")
102102
"Apply a prefix to BUFFER-NAME that will hide the buffer."
103103
(concat (if nrepl-hide-special-buffers " " "") buffer-name))
104104

105+
(defun nrepl-format-buffer-name-template (buffer-name-template designation)
106+
"Apply the DESIGNATION to the corresponding BUFFER-NAME-TEMPLATE."
107+
(format buffer-name-template
108+
(if (> (length designation) 0)
109+
(concat nrepl-buffer-name-separator designation)
110+
"")))
111+
105112
(defun nrepl-buffer-name (buffer-name-template)
106113
"Generate a buffer name using BUFFER-NAME-TEMPLATE.
107114
@@ -111,10 +118,9 @@ connection port if `nrepl-buffer-name-show-port' is true."
111118
(generate-new-buffer-name
112119
(let ((project-name (nrepl--project-name nrepl-project-dir))
113120
(nrepl-proj-port (cadr nrepl-endpoint)))
114-
(format
121+
(nrepl-format-buffer-name-template
115122
buffer-name-template
116-
(concat (format "%s%s" nrepl-buffer-name-separator
117-
(if project-name project-name (car nrepl-endpoint)))
123+
(concat (if project-name project-name (car nrepl-endpoint))
118124
(if (and nrepl-proj-port nrepl-buffer-name-show-port)
119125
(format ":%s" nrepl-proj-port) ""))))))
120126

test/cider-tests.el

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,23 @@
212212
(should (equal b3 (current-buffer))))))
213213
(kill-buffer "*nrepl-connections*"))))))))
214214

215+
(ert-deftest test-nrepl-format-buffer-name-template ()
216+
(should (equal "*template designation-foo*"
217+
(nrepl-format-buffer-name-template "*template%s*" "designation-foo"))))
218+
219+
(ert-deftest test-nrepl-format-buffer-name-template-use-separator ()
220+
(let ((nrepl-buffer-name-separator "_"))
221+
(should (equal "*template_designation-foo*"
222+
(nrepl-format-buffer-name-template "*template%s*" "designation-foo")))))
223+
224+
(ert-deftest test-nrepl-format-buffer-name-template-handle-nil-designation ()
225+
(should (equal "*template*"
226+
(nrepl-format-buffer-name-template "*template%s*" nil))))
227+
228+
(ert-deftest test-nrepl-format-buffer-name-template-handle-empty-designation ()
229+
(should (equal "*template*"
230+
(nrepl-format-buffer-name-template "*template%s*" ""))))
231+
215232
(ert-deftest test-nrepl-buffer-name ()
216233
(with-temp-buffer
217234
(setq-local nrepl-endpoint '("localhost" 1))

0 commit comments

Comments
 (0)