@@ -143,6 +143,24 @@ send the code to the kernel."
143
143
:type 'boolean
144
144
:group 'jupyter-repl )
145
145
146
+ (defcustom jupyter-repl-without-is-complete nil
147
+ " Whether or not is_complete_request handling is done.
148
+ If this variable is nil, an is_complete_request is usually sent
149
+ to the kernel on every press of
150
+ \\ <jupyter-repl-mode-map>\\ [jupyter-repl-ret] to determine if the
151
+ code is syntactically correct before sending it to be executed.
152
+ If the kernel responds to this message by saying that the code is
153
+ correct, then the code is sent to be executed immediately.
154
+
155
+ If this variable is non-nil,
156
+ \\ <jupyter-repl-mode-map>\\ [jupyter-repl-ret] no longer sends
157
+ is_complete_request messages nor does what is explained by
158
+ `jupyter-repl-use-builtin-is-complete' and just inserts a newline
159
+ and indents. In order to send an execute_request in this case,
160
+ you have to press \\ <jupyter-repl-mode-map>\\ [jupyter-repl-send]."
161
+ :type 'boolean
162
+ :group 'jupyter-repl )
163
+
146
164
(defcustom jupyter-repl-echo-eval-p nil
147
165
" Copy evaluation input to a REPL cell if non-nil.
148
166
If non-nil, and when calling the `jupyter-eval-*' functions like
@@ -196,11 +214,18 @@ current output of the cell. Set when the kernel sends a
196
214
" The history of the current Jupyter REPL." )
197
215
198
216
(defvar-local jupyter-repl-use-builtin-is-complete nil
199
- " Whether or not to send `:is-complete-request' s to a kernel.
217
+ " Whether or not to send an is_complete_request to a kernel.
200
218
If a Jupyter kernel does not respond to an is_complete_request,
201
219
the buffer local value of this variable is set to t and code in a
202
220
cell is considered complete if the last line in a code cell is a
203
- blank line, i.e. if RET is pressed twice in a row." )
221
+ blank line, i.e. if \\ <jupyter-repl-mode-map>\\ [jupyter-repl-ret]
222
+ is pressed twice in a row.
223
+
224
+ Note `jupyter-repl-without-is-complete' takes precedence over
225
+ this variable so when `jupyter-repl-without-is-complete' is
226
+ non-nil you have to press
227
+ \\ <jupyter-repl-mode-map>\\ [jupyter-repl-send] to send the code
228
+ regardless of the setting of this variable.." )
204
229
205
230
(cl-generic-define-context-rewriter jupyter-repl-mode (mode &rest modes)
206
231
`(jupyter-repl-lang-mode (derived-mode , mode ,@modes )))
@@ -1169,16 +1194,23 @@ elements."
1169
1194
(when restart
1170
1195
(jupyter-repl--insert-banner-and-prompt client))))))))
1171
1196
1197
+ (defun jupyter-repl-send ()
1198
+ " Send the current cell code to the kernel.
1199
+ As opposed to `jupyter-repl-ret' this sends the code immediately
1200
+ without considering the syntactical correctness of the code."
1201
+ (interactive )
1202
+ (jupyter-repl-ret 'force ))
1203
+
1172
1204
(defun jupyter-repl-ret (&optional force )
1173
1205
" Send the current cell code to the kernel.
1174
1206
If `point' is before the last cell in the REPL buffer move to
1175
1207
`point-max' , i.e. move to the last cell. Otherwise if `point' is
1176
1208
at some position within the last cell, either insert a newline or
1177
1209
ask the kernel to execute the cell code depending on the kernel's
1178
- response to an `:is-complete-request' .
1210
+ response to an is_complete_request .
1179
1211
1180
1212
If a prefix argument is given, FORCE the kernel to execute the
1181
- current cell code without sending an `:is-complete-request' . See
1213
+ current cell code without sending an is_complete_request . See
1182
1214
`jupyter-repl-use-builtin-is-complete' for yet another way to
1183
1215
execute the current cell."
1184
1216
(interactive " P" )
@@ -1190,27 +1222,33 @@ execute the current cell."
1190
1222
(goto-char (point-max ))
1191
1223
(unless (jupyter-repl-connected-p)
1192
1224
(error " Kernel not alive " ))
1193
- ; ; NOTE: kernels allow execution requests to queue up, but we prevent
1194
- ; ; sending a request when the kernel is busy because of the
1195
- ; ; is-complete request. Some kernels don't respond to this request
1196
- ; ; when the kernel is busy.
1197
- (when (and (jupyter-kernel-busy-p jupyter-current-client)
1198
- (not jupyter-repl-allow-RET-when-busy))
1199
- (error " Kernel busy " ))
1225
+ (unless (eq this-command 'jupyter-repl-send )
1226
+ ; ; NOTE: kernels allow execution requests to queue up, but
1227
+ ; ; we prevent sending a request when the kernel is busy
1228
+ ; ; because of the is_complete_request. Some kernels don't
1229
+ ; ; respond to this request when the kernel is busy.
1230
+ (when (and (jupyter-kernel-busy-p jupyter-current-client)
1231
+ (not jupyter-repl-allow-RET-when-busy))
1232
+ (error " Kernel busy " )))
1200
1233
(cond
1201
1234
(force (jupyter-repl-execute-cell))
1235
+ (jupyter-repl-without-is-complete
1236
+ (newline )
1237
+ (jupyter-repl-indent-line))
1202
1238
((or jupyter-repl-use-builtin-is-complete
1203
1239
(and jupyter-repl-allow-RET-when-busy
1204
1240
(jupyter-kernel-busy-p jupyter-current-client)))
1205
- (goto-char (point-max ))
1206
- (let ((complete-p (equal (buffer-substring-no-properties
1207
- (line-beginning-position ) (point ))
1208
- " " )))
1209
- (jupyter-handle-is-complete-reply
1210
- jupyter-current-client
1211
- nil `(:content
1212
- (:status ,(if complete-p " complete" " incomplete" )
1213
- :indent " " )))))
1241
+ (if (save-excursion
1242
+ (goto-char (point-max ))
1243
+ (string-empty-p
1244
+ (buffer-substring
1245
+ (line-beginning-position )
1246
+ (point ))))
1247
+ (let ((client jupyter-current-client))
1248
+ (jupyter-run-soon
1249
+ (jupyter-repl-execute-cell client)))
1250
+ (newline )
1251
+ (jupyter-repl-indent-line)))
1214
1252
(t
1215
1253
(condition-case nil
1216
1254
(jupyter-run-with-client jupyter-current-client
@@ -1221,7 +1259,7 @@ execute the current cell."
1221
1259
jupyter-repl-maximum-is-complete-timeout))
1222
1260
(jupyter-timeout-before-idle
1223
1261
(message " \
1224
- Kernel did not respond to is-complete-request , using built-in is-complete .
1262
+ Kernel did not respond to is_complete_request , using built-in is_complete .
1225
1263
Reset `jupyter-repl-use-builtin-is-complete' to nil if this is only temporary. " )
1226
1264
(setq jupyter-repl-use-builtin-is-complete t )
1227
1265
(jupyter-repl-ret force)))))))
@@ -1658,6 +1696,9 @@ Return the buffer switched to."
1658
1696
(define-key map [remap backward-sentence] #'jupyter-repl-backward-cell )
1659
1697
(define-key map [remap forward-sentence] #'jupyter-repl-forward-cell )
1660
1698
(define-key map (kbd " RET" ) #'jupyter-repl-ret )
1699
+ (define-key map (kbd " S-RET" ) #'jupyter-repl-send )
1700
+ (define-key map (kbd " <return>" ) #'jupyter-repl-ret )
1701
+ (define-key map (kbd " S-<return>" ) #'jupyter-repl-send )
1661
1702
(define-key map (kbd " M-n" ) #'jupyter-repl-history-next )
1662
1703
(define-key map (kbd " M-p" ) #'jupyter-repl-history-previous )
1663
1704
(define-key map (kbd " C-c C-o" ) #'jupyter-repl-clear-cells )
0 commit comments