Skip to content

Commit 32ae8a0

Browse files
committed
Add jupyter-describe function for interactive inspect
jupyter-describe implements an interface (with completion) similar to emacs builtin describe-function for interacting with jupyter kernels. Closes emacs-jupyter#199
1 parent a56a358 commit 32ae8a0

File tree

3 files changed

+47
-26
lines changed

3 files changed

+47
-26
lines changed

README.org

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,18 @@ associate with the =current-buffer= and enable the minor mode
279279
=jupyter-repl-interaction-mode=. This minor mode populates the following
280280
keybindings for interacting with the REPL:
281281

282-
| Key binding | Command |
283-
|-------------+-------------------------------|
284-
| =C-M-x= | =jupyter-eval-defun= |
285-
| =M-i= | =jupyter-inspect-at-point= |
286-
| =C-c C-b= | =jupyter-eval-buffer= |
287-
| =C-c C-c= | =jupyter-eval-line-or-region= |
288-
| =C-c C-i= | =jupyter-repl-interrupt-kernel= |
289-
| =C-c C-r= | =jupyter-repl-restart-kernel= |
290-
| =C-c C-s= | =jupyter-repl-scratch-buffer= |
291-
| =C-c C-o= | =jupyter-eval-remove-overlays= |
292-
| =C-c M-:= | =jupyter-eval-string= |
282+
| Key binding | Command |
283+
|-------------+---------------------------------|
284+
| =C-M-x= | =jupyter-eval-defun= |
285+
| =M-i= | =jupyter-inspect-at-point= |
286+
| =C-c C-d= | =jupyter-describe= |
287+
| =C-c C-b= | =jupyter-eval-buffer= |
288+
| =C-c C-c= | =jupyter-eval-line-or-region= |
289+
| =C-c C-i= | =jupyter-repl-interrupt-kernel= |
290+
| =C-c C-r= | =jupyter-repl-restart-kernel= |
291+
| =C-c C-s= | =jupyter-repl-scratch-buffer= |
292+
| =C-c C-o= | =jupyter-eval-remove-overlays= |
293+
| =C-c M-:= | =jupyter-eval-string= |
293294

294295
**** Integration with =emacsclient=
295296

jupyter-client.el

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -946,24 +946,32 @@ client local variable.
946946
947947
Methods that extend this generic function should
948948
`cl-call-next-method' as a last step."
949-
(cl-check-type jupyter-current-client jupyter-kernel-client
950-
"Need a client to read an expression")
951949
(let* ((client jupyter-current-client)
952950
(jupyter--read-expression-history
953951
(jupyter-get client 'jupyter-eval-expression-history)))
954-
(minibuffer-with-setup-hook
955-
(lambda ()
956-
(setq jupyter-current-client client)
957-
(add-hook 'completion-at-point-functions
958-
'jupyter-completion-at-point nil t)
959-
(add-hook 'minibuffer-exit-hook
960-
'jupyter--teardown-minibuffer nil t))
961-
(prog1 (read-from-minibuffer
962-
(format "Eval (%s): " (jupyter-kernel-language client))
963-
nil read-expression-map
964-
nil 'jupyter--read-expression-history)
965-
(jupyter-set client 'jupyter-eval-expression-history
966-
jupyter--read-expression-history)))))
952+
(prog1
953+
(jupyter--read-with-completion
954+
client "Eval (%s): " jupyter--read-expression-history)
955+
(jupyter-set client 'jupyter-eval-expression-history
956+
jupyter--read-expression-history))))
957+
958+
(defun jupyter--read-with-completion (client prompt &optional history)
959+
"Read an expression using CLIENT for completion.
960+
The expression is read from the minibuffer with PROMPT and expression
961+
history HISTORY."
962+
(cl-check-type client jupyter-kernel-client
963+
"Need a client to read an expression")
964+
(minibuffer-with-setup-hook
965+
(lambda ()
966+
(setq jupyter-current-client client)
967+
(add-hook 'completion-at-point-functions
968+
'jupyter-completion-at-point nil t)
969+
(add-hook 'minibuffer-exit-hook
970+
'jupyter--teardown-minibuffer nil t))
971+
(read-from-minibuffer
972+
(format prompt (jupyter-kernel-language client))
973+
nil read-expression-map
974+
nil history)))
967975

968976
(defun jupyter-eval (code &optional mime)
969977
"Send an execute request for CODE, wait for the execute result.
@@ -1419,6 +1427,16 @@ BUFFER and DETAIL have the same meaning as in `jupyter-inspect'."
14191427
(jupyter-code-context 'inspect)
14201428
(jupyter-inspect code pos buffer detail)))
14211429

1430+
(cl-defgeneric jupyter-describe (code &optional buffer detail)
1431+
"Inspect CODE provided interactively.
1432+
Call `jupter-inspect' for CODE which can be interactively supplied by user.
1433+
1434+
BUFFER and DETAIL have the same meaning a in `jupyter-inspect'."
1435+
(interactive (list (jupyter--read-with-completion
1436+
jupyter-current-client "Describe (%s): ")
1437+
nil 0))
1438+
(jupyter-inspect code nil buffer detail))
1439+
14221440
(cl-defgeneric jupyter-inspect (code &optional pos buffer detail)
14231441
"Inspect CODE.
14241442
Send an `:inspect-request' with the `jupyter-current-client' and

jupyter-repl.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
;; C-c C-c `jupyter-eval-line-or-region'
4545
;; C-c C-l `jupyter-eval-file'
4646
;; M-i `jupyter-inspect-at-point'
47+
;; C-c C-d `jupyter-describe'
4748
;; C-c C-r `jupyter-repl-restart-kernel'
4849
;; C-c C-i `jupyter-repl-interrupt-kernel'
4950
;; C-c C-z `jupyter-repl-pop-to-buffer'
@@ -1947,6 +1948,7 @@ the updated state."
19471948
(define-key map (kbd "C-c C-l") #'jupyter-load-file)
19481949
(define-key map (kbd "C-c M-:") #'jupyter-eval-string-command)
19491950
(define-key map (kbd "M-i") #'jupyter-inspect-at-point)
1951+
(define-key map (kbd "C-c C-d") #'jupyter-describe)
19501952
(define-key map (kbd "C-c C-r") #'jupyter-repl-restart-kernel)
19511953
(define-key map (kbd "C-c C-i") #'jupyter-repl-interrupt-kernel)
19521954
(define-key map (kbd "C-c C-z") #'jupyter-repl-pop-to-buffer)

0 commit comments

Comments
 (0)