mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-05 15:41:37 -05:00
Handle the case when a kernel does not respond to an is_complete_request
This commit is contained in:
parent
af82c55b1c
commit
3385498cab
1 changed files with 24 additions and 13 deletions
|
@ -98,6 +98,13 @@
|
||||||
(defvar jupyter-repl-history nil
|
(defvar jupyter-repl-history nil
|
||||||
"The history of the current Jupyter REPL.")
|
"The history of the current Jupyter REPL.")
|
||||||
|
|
||||||
|
(defvar jupyter-repl-use-builtin-is-complete nil
|
||||||
|
"Whether or not to send an is_complete_request to a kernel.
|
||||||
|
If a Jupyter kernel does not respond to an is_complete_request,
|
||||||
|
this variable is automatically set to t and code in a cell is
|
||||||
|
considered complete if the last line in a code cell is a blank
|
||||||
|
line, i.e. if RET is pressed twice in a row.")
|
||||||
|
|
||||||
;;; Convenience macros
|
;;; Convenience macros
|
||||||
|
|
||||||
(defmacro with-jupyter-repl-buffer (client &rest body)
|
(defmacro with-jupyter-repl-buffer (client &rest body)
|
||||||
|
@ -750,23 +757,27 @@ a Jupyter REPL buffer."
|
||||||
|
|
||||||
(defun jupyter-repl-ret (arg)
|
(defun jupyter-repl-ret (arg)
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(let ((last-cell-pos (save-excursion
|
(let ((client jupyter-repl-current-client)
|
||||||
|
(last-cell-pos (save-excursion
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(jupyter-repl-cell-beginning-position))))
|
(jupyter-repl-cell-beginning-position))))
|
||||||
(if (< (point) last-cell-pos)
|
(if (< (point) last-cell-pos)
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
;; TODO: Not all kernels will respond to an is_complete_request. The
|
(if (not jupyter-repl-use-builtin-is-complete)
|
||||||
;; jupyter console will switch to its own internal handler when the
|
(let ((res (jupyter-wait-until-received :is-complete-reply
|
||||||
;; request times out.
|
(jupyter-is-complete-request client
|
||||||
(let ((res (jupyter-wait-until-received :is-complete-reply
|
:code (jupyter-repl-cell-code)))))
|
||||||
(jupyter-is-complete-request
|
(unless res
|
||||||
jupyter-repl-current-client
|
(setq-local jupyter-repl-use-builtin-is-complete t)
|
||||||
:code (jupyter-repl-cell-code)))))
|
(jupyter-repl-ret arg)))
|
||||||
;; If the kernel responds to an is-complete request then the
|
(let ((complete-p (equal
|
||||||
;; is-complete handler takes care of executing the code.
|
(save-excursion
|
||||||
(unless res
|
(goto-char (jupyter-repl-cell-code-end-position))
|
||||||
;; TODO: Indent or send (on prefix arg)?
|
(buffer-substring-no-properties
|
||||||
)))))
|
(line-beginning-position) (point)))
|
||||||
|
"")))
|
||||||
|
(jupyter-handle-is-complete-reply client
|
||||||
|
nil (if complete-p "complete" "incomplete") ""))))))
|
||||||
|
|
||||||
(defun jupyter-repl-indent-line ()
|
(defun jupyter-repl-indent-line ()
|
||||||
"Indent the line according to the language of the REPL."
|
"Indent the line according to the language of the REPL."
|
||||||
|
|
Loading…
Add table
Reference in a new issue