2012-05-07 14:41:15 +02:00
|
|
|
;;; ein-notebooklist.el --- Notebook list buffer
|
|
|
|
|
|
|
|
;; Copyright (C) 2012- Takafumi Arakaki
|
|
|
|
|
|
|
|
;; Author: Takafumi Arakaki
|
|
|
|
|
|
|
|
;; 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)
|
|
|
|
|
|
|
|
(require 'ein-utils)
|
|
|
|
(require 'ein-notebook)
|
|
|
|
|
2012-05-12 22:55:06 +02:00
|
|
|
(ein:deflocal ein:notebooklist-data nil
|
2012-05-12 00:59:15 +02:00
|
|
|
"Buffer local variable to store data from the server.")
|
2012-05-07 14:41:15 +02:00
|
|
|
|
|
|
|
(defvar ein:notebooklist-buffer-name-template "*ein:notebooklist %s*")
|
|
|
|
|
|
|
|
|
|
|
|
(defun ein:notebooklist-url ()
|
|
|
|
(concat (ein:base-project-url) "notebooks"))
|
|
|
|
|
2012-05-12 00:34:00 +02:00
|
|
|
(defun ein:notebooklist-new-url ()
|
|
|
|
(concat (ein:base-project-url) "new"))
|
|
|
|
|
|
|
|
(defun ein:notebooklist-get-buffer ()
|
|
|
|
(get-buffer-create
|
|
|
|
(format ein:notebooklist-buffer-name-template ein:port)))
|
|
|
|
|
|
|
|
(defun ein:notebooklist-open (&optional no-popup)
|
2012-05-12 00:59:15 +02:00
|
|
|
"Open notebook list buffer."
|
2012-05-07 14:41:15 +02:00
|
|
|
(interactive)
|
2012-05-12 00:59:15 +02:00
|
|
|
;; FIXME: This function must ask server address or port number.
|
2012-05-07 14:41:15 +02:00
|
|
|
(url-retrieve
|
|
|
|
(ein:notebooklist-url)
|
2012-05-12 00:34:00 +02:00
|
|
|
(if no-popup
|
|
|
|
(lambda (s) (ein:notebooklist-url-retrieve-callback))
|
|
|
|
(lambda (s) (pop-to-buffer (ein:notebooklist-url-retrieve-callback))))))
|
2012-05-07 14:41:15 +02:00
|
|
|
|
2012-05-12 00:34:00 +02:00
|
|
|
(defun ein:notebooklist-url-retrieve-callback ()
|
2012-05-12 00:59:15 +02:00
|
|
|
"Called via `ein:notebooklist-open'."
|
2012-05-07 14:41:15 +02:00
|
|
|
(let ((data (ein:json-read)))
|
|
|
|
(kill-buffer (current-buffer))
|
2012-05-12 00:34:00 +02:00
|
|
|
(with-current-buffer (ein:notebooklist-get-buffer)
|
2012-05-07 14:41:15 +02:00
|
|
|
(setq ein:notebooklist-data data)
|
|
|
|
(ein:notebooklist-render)
|
2012-05-12 00:34:00 +02:00
|
|
|
(current-buffer))))
|
|
|
|
|
|
|
|
(defun ein:notebooklist-new-notebook ()
|
2012-05-12 00:59:15 +02:00
|
|
|
"Ask server to create a new notebook and update the notebook list buffer."
|
2012-05-12 00:34:00 +02:00
|
|
|
(message "Creating a new notebook...")
|
|
|
|
(url-retrieve
|
|
|
|
(ein:notebooklist-new-url)
|
|
|
|
(lambda (s buffer)
|
|
|
|
;; To support opening notebook buffer from here will need parsing
|
|
|
|
;; HTML file. Let's just reload notebook list buffer.
|
|
|
|
(with-current-buffer buffer
|
|
|
|
(ein:notebooklist-open t) ; FIXME: pass buffer to update (open)
|
|
|
|
(message "Creating a new notebook... Done.")))
|
|
|
|
(list (ein:notebooklist-get-buffer))))
|
2012-05-07 14:41:15 +02:00
|
|
|
|
2012-05-12 00:59:15 +02:00
|
|
|
;; FIXME: implement notebook deletion.
|
|
|
|
;; See `add_delete_button' in `notebooklist.js'.
|
|
|
|
|
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
|
2012-05-12 00:48:39 +02:00
|
|
|
(widget-insert "IPython Notebook list\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-12 00:48:39 +02:00
|
|
|
(widget-insert "\n")
|
2012-05-07 14:41:15 +02:00
|
|
|
(loop for note in ein:notebooklist-data
|
|
|
|
for name = (plist-get note :name)
|
|
|
|
for notebook-id = (plist-get note :notebook_id)
|
2012-05-12 00:48:39 +02:00
|
|
|
do (progn (widget-create
|
2012-05-07 14:41:15 +02:00
|
|
|
'link
|
|
|
|
:notify (lexical-let ((name name)
|
|
|
|
(notebook-id notebook-id))
|
|
|
|
(lambda (&rest ignore)
|
|
|
|
(message "Open notebook %s." name)
|
|
|
|
(ein:notebook-open notebook-id)))
|
2012-05-12 00:48:39 +02:00
|
|
|
"Open")
|
|
|
|
(widget-insert " " name)
|
2012-05-07 14:41:15 +02:00
|
|
|
(widget-insert "\n")))
|
|
|
|
(use-local-map widget-keymap)
|
|
|
|
(widget-setup))
|
|
|
|
|
|
|
|
(provide 'ein-notebooklist)
|
|
|
|
|
|
|
|
;;; ein-notebooklist.el ends here
|