From b8aa391b31c45936e2186090e6c7f35277d0d95c Mon Sep 17 00:00:00 2001 From: John Miller Date: Fri, 4 Dec 2015 14:15:41 -0600 Subject: [PATCH] Fix `ein:make-content-hierarchy`. In the end so ein:notebooklist-open-notebook-global can work. --- lisp/ein-contents-api.el | 21 +++++++++++++-------- lisp/ein-notebook.el | 1 + lisp/ein-notebooklist.el | 4 ++-- lisp/ein-org.el | 5 ++--- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lisp/ein-contents-api.el b/lisp/ein-contents-api.el index 3e8ec4d..c769ffb 100644 --- a/lisp/ein-contents-api.el +++ b/lisp/ein-contents-api.el @@ -99,13 +99,13 @@ global setting. For global setting and more information, see (defun ein:content-url (content) (let ((url-or-port (ein:$content-url-or-port 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) "Generate content url's for IPython Notebook version 2.x" (let ((url-or-port (ein:$content-url-or-port content)) - (path (ein:$content-path content))) - (ein:url url-or-port "api/notebooks" (url-hexify-string path)))) + (path (ein:$content-path content))) + (url-encode-url (ein:url url-or-port "api/notebooks")))) (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." @@ -220,11 +220,15 @@ global setting. For global setting and more information, see (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) (let* ((node (ein:content-query-contents path url-or-port t)) (active-sessions (make-hash-table :test 'equal)) (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 for c = (make-ein:$content :url-or-port url-or-port) 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") (cons c (ein:make-content-hierarchy (ein:$content-path c) url-or-port))) - (t (progv c - (setf (ein:$content-session-p c) - (gethash active-sessions (ein:$content-path c)))))))))) + (t (progn + (setf (ein:$content-session-p c) + (gethash (ein:$content-path c) active-sessions)) + c))))))) (defun ein:refresh-content-hierarchy (&optional 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) (ein:query-singleton-ajax - (list 'content-queyr-sessions) + (list 'content-query-sessions) (ein:url url-or-port "api/sessions") :type "GET" :parser #'ein:json-read diff --git a/lisp/ein-notebook.el b/lisp/ein-notebook.el index 302ef52..b7cef91 100644 --- a/lisp/ein-notebook.el +++ b/lisp/ein-notebook.el @@ -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 responsibility to do so. The current buffer is set to the notebook buffer when CALLBACK is called." + ;(interactive) (unless callback (setq callback #'ein:notebook-pop-to-current-buffer)) (let ((buffer (ein:notebook-get-opened-buffer url-or-port path))) (if (buffer-live-p buffer) diff --git a/lisp/ein-notebooklist.el b/lisp/ein-notebooklist.el index b734303..7106d43 100644 --- a/lisp/ein-notebooklist.el +++ b/lisp/ein-notebooklist.el @@ -341,7 +341,7 @@ You may find the new one in the notebook list." error) (ein:notebooklist-reload))) (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) (ein:aif (cl-position ?/ path :from-end t) (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 api-version = (ein:$notebooklist-api-version nblist) 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 (ein:$content-path note) )) diff --git a/lisp/ein-org.el b/lisp/ein-org.el index 40be1e3..8fa84a2 100644 --- a/lisp/ein-org.el +++ b/lisp/ein-org.el @@ -57,8 +57,7 @@ This function is to be used for FOLLOW function of (let ((link (read link-path))) (destructuring-bind (&key url-or-port name &allow-other-keys) link - (ein:notebooklist-open-notebook-by-name name url-or-port - #'ein:org-goto-link link)))) + (ein:notebook-open url-or-port name)))) ;;;###autoload (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'" (ein:and-let* (((ein:worksheet-buffer-p)) (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) :name name)) (description name))