mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-05 07:41:37 -05:00
jupyter-repl-after-change (julia): Use :user-expressions key to compute Pkg prompt (#73)
Instead of using `jupyter-eval` which creates unnecessary `:execute-input` and `:execute-result` messages, use the `:user-expressions` key of an execute request to compute the Pkg prompt. This way the only message generated is an `:execute-reply` and we avoid modifying the execution count. This requires JuliaLang/IJulia.jl@85eb54ae17
This commit is contained in:
parent
96c872fb7c
commit
53c2ffdd51
1 changed files with 24 additions and 10 deletions
|
@ -116,6 +116,26 @@ Make the character after `point' invisible."
|
|||
(overlay-put ov 'after-string (propertize " " 'display md))
|
||||
(overlay-put ov 'evaporate t)))
|
||||
|
||||
(defun jupyter-julia-pkg-prompt ()
|
||||
"Return the Pkg prompt.
|
||||
If the Pkg prompt can't be retrieved from the kernel, return
|
||||
nil."
|
||||
(when-let* ((msg (jupyter-wait-until-received :execute-reply
|
||||
(jupyter-send-execute-request jupyter-current-client
|
||||
:code ""
|
||||
:silent t
|
||||
:user-expressions
|
||||
(list :prompt "import Pkg; Pkg.REPLMode.promptf()"))
|
||||
;; Longer timeout to account for initial Pkg import and
|
||||
;; compilation.
|
||||
jupyter-long-timeout)))
|
||||
(cl-destructuring-bind (&key prompt &allow-other-keys)
|
||||
(jupyter-message-get msg :user_expressions)
|
||||
(cl-destructuring-bind (&key status data &allow-other-keys)
|
||||
prompt
|
||||
(when (equal status "ok")
|
||||
(plist-get data :text/plain))))))
|
||||
|
||||
(cl-defmethod jupyter-repl-after-change ((_type (eql insert)) beg _end
|
||||
&context (jupyter-lang julia))
|
||||
"Change the REPL prompt when a REPL mode is entered."
|
||||
|
@ -129,16 +149,10 @@ Make the character after `point' invisible."
|
|||
(setq last-command-event ?\[))
|
||||
(cl-case (char-after)
|
||||
(?\]
|
||||
;; Longer timeout to account for initial Pkg import and compilation.
|
||||
(let* ((jupyter-default-timeout jupyter-long-timeout)
|
||||
(pkg-prompt
|
||||
;; FIXME: This modifies the ans variable in IJulia. Maybe
|
||||
;; evaluate this in the user-expressions of an execute-request?
|
||||
(jupyter-eval "import Pkg; Pkg.REPLMode.promptf()")))
|
||||
(when pkg-prompt
|
||||
(jupyter-julia-add-prompt
|
||||
(substring pkg-prompt 1 (1- (length pkg-prompt)))
|
||||
(aref ansi-color-names-vector 5))))) ; magenta
|
||||
(when-let* ((pkg-prompt (jupyter-julia-pkg-prompt)))
|
||||
(jupyter-julia-add-prompt
|
||||
(substring pkg-prompt 1 (1- (length pkg-prompt)))
|
||||
(aref ansi-color-names-vector 5)))) ; magenta
|
||||
(?\;
|
||||
(jupyter-julia-add-prompt
|
||||
"shell> " (aref ansi-color-names-vector 1))) ; red
|
||||
|
|
Loading…
Add table
Reference in a new issue