Skip to content

Commit 98fe8de

Browse files
committed
Move the REPL config info in the "Using the REPL" section of the README
1 parent 0a9b518 commit 98fe8de

File tree

1 file changed

+118
-116
lines changed

1 file changed

+118
-116
lines changed

README.md

Lines changed: 118 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ specific CIDER release.**
4747
- [Connect to a running nREPL server](#connect-to-a-running-nrepl-server)
4848
- [Using cider-mode](#using-cider-mode)
4949
- [Using the REPL](#using-the-repl)
50+
- [REPL Configuration](#repl-configuration)
51+
- [REPL history](#repl-history)
5052
- [ClojureScript usage](#clojurescript-usage)
5153
- [Extended Workflow](#extended-workflow)
5254
- [Macroexpansion](#macroexpansion)
@@ -60,11 +62,8 @@ specific CIDER release.**
6062
- [Specifying indentation](#specifying-indentation)
6163
- [Running tests](#running-tests)
6264
- [Code reloading](#code-reloading)
63-
- [REPL history](#repl-history)
6465
- [Minibuffer completion](#minibuffer-completion)
6566
- [Auto-completion](#auto-completion)
66-
- [Pretty printing in the REPL](#pretty-printing-in-the-repl)
67-
- [Limiting printed output in the REPL](#limiting-printed-output-in-the-repl)
6867
- [Integration with other modes](#integration-with-other-modes)
6968
- [Caveats](#caveats)
7069
- [Var Metadata](#var-metadata)
@@ -475,6 +474,122 @@ character used to trigger the shortcuts is configurable via
475474
(setq cider-repl-shortcut-dispatch-char ?\:)
476475
```
477476

477+
#### REPL Configuration
478+
479+
* You can customize the prompt in REPL buffer. To do that you can customize
480+
`cider-repl-prompt-function` and set it to a function that takes one argument,
481+
a namespace name. For convenience, three functions are already provided:
482+
`cider-repl-prompt-lastname`, `cider-repl-prompt-abbreviated`,
483+
`cider-repl-prompt-default` and by default the last one is being used.
484+
Prompt for each of them for namespace `leiningen.core.ssl`:
485+
486+
* `cider-repl-prompt-lastname`:
487+
488+
```
489+
ssl>
490+
```
491+
492+
* `cider-repl-prompt-abbreviated`:
493+
494+
```
495+
l.c.ssl>
496+
```
497+
498+
* `cider-repl-prompt-default`:
499+
500+
```
501+
leiningen.core.ssl>
502+
```
503+
504+
You may, of course, write your own function. For example, in `leiningen` there
505+
are two namespaces with similar names - `leiningen.classpath` and
506+
`leiningen.core.classpath`. To make them easily recognizable you can either
507+
use the default value or you can opt to show only two segments of the
508+
namespace and still be able to know which is the REPL's current
509+
namespace. Here is an example function that will do exactly that:
510+
511+
```el
512+
(defun cider-repl-prompt-show-two (namespace)
513+
"Return a prompt string with the last name in NAMESPACE."
514+
(let* ((names (reverse (-take 2 (reverse (split-string namespace "\\."))))))
515+
(concat (car names) "." (cadr names) "> ")))
516+
```
517+
518+
* By default, interactive commands that require a symbol will prompt for the
519+
symbol, with the prompt defaulting to the symbol at point. You can set
520+
`cider-prompt-for-symbol` to nil to instead try the command with the symbol at
521+
point first, and only prompt if that fails.
522+
523+
* You can control the <kbd>TAB</kbd> key behavior in the REPL via the
524+
`cider-repl-tab-command` variable. While the default command
525+
`cider-repl-indent-and-complete-symbol` should be an adequate choice for
526+
most users, it's very easy to switch to another command if you wish
527+
to. For instance if you'd like <kbd>TAB</kbd> to only indent (maybe
528+
because you're used to completing with <kbd>M-TAB</kbd>) use the
529+
following snippet:
530+
531+
```el
532+
(setq cider-repl-tab-command #'indent-for-tab-command)
533+
```
534+
535+
* Change the result prefix for REPL evaluation (by default there's no prefix):
536+
537+
```el
538+
(setq cider-repl-result-prefix ";; => ")
539+
```
540+
541+
And here's the result of that change:
542+
543+
```
544+
user> (+ 1 2)
545+
;; => 3
546+
```
547+
548+
##### Pretty printing in the REPL
549+
550+
Make the REPL always pretty-print the results of your commands. Note
551+
that this will not work correctly with forms such as `(def a 1) (def b2)`
552+
and it expects `clojure.pprint` to have been required already
553+
(the default in more recent versions of Clojure):
554+
555+
<kbd>M-x cider-repl-toggle-pretty-printing</kbd>
556+
557+
##### Limiting printed output in the REPL
558+
559+
Accidentally printing large objects can be detrimental to your
560+
productivity. Clojure provides the `*print-length*` var which, if set,
561+
controls how many items of each collection the printer will print. You
562+
can supply a default value for REPL sessions via the `repl-options`
563+
section of your Leiningen project's configuration.
564+
565+
```clojure
566+
:repl-options {:init (set! *print-length* 50)}
567+
```
568+
569+
##### REPL history
570+
571+
* To make the REPL history wrap around when its end is reached:
572+
573+
```el
574+
(setq cider-repl-wrap-history t)
575+
```
576+
577+
* To adjust the maximum number of items kept in the REPL history:
578+
579+
```el
580+
(setq cider-repl-history-size 1000) ; the default is 500
581+
```
582+
583+
* To store the REPL history in a file:
584+
585+
```el
586+
(setq cider-repl-history-file "path/to/file")
587+
```
588+
589+
Note that the history is written to the file when you kill the REPL
590+
buffer (which includes invoking `cider-quit`) or you quitting Emacs.
591+
592+
478593
### ClojureScript usage
479594

480595
ClojureScript support relies on the
@@ -751,62 +866,6 @@ When using `switch-to-buffer`, pressing <kbd>SPC</kbd> after the command will
751866
make the hidden buffers visible. They'll always be visible in
752867
`list-buffers` (<kbd>C-x C-b</kbd>).
753868

754-
* You can customize the prompt in REPL buffer. To do that you can customize
755-
`cider-repl-prompt-function` and set it to a function that takes one argument,
756-
a namespace name. For convenience, three functions are already provided:
757-
`cider-repl-prompt-lastname`, `cider-repl-prompt-abbreviated`,
758-
`cider-repl-prompt-default` and by default the last one is being used.
759-
Prompt for each of them for namespace `leiningen.core.ssl`:
760-
761-
* `cider-repl-prompt-lastname`:
762-
763-
```
764-
ssl>
765-
```
766-
767-
* `cider-repl-prompt-abbreviated`:
768-
769-
```
770-
l.c.ssl>
771-
```
772-
773-
* `cider-repl-prompt-default`:
774-
775-
```
776-
leiningen.core.ssl>
777-
```
778-
779-
You may, of course, write your own function. For example, in `leiningen` there
780-
are two namespaces with similar names - `leiningen.classpath` and
781-
`leiningen.core.classpath`. To make them easily recognizable you can either
782-
use the default value or you can opt to show only two segments of the
783-
namespace and still be able to know which is the REPL's current
784-
namespace. Here is an example function that will do exactly that:
785-
786-
```el
787-
(defun cider-repl-prompt-show-two (namespace)
788-
"Return a prompt string with the last name in NAMESPACE."
789-
(let* ((names (reverse (-take 2 (reverse (split-string namespace "\\."))))))
790-
(concat (car names) "." (cadr names) "> ")))
791-
```
792-
793-
* By default, interactive commands that require a symbol will prompt for the
794-
symbol, with the prompt defaulting to the symbol at point. You can set
795-
`cider-prompt-for-symbol` to nil to instead try the command with the symbol at
796-
point first, and only prompt if that fails.
797-
798-
* You can control the <kbd>TAB</kbd> key behavior in the REPL via the
799-
`cider-repl-tab-command` variable. While the default command
800-
`cider-repl-indent-and-complete-symbol` should be an adequate choice for
801-
most users, it's very easy to switch to another command if you wish
802-
to. For instance if you'd like <kbd>TAB</kbd> to only indent (maybe
803-
because you're used to completing with <kbd>M-TAB</kbd>) use the
804-
following snippet:
805-
806-
```el
807-
(setq cider-repl-tab-command #'indent-for-tab-command)
808-
```
809-
810869
* To prefer local resources to remote (tramp) ones when both are available:
811870

812871
```el
@@ -893,19 +952,6 @@ Buffer name will look like *cider-repl project-name:port*.
893952
(setq cider-prompt-save-file-on-load 'always-save)
894953
```
895954

896-
* Change the result prefix for REPL evaluation (by default there's no prefix):
897-
898-
```el
899-
(setq cider-repl-result-prefix ";; => ")
900-
```
901-
902-
And here's the result of that change:
903-
904-
```
905-
user> (+ 1 2)
906-
;; => 3
907-
```
908-
909955
* Change the result prefix for interactive evaluation (by default it's `=> `):
910956

911957
```el
@@ -1060,29 +1106,6 @@ passed or failed:
10601106
(setq cider-refresh-show-log-buffer t)
10611107
```
10621108

1063-
### REPL history
1064-
1065-
* To make the REPL history wrap around when its end is reached:
1066-
1067-
```el
1068-
(setq cider-repl-wrap-history t)
1069-
```
1070-
1071-
* To adjust the maximum number of items kept in the REPL history:
1072-
1073-
```el
1074-
(setq cider-repl-history-size 1000) ; the default is 500
1075-
```
1076-
1077-
* To store the REPL history in a file:
1078-
1079-
```el
1080-
(setq cider-repl-history-file "path/to/file")
1081-
```
1082-
1083-
Note that the history is written to the file when you kill the REPL
1084-
buffer (which includes invoking `cider-quit`) or you quitting Emacs.
1085-
10861109
### Minibuffer completion
10871110

10881111
Out-of-the box CIDER uses the standard `completing-read` Emacs mechanism. While it's not
@@ -1165,27 +1188,6 @@ Completion annotations can be disabled by setting
11651188
<img src="screenshots/completion-annotations.png" width="400" />
11661189
</p>
11671190

1168-
### Pretty printing in the REPL
1169-
1170-
Make the REPL always pretty-print the results of your commands. Note
1171-
that this will not work correctly with forms such as `(def a 1) (def b2)`
1172-
and it expects `clojure.pprint` to have been required already
1173-
(the default in more recent versions of Clojure):
1174-
1175-
<kbd>M-x cider-repl-toggle-pretty-printing</kbd>
1176-
1177-
### Limiting printed output in the REPL
1178-
1179-
Accidentally printing large objects can be detrimental to your
1180-
productivity. Clojure provides the `*print-length*` var which, if set,
1181-
controls how many items of each collection the printer will print. You
1182-
can supply a default value for REPL sessions via the `repl-options`
1183-
section of your Leiningen project's configuration.
1184-
1185-
```clojure
1186-
:repl-options {:init (set! *print-length* 50)}
1187-
```
1188-
11891191
### Integration with other modes
11901192

11911193
* Enabling `CamelCase` support for editing commands(like

0 commit comments

Comments
 (0)