mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-06 01:21:38 -05:00
Add raw and heading cell types; Now it can read v3
This commit is contained in:
parent
b9b5dc57ba
commit
10fb29f7d4
1 changed files with 22 additions and 3 deletions
25
ein-cell.el
25
ein-cell.el
|
@ -87,8 +87,12 @@
|
|||
(defclass ein:markdowncell (ein:textcell)
|
||||
((cell-type :initarg :cell-type :initform "markdown")))
|
||||
|
||||
(defclass ein:rstcell (ein:textcell)
|
||||
((cell-type :initarg :cell-type :initform "rst")))
|
||||
(defclass ein:rawcell (ein:textcell)
|
||||
((cell-type :initarg :cell-type :initform "raw")))
|
||||
|
||||
(defclass ein:headingcell (ein:textcell)
|
||||
((cell-type :initarg :cell-type :initform "heading")
|
||||
(level :initarg :level :initform 1)))
|
||||
|
||||
|
||||
;;; Cell factory
|
||||
|
@ -99,7 +103,8 @@
|
|||
(("text") 'ein:textcell)
|
||||
(("html") 'ein:htmlcell)
|
||||
(("markdown") 'ein:markdowncell)
|
||||
(("rst") 'ein:rstcell)))
|
||||
(("raw") 'ein:rawcell)
|
||||
(("heading") 'ein:headingcell)))
|
||||
|
||||
(defun ein:cell-from-type (type &rest args)
|
||||
(apply (ein:cell-class-from-type type) "Cell" args))
|
||||
|
@ -123,6 +128,12 @@
|
|||
(oset cell :input it))
|
||||
cell)
|
||||
|
||||
(defmethod ein:cell-init ((cell ein:headingcell) data)
|
||||
(call-next-method)
|
||||
(ein:aif (plist-get data :level)
|
||||
(oset cell :level it))
|
||||
cell)
|
||||
|
||||
(defmethod ein:cell-convert ((cell ein:basecell) type)
|
||||
(let ((new (ein:cell-from-type type)))
|
||||
;; copy attributes
|
||||
|
@ -292,6 +303,10 @@ A specific node can be specified using optional ARGS."
|
|||
(ein:insert-read-only
|
||||
(format "In [%s]:" (oref cell :cell-type))))
|
||||
|
||||
(defmethod ein:cell-insert-prompt ((cell ein:headingcell))
|
||||
(ein:insert-read-only
|
||||
(format "In [%s %s]:" (oref cell :cell-type) (oref cell :level))))
|
||||
|
||||
(defun ein:cell-insert-input (cell)
|
||||
;; Newlines must allow insertion before/after its position.
|
||||
(insert (propertize "\n" 'read-only t 'rear-nonsticky t)
|
||||
|
@ -587,6 +602,10 @@ If END is non-`nil', return the location of next element."
|
|||
`((cell_type . ,(oref cell :cell-type))
|
||||
(source . ,(ein:cell-get-text cell))))
|
||||
|
||||
(defmethod ein:cell-to-json ((cell ein:headingcell))
|
||||
(let ((json (call-next-method)))
|
||||
(append json `((level . ,(oref cell :level))))))
|
||||
|
||||
(defun ein:cell-next (cell)
|
||||
"Return next cell of the given CELL or nil if CELL is the last one."
|
||||
(ein:aif (ewoc-next (oref cell :ewoc)
|
||||
|
|
Loading…
Add table
Reference in a new issue