Skip to content

Commit

Permalink
[Fix #2160] Make it possible to customize *print-length* and *print-l…
Browse files Browse the repository at this point in the history
…evel* via defcustoms

We also set a default *print-level* of 100 to help people kill their REPLs less
often. :-)
  • Loading branch information
bbatsov committed Jan 20, 2018
1 parent 732c571 commit 107e05c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Add new interactive command `cider-repl-set-type`.
* [#1976](https://github.com/clojure-emacs/cider/issues/1976): Add new interactive command `cider-connect-clojurescript`.
* Add a menu for `cider-browse-ns-mode`.
* [#2160](https://github.com/clojure-emacs/cider/issues/2160): Make it possible to configure the default `*print-level*` and `*print-length*` via defcustoms (`cider-repl-print-level` and `cider-repl-print-length`).

### Bugs Fixed

Expand Down
31 changes: 31 additions & 0 deletions cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ you'd like to use the default Emacs behavior use
:type 'symbol
:group 'cider-repl)

(defcustom cider-repl-print-length 100
"Initial value for *print-length* set during REPL start."
:type 'integer
:group 'cider
:package-version '(cider . "0.17.0"))

(defcustom cider-repl-print-level nil
"Initial value for *print-level* set during REPL start."
:type 'integer
:group 'cider
:package-version '(cider . "0.17.0"))

(defcustom cider-repl-display-help-banner t
"When non-nil a bit of help text will be displayed on REPL start."
:type 'boolean
Expand Down Expand Up @@ -286,6 +298,24 @@ efficiency."
"inhibit-cider-middleware" "true")
(cider-current-connection)))

(defun cider-repl--build-config-expression ()
"Build the initial config expression."
(concat
"(do"
(when cider-repl-print-length (format " (set! *print-length* %d)" cider-repl-print-length))
(when cider-repl-print-level (format " (set! *print-level* %d)" cider-repl-print-level))
")"))

(defun cider-repl-set-config ()
"Set an inititial REPL configuration."
(interactive)
(nrepl-send-sync-request
(lax-plist-put
(nrepl--eval-request
(cider-repl--build-config-expression))
"inhibit-cider-middleware" "true")
(cider-current-connection)))

(defun cider-repl-init (buffer &optional no-banner)
"Initialize the REPL in BUFFER.
BUFFER must be a REPL buffer with `cider-repl-mode' and a running
Expand All @@ -297,6 +327,7 @@ client process connection. Unless NO-BANNER is non-nil, insert a banner."
((pred identity) (pop-to-buffer buffer)))
(cider-repl-set-initial-ns buffer)
(cider-repl-require-repl-utils)
(cider-repl-set-config)
(unless no-banner
(cider-repl--insert-banner-and-prompt buffer))
buffer)
Expand Down
6 changes: 6 additions & 0 deletions doc/using_the_repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ section of your Leiningen project's configuration.
:repl-options {:init (set! *print-length* 50)}
```

or via `cider-repl-print-length` (set to 100 by default). In case both are
present, CIDER's config will take precedence over what came from Lein.

Everything about applies for `*print-level*` as well. CIDER's configuration
variable for it is named `cider-repl-print-level` (set to `nil` by default).

#### Customizing the initial REPL namespace

Normally the CIDER REPL will start with the `user` namespace.
Expand Down

0 comments on commit 107e05c

Please sign in to comment.