From ryo.takaishi.0 at gmail.com Thu Dec 22 03:31:43 2011 From: ryo.takaishi.0 at gmail.com (Ryo TAKAISHI) Date: Thu, 22 Dec 2011 12:31:43 +0900 Subject: [cl-org-mode-devel] [PATCH] * src/cl-org-mode.lisp: specifing file encoding Message-ID: <1324524703-18479-1-git-send-email-ryo.takaishi.0@gmail.com> read-org-file become available to understand non ASCII character in org-file. --- src/cl-org-mode.lisp | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cl-org-mode.lisp b/src/cl-org-mode.lisp index b24fdfc..5fce5d9 100644 --- a/src/cl-org-mode.lisp +++ b/src/cl-org-mode.lisp @@ -85,9 +85,9 @@ then stick it in the default node" (defclass org-file (org-parent-node) ((pathname :accessor node.pathname :initarg :pathname))) -(defun read-org-file (pathname) +(defun read-org-file (pathname &key (external-format nil)) (let ((node (make-instance 'org-file :pathname pathname))) - (alexandria:with-input-from-file (stream pathname) + (alexandria:with-input-from-file (stream pathname :external-format external-format) (read-parent-node node stream))))(in-package :cl-org-mode) (defclass delimited-node (org-parent-node) -- 1.7.8.rc1 From ryo.takaishi.0 at gmail.com Thu Dec 22 14:53:10 2011 From: ryo.takaishi.0 at gmail.com (Ryo TAKAISHI) Date: Thu, 22 Dec 2011 23:53:10 +0900 Subject: [cl-org-mode-devel] [PATCH] * src/cl-org-mode.lisp: Added support for link format. Message-ID: <1324565590-28855-1-git-send-email-ryo.takaishi.0@gmail.com> It can parse "[[link]]" and "[[link][description]]". --- src/cl-org-mode.lisp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/cl-org-mode.lisp b/src/cl-org-mode.lisp index b24fdfc..653105f 100644 --- a/src/cl-org-mode.lisp +++ b/src/cl-org-mode.lisp @@ -11,7 +11,10 @@ (defmethod node-dispatchers ((node org-node)) (or *dispatchers* - (mapcar #'make-instance '(src-node properties-node outline-node)))) + (mapcar #'make-instance '(link-node + src-node + properties-node + outline-node)))) (defmethod node-prototypes (node) (error "never call")) @@ -246,4 +249,57 @@ then stick it in the default node" (and (typep n 'property-node) (equal (property-node.property n) key))) (node.children node)))) - (when node (property-node.value node)))) \ No newline at end of file + (when node (property-node.value node)))) + + +(defclass link-node (org-parent-node) + ((link :accessor node.link :initform nil :initarg :link) + (description :accessor node.description :initform nil :initarg :description))) + +(defun at-link-node-p (stack) + (let ((char (first stack)) + (stack (rest stack))) + (and (eql char #\[) + (eql (first stack) #\[) + (if (or (null (rest stack)) + (second stack)) + (values t (rest stack)) + (at-link-node-p (cons char (rest stack))))))) + +(defmethod node-start ((node link-node) stack) + (multiple-value-bind (pred old-stack) + (at-link-node-p stack) + (if pred + (values + (make-instance (class-of node)) + old-stack)))) + +(defmethod node-end ((node link-node) (next-node link-node) stack) + T) + +(defmethod node-end ((node link-node) (next-node text-node) stack) + T) + +(defmethod finalize-node ((node link-node) next-node stack) + (setf (node.next-node node) + (if stack + (make-default-node node next-node stack) + next-node))) + +(defmethod read-next-node ((node link-node) (next-node null) stream) + (let (text c) + (loop for char = (read-char stream nil) + :if (and (eql #\] char) + (eql #\] (car text))) + :do (if (eql (node.link node) nil) + (setf (node.link node) (stack->string (cdr text))) + (setf (node.description node) (stack->string (cdr text)))) + (return) + :if (and (eql #\[ char) + (eql #\] (car text))) + :do (setf (node.link node) (stack->string (cdr text))) + (setf text nil) + :else + :do ;;(unread-char c stream) + (push char text)) + (call-next-method))) -- 1.7.8.rc1 From ryo.takaishi.0 at gmail.com Wed Dec 28 13:27:24 2011 From: ryo.takaishi.0 at gmail.com (Ryo TAKAISHI) Date: Wed, 28 Dec 2011 22:27:24 +0900 Subject: [cl-org-mode-devel] [PATCH] * src/utils.lisp: do not discriminate between lowercase char and uppercase char. Message-ID: <1325078844-12562-1-git-send-email-ryo.takaishi.0@gmail.com> This will be able to make out lower-case character similarly upper-case character. For example, "#+begin_src" similarly "#+BEGIN_SRC", "#+begin_example" similarly "#+BEGIN_EXAMPLE". --- Hello, I want to parse "#+begin_src" line, so I write this patch. Thanks, Ryo TAKAISHI src/utils.lisp | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/src/utils.lisp b/src/utils.lisp index 536ea4a..57a29f8 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -12,7 +12,8 @@ If maybe-starts-with is a string. reverse it before testing against stack") (let ((does-it? (when (>= (length stack)(length list)) (loop :for cons on stack :for pair on list - :always (eql (car cons) (first pair)))))) + :always (eql (char-downcase (car cons)) + (char-downcase (first pair))))))) (when does-it? (values list (nthcdr (length list) stack))))) -- 1.7.8.rc1