Commit ef1c3bd1 authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

kernel: Handle ";;guix describe" magic.

* guix-jupyter-kernel.scm (channels->shtml): Move heading to...
(reply-for-channels): ... here.
(reply-channel-description): New procedure.
(reply-execute-request): Handle ";;guix describe".
(%magic-commands): Add "describe".
parent b1f7b125
...@@ -162,16 +162,14 @@ NAME with MANIFEST." ...@@ -162,16 +162,14 @@ NAME with MANIFEST."
(define (channels->shtml channels) (define (channels->shtml channels)
"Return SHTML representing CHANNELS." "Return SHTML representing CHANNELS."
`(div `(p (table
(bold "Switched to these Guix channels:") ,@(map (lambda (channel)
(p (table `(tr (tc (a (@ (href ,(channel-url channel)))
,@(map (lambda (channel) (code ,(channel-name channel))))
`(tr (tc (a (@ (href ,(channel-url channel))) (tc (code ,(if (channel-commit channel)
(code ,(channel-name channel)))) (channel-commit-hyperlink channel)
(tc (code ,(if (channel-commit channel) (channel-branch channel))))))
(channel-commit-hyperlink channel) channels))))
(channel-branch channel))))))
(define* (reply-for-channels kernel message channels (define* (reply-for-channels kernel message channels
#:key profile (count 0)) #:key profile (count 0))
...@@ -183,7 +181,26 @@ to CHANNELS in PROFILE." ...@@ -183,7 +181,26 @@ to CHANNELS in PROFILE."
(lst lst)) (lst lst))
channels))) channels)))
(reply-html kernel message (reply-html kernel message
(sxml->html-string (channels->shtml instances)) (sxml->html-string
(bold "Switched to these Guix channels:")
,(channels->shtml instances)))
(define* (reply-channel-description kernel message inferior
#:key (count 0))
"Reply to MESSAGE, which comes from KERNEL, with a description of the
channels currently used by INFERIOR."
(let* ((profile (inferior-eval '(begin
(use-modules (guix describe))
(channels (profile-channels profile)))
(reply-html kernel message
(bold "Using these Guix channels:")
,(channels->shtml channels)))
count))) count)))
(define* (reply-for-channel-failure kernel message channels error (define* (reply-for-channel-failure kernel message channels error
...@@ -402,6 +419,13 @@ stripped." ...@@ -402,6 +419,13 @@ stripped."
(send-message proxy (execute-request-sans-magic message)) (send-message proxy (execute-request-sans-magic message))
(let ((state (increment-execution-count state))) (let ((state (increment-execution-count state)))
(set-proxy-state-default-environment state name))))) (set-proxy-state-default-environment state name)))))
((";;guix" "describe")
(let* ((state (ensure-proxy-state-inferior state))
(inferior (proxy-state-inferior state)))
(reply-channel-description kernel message
(proxy-state-inferior state)
#:count count)
(increment-execution-count state)))
((";;guix" "pin" commit) ((";;guix" "pin" commit)
(let ((count (proxy-state-execution-count state)) (let ((count (proxy-state-execution-count state))
(channels (map (lambda (ch) (channels (map (lambda (ch)
...@@ -471,7 +495,7 @@ python-ipykernel")) ...@@ -471,7 +495,7 @@ python-ipykernel"))
(define %magic-commands (define %magic-commands
;; The ";;guix" magic commands. ;; The ";;guix" magic commands.
'("download" "environment" "pin")) '("describe" "download" "environment" "pin"))
(define (reply-complete-request kernel kind message state) (define (reply-complete-request kernel kind message state)
"Reply to a \"complete_request\" message--i.e., a completion request. "Reply to a \"complete_request\" message--i.e., a completion request.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment