Reuse existing machinery
This commit is contained in:
parent
b9ecf4b355
commit
f608e09be3
@ -115,44 +115,13 @@ position in the CONTENT."
|
|||||||
build-nodes
|
build-nodes
|
||||||
cdr))))
|
cdr))))
|
||||||
|
|
||||||
;; Added support for C-Makros
|
|
||||||
(defun origami-build-pair-tree-makro-c (create open openM close closeM positions)
|
|
||||||
(cl-labels ((build (positions)
|
|
||||||
;; this is so horrible, but fast
|
|
||||||
(let (acc beg (should-continue t))
|
|
||||||
(while (and should-continue positions)
|
|
||||||
(cond ((or (equal (caar positions) open)
|
|
||||||
(equal (caar positions) openM))
|
|
||||||
(if beg ;go down a level
|
|
||||||
(let* ((res (build positions))
|
|
||||||
(new-pos (car res))
|
|
||||||
(children (cdr res)))
|
|
||||||
(setq positions (cdr new-pos))
|
|
||||||
(setq acc (cons (funcall create beg (cdar new-pos) (length open) children)
|
|
||||||
acc))
|
|
||||||
(setq beg nil))
|
|
||||||
;; begin a new pair
|
|
||||||
(setq beg (cdar positions))
|
|
||||||
(setq positions (cdr positions))))
|
|
||||||
( (or (equal (caar positions) closeM)
|
|
||||||
(equal (caar positions) close))
|
|
||||||
(if beg
|
|
||||||
(progn ;close with no children
|
|
||||||
(setq acc (cons (funcall create beg (cdar positions) (length close) nil)
|
|
||||||
acc))
|
|
||||||
(setq positions (cdr positions))
|
|
||||||
(setq beg nil))
|
|
||||||
(setq should-continue nil)))))
|
|
||||||
(cons positions (reverse acc)))))
|
|
||||||
(cdr (build positions))))
|
|
||||||
|
|
||||||
(defun origami-build-pair-tree (create open close positions)
|
(defun origami-build-pair-tree (create open close positions)
|
||||||
(cl-labels ((build (positions)
|
(cl-labels ((build (positions)
|
||||||
;; this is so horrible, but fast
|
;; this is so horrible, but fast
|
||||||
(let (acc beg (should-continue t))
|
(let (acc beg (should-continue t))
|
||||||
(while (and should-continue positions)
|
(while (and should-continue positions)
|
||||||
(cond ((equal (caar positions) open)
|
(cond ((equal (caar positions) open)
|
||||||
(if beg ;go down a level
|
(if beg ;go down a level
|
||||||
(let* ((res (build positions))
|
(let* ((res (build positions))
|
||||||
(new-pos (car res))
|
(new-pos (car res))
|
||||||
(children (cdr res)))
|
(children (cdr res)))
|
||||||
@ -165,7 +134,7 @@ position in the CONTENT."
|
|||||||
(setq positions (cdr positions))))
|
(setq positions (cdr positions))))
|
||||||
((equal (caar positions) close)
|
((equal (caar positions) close)
|
||||||
(if beg
|
(if beg
|
||||||
(progn ;close with no children
|
(progn ;close with no children
|
||||||
(setq acc (cons (funcall create beg (cdar positions) (length close) nil)
|
(setq acc (cons (funcall create beg (cdar positions) (length close) nil)
|
||||||
acc))
|
acc))
|
||||||
(setq positions (cdr positions))
|
(setq positions (cdr positions))
|
||||||
@ -174,13 +143,6 @@ position in the CONTENT."
|
|||||||
(cons positions (reverse acc)))))
|
(cons positions (reverse acc)))))
|
||||||
(cdr (build positions))))
|
(cdr (build positions))))
|
||||||
|
|
||||||
;; Support for C-Makros
|
|
||||||
(defun origami-c-with-makros-parser (create)
|
|
||||||
(lambda (content)
|
|
||||||
(let ((positions (origami-get-positions content "#ifdef\\|#endif\\|[{}]")))
|
|
||||||
(origami-build-pair-tree-makro-c
|
|
||||||
create "{" "#ifdef" "}" "#endif" positions))))
|
|
||||||
|
|
||||||
;;; TODO: tag these nodes? have ability to manipulate nodes that are
|
;;; TODO: tag these nodes? have ability to manipulate nodes that are
|
||||||
;;; tagged? in a scoped fashion?
|
;;; tagged? in a scoped fashion?
|
||||||
(defun origami-javadoc-parser (create)
|
(defun origami-javadoc-parser (create)
|
||||||
@ -203,6 +165,20 @@ position in the CONTENT."
|
|||||||
(if (listp face) face (list face)))))))))
|
(if (listp face) face (list face)))))))))
|
||||||
(origami-build-pair-tree create "{" "}" positions))))
|
(origami-build-pair-tree create "{" "}" positions))))
|
||||||
|
|
||||||
|
(defun origami-c-macro-parser (create)
|
||||||
|
(lambda (content)
|
||||||
|
(let ((positions (origami-get-positions content "#ifdef\\|#endif")))
|
||||||
|
(origami-build-pair-tree create "#ifdef" "#endif" positions))))
|
||||||
|
|
||||||
|
(defun origami-c-parser (create)
|
||||||
|
(let ((c-style (origami-c-style-parser create))
|
||||||
|
(macros (origami-c-macro-parser create)))
|
||||||
|
(lambda (content)
|
||||||
|
(origami-fold-children
|
||||||
|
(origami-fold-shallow-merge
|
||||||
|
(origami-fold-root-node (funcall c-style content))
|
||||||
|
(origami-fold-root-node (funcall macros content)))))))
|
||||||
|
|
||||||
(defun origami-java-parser (create)
|
(defun origami-java-parser (create)
|
||||||
(let ((c-style (origami-c-style-parser create))
|
(let ((c-style (origami-c-style-parser create))
|
||||||
(javadoc (origami-javadoc-parser create)))
|
(javadoc (origami-javadoc-parser create)))
|
||||||
@ -246,8 +222,8 @@ position in the CONTENT."
|
|||||||
|
|
||||||
(defcustom origami-parser-alist
|
(defcustom origami-parser-alist
|
||||||
`((java-mode . origami-java-parser)
|
`((java-mode . origami-java-parser)
|
||||||
(c-mode . origami-c-with-makros-parser)
|
(c-mode . origami-c-parser)
|
||||||
(c++-mode . origami-c-with-makros-parser)
|
(c++-mode . origami-c-parser)
|
||||||
(perl-mode . origami-c-style-parser)
|
(perl-mode . origami-c-style-parser)
|
||||||
(cperl-mode . origami-c-style-parser)
|
(cperl-mode . origami-c-style-parser)
|
||||||
(js-mode . origami-c-style-parser)
|
(js-mode . origami-c-style-parser)
|
||||||
|
Loading…
Reference in New Issue
Block a user