You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/site/evaluation.md
+49-12
Original file line number
Diff line number
Diff line change
@@ -66,9 +66,22 @@ An ”exception” is introduced by the `comment` form. It will create a new top
66
66
67
67
At the top level the selection of which form is the current top level form follows the same rules as those for [the current form](#current-form).
68
68
69
+
### Evaluate Enclosing Form
70
+
71
+
The default keyboard shortcut for evaluating the current enclosing form (the list the cursor is in) is `ctrl+shift+enter`.
72
+
73
+
```clojure
74
+
(let [foo :bar]
75
+
(whenfalse (str| foo))) ; => ":bar"
76
+
```
77
+
69
78
### Evaluate to Cursor
70
79
71
-
There is also a command for evaluating the text from the start of the current list to where the cursor is. Convenient for checking intermediate results in thread or `doto`, or similar pipelines. The cursor is right behind `:d` in this form:
80
+
There are several commands for evaluating a piece of code, closing brackets. It's good, especially in threads, but can also come in handy in other situations, for instance when you want to evaluate something that depends on bindings, such as in a `let` form.
81
+
82
+
### Evaluate From Start of List to Cursor, Closing Brackets
83
+
84
+
This command evaluates the text from the start of the current enclosing list to where the cursor is, and it adds the missing closing bracket for you. Convenient for checking intermediate results in thread or `doto`, or similar pipelines. The cursor is right behind `:d` in this form:
72
85
73
86
```clojure
74
87
(->> [1123581321]
@@ -79,11 +92,40 @@ There is also a command for evaluating the text from the start of the current li
79
92
(Math/abs))
80
93
```
81
94
82
-
The default shortcut for this command is `ctrl+alt+enter`.
95
+
The default shortcut for this command is <kbd>ctrl+alt+enter</kbd>.
96
+
97
+
### Evaluate Selection, Closing Brackets
98
+
99
+
This is the most versatile of the ”evaluation, closing brackets” commands. It will do what it says. 😄 It's extra handy in combination with the command **Paredit: Select Backward Up Sexp/Form** (<kbd>shift+ctrl+up</kbd>). Consider this contrieved form (buggy code, because it was supposed to result in `42`, not `-42`):
100
+
101
+
```clojure
102
+
(defnfortytwo-from-thirty
103
+
[]
104
+
(let [thirty 30]
105
+
(-> thirty
106
+
inc ;1
107
+
(send-off)
108
+
(+123)
109
+
(->>
110
+
(+22) ;2
111
+
(+))
112
+
list
113
+
(->>
114
+
(into [1])
115
+
(reduce + 1))
116
+
(-1) ;3
117
+
(*-1))))
118
+
```
119
+
120
+
At `;1`, you can do **backward up sexp** (<kbd>shift+ctrl+up</kbd>) twice to select up to the `(let ..)`, then issue **Evaluate Selection, Closing Brackets**. It has the same default keybinding as the command for [evaluating the current list up to the cursor](#evaluate-from-start-of-list-to-cursor-closing-brackets): <kbd>ctrl+alt+enter</kbd>.
83
121
84
-
### Evaluate Top Level Form to Cursor
122
+
At `;2` you need select backwards up three times.
85
123
86
-
This command has a default shortcut keybinding of `shift+alt+enter`. It will create a form from the start of the current top level form, up to the cursor, then fold the form, closing all brackets, and this will then be evaluated. Good for examining code blocks up to a certain point.
124
+
`;3` is included because it is close to the bug. (Which was introduced when the thread-last, `->>` was added to make this example.) Please practice the **Evaluate Selection, Closing Brackets** command to fix the bug.
125
+
126
+
### Evaluate From Start of Top Level Form to Cursor, Closing Brackets
127
+
128
+
This command has a default shortcut keybinding of `shift+alt+enter`. It will create a form from the start of the current top level form, up to the cursor, close all brackets, and this will then be evaluated. Good for examining code blocks up to a certain point. Often comes in handy in Rich comments (`(comment ...)`).
87
129
88
130
Take this example and paste it in a file loaded into the REPL, then place the cursor in front of each line comment and try the command.
89
131
@@ -116,16 +158,11 @@ Take this example and paste it in a file loaded into the REPL, then place the cu
116
158
))))
117
159
```
118
160
119
-
### Evaluate Enclosing Form
161
+
### Evaluate From Start of File to Cursor, Closing Brackets
120
162
121
-
The default keyboard shortcut for evaluating the current enclosing form (the list the cursor is in) is `ctrl+shift+enter`.
122
-
123
-
```clojure
124
-
(let [foo :bar]
125
-
(whenfalse (str| foo))) ; => ":bar"
126
-
```
163
+
Yup, that command also exists. 😄
127
164
128
-
###Copying the inline results
165
+
## Copying the inline results
129
166
130
167
There is a command called **Copy last evaluation results**, `ctrl+alt+c ctrl+c`.
0 commit comments