Skip to content

Commit

Permalink
[Fix #501] Nil appearing in nrepl-server buffer name when no project …
Browse files Browse the repository at this point in the history
…directory.
  • Loading branch information
jonpither committed Mar 7, 2014
1 parent 35c8429 commit 60003a0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ visually distinctive from `cider-repl-output-face` (used for STDOUT output).

### Bugs fixed

* [#501](https://github.com/clojure-emacs/cider/issues/501) Fix
nil appearing in nrepl-server buffer name when no project directory.
* [#493](https://github.com/clojure-emacs/cider/issues/493) Fix rotate connection to handle no
nREPL connection.
* [#468](https://github.com/clojure-emacs/cider/issues/468) Fix
Expand Down
12 changes: 9 additions & 3 deletions nrepl-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ buffer will be hidden.")
"Apply a prefix to BUFFER-NAME that will hide the buffer."
(concat (if nrepl-hide-special-buffers " " "") buffer-name))

(defun nrepl-format-buffer-name-template (buffer-name-template designation)
"Apply the DESIGNATION to the corresponding BUFFER-NAME-TEMPLATE."
(format buffer-name-template
(if (> (length designation) 0)
(concat nrepl-buffer-name-separator designation)
"")))

(defun nrepl-buffer-name (buffer-name-template)
"Generate a buffer name using BUFFER-NAME-TEMPLATE.
Expand All @@ -111,10 +118,9 @@ connection port if `nrepl-buffer-name-show-port' is true."
(generate-new-buffer-name
(let ((project-name (nrepl--project-name nrepl-project-dir))
(nrepl-proj-port (cadr nrepl-endpoint)))
(format
(nrepl-format-buffer-name-template
buffer-name-template
(concat (format "%s%s" nrepl-buffer-name-separator
(if project-name project-name (car nrepl-endpoint)))
(concat (if project-name project-name (car nrepl-endpoint))
(if (and nrepl-proj-port nrepl-buffer-name-show-port)
(format ":%s" nrepl-proj-port) ""))))))

Expand Down
17 changes: 17 additions & 0 deletions test/cider-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,23 @@
(should (equal b3 (current-buffer))))))
(kill-buffer "*nrepl-connections*"))))))))

(ert-deftest test-nrepl-format-buffer-name-template ()
(should (equal "*template designation-foo*"
(nrepl-format-buffer-name-template "*template%s*" "designation-foo"))))

(ert-deftest test-nrepl-format-buffer-name-template-use-separator ()
(let ((nrepl-buffer-name-separator "_"))
(should (equal "*template_designation-foo*"
(nrepl-format-buffer-name-template "*template%s*" "designation-foo")))))

(ert-deftest test-nrepl-format-buffer-name-template-handle-nil-designation ()
(should (equal "*template*"
(nrepl-format-buffer-name-template "*template%s*" nil))))

(ert-deftest test-nrepl-format-buffer-name-template-handle-empty-designation ()
(should (equal "*template*"
(nrepl-format-buffer-name-template "*template%s*" ""))))

(ert-deftest test-nrepl-buffer-name ()
(with-temp-buffer
(setq-local nrepl-endpoint '("localhost" 1))
Expand Down

0 comments on commit 60003a0

Please sign in to comment.