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,12 +54,13 @@
(reverse acc)))) (reverse acc))))
(defun origami-build-pair-tree (create open close positions) (defun origami-build-pair-tree (create open close 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 (origami-build-pair-tree create open close positions)) (let* ((res (build positions))
(new-pos (car res)) (new-pos (car res))
(children (cdr res))) (children (cdr res)))
(setq positions (cdr new-pos)) (setq positions (cdr new-pos))
@ -74,12 +76,13 @@
(setq positions (cdr positions)) (setq positions (cdr positions))
(setq beg nil)) (setq beg nil))
(setq should-continue nil))))) (setq should-continue nil)))))
(cons positions (reverse acc)))) (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)