Add a new command ein:notebook-scratchsheet-open

This commit is contained in:
Takafumi Arakaki 2012-08-27 00:32:40 +02:00
parent 4b9d10d5c9
commit d5ffb38436
2 changed files with 37 additions and 0 deletions

View file

@ -44,6 +44,7 @@
(require 'ein-kernelinfo)
(require 'ein-cell)
(require 'ein-worksheet)
(require 'ein-scratchsheet)
(require 'ein-completer)
(require 'ein-pager)
(require 'ein-events)
@ -252,6 +253,9 @@ will be updated with kernel's cwd."
(append (ein:$notebook-worksheets notebook)
(ein:$notebook-scratchsheets notebook)))))
(defun ein:notebook--get-nb-or-error ()
(or ein:%notebook% (error "Not in notebook buffer.")))
(defalias 'ein:notebook-name 'ein:$notebook-notebook-name)
(defun ein:notebook-url (notebook)
@ -619,6 +623,34 @@ as usual."
(ein:kernel-kill kernel #'ein:notebook-close (list ein:%notebook%))
(ein:notebook-close ein:%notebook%)))))
;;; Scratch sheet
(defun ein:notebook-scratchsheet-new (notebook)
"Create new scratchsheet in NOTEBOOK."
(let ((ss (ein:scratchsheet-new
notebook
(ein:$notebook-kernel notebook)
(ein:$notebook-events notebook))))
(ein:worksheet-render ss)
(with-current-buffer (ein:worksheet-buffer ss)
(setq ein:%notebook% notebook))
ss))
(defun ein:notebook-scratchsheet-open (notebook &optional popup)
"Open new \"scratch sheet\".
Scratch sheet is almost identical to worksheet. However, EIN
will not save the buffer. Use this buffer like of normal IPython
console. Note that you can always copy cells into the normal
worksheet to save result."
(interactive (list (ein:notebook--get-nb-or-error)
t))
(let ((ss (or (car (ein:$notebook-worksheets notebook))
(ein:notebook-scratchsheet-new notebook))))
(when popup
(pop-to-buffer (ein:worksheet-buffer ss)))
ss))
;;; Opened notebooks

View file

@ -34,6 +34,11 @@
:documentation
"Worksheet without needs for saving.")
(defun ein:scratchsheet-new (notebook kernel events &rest args)
(apply #'make-instance 'ein:scratchsheet
:notebook notebook :kernel kernel :events events
args))
(defmethod ein:worksheet--buffer-name ((ws ein:scratchsheet))
(format ein:scratchsheet-buffer-name-template
(ein:worksheet-url-or-port ws)