Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1236] Add two more functions for use in cider-repl-prompt-function #1237

Merged
merged 1 commit into from
Aug 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### New features

* [#1212](https://github.com/clojure-emacs/cider/pull/1212): Add pagination of long collections to inspector.
* [#1237](https://github.com/clojure-emacs/cider/pull/1237): Add two functions for use with `cider-repl-prompt-function`, `cider-repl-prompt-lastname` and `repl-prompt-abbreviated`.
* [#1201](https://github.com/clojure-emacs/cider/pull/1201): Integrate overlays with interactive evaluation. `cider-use-overlays` can be used to turn this on or off.
* [#1195](https://github.com/clojure-emacs/cider/pull/1195): CIDER can [create cljs REPLs](https://github.com/clojure-emacs/cider#clojurescript-usage).
* [#1191](https://github.com/clojure-emacs/cider/pull/1191): New custom variables `cider-debug-print-level` and `cider-debug-print-length`.
Expand Down
32 changes: 27 additions & 5 deletions cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,36 @@ This will not work on non-current prompts."

(put 'cider-save-marker 'lisp-indent-function 1)

(defun cider-repl-default-prompt (namespace)
(defun cider-repl-prompt-default (namespace)
"Return a prompt string that mentions NAMESPACE."
(format "%s> " namespace))

(defcustom cider-repl-prompt-function #'cider-repl-default-prompt
(define-obsolete-function-alias 'cider-repl-default-prompt 'cider-repl-prompt-default "0.10.0")

(defun cider-repl-prompt-abbreviated (namespace)
"Return a prompt string that abbreviates NAMESPACE."
(let* ((names (reverse (split-string namespace "\\.")))
(lastname (car names)))
(concat (mapconcat (lambda (s) (concat (substring s 0 1) "."))
(reverse (cdr names))
"")
lastname
"> ")))

(defun cider-repl-prompt-lastname (namespace)
"Return a prompt string with the last name in NAMESPACE."
(let* ((name (car (reverse (split-string namespace "\\.")))))
(concat name "> ")))

(defcustom cider-repl-prompt-function #'cider-repl-prompt-default
"A function that returns a prompt string.
Takes one argument, a namespace name."
:type 'function
Takes one argument, a namespace name.
For convenience, three functions are already provided for this purpose:
`cider-repl-prompt-lastname', `cider-repl-prompt-abbreviated', and
`cider-repl-prompt-default'"
:type '(choice (const :tag "Full namespace" cider-repl-prompt-default)
(const :tag "Abbreviated namespace" cider-repl-prompt-abbreviated)
(const :tag "Last name in namespace" cider-repl-prompt-lastname)
(function :tag "Custom function"))
:group 'cider-repl
:package-version '(cider . "0.9.0"))

Expand Down
8 changes: 8 additions & 0 deletions test/cider-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,14 @@
(noflet ((thing-at-point (thing) "boogie>"))
(should (string= (cider-symbol-at-point) "boogie>"))))

(ert-deftest cider-repl-prompt-function ()
(should (equal (cider-repl-prompt-default "some.pretty.long.namespace.name")
"some.pretty.long.namespace.name> "))
(should (equal (cider-repl-prompt-lastname "some.pretty.long.namespace.name")
"name> "))
(should (equal (cider-repl-prompt-abbreviated "some.pretty.long.namespace.name")
"s.p.l.n.name> ")))

(ert-deftest test-cider--url-to-file ()
(should (equal "/space test" (cider--url-to-file "file:/space%20test")))
(should (equal "C:/space test" (cider--url-to-file "file:/C:/space%20test"))))
Expand Down