mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-05 23:41:38 -05:00
jupyter-current-server: Also consider a remote default-directory
This commit is contained in:
parent
4a87d35f76
commit
de320f83d2
1 changed files with 57 additions and 28 deletions
|
@ -86,6 +86,10 @@
|
||||||
(require 'jupyter-ioloop-comm)
|
(require 'jupyter-ioloop-comm)
|
||||||
(require 'jupyter-server-ioloop)
|
(require 'jupyter-server-ioloop)
|
||||||
|
|
||||||
|
(declare-function jupyter-tramp-file-name-p "jupyter-tramp" (filename))
|
||||||
|
(declare-function jupyter-tramp-server-from-file-name "jupyter-tramp" (filename))
|
||||||
|
(declare-function jupyter-tramp-file-name-from-url "jupyter-tramp" (url))
|
||||||
|
|
||||||
(defgroup jupyter-server nil
|
(defgroup jupyter-server nil
|
||||||
"Support for the Jupyter kernel gateway"
|
"Support for the Jupyter kernel gateway"
|
||||||
:group 'jupyter)
|
:group 'jupyter)
|
||||||
|
@ -397,40 +401,61 @@ least the following keys:
|
||||||
(append kernels nil))))
|
(append kernels nil))))
|
||||||
|
|
||||||
(defun jupyter-current-server (&optional ask)
|
(defun jupyter-current-server (&optional ask)
|
||||||
"Return an existing `jupyter-server' or a new one.
|
"Return an existing `jupyter-server' or ASK for a new one.
|
||||||
If `jupyter-current-server' is non-nil, return its value.
|
If ASK is non-nil, always ask for a URL and return the
|
||||||
Otherwise, return the most recently used server.
|
`jupyter-server' object corresponding to it.
|
||||||
|
|
||||||
With a prefix argument, ASK to select one and set the selected
|
If the buffer local value of `jupyter-current-server' is non-nil,
|
||||||
one as the most recently used.
|
return its value. If `jupyter-current-server' is nil and the
|
||||||
|
`jupyter-current-client' is communicating with a kernel behind a
|
||||||
|
kernel server, return the `jupyter-server' managing the
|
||||||
|
connection.
|
||||||
|
|
||||||
If no servers exist, ask the user to create one and return its
|
If `jupyter-current-client' is nil or not communicating with a
|
||||||
value."
|
kernel behind a server and if `default-directory' is a Jupyter
|
||||||
|
remote file name, return the `jupyter-server' object
|
||||||
|
corresponding to that connection.
|
||||||
|
|
||||||
|
If all of the above fails, either return the most recently used
|
||||||
|
`jupyter-server' object if there is one or ask for one based off
|
||||||
|
a URL."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(let ((read-url-make-server
|
(let ((read-url-make-server
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(let ((url (read-string "Server URL: " "http://localhost:8888"))
|
;; From the list of available server
|
||||||
(ws-url (read-string "Websocket URL: " "ws://localhost:8888")))
|
;; (if (> (length jupyter--servers) 1)
|
||||||
|
;; (let ((server (cdr (completing-read
|
||||||
|
;; "Jupyter Server: "
|
||||||
|
;; (mapcar (lambda (x) (cons (oref x url) x))
|
||||||
|
;; jupyter--servers)))))
|
||||||
|
;; )
|
||||||
|
(let* ((url (read-string "Server URL: " "http://localhost:8888"))
|
||||||
|
(ws-url (read-string "Websocket URL: " "ws://localhost:8888")))
|
||||||
(or (jupyter-find-server url ws-url)
|
(or (jupyter-find-server url ws-url)
|
||||||
(jupyter-server :url url :ws-url ws-url))))))
|
(jupyter-server :url url :ws-url ws-url))))))
|
||||||
(if ask (let ((server (funcall read-url-make-server)))
|
(let ((server
|
||||||
(prog1 server
|
(if ask (funcall read-url-make-server)
|
||||||
(setq jupyter--servers
|
(cond
|
||||||
(cons server (delq server jupyter--servers)))))
|
(jupyter-current-server)
|
||||||
(or jupyter-current-server
|
;; Server of the current kernel client
|
||||||
(and (file-remote-p default-directory)
|
((and jupyter-current-client
|
||||||
(jupyter-tramp-file-name-p default-directory)
|
(object-of-class-p
|
||||||
(jupyter-tramp-server-from-file-name default-directory))
|
(oref jupyter-current-client kcomm)
|
||||||
(if (> (length jupyter--servers) 1)
|
'jupyter-server-kernel-comm)
|
||||||
(let ((server (cdr (completing-read
|
(thread-first jupyter-current-client
|
||||||
"Jupyter Server: "
|
(oref kcomm)
|
||||||
(mapcar (lambda (x) (cons (oref x url) x))
|
(oref server))))
|
||||||
jupyter--servers)))))
|
;; Server of the current TRAMP remote context
|
||||||
(prog1 server
|
((and (file-remote-p default-directory)
|
||||||
(setq jupyter--servers
|
(jupyter-tramp-file-name-p default-directory)
|
||||||
(cons server (delq server jupyter--servers)))))
|
(jupyter-tramp-server-from-file-name default-directory)))
|
||||||
(or (car jupyter--servers)
|
;; Most recently accessed
|
||||||
(funcall read-url-make-server)))))))
|
(t
|
||||||
|
(or (car jupyter--servers)
|
||||||
|
(funcall read-url-make-server)))))))
|
||||||
|
(prog1 server
|
||||||
|
(setq jupyter--servers
|
||||||
|
(cons server (delq server jupyter--servers)))))))
|
||||||
|
|
||||||
;;; Commands
|
;;; Commands
|
||||||
|
|
||||||
|
@ -626,7 +651,11 @@ the same meaning as in `jupyter-connect-repl'."
|
||||||
(overlay-put
|
(overlay-put
|
||||||
(make-overlay 1 2)
|
(make-overlay 1 2)
|
||||||
'before-string
|
'before-string
|
||||||
(concat (propertize url 'face '(fixed-pitch default)) "\n"))))
|
(concat (propertize url 'face '(fixed-pitch default)) "\n")))
|
||||||
|
;; So that `dired-jump' will visit the directory of the kernel server.
|
||||||
|
(setq default-directory
|
||||||
|
(jupyter-tramp-file-name-from-url
|
||||||
|
(oref jupyter-current-server url))))
|
||||||
|
|
||||||
(defun jupyter-server--kernel-list-format ()
|
(defun jupyter-server--kernel-list-format ()
|
||||||
(let* ((get-time
|
(let* ((get-time
|
||||||
|
|
Loading…
Add table
Reference in a new issue