Support collapsed cell

This commit is contained in:
Takafumi Arakaki 2012-05-16 20:44:47 +02:00
parent 93556a82b2
commit ad05fa8f8d
2 changed files with 34 additions and 10 deletions

View file

@ -69,6 +69,7 @@
;; make this slot typed. ;; make this slot typed.
;; :type integer ;; :type integer
) )
(collapsed :initarg :collapsed :initform nil :type boolean)
(running :initarg :running :initform nil :type boolean))) (running :initarg :running :initform nil :type boolean)))
(defclass ein:textcell (ein:basecell) (defclass ein:textcell (ein:basecell)
@ -107,6 +108,9 @@
(ein:oset-if-empty cell :input (plist-get data :input)) (ein:oset-if-empty cell :input (plist-get data :input))
(ein:aif (plist-get data :prompt_number) (ein:aif (plist-get data :prompt_number)
(ein:oset-if-empty cell :input-prompt-number it)) (ein:oset-if-empty cell :input-prompt-number it))
(ein:oset-if-empty cell :collapsed
(let ((v (plist-get data :collapsed)))
(if (eql v json-false) nil v)))
cell) cell)
(defmethod ein:cell-init ((cell ein:textcell) data) (defmethod ein:cell-init ((cell ein:textcell) data)
@ -292,14 +296,15 @@ A specific node can be specified using optional ARGS."
(defvar ein:cell-output-dynamic nil) (defvar ein:cell-output-dynamic nil)
(defun ein:cell-insert-output (index cell) (defun ein:cell-insert-output (index cell)
(let ((out (nth index (oref cell :outputs))) (unless (oref cell :collapsed)
(dynamic ein:cell-output-dynamic)) (let ((out (nth index (oref cell :outputs)))
(ein:case-equal (plist-get out :output_type) (dynamic ein:cell-output-dynamic))
(("pyout") (ein:cell-append-pyout cell out dynamic)) (ein:case-equal (plist-get out :output_type)
(("pyerr") (ein:cell-append-pyerr cell out)) (("pyout") (ein:cell-append-pyout cell out dynamic))
(("display_data") (ein:cell-append-display-data cell out dynamic)) (("pyerr") (ein:cell-append-pyerr cell out))
(("stream") (ein:cell-append-stream cell out)))) (("display_data") (ein:cell-append-display-data cell out dynamic))
(ein:insert-read-only "\n")) (("stream") (ein:cell-append-stream cell out))))
(ein:insert-read-only "\n")))
(defun ein:cell-insert-footer () (defun ein:cell-insert-footer ()
(ein:insert-read-only "\n")) (ein:insert-read-only "\n"))
@ -353,6 +358,13 @@ A specific node can be specified using optional ARGS."
;; FIXME: change the appearance of the cell ;; FIXME: change the appearance of the cell
(oset cell :running running)) (oset cell :running running))
(defmethod ein:cell-toggle-output ((cell ein:codecell))
"Toggle `:collapsed' slot of CELL and invalidate output ewoc nodes."
(oset cell :collapsed (not (oref cell :collapsed)))
(apply #'ewoc-invalidate
(oref cell :ewoc)
(ein:cell-element-get cell :output)))
(defun ein:cell-set-input-prompt (cell &optional number) (defun ein:cell-set-input-prompt (cell &optional number)
(oset cell :input-prompt-number number) (oset cell :input-prompt-number number)
(let ((inhibit-read-only t) (let ((inhibit-read-only t)
@ -527,8 +539,7 @@ A specific node can be specified using optional ARGS."
`((prompt_number . ,it))) `((prompt_number . ,it)))
(outputs . ,(apply #'vector (oref cell :outputs))) (outputs . ,(apply #'vector (oref cell :outputs)))
(language . "python") (language . "python")
;; FIXME: implement `collapsed' (collapsed . ,(if (oref cell :collapsed) t json-false))))
(collapsed . ,json-false)))
(defmethod ein:cell-to-json ((cell ein:textcell)) (defmethod ein:cell-to-json ((cell ein:textcell))
`((cell_type . ,(oref cell :cell-type)) `((cell_type . ,(oref cell :cell-type))

View file

@ -349,6 +349,18 @@ when the prefix argument is given."
(ein:cell-goto it) (ein:cell-goto it)
(ein:log 'warn "No previous cell")))) (ein:log 'warn "No previous cell"))))
;;; Cell collapsing and output clearing
(defun ein:notebook-toggle-output (notebook cell)
(ein:cell-toggle-output cell)
(setf (ein:$notebook-dirty notebook) t))
(defun ein:notebook-toggle-output-command ()
(interactive)
(ein:notebook-with-cell #'ein:codecell-p
(ein:notebook-toggle-output ein:notebook cell)))
;;; Kernel related things ;;; Kernel related things
@ -677,6 +689,7 @@ NAME is any non-empty string that does not contain '/' or '\\'."
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
(define-key map "\C-c\C-r" 'ein:notebook-render) (define-key map "\C-c\C-r" 'ein:notebook-render)
(define-key map "\C-c\C-c" 'ein:notebook-execute-current-cell) (define-key map "\C-c\C-c" 'ein:notebook-execute-current-cell)
(define-key map "\C-c\C-e" 'ein:notebook-toggle-output-command)
(define-key map "\C-c\C-d" 'ein:notebook-delete-cell-command) (define-key map "\C-c\C-d" 'ein:notebook-delete-cell-command)
(define-key map "\C-c\C-k" 'ein:notebook-kill-cell-command) (define-key map "\C-c\C-k" 'ein:notebook-kill-cell-command)
(define-key map "\C-c\M-w" 'ein:notebook-copy-cell-command) (define-key map "\C-c\M-w" 'ein:notebook-copy-cell-command)