From 10fb29f7d4298bdd18b7cf55d43d90dc5ba66432 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sat, 19 May 2012 23:45:59 +0200 Subject: [PATCH] Add raw and heading cell types; Now it can read v3 --- ein-cell.el | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/ein-cell.el b/ein-cell.el index 3709739..c9e3131 100644 --- a/ein-cell.el +++ b/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)