Skip to content

Commit

Permalink
Support collapsed cell
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed May 16, 2012
1 parent 93556a8 commit ad05fa8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
31 changes: 21 additions & 10 deletions ein-cell.el
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
;; make this slot typed.
;; :type integer
)
(collapsed :initarg :collapsed :initform nil :type boolean)
(running :initarg :running :initform nil :type boolean)))

(defclass ein:textcell (ein:basecell)
Expand Down Expand Up @@ -107,6 +108,9 @@
(ein:oset-if-empty cell :input (plist-get data :input))
(ein:aif (plist-get data :prompt_number)
(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)

(defmethod ein:cell-init ((cell ein:textcell) data)
Expand Down Expand Up @@ -292,14 +296,15 @@ A specific node can be specified using optional ARGS."
(defvar ein:cell-output-dynamic nil)

(defun ein:cell-insert-output (index cell)
(let ((out (nth index (oref cell :outputs)))
(dynamic ein:cell-output-dynamic))
(ein:case-equal (plist-get out :output_type)
(("pyout") (ein:cell-append-pyout cell out dynamic))
(("pyerr") (ein:cell-append-pyerr cell out))
(("display_data") (ein:cell-append-display-data cell out dynamic))
(("stream") (ein:cell-append-stream cell out))))
(ein:insert-read-only "\n"))
(unless (oref cell :collapsed)
(let ((out (nth index (oref cell :outputs)))
(dynamic ein:cell-output-dynamic))
(ein:case-equal (plist-get out :output_type)
(("pyout") (ein:cell-append-pyout cell out dynamic))
(("pyerr") (ein:cell-append-pyerr cell out))
(("display_data") (ein:cell-append-display-data cell out dynamic))
(("stream") (ein:cell-append-stream cell out))))
(ein:insert-read-only "\n")))

(defun ein:cell-insert-footer ()
(ein:insert-read-only "\n"))
Expand Down Expand Up @@ -353,6 +358,13 @@ A specific node can be specified using optional ARGS."
;; FIXME: change the appearance of the cell
(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)
(oset cell :input-prompt-number number)
(let ((inhibit-read-only t)
Expand Down Expand Up @@ -527,8 +539,7 @@ A specific node can be specified using optional ARGS."
`((prompt_number . ,it)))
(outputs . ,(apply #'vector (oref cell :outputs)))
(language . "python")
;; FIXME: implement `collapsed'
(collapsed . ,json-false)))
(collapsed . ,(if (oref cell :collapsed) t json-false))))

(defmethod ein:cell-to-json ((cell ein:textcell))
`((cell_type . ,(oref cell :cell-type))
Expand Down
13 changes: 13 additions & 0 deletions ein-notebook.el
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,18 @@ when the prefix argument is given."
(ein:cell-goto it)
(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

Expand Down Expand Up @@ -677,6 +689,7 @@ NAME is any non-empty string that does not contain '/' or '\\'."
(let ((map (make-sparse-keymap)))
(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-e" 'ein:notebook-toggle-output-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\M-w" 'ein:notebook-copy-cell-command)
Expand Down

0 comments on commit ad05fa8

Please sign in to comment.