Fix ein:make-content-hierarchy.

In the end so ein:notebooklist-open-notebook-global can work.
This commit is contained in:
John Miller 2015-12-04 14:15:41 -06:00
parent 3aa290ed91
commit b8aa391b31
4 changed files with 18 additions and 13 deletions

View file

@ -99,13 +99,13 @@ global setting. For global setting and more information, see
(defun ein:content-url (content) (defun ein:content-url (content)
(let ((url-or-port (ein:$content-url-or-port content)) (let ((url-or-port (ein:$content-url-or-port content))
(path (ein:$content-path content))) (path (ein:$content-path content)))
(ein:url url-or-port "api/contents" (url-hexify-string path)))) (url-encode-url (ein:url url-or-port "api/contents" path))))
(defun ein:content-url-legacy (content) (defun ein:content-url-legacy (content)
"Generate content url's for IPython Notebook version 2.x" "Generate content url's for IPython Notebook version 2.x"
(let ((url-or-port (ein:$content-url-or-port content)) (let ((url-or-port (ein:$content-url-or-port content))
(path (ein:$content-path content))) (path (ein:$content-path content)))
(ein:url url-or-port "api/notebooks" (url-hexify-string path)))) (url-encode-url (ein:url url-or-port "api/notebooks"))))
(defun ein:content-query-contents (path &optional url-or-port force-sync callback) (defun ein:content-query-contents (path &optional url-or-port force-sync callback)
"Return the contents of the object at the specified path from the Jupyter server." "Return the contents of the object at the specified path from the Jupyter server."
@ -220,11 +220,15 @@ global setting. For global setting and more information, see
(defvar *ein:content-hierarchy* (make-hash-table)) (defvar *ein:content-hierarchy* (make-hash-table))
(defun ein:get-content-hierarchy (url-or-port)
(or (gethash url-or-port *ein:content-hierarchy*)
(ein:refresh-content-hierarchy url-or-port)))
(defun ein:make-content-hierarchy (path url-or-port) (defun ein:make-content-hierarchy (path url-or-port)
(let* ((node (ein:content-query-contents path url-or-port t)) (let* ((node (ein:content-query-contents path url-or-port t))
(active-sessions (make-hash-table :test 'equal)) (active-sessions (make-hash-table :test 'equal))
(items (ein:$content-raw-content node))) (items (ein:$content-raw-content node)))
(ein:content-query-sessions url-or-port active-sessions t) (ein:content-query-sessions active-sessions url-or-port t)
(ein:flatten (loop for item in items (ein:flatten (loop for item in items
for c = (make-ein:$content :url-or-port url-or-port) for c = (make-ein:$content :url-or-port url-or-port)
do (ein:new-content c nil :data item) do (ein:new-content c nil :data item)
@ -232,9 +236,10 @@ global setting. For global setting and more information, see
(cond ((string= (ein:$content-type c) "directory") (cond ((string= (ein:$content-type c) "directory")
(cons c (cons c
(ein:make-content-hierarchy (ein:$content-path c) url-or-port))) (ein:make-content-hierarchy (ein:$content-path c) url-or-port)))
(t (progv c (t (progn
(setf (ein:$content-session-p c) (setf (ein:$content-session-p c)
(gethash active-sessions (ein:$content-path c)))))))))) (gethash (ein:$content-path c) active-sessions))
c)))))))
(defun ein:refresh-content-hierarchy (&optional url-or-port) (defun ein:refresh-content-hierarchy (&optional url-or-port)
(let ((url-or-port (or url-or-port (ein:default-url-or-port)))) (let ((url-or-port (or url-or-port (ein:default-url-or-port))))
@ -331,7 +336,7 @@ global setting. For global setting and more information, see
(defun ein:content-query-sessions (session-hash url-or-port &optional force-sync) (defun ein:content-query-sessions (session-hash url-or-port &optional force-sync)
(ein:query-singleton-ajax (ein:query-singleton-ajax
(list 'content-queyr-sessions) (list 'content-query-sessions)
(ein:url url-or-port "api/sessions") (ein:url url-or-port "api/sessions")
:type "GET" :type "GET"
:parser #'ein:json-read :parser #'ein:json-read

View file

@ -323,6 +323,7 @@ is newly created or not. When CALLBACK is specified, buffer is
**not** brought up by `pop-to-buffer'. It is caller's **not** brought up by `pop-to-buffer'. It is caller's
responsibility to do so. The current buffer is set to the responsibility to do so. The current buffer is set to the
notebook buffer when CALLBACK is called." notebook buffer when CALLBACK is called."
;(interactive)
(unless callback (setq callback #'ein:notebook-pop-to-current-buffer)) (unless callback (setq callback #'ein:notebook-pop-to-current-buffer))
(let ((buffer (ein:notebook-get-opened-buffer url-or-port path))) (let ((buffer (ein:notebook-get-opened-buffer url-or-port path)))
(if (buffer-live-p buffer) (if (buffer-live-p buffer)

View file

@ -341,7 +341,7 @@ You may find the new one in the notebook list." error)
(ein:notebooklist-reload))) (ein:notebooklist-reload)))
(current-buffer) path))) (current-buffer) path)))
;; Because MinRK wants me to suffer... ;; Because MinRK wants me to suffer (not really, I love MinRK)...
(defun ein:get-actual-path (path) (defun ein:get-actual-path (path)
(ein:aif (cl-position ?/ path :from-end t) (ein:aif (cl-position ?/ path :from-end t)
(substring path 0 it) (substring path 0 it)
@ -467,7 +467,7 @@ is a string of the format \"URL-OR-PORT/NOTEBOOK-NAME\"."
for url-or-port = (ein:$notebooklist-url-or-port nblist) for url-or-port = (ein:$notebooklist-url-or-port nblist)
for api-version = (ein:$notebooklist-api-version nblist) for api-version = (ein:$notebooklist-api-version nblist)
collect collect
(loop for note in (ein:make-content-hierarchy "" url-or-port) (loop for note in (ein:get-content-hierarchy url-or-port)
collect (format "%s/%s" url-or-port collect (format "%s/%s" url-or-port
(ein:$content-path note) (ein:$content-path note)
)) ))

View file

@ -57,8 +57,7 @@ This function is to be used for FOLLOW function of
(let ((link (read link-path))) (let ((link (read link-path)))
(destructuring-bind (&key url-or-port name &allow-other-keys) (destructuring-bind (&key url-or-port name &allow-other-keys)
link link
(ein:notebooklist-open-notebook-by-name name url-or-port (ein:notebook-open url-or-port name))))
#'ein:org-goto-link link))))
;;;###autoload ;;;###autoload
(defun ein:org-store-link () (defun ein:org-store-link ()
@ -81,7 +80,7 @@ easier. For the examples of link format in general, see Info
node `(org) External links' and Info node `(org) Search options'" node `(org) External links' and Info node `(org) Search options'"
(ein:and-let* (((ein:worksheet-buffer-p)) (ein:and-let* (((ein:worksheet-buffer-p))
(notebook (ein:get-notebook)) (notebook (ein:get-notebook))
(name (ein:notebook-name notebook)) (name (ein:$notebook-notebook-path notebook))
(link (list :url-or-port (ein:get-url-or-port) (link (list :url-or-port (ein:get-url-or-port)
:name name)) :name name))
(description name)) (description name))