Extract out local function

This commit is contained in:
Greg Sexton 2014-11-15 16:38:50 +00:00
parent 775d3058a8
commit d586c41b21

View File

@ -30,6 +30,7 @@
;;; Commentary: ;;; Commentary:
;;; Code: ;;; Code:
(require 'cl)
(defcustom origami-parser-alist (defcustom origami-parser-alist
'((java-mode . origami-c-style-parser) '((java-mode . origami-c-style-parser)
@ -53,33 +54,35 @@
(reverse acc)))) (reverse acc))))
(defun origami-build-pair-tree (create open close positions) (defun origami-build-pair-tree (create open close positions)
;; this is so horrible, but fast (cl-labels ((build (positions)
(let (acc beg (should-continue t)) ;; this is so horrible, but fast
(while (and should-continue positions) (let (acc beg (should-continue t))
(cond ((equal (caar positions) open) (while (and should-continue positions)
(if beg ;go down a level (cond ((equal (caar positions) open)
(let* ((res (origami-build-pair-tree create open close positions)) (if beg ;go down a level
(new-pos (car res)) (let* ((res (build positions))
(children (cdr res))) (new-pos (car res))
(setq positions (cdr new-pos)) (children (cdr res)))
(setq acc (cons (funcall create beg (cdar new-pos) 0 children) acc)) (setq positions (cdr new-pos))
(setq beg nil)) (setq acc (cons (funcall create beg (cdar new-pos) 0 children) acc))
;; begin a new pair (setq beg nil))
(setq beg (cdar positions)) ;; begin a new pair
(setq positions (cdr positions)))) (setq beg (cdar positions))
((equal (caar positions) close) (setq positions (cdr positions))))
(if beg ((equal (caar positions) close)
(progn ;close with no children (if beg
(setq acc (cons (funcall create beg (cdar positions) 0 nil) acc)) (progn ;close with no children
(setq positions (cdr positions)) (setq acc (cons (funcall create beg (cdar positions) 0 nil) acc))
(setq beg nil)) (setq positions (cdr positions))
(setq should-continue nil))))) (setq beg nil))
(cons positions (reverse acc)))) (setq should-continue nil)))))
(cons positions (reverse acc)))))
(cdr (build positions))))
(defun origami-c-style-parser (create) (defun origami-c-style-parser (create)
(lambda (content) (lambda (content)
(let ((positions (origami-get-positions content "[{}]"))) (let ((positions (origami-get-positions content "[{}]")))
(cdr (origami-build-pair-tree create "{" "}" positions))))) (origami-build-pair-tree create "{" "}" positions))))
(defun origami-lisp-parser (create regex) (defun origami-lisp-parser (create regex)
(lambda (content) (lambda (content)