Add ein:notebook-insert-cell-above-command

This commit is contained in:
Takafumi Arakaki 2012-05-14 22:12:08 +02:00
parent 7212b99991
commit 57c7a36e60
3 changed files with 44 additions and 1 deletions

View file

@ -238,6 +238,21 @@ A specific node can be specified using optional ARGS."
(oset cell :element element)
cell))
(defun ein:cell-enter-first (cell)
(let* ((ewoc (oref cell :ewoc))
(node nil)
(make-node
(lambda (&rest path)
(let ((ewoc-data (ein:node-new `(cell ,@path) cell)))
(setq node
(if node
(ewoc-enter-after ewoc node ewoc-data)
(ewoc-enter-first ewoc ewoc-data))))))
(element (ein:cell-make-element make-node
(ein:cell-num-outputs cell))))
(oset cell :element element)
cell))
(defun ein:cell-insert-below (base-cell other-cell)
(let* ((ewoc (oref base-cell :ewoc))
(node (ein:cell-element-get base-cell :footer))

View file

@ -251,7 +251,7 @@ is `nil', BODY is executed with any cell types."
cell))
(defun ein:notebook-insert-cell-below-command (&optional markdown)
"Insert cell bellow. Insert markdown cell instead of code cell
"Insert cell below. Insert markdown cell instead of code cell
when the prefix argument is given."
(interactive "P")
(let ((cell (ein:notebook-get-current-cell)))
@ -262,6 +262,32 @@ when the prefix argument is given."
(if markdown 'markdown 'code)
cell)))
(defun ein:notebook-insert-cell-above (notebook type base-cell)
(let ((cell (ein:notebook-cell-from-type notebook type)))
(when cell
(cond
((< (ein:notebook-ncells notebook) 2)
(ein:cell-enter-first cell))
(base-cell
(let ((prev-cell (ein:cell-prev base-cell)))
(if prev-cell
(ein:cell-insert-below prev-cell cell)
(ein:cell-enter-first cell))))
(t (error (concat "`base-cell' is `nil' but ncells > 1. "
"There is something wrong..."))))
(ein:cell-goto cell)
(setf (ein:$notebook-dirty notebook) t))
cell))
(defun ein:notebook-insert-cell-above-command (&optional markdown)
"Insert cell above. Insert markdown cell instead of code cell
when the prefix argument is given."
(interactive "P")
(let ((cell (ein:notebook-get-current-cell)))
(ein:notebook-insert-cell-above ein:notebook
(if markdown 'markdown 'code)
cell)))
(defun ein:notebook-toggle-cell-type ()
(interactive)
(ein:notebook-with-cell nil
@ -602,6 +628,7 @@ NAME is any non-empty string that does not contain '/' or '\\'."
(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-d" 'ein:notebook-delete-cell-command)
(define-key map "\C-c\C-a" 'ein:notebook-insert-cell-above-command)
(define-key map "\C-c\C-b" 'ein:notebook-insert-cell-below-command)
(define-key map "\C-c\C-t" 'ein:notebook-toggle-cell-type)
(define-key map "\C-c\C-n" 'ein:notebook-goto-next-cell)

View file

@ -33,6 +33,7 @@
"C-c"
'(("C-t" . ein:notebook-toggle-cell-type)
("C-d" . ein:notebook-delete-cell-command)
("C-a" . ein:notebook-insert-cell-above-command)
("C-b" . ein:notebook-insert-cell-below-command)
("C-n" . ein:notebook-goto-next-cell)
("C-p" . ein:notebook-goto-prev-cell)