2012-05-07 14:41:15 +02:00
|
|
|
|
;;; ein-notebooklist.el --- Notebook list buffer
|
|
|
|
|
|
|
|
|
|
;; Copyright (C) 2012- Takafumi Arakaki
|
|
|
|
|
|
2015-01-31 10:13:49 -06:00
|
|
|
|
;; Authors: Takafumi Arakaki <aka.tkf at gmail.com>
|
|
|
|
|
;; John M. Miller <millejoh at mac.com>
|
2012-05-07 14:41:15 +02:00
|
|
|
|
|
|
|
|
|
;; This file is NOT part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; ein-notebooklist.el is free software: you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; ein-notebooklist.el is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with ein-notebooklist.el. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(eval-when-compile (require 'cl))
|
|
|
|
|
(require 'widget)
|
|
|
|
|
|
2012-08-28 15:26:32 +02:00
|
|
|
|
(require 'ein-core)
|
2012-05-07 14:41:15 +02:00
|
|
|
|
(require 'ein-notebook)
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(require 'ein-contents-api)
|
2012-05-19 15:47:09 +02:00
|
|
|
|
(require 'ein-subpackages)
|
2012-05-07 14:41:15 +02:00
|
|
|
|
|
2012-07-05 00:13:12 +02:00
|
|
|
|
(defcustom ein:notebooklist-first-open-hook nil
|
|
|
|
|
"Hooks to run when the notebook list is opened at first time.
|
|
|
|
|
|
|
|
|
|
Example to open a notebook named _scratch_ when the notebook list
|
|
|
|
|
is opened at first time.::
|
|
|
|
|
|
|
|
|
|
(add-hook
|
|
|
|
|
'ein:notebooklist-first-open-hook
|
|
|
|
|
(lambda () (ein:notebooklist-open-notebook-by-name \"_scratch_\")))
|
|
|
|
|
|
|
|
|
|
"
|
|
|
|
|
:type 'hook
|
|
|
|
|
:group 'ein)
|
|
|
|
|
|
2012-05-13 02:51:47 +02:00
|
|
|
|
(defstruct ein:$notebooklist
|
|
|
|
|
"Hold notebooklist variables.
|
|
|
|
|
|
|
|
|
|
`ein:$notebooklist-url-or-port'
|
|
|
|
|
URL or port of IPython server.
|
|
|
|
|
|
2014-09-12 12:37:24 -05:00
|
|
|
|
`ein:$notbooklist-path'
|
2014-09-11 20:04:00 -05:00
|
|
|
|
The path for the notebooklist.
|
|
|
|
|
|
2012-05-13 02:51:47 +02:00
|
|
|
|
`ein:$notebooklist-data'
|
2014-10-17 16:44:04 -05:00
|
|
|
|
JSON data sent from the server.
|
|
|
|
|
`ein:$notebooklist-api-version'
|
|
|
|
|
Major version of the IPython notebook server we are talking to."
|
2012-05-13 02:51:47 +02:00
|
|
|
|
url-or-port
|
2014-09-11 20:04:00 -05:00
|
|
|
|
path
|
2014-10-17 16:44:04 -05:00
|
|
|
|
data
|
|
|
|
|
api-version)
|
2012-05-13 02:51:47 +02:00
|
|
|
|
|
2012-08-18 22:31:15 +02:00
|
|
|
|
(ein:deflocal ein:%notebooklist% nil
|
2012-05-13 02:51:47 +02:00
|
|
|
|
"Buffer local variable to store an instance of `ein:$notebooklist'.")
|
2012-08-18 22:31:15 +02:00
|
|
|
|
(define-obsolete-variable-alias 'ein:notebooklist 'ein:%notebooklist% "0.1.2")
|
2012-05-07 14:41:15 +02:00
|
|
|
|
|
|
|
|
|
(defvar ein:notebooklist-buffer-name-template "*ein:notebooklist %s*")
|
|
|
|
|
|
2012-06-26 17:45:51 +02:00
|
|
|
|
(defvar ein:notebooklist-map (make-hash-table :test 'equal)
|
|
|
|
|
"Data store for `ein:notebooklist-list'.
|
|
|
|
|
Mapping from URL-OR-PORT to an instance of `ein:$notebooklist'.")
|
2012-06-05 14:54:18 +02:00
|
|
|
|
|
2012-06-26 17:45:51 +02:00
|
|
|
|
(defun ein:notebooklist-list ()
|
|
|
|
|
"Get a list of opened `ein:$notebooklist'."
|
|
|
|
|
(ein:hash-vals ein:notebooklist-map))
|
|
|
|
|
|
|
|
|
|
(defun ein:notebooklist-list-add (nblist)
|
|
|
|
|
"Register notebook list instance NBLIST for global lookup.
|
|
|
|
|
This function adds NBLIST to `ein:notebooklist-map'."
|
|
|
|
|
(puthash (ein:$notebooklist-url-or-port nblist)
|
|
|
|
|
nblist
|
|
|
|
|
ein:notebooklist-map))
|
2012-05-07 14:41:15 +02:00
|
|
|
|
|
2012-07-05 00:13:12 +02:00
|
|
|
|
(defun ein:notebooklist-list-get (url-or-port)
|
|
|
|
|
"Get an instance of `ein:$notebooklist' by URL-OR-PORT as a key."
|
|
|
|
|
(gethash url-or-port ein:notebooklist-map))
|
|
|
|
|
|
2015-02-10 14:53:08 -06:00
|
|
|
|
;; TODO: FIXME. Use content API.
|
2012-07-12 02:56:23 +02:00
|
|
|
|
(defun ein:notebooklist-open-notebook-by-name (name &optional url-or-port
|
|
|
|
|
callback cbargs)
|
2012-07-05 00:13:12 +02:00
|
|
|
|
"Open notebook named NAME in the server URL-OR-PORT.
|
|
|
|
|
If URL-OR-PORT is not given or `nil', and the current buffer is
|
|
|
|
|
the notebook list buffer, the notebook is searched in the
|
2012-07-12 02:56:23 +02:00
|
|
|
|
notebook list of the current buffer.
|
|
|
|
|
|
|
|
|
|
When used in lisp, CALLBACK and CBARGS are passed to `ein:notebook-open'.
|
|
|
|
|
To suppress popup, you can pass a function `ein:do-nothing' as CALLBACK."
|
2012-07-05 00:13:12 +02:00
|
|
|
|
(loop with nblist = (if url-or-port
|
|
|
|
|
(ein:notebooklist-list-get url-or-port)
|
2012-08-18 22:31:15 +02:00
|
|
|
|
ein:%notebooklist%)
|
2012-07-05 00:13:12 +02:00
|
|
|
|
for note in (ein:$notebooklist-data nblist)
|
|
|
|
|
for notebook-name = (plist-get note :name)
|
2014-09-11 20:04:00 -05:00
|
|
|
|
for notebook-path = (plist-get note :path)
|
2012-07-05 00:13:12 +02:00
|
|
|
|
when (equal notebook-name name)
|
|
|
|
|
return (ein:notebook-open (ein:$notebooklist-url-or-port nblist)
|
2015-02-10 14:53:08 -06:00
|
|
|
|
notebook-path callback cbargs)))
|
2012-07-05 00:13:12 +02:00
|
|
|
|
|
2014-10-17 16:44:04 -05:00
|
|
|
|
(defun ein:notebooklist-url (url-or-port version &optional path)
|
|
|
|
|
(let ((base-path (cond ((= version 2) "api/notebooks")
|
|
|
|
|
((= version 3) "api/contents"))))
|
|
|
|
|
(if path
|
|
|
|
|
(ein:url url-or-port base-path (or path ""))
|
|
|
|
|
(ein:url url-or-port base-path))))
|
|
|
|
|
|
|
|
|
|
(defun ein:notebooklist-new-url (url-or-port version &optional path)
|
|
|
|
|
(let ((base-path (cond ((= version 2) "api/notebooks")
|
|
|
|
|
((= version 3) "api/contents"))))
|
|
|
|
|
(ein:log 'info "New notebook. Port: %s, Path: %s" url-or-port path)
|
|
|
|
|
(if (and path (not (string= path "")))
|
|
|
|
|
(ein:url url-or-port base-path path)
|
|
|
|
|
(ein:url url-or-port base-path))))
|
2012-05-12 00:34:00 +02:00
|
|
|
|
|
2012-05-13 02:51:47 +02:00
|
|
|
|
(defun ein:notebooklist-get-buffer (url-or-port)
|
2012-05-12 00:34:00 +02:00
|
|
|
|
(get-buffer-create
|
2012-05-13 02:51:47 +02:00
|
|
|
|
(format ein:notebooklist-buffer-name-template url-or-port)))
|
2012-05-12 00:34:00 +02:00
|
|
|
|
|
2012-06-09 01:02:53 +02:00
|
|
|
|
(defun ein:notebooklist-ask-url-or-port ()
|
|
|
|
|
(let* ((url-or-port-list (mapcar (lambda (x) (format "%s" x))
|
|
|
|
|
ein:url-or-port))
|
2012-08-13 19:19:23 +02:00
|
|
|
|
(default (format "%s" (ein:aif (ein:get-notebook)
|
2012-06-15 21:55:32 +02:00
|
|
|
|
(ein:$notebook-url-or-port it)
|
2012-08-18 22:31:15 +02:00
|
|
|
|
(ein:aif ein:%notebooklist%
|
2012-06-15 21:55:32 +02:00
|
|
|
|
(ein:$notebooklist-url-or-port it)
|
|
|
|
|
(ein:default-url-or-port)))))
|
2012-06-09 01:02:53 +02:00
|
|
|
|
(url-or-port
|
2012-06-17 09:08:33 +02:00
|
|
|
|
(completing-read (format "URL or port number (default %s): " default)
|
2012-06-09 01:02:53 +02:00
|
|
|
|
url-or-port-list
|
|
|
|
|
nil nil nil nil
|
2012-06-12 18:58:38 +02:00
|
|
|
|
default)))
|
2012-06-09 01:02:53 +02:00
|
|
|
|
(if (string-match "^[0-9]+$" url-or-port)
|
|
|
|
|
(string-to-number url-or-port)
|
|
|
|
|
url-or-port)))
|
|
|
|
|
|
2012-05-14 18:47:08 +02:00
|
|
|
|
;;;###autoload
|
2014-09-11 20:04:00 -05:00
|
|
|
|
(defun ein:notebooklist-open (&optional url-or-port path no-popup)
|
2012-05-12 00:59:15 +02:00
|
|
|
|
"Open notebook list buffer."
|
2012-06-09 01:02:53 +02:00
|
|
|
|
(interactive (list (ein:notebooklist-ask-url-or-port)))
|
2012-06-15 21:46:55 +02:00
|
|
|
|
(unless url-or-port (setq url-or-port (ein:default-url-or-port)))
|
2014-09-12 12:37:24 -05:00
|
|
|
|
(unless path (setq path ""))
|
2012-05-19 15:47:09 +02:00
|
|
|
|
(ein:subpackages-load)
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(let ((success
|
2012-05-26 16:57:42 +02:00
|
|
|
|
(if no-popup
|
|
|
|
|
#'ein:notebooklist-url-retrieve-callback
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(lambda (content)
|
2012-05-26 16:57:42 +02:00
|
|
|
|
(pop-to-buffer
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(funcall #'ein:notebooklist-url-retrieve-callback content))))))
|
|
|
|
|
(ein:content-query-contents path url-or-port nil success)
|
|
|
|
|
;; (ein:query-singleton-ajax
|
|
|
|
|
;; (list 'notebooklist-open url-or-port api-version path)
|
|
|
|
|
;; (ein:notebooklist-url url-or-port api-version path)
|
|
|
|
|
;; :parser #'ein:json-read
|
|
|
|
|
;; :error (apply-partially #'ein:notebooklist-open-error url-or-port api-version path)
|
|
|
|
|
;; :success (apply-partially success url-or-port api-version path))
|
|
|
|
|
)
|
2012-05-17 20:12:40 +02:00
|
|
|
|
(ein:notebooklist-get-buffer url-or-port))
|
2012-05-07 14:41:15 +02:00
|
|
|
|
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(defun* ein:notebooklist-url-retrieve-callback (content)
|
2012-05-12 00:59:15 +02:00
|
|
|
|
"Called via `ein:notebooklist-open'."
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(let ((url-or-port (ein:$content-url-or-port content))
|
|
|
|
|
(path (ein:$content-path content))
|
|
|
|
|
(ipy-version (ein:$content-ipython-version content))
|
|
|
|
|
(data (ein:$content-raw-content content)))
|
|
|
|
|
(with-current-buffer (ein:notebooklist-get-buffer url-or-port)
|
|
|
|
|
(let ((already-opened-p (ein:notebooklist-list-get url-or-port))
|
|
|
|
|
(orig-point (point)))
|
|
|
|
|
(setq ein:%notebooklist%
|
|
|
|
|
(make-ein:$notebooklist :url-or-port url-or-port
|
|
|
|
|
:path path
|
|
|
|
|
:data data
|
|
|
|
|
:api-version ipy-version))
|
|
|
|
|
(ein:notebooklist-list-add ein:%notebooklist%)
|
|
|
|
|
(ein:notebooklist-render)
|
|
|
|
|
(goto-char orig-point)
|
|
|
|
|
(ein:log 'info "Opened notebook list at %s with path %s" url-or-port path)
|
|
|
|
|
(unless already-opened-p
|
|
|
|
|
(run-hooks 'ein:notebooklist-first-open-hook))
|
|
|
|
|
(current-buffer)))))
|
2012-05-12 00:34:00 +02:00
|
|
|
|
|
2014-09-11 20:04:00 -05:00
|
|
|
|
(defun* ein:notebooklist-open-error (url-or-port path
|
2012-12-29 17:44:49 +01:00
|
|
|
|
&key symbol-status response
|
2012-06-26 19:30:35 +02:00
|
|
|
|
&allow-other-keys)
|
2012-12-29 17:44:49 +01:00
|
|
|
|
(ein:log 'verbose
|
|
|
|
|
"Error thrown: %S" (request-response-error-thrown response))
|
2012-06-26 19:30:35 +02:00
|
|
|
|
(ein:log 'error
|
2014-09-11 20:04:00 -05:00
|
|
|
|
"Error (%s) while opening notebook list with path %s at the server %s."
|
|
|
|
|
symbol-status path url-or-port))
|
2012-06-26 19:30:35 +02:00
|
|
|
|
|
2012-09-01 20:51:55 +02:00
|
|
|
|
;;;###autoload
|
2015-01-13 06:40:15 -06:00
|
|
|
|
(defun ein:notebooklist-reload (&optional notebooklist)
|
2012-05-13 05:18:38 +02:00
|
|
|
|
"Reload current Notebook list."
|
|
|
|
|
(interactive)
|
2015-01-13 06:40:15 -06:00
|
|
|
|
(unless notebooklist
|
|
|
|
|
(setq notebooklist ein:%notebooklist%))
|
|
|
|
|
(ein:notebooklist-open (ein:$notebooklist-url-or-port notebooklist)
|
|
|
|
|
(ein:$notebooklist-path notebooklist) t))
|
2012-05-13 05:18:38 +02:00
|
|
|
|
|
2012-06-26 17:03:36 +02:00
|
|
|
|
(defun ein:notebooklist-refresh-related ()
|
|
|
|
|
"Reload notebook list in which current notebook locates.
|
|
|
|
|
This function is called via `ein:notebook-after-rename-hook'."
|
2015-01-13 06:40:15 -06:00
|
|
|
|
(ein:notebooklist-open (ein:$notebook-url-or-port ein:%notebook%)
|
|
|
|
|
(ein:$notebook-notebook-path ein:%notebook%) t))
|
2012-06-26 17:03:36 +02:00
|
|
|
|
|
|
|
|
|
(add-hook 'ein:notebook-after-rename-hook 'ein:notebooklist-refresh-related)
|
|
|
|
|
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(defun ein:notebooklist-open-notebook (nblist path &optional callback cbargs)
|
2014-10-17 16:44:04 -05:00
|
|
|
|
(ein:notebook-open (ein:$notebooklist-url-or-port nblist)
|
2015-02-10 14:53:08 -06:00
|
|
|
|
path
|
|
|
|
|
callback
|
|
|
|
|
cbargs))
|
2012-05-18 02:23:30 +02:00
|
|
|
|
|
2012-09-01 20:51:55 +02:00
|
|
|
|
;;;###autoload
|
2014-10-17 16:44:04 -05:00
|
|
|
|
(defun ein:notebooklist-new-notebook (&optional url-or-port path callback cbargs)
|
2012-06-11 14:13:57 +02:00
|
|
|
|
"Ask server to create a new notebook and open it in a new buffer."
|
2012-06-09 01:02:53 +02:00
|
|
|
|
(interactive (list (ein:notebooklist-ask-url-or-port)))
|
2014-12-04 13:52:36 -06:00
|
|
|
|
(let ((path (or path (ein:$notebooklist-path (or ein:%notebooklist%
|
|
|
|
|
(ein:notebooklist-list-get url-or-port)))))
|
|
|
|
|
(version (ein:$notebooklist-api-version (or ein:%notebooklist%
|
|
|
|
|
(ein:notebooklist-list-get url-or-port)))))
|
2014-09-19 09:17:12 -05:00
|
|
|
|
(ein:log 'info "Creating a new notebook at %s..." path)
|
|
|
|
|
(unless url-or-port
|
|
|
|
|
(setq url-or-port (ein:$notebooklist-url-or-port ein:%notebooklist%)))
|
|
|
|
|
(assert url-or-port nil
|
|
|
|
|
(concat "URL-OR-PORT is not given and the current buffer "
|
|
|
|
|
"is not the notebook list buffer."))
|
|
|
|
|
(let ((url (ein:notebooklist-new-url url-or-port
|
2014-11-07 19:28:09 -06:00
|
|
|
|
version
|
2014-09-19 09:17:12 -05:00
|
|
|
|
path)))
|
|
|
|
|
(ein:query-singleton-ajax
|
|
|
|
|
(list 'notebooklist-new-notebook url-or-port path)
|
|
|
|
|
url
|
|
|
|
|
:type "POST"
|
2015-01-16 22:01:54 -06:00
|
|
|
|
:data (json-encode '((:type . "notebook")))
|
2014-12-04 13:52:36 -06:00
|
|
|
|
:parser #'ein:json-read
|
|
|
|
|
;; (lambda ()
|
|
|
|
|
;; (ein:html-get-data-in-body-tag "data-notebook-id"))
|
2014-09-19 09:17:12 -05:00
|
|
|
|
:error (apply-partially #'ein:notebooklist-new-notebook-error
|
|
|
|
|
url-or-port path callback cbargs)
|
|
|
|
|
:success (apply-partially #'ein:notebooklist-new-notebook-callback
|
|
|
|
|
url-or-port path callback cbargs)))))
|
2012-12-29 17:17:39 +01:00
|
|
|
|
|
|
|
|
|
(defun* ein:notebooklist-new-notebook-callback (url-or-port
|
2014-09-19 09:17:12 -05:00
|
|
|
|
path
|
2012-12-29 17:17:39 +01:00
|
|
|
|
callback
|
|
|
|
|
cbargs
|
|
|
|
|
&key
|
2012-12-29 17:52:05 +01:00
|
|
|
|
data
|
|
|
|
|
&allow-other-keys
|
|
|
|
|
&aux
|
|
|
|
|
(no-popup t))
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(ein:log 'info "Creating a new notebook (%s)... Done." path)
|
2014-12-04 13:52:36 -06:00
|
|
|
|
(if data
|
|
|
|
|
(let ((name (plist-get data :name))
|
|
|
|
|
(path (plist-get data :path)))
|
2015-03-25 09:52:16 -05:00
|
|
|
|
(if (= (ein:query-ipython-version url-or-port) 2)
|
|
|
|
|
(if (string= path "")
|
|
|
|
|
(setq path name)
|
|
|
|
|
(setq path (format "%s/%s" path name))))
|
2015-02-12 09:20:34 -06:00
|
|
|
|
(ein:notebook-open url-or-port path callback cbargs))
|
2012-12-29 17:52:05 +01:00
|
|
|
|
(ein:log 'info (concat "Oops. EIN failed to open new notebook. "
|
|
|
|
|
"Please find it in the notebook list."))
|
|
|
|
|
(setq no-popup nil))
|
|
|
|
|
;; reload or open notebook list
|
2014-09-19 09:17:12 -05:00
|
|
|
|
(ein:notebooklist-open url-or-port path no-popup))
|
2012-05-26 19:51:57 +02:00
|
|
|
|
|
2012-09-06 23:46:29 +02:00
|
|
|
|
(defun* ein:notebooklist-new-notebook-error
|
2012-12-29 17:44:49 +01:00
|
|
|
|
(url-or-port callback cbargs
|
|
|
|
|
&key response &allow-other-keys
|
|
|
|
|
&aux
|
|
|
|
|
(no-popup t)
|
|
|
|
|
(error (request-response-error-thrown response))
|
2013-01-10 19:10:59 +01:00
|
|
|
|
(dest (request-response-url response)))
|
2012-09-06 23:46:29 +02:00
|
|
|
|
(ein:log 'verbose
|
2013-01-10 19:10:59 +01:00
|
|
|
|
"NOTEBOOKLIST-NEW-NOTEBOOK-ERROR url-or-port: %S; error: %S; dest: %S"
|
|
|
|
|
url-or-port error dest)
|
|
|
|
|
(ein:log 'error
|
|
|
|
|
"Failed to open new notebook (error: %S). \
|
|
|
|
|
You may find the new one in the notebook list." error)
|
|
|
|
|
(setq no-popup nil)
|
2012-12-29 17:52:05 +01:00
|
|
|
|
(ein:notebooklist-open url-or-port no-popup))
|
2012-09-06 23:46:29 +02:00
|
|
|
|
|
2012-09-01 20:51:55 +02:00
|
|
|
|
;;;###autoload
|
2014-10-17 16:44:04 -05:00
|
|
|
|
(defun ein:notebooklist-new-notebook-with-name (name &optional url-or-port path)
|
2012-06-08 12:59:14 +02:00
|
|
|
|
"Open new notebook and rename the notebook."
|
2012-09-05 14:51:35 +02:00
|
|
|
|
(interactive (let* ((url-or-port (or (ein:get-url-or-port)
|
|
|
|
|
(ein:default-url-or-port)))
|
|
|
|
|
(name (read-from-minibuffer
|
|
|
|
|
(format "Notebook name (at %s): " url-or-port))))
|
|
|
|
|
(list name url-or-port)))
|
2015-03-25 09:52:16 -05:00
|
|
|
|
(let ((path (or path (ein:$notebooklist-path
|
|
|
|
|
(or ein:%notebooklist%
|
|
|
|
|
(ein:get-notebook)
|
|
|
|
|
(gethash url-or-port ein:notebooklist-map))))))
|
2014-10-17 16:44:04 -05:00
|
|
|
|
(ein:notebooklist-new-notebook
|
|
|
|
|
url-or-port
|
|
|
|
|
path
|
|
|
|
|
(lambda (notebook created name)
|
|
|
|
|
(assert created)
|
|
|
|
|
(with-current-buffer (ein:notebook-buffer notebook)
|
|
|
|
|
(ein:notebook-rename-command name)
|
|
|
|
|
;; As `ein:notebook-open' does not call `pop-to-buffer' when
|
|
|
|
|
;; callback is specified, `pop-to-buffer' must be called here:
|
|
|
|
|
(pop-to-buffer (current-buffer))))
|
|
|
|
|
(list name))))
|
2012-06-08 12:59:14 +02:00
|
|
|
|
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(defun ein:notebooklist-delete-notebook-ask (path)
|
|
|
|
|
(when (y-or-n-p (format "Delete notebook %s?" path))
|
|
|
|
|
(ein:notebooklist-delete-notebook path)))
|
2012-05-13 06:51:26 +02:00
|
|
|
|
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(defun ein:notebooklist-delete-notebook (path)
|
|
|
|
|
(ein:log 'info "Deleting notebook %s..." path)
|
2012-06-20 21:01:58 +02:00
|
|
|
|
(ein:query-singleton-ajax
|
|
|
|
|
(list 'notebooklist-delete-notebook
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(ein:$notebooklist-url-or-port ein:%notebooklist%) path)
|
2012-05-26 19:01:39 +02:00
|
|
|
|
(ein:notebook-url-from-url-and-id
|
2012-08-18 22:31:15 +02:00
|
|
|
|
(ein:$notebooklist-url-or-port ein:%notebooklist%)
|
2014-10-17 16:44:04 -05:00
|
|
|
|
(ein:$notebooklist-api-version ein:%notebooklist%)
|
2015-02-10 14:53:08 -06:00
|
|
|
|
path)
|
2012-05-26 19:01:39 +02:00
|
|
|
|
:type "DELETE"
|
2015-02-10 14:53:08 -06:00
|
|
|
|
:success (apply-partially (lambda (buffer path &rest ignore)
|
2012-12-29 17:17:39 +01:00
|
|
|
|
(ein:log 'info
|
2015-02-10 14:53:08 -06:00
|
|
|
|
"Deleting notebook %s... Done." path)
|
2012-12-29 18:29:15 +01:00
|
|
|
|
(with-current-buffer buffer
|
2012-12-29 17:17:39 +01:00
|
|
|
|
(ein:notebooklist-reload)))
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(current-buffer) path)))
|
2012-05-12 00:59:15 +02:00
|
|
|
|
|
2014-11-12 06:38:02 -06:00
|
|
|
|
;; Because MinRK wants me to suffer...
|
|
|
|
|
(defun ein:get-actual-path (path)
|
|
|
|
|
(ein:aif (cl-position ?/ path :from-end t)
|
|
|
|
|
(substring path 0 it)
|
|
|
|
|
""))
|
|
|
|
|
|
2014-12-09 10:41:53 -06:00
|
|
|
|
(defun generate-breadcrumbs (path)
|
|
|
|
|
"Given notebooklist path, generate alist of breadcrumps of form (name . path)."
|
|
|
|
|
(let* ((paths (split-string path "/" t))
|
|
|
|
|
(current-path "/")
|
|
|
|
|
(pairs (list (cons "Home" ""))))
|
|
|
|
|
(dolist (p paths pairs)
|
|
|
|
|
(setf current-path (concat current-path p)
|
|
|
|
|
pairs (append pairs (list (cons p current-path)))))))
|
|
|
|
|
|
2012-05-07 14:41:15 +02:00
|
|
|
|
(defun ein:notebooklist-render ()
|
2012-05-12 00:59:15 +02:00
|
|
|
|
"Render notebook list widget.
|
|
|
|
|
Notebook list data is passed via the buffer local variable
|
|
|
|
|
`ein:notebooklist-data'."
|
2012-05-07 14:41:15 +02:00
|
|
|
|
(kill-all-local-variables)
|
|
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
|
(erase-buffer))
|
|
|
|
|
(remove-overlays)
|
|
|
|
|
;; Create notebook list
|
2015-05-28 11:56:40 -05:00
|
|
|
|
(widget-insert (format "IPython %s Notebook list\n\n" (ein:$notebooklist-api-version ein:%notebooklist%)))
|
2014-12-09 10:41:53 -06:00
|
|
|
|
(let ((breadcrumbs (generate-breadcrumbs (ein:$notebooklist-path ein:%notebooklist%))))
|
|
|
|
|
(dolist (p breadcrumbs)
|
|
|
|
|
(lexical-let ((name (car p))
|
|
|
|
|
(path (cdr p)))
|
|
|
|
|
(widget-insert " | ")
|
|
|
|
|
(widget-create
|
|
|
|
|
'link
|
|
|
|
|
:notify (lambda (&rest ignore) (ein:notebooklist-open
|
|
|
|
|
(ein:$notebooklist-url-or-port ein:%notebooklist%)
|
|
|
|
|
path))
|
|
|
|
|
name)))
|
2015-05-28 11:56:40 -05:00
|
|
|
|
(widget-insert " |\n\n"))
|
2012-05-12 00:34:00 +02:00
|
|
|
|
(widget-create
|
|
|
|
|
'link
|
|
|
|
|
:notify (lambda (&rest ignore) (ein:notebooklist-new-notebook))
|
|
|
|
|
"New Notebook")
|
2012-05-13 05:18:38 +02:00
|
|
|
|
(widget-insert " ")
|
|
|
|
|
(widget-create
|
|
|
|
|
'link
|
|
|
|
|
:notify (lambda (&rest ignore) (ein:notebooklist-reload))
|
|
|
|
|
"Reload List")
|
2012-05-19 17:09:22 +02:00
|
|
|
|
(widget-insert " ")
|
|
|
|
|
(widget-create
|
|
|
|
|
'link
|
|
|
|
|
:notify (lambda (&rest ignore)
|
|
|
|
|
(browse-url
|
2012-08-18 22:31:15 +02:00
|
|
|
|
(ein:url (ein:$notebooklist-url-or-port ein:%notebooklist%))))
|
2012-05-19 17:09:22 +02:00
|
|
|
|
"Open In Browser")
|
2015-05-28 11:56:40 -05:00
|
|
|
|
(widget-insert "\n\n")
|
|
|
|
|
(let ((api-version (ein:$notebooklist-api-version ein:%notebooklist%))
|
|
|
|
|
(sessions (make-hash-table :test 'equal)))
|
|
|
|
|
(ein:content-query-sessions sessions (ein:$notebooklist-url-or-port ein:%notebooklist%) t)
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(loop for note in (ein:$notebooklist-data ein:%notebooklist%)
|
2014-11-12 06:38:02 -06:00
|
|
|
|
for urlport = (ein:$notebooklist-url-or-port ein:%notebooklist%)
|
|
|
|
|
for name = (plist-get note :name)
|
2015-02-10 14:53:08 -06:00
|
|
|
|
for path = (plist-get note :path)
|
|
|
|
|
;; (cond ((= 2 api-version)
|
|
|
|
|
;; (plist-get note :path))
|
|
|
|
|
;; ((= 3 api-version)
|
|
|
|
|
;; (ein:get-actual-path (plist-get note :path))))
|
2014-11-12 06:38:02 -06:00
|
|
|
|
for type = (plist-get note :type)
|
2015-02-10 14:56:41 -06:00
|
|
|
|
for opened-notebook-maybe = (ein:notebook-get-opened-notebook urlport path)
|
2015-05-28 11:56:40 -05:00
|
|
|
|
do (widget-insert " ")
|
2014-11-12 06:38:02 -06:00
|
|
|
|
if (string= type "directory")
|
|
|
|
|
do (progn (widget-create
|
|
|
|
|
'link
|
|
|
|
|
:notify (lexical-let ((urlport urlport)
|
|
|
|
|
(path name))
|
|
|
|
|
(lambda (&rest ignore)
|
|
|
|
|
(ein:notebooklist-open urlport
|
|
|
|
|
(ein:url (ein:$notebooklist-path ein:%notebooklist%)
|
|
|
|
|
path))))
|
|
|
|
|
"Dir")
|
|
|
|
|
(widget-insert " : " name)
|
|
|
|
|
(widget-insert "\n"))
|
|
|
|
|
if (string= type "notebook")
|
|
|
|
|
do (progn (widget-create
|
|
|
|
|
'link
|
|
|
|
|
:notify (lexical-let ((name name)
|
2014-12-19 16:24:59 -06:00
|
|
|
|
(path path))
|
2014-11-12 06:38:02 -06:00
|
|
|
|
(lambda (&rest ignore)
|
2015-01-13 06:40:15 -06:00
|
|
|
|
(run-at-time 3 nil
|
|
|
|
|
#'ein:notebooklist-reload ein:%notebooklist%) ;; TODO using deferred better?
|
2014-11-12 06:38:02 -06:00
|
|
|
|
(ein:notebooklist-open-notebook
|
2015-02-10 14:53:08 -06:00
|
|
|
|
ein:%notebooklist% path)))
|
2014-11-12 06:38:02 -06:00
|
|
|
|
"Open")
|
|
|
|
|
(widget-insert " ")
|
2015-05-28 11:56:40 -05:00
|
|
|
|
(when (gethash path sessions)
|
2014-12-19 16:24:59 -06:00
|
|
|
|
(widget-create
|
|
|
|
|
'link
|
2015-05-28 11:56:40 -05:00
|
|
|
|
:notify (lexical-let ((session (car (gethash path sessions)))
|
|
|
|
|
(nblist ein:%notebooklist%))
|
2014-12-19 16:24:59 -06:00
|
|
|
|
(lambda (&rest ignore)
|
2015-05-28 11:56:40 -05:00
|
|
|
|
(run-at-time 1 nil
|
2015-01-13 06:40:15 -06:00
|
|
|
|
#'ein:notebooklist-reload
|
|
|
|
|
ein:%notebooklist%)
|
2015-05-28 11:56:40 -05:00
|
|
|
|
(ein:kernel-kill (make-ein:$kernel :url-or-port (ein:$notebooklist-url-or-port nblist)
|
|
|
|
|
:session-id session))))
|
2014-12-19 16:24:59 -06:00
|
|
|
|
"Stop")
|
|
|
|
|
(widget-insert " "))
|
2014-11-12 06:38:02 -06:00
|
|
|
|
(widget-create
|
|
|
|
|
'link
|
2015-02-10 14:53:08 -06:00
|
|
|
|
:notify (lexical-let ((path path))
|
2014-11-12 06:38:02 -06:00
|
|
|
|
(lambda (&rest ignore)
|
|
|
|
|
(ein:notebooklist-delete-notebook-ask
|
|
|
|
|
path)))
|
|
|
|
|
"Delete")
|
|
|
|
|
(widget-insert " : " name)
|
|
|
|
|
(widget-insert "\n"))))
|
2012-05-15 03:41:08 +02:00
|
|
|
|
(ein:notebooklist-mode)
|
2012-05-07 14:41:15 +02:00
|
|
|
|
(widget-setup))
|
|
|
|
|
|
2012-09-01 20:51:55 +02:00
|
|
|
|
;;;###autoload
|
2012-07-12 01:05:37 +02:00
|
|
|
|
(defun ein:notebooklist-list-notebooks ()
|
|
|
|
|
"Return a list of notebook path (NBPATH). Each element NBPATH
|
|
|
|
|
is a string of the format \"URL-OR-PORT/NOTEBOOK-NAME\"."
|
|
|
|
|
(apply #'append
|
|
|
|
|
(loop for nblist in (ein:notebooklist-list)
|
|
|
|
|
for url-or-port = (ein:$notebooklist-url-or-port nblist)
|
2015-02-10 14:53:08 -06:00
|
|
|
|
for api-version = (ein:$notebooklist-api-version nblist)
|
2012-07-12 01:05:37 +02:00
|
|
|
|
collect
|
2015-02-12 09:20:34 -06:00
|
|
|
|
(loop for note in (ein:make-content-hierarchy "" url-or-port)
|
2015-02-10 14:53:08 -06:00
|
|
|
|
collect (format "%s/%s" url-or-port
|
|
|
|
|
(ein:$content-path note)
|
|
|
|
|
))
|
2015-02-12 09:20:34 -06:00
|
|
|
|
;; (if (= api-version 3)
|
|
|
|
|
;; (loop for note in (ein:make-content-hierarchy "" url-or-port)
|
|
|
|
|
;; collect (format "%s/%s" url-or-port
|
|
|
|
|
;; (ein:$content-path note)
|
|
|
|
|
;; ))
|
|
|
|
|
;; (loop for note in (ein:$notebooklist-data nblist)
|
|
|
|
|
;; collect (format "%s/%s"
|
|
|
|
|
;; url-or-port
|
|
|
|
|
;; (plist-get note :name))))
|
|
|
|
|
)))
|
2012-07-12 01:05:37 +02:00
|
|
|
|
|
2014-12-03 19:44:02 -06:00
|
|
|
|
;;FIXME: Code below assumes notebook is in root directory - need to do a better
|
|
|
|
|
;; job listing notebooks in subdirectories and parsing out the path.
|
2012-09-01 20:51:55 +02:00
|
|
|
|
;;;###autoload
|
2012-07-12 02:04:50 +02:00
|
|
|
|
(defun ein:notebooklist-open-notebook-global (nbpath &optional callback cbargs)
|
2012-07-12 01:05:37 +02:00
|
|
|
|
"Choose notebook from all opened notebook list and open it.
|
|
|
|
|
Notebook is specified by a string NBPATH whose format is
|
2012-07-12 02:04:50 +02:00
|
|
|
|
\"URL-OR-PORT/NOTEBOOK-NAME\".
|
|
|
|
|
|
|
|
|
|
When used in lisp, CALLBACK and CBARGS are passed to `ein:notebook-open'."
|
2012-06-05 14:54:18 +02:00
|
|
|
|
(interactive
|
|
|
|
|
(list (completing-read
|
|
|
|
|
"Open notebook [URL-OR-PORT/NAME]: "
|
2012-07-12 01:05:37 +02:00
|
|
|
|
(ein:notebooklist-list-notebooks))))
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(let* ((url-or-port (substring nbpath 0 (cl-position ?/ nbpath)))
|
|
|
|
|
(path (substring nbpath (1+ (cl-position ?/ nbpath)))))
|
2012-06-05 14:54:18 +02:00
|
|
|
|
(when (and (stringp url-or-port)
|
|
|
|
|
(string-match "^[0-9]+$" url-or-port))
|
|
|
|
|
(setq url-or-port (string-to-number url-or-port)))
|
2015-02-12 09:20:34 -06:00
|
|
|
|
(ein:notebook-open url-or-port path callback cbargs)
|
2014-12-03 19:44:02 -06:00
|
|
|
|
(ein:log 'info "Notebook '%s' not found" nbpath)))
|
2012-06-05 14:54:18 +02:00
|
|
|
|
|
2012-09-01 20:51:55 +02:00
|
|
|
|
;;;###autoload
|
2012-08-26 22:12:49 +02:00
|
|
|
|
(defun ein:notebooklist-load (&optional url-or-port)
|
|
|
|
|
"Load notebook list but do not pop-up the notebook list buffer.
|
|
|
|
|
|
|
|
|
|
For example, if you want to load notebook list when Emacs starts,
|
|
|
|
|
add this in the Emacs initialization file::
|
|
|
|
|
|
|
|
|
|
(add-to-hook 'after-init-hook 'ein:notebooklist-load)
|
|
|
|
|
|
|
|
|
|
or even this (if you want fast Emacs start-up)::
|
|
|
|
|
|
|
|
|
|
;; load notebook list if Emacs is idle for 3 sec after start-up
|
|
|
|
|
(run-with-idle-timer 3 nil #'ein:notebooklist-load)
|
|
|
|
|
|
|
|
|
|
You should setup `ein:url-or-port' or `ein:default-url-or-port'
|
|
|
|
|
in order to make this code work.
|
|
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
`ein:connect-to-default-notebook', `ein:connect-default-notebook'."
|
|
|
|
|
(ein:notebooklist-open url-or-port t))
|
|
|
|
|
|
2012-09-05 17:27:29 +02:00
|
|
|
|
|
|
|
|
|
(defun ein:notebooklist-find-server-by-notebook-name (name)
|
2015-02-10 14:53:08 -06:00
|
|
|
|
"Find a notebook named NAME and return a list (URL-OR-PORT PATH)."
|
2012-09-05 17:27:29 +02:00
|
|
|
|
(loop named outer
|
|
|
|
|
for nblist in (ein:notebooklist-list)
|
|
|
|
|
for url-or-port = (ein:$notebooklist-url-or-port nblist)
|
2015-02-10 14:53:08 -06:00
|
|
|
|
for ipython-version = (ein:$notebooklist-api-version nblist)
|
|
|
|
|
do
|
|
|
|
|
(if (= ipython-version 3)
|
|
|
|
|
(loop for note in (ein:make-content-hierarchy "" url-or-port)
|
|
|
|
|
when (equal (ein:$content-name note) name)
|
|
|
|
|
do (return-from outer
|
|
|
|
|
(list url-or-port (ein:$content-path note))))
|
|
|
|
|
(loop for note in (ein:$notebooklist-data nblist)
|
|
|
|
|
when (equal (plist-get note :name) name)
|
|
|
|
|
do (return-from outer
|
|
|
|
|
(list url-or-port
|
|
|
|
|
(format "%s/%s" (plist-get note :path) (plist-get note :name))))))))
|
2012-09-05 17:27:29 +02:00
|
|
|
|
|
2012-09-05 17:52:46 +02:00
|
|
|
|
(defun ein:notebooklist-open-notebook-by-file-name
|
2012-09-05 18:02:35 +02:00
|
|
|
|
(&optional filename noerror buffer-callback)
|
2012-09-05 17:27:29 +02:00
|
|
|
|
"Find the notebook named as same as the current file in the servers.
|
|
|
|
|
Open the notebook if found. Note that this command will *not*
|
|
|
|
|
upload the current file to the server.
|
|
|
|
|
|
|
|
|
|
.. When FILENAME is unspecified the variable `buffer-file-name'
|
2012-09-05 17:52:46 +02:00
|
|
|
|
is used instead. Set NOERROR to non-`nil' to suppress errors.
|
2012-09-05 18:02:35 +02:00
|
|
|
|
BUFFER-CALLBACK is called after opening notebook with the
|
|
|
|
|
current buffer as the only one argument."
|
2012-09-05 17:27:29 +02:00
|
|
|
|
(interactive (progn (assert buffer-file-name nil "Not visiting a file.")
|
|
|
|
|
nil))
|
|
|
|
|
(unless filename (setq filename buffer-file-name))
|
|
|
|
|
(assert filename nil "No file found.")
|
|
|
|
|
(let* ((name (file-name-sans-extension
|
|
|
|
|
(file-name-nondirectory (or filename))))
|
2012-09-05 18:02:35 +02:00
|
|
|
|
(found (ein:notebooklist-find-server-by-notebook-name name))
|
|
|
|
|
(callback (lambda (-ignore-1- -ignore-2- buffer buffer-callback)
|
|
|
|
|
(ein:notebook-pop-to-current-buffer) ; default
|
|
|
|
|
(when (buffer-live-p buffer)
|
|
|
|
|
(funcall buffer-callback buffer))))
|
|
|
|
|
(cbargs (list (current-buffer) (or buffer-callback #'ignore))))
|
2012-09-05 20:33:21 +02:00
|
|
|
|
(unless noerror
|
|
|
|
|
(assert found nil "No server has notebook named: %s" name))
|
2015-02-10 14:53:08 -06:00
|
|
|
|
(destructuring-bind (url-or-port path) found
|
2015-02-12 09:20:34 -06:00
|
|
|
|
(ein:notebook-open url-or-port path callback cbargs))))
|
2012-09-05 17:52:46 +02:00
|
|
|
|
|
2012-09-05 18:02:35 +02:00
|
|
|
|
(defvar ein:notebooklist-find-file-buffer-callback #'ignore)
|
2012-09-05 17:52:46 +02:00
|
|
|
|
|
|
|
|
|
(defun ein:notebooklist-find-file-callback ()
|
2012-09-05 18:02:35 +02:00
|
|
|
|
"A callback function for `find-file-hook' to open notebook.
|
|
|
|
|
|
|
|
|
|
FIMXE: document how to use `ein:notebooklist-find-file-callback'
|
|
|
|
|
when I am convinced with the API."
|
2012-09-05 17:52:46 +02:00
|
|
|
|
(ein:and-let* ((filename buffer-file-name)
|
|
|
|
|
((string-match-p "\\.ipynb$" filename)))
|
2012-09-05 18:02:35 +02:00
|
|
|
|
(ein:notebooklist-open-notebook-by-file-name
|
|
|
|
|
filename t ein:notebooklist-find-file-buffer-callback)))
|
2012-09-05 17:27:29 +02:00
|
|
|
|
|
2012-12-17 16:51:31 +01:00
|
|
|
|
|
|
|
|
|
;;; Login
|
|
|
|
|
|
|
|
|
|
(defun ein:notebooklist-login (url-or-port password)
|
|
|
|
|
"Login to IPython notebook server."
|
|
|
|
|
(interactive (list (ein:notebooklist-ask-url-or-port)
|
2012-12-17 17:55:30 +01:00
|
|
|
|
(read-passwd "Password: ")))
|
2012-12-17 19:26:13 +01:00
|
|
|
|
(ein:log 'debug "NOTEBOOKLIST-LOGIN: %s" url-or-port)
|
2012-12-17 16:51:31 +01:00
|
|
|
|
(ein:query-singleton-ajax
|
|
|
|
|
(list 'notebooklist-login url-or-port)
|
|
|
|
|
(ein:url url-or-port "login")
|
|
|
|
|
:type "POST"
|
2012-12-17 23:15:21 +01:00
|
|
|
|
:data (concat "password=" (url-hexify-string password))
|
2012-12-17 19:26:13 +01:00
|
|
|
|
:parser #'ein:notebooklist-login--parser
|
2012-12-29 17:17:39 +01:00
|
|
|
|
:error (apply-partially #'ein:notebooklist-login--error url-or-port)
|
|
|
|
|
:success (apply-partially #'ein:notebooklist-login--success url-or-port)))
|
2012-12-17 19:26:13 +01:00
|
|
|
|
|
|
|
|
|
(defun ein:notebooklist-login--parser ()
|
|
|
|
|
(goto-char (point-min))
|
2013-01-10 19:25:08 +01:00
|
|
|
|
(list :bad-page (re-search-forward "<input type=.?password" nil t)))
|
2012-12-17 19:26:13 +01:00
|
|
|
|
|
|
|
|
|
(defun ein:notebooklist-login--success-1 (url-or-port)
|
|
|
|
|
(ein:log 'info "Login to %s complete. \
|
2012-12-17 16:51:31 +01:00
|
|
|
|
Now you can open notebook list by `ein:notebooklist-open'." url-or-port))
|
2012-12-17 19:26:13 +01:00
|
|
|
|
|
|
|
|
|
(defun ein:notebooklist-login--error-1 (url-or-port)
|
|
|
|
|
(ein:log 'info "Failed to login to %s" url-or-port))
|
|
|
|
|
|
|
|
|
|
(defun* ein:notebooklist-login--success (url-or-port &key
|
|
|
|
|
data
|
|
|
|
|
&allow-other-keys)
|
|
|
|
|
(if (plist-get data :bad-page)
|
|
|
|
|
(ein:notebooklist-login--error-1 url-or-port)
|
|
|
|
|
(ein:notebooklist-login--success-1 url-or-port)))
|
|
|
|
|
|
2013-01-09 05:51:25 +01:00
|
|
|
|
(defun* ein:notebooklist-login--error
|
|
|
|
|
(url-or-port &key
|
|
|
|
|
data
|
|
|
|
|
symbol-status
|
|
|
|
|
response
|
|
|
|
|
&allow-other-keys
|
|
|
|
|
&aux
|
|
|
|
|
(response-status (request-response-status-code response)))
|
2013-01-10 19:25:08 +01:00
|
|
|
|
(if (or
|
|
|
|
|
;; workaround for url-retrieve backend
|
|
|
|
|
(and (eq symbol-status 'timeout)
|
|
|
|
|
(equal response-status 302)
|
|
|
|
|
(request-response-header response "set-cookie"))
|
|
|
|
|
;; workaround for curl backend
|
|
|
|
|
(and (equal response-status 405)
|
|
|
|
|
(ein:aand (car (request-response-history response))
|
|
|
|
|
(request-response-header it "set-cookie"))))
|
2012-12-17 19:26:13 +01:00
|
|
|
|
(ein:notebooklist-login--success-1 url-or-port)
|
|
|
|
|
(ein:notebooklist-login--error-1 url-or-port)))
|
2012-12-17 16:51:31 +01:00
|
|
|
|
|
2012-08-13 18:55:32 +02:00
|
|
|
|
|
|
|
|
|
;;; Generic getter
|
|
|
|
|
|
|
|
|
|
(defun ein:get-url-or-port--notebooklist ()
|
2012-08-18 22:31:15 +02:00
|
|
|
|
(when (ein:$notebooklist-p ein:%notebooklist%)
|
|
|
|
|
(ein:$notebooklist-url-or-port ein:%notebooklist%)))
|
2012-08-13 18:55:32 +02:00
|
|
|
|
|
2012-05-15 03:41:08 +02:00
|
|
|
|
|
|
|
|
|
;;; Notebook list mode
|
|
|
|
|
|
|
|
|
|
(define-derived-mode ein:notebooklist-mode fundamental-mode "ein:notebooklist"
|
|
|
|
|
"IPython notebook list mode.")
|
|
|
|
|
|
2012-05-15 04:16:06 +02:00
|
|
|
|
(defun ein:notebooklist-prev-item () (interactive) (move-beginning-of-line 0))
|
|
|
|
|
(defun ein:notebooklist-next-item () (interactive) (move-beginning-of-line 2))
|
|
|
|
|
|
2012-06-14 12:42:57 +02:00
|
|
|
|
(setq ein:notebooklist-mode-map (copy-keymap widget-keymap))
|
|
|
|
|
|
|
|
|
|
(let ((map ein:notebooklist-mode-map))
|
|
|
|
|
(define-key map "\C-c\C-r" 'ein:notebooklist-reload)
|
|
|
|
|
(define-key map "g" 'ein:notebooklist-reload)
|
|
|
|
|
(define-key map "p" 'ein:notebooklist-prev-item)
|
|
|
|
|
(define-key map "n" 'ein:notebooklist-next-item)
|
2012-09-01 19:17:41 +02:00
|
|
|
|
(define-key map "q" 'bury-buffer)
|
|
|
|
|
(easy-menu-define ein:notebooklist-menu map "EIN Notebook List Mode Menu"
|
|
|
|
|
`("EIN Notebook List"
|
|
|
|
|
,@(ein:generate-menu
|
|
|
|
|
'(("Reload" ein:notebooklist-reload)
|
|
|
|
|
("New Notebook" ein:notebooklist-new-notebook)
|
|
|
|
|
("New Notebook (with name)"
|
|
|
|
|
ein:notebooklist-new-notebook-with-name)
|
|
|
|
|
("New Junk Notebook" ein:junk-new))))))
|
2012-05-15 03:41:08 +02:00
|
|
|
|
|
2012-05-07 14:41:15 +02:00
|
|
|
|
(provide 'ein-notebooklist)
|
|
|
|
|
|
|
|
|
|
;;; ein-notebooklist.el ends here
|