Extract out local function
This commit is contained in:
parent
775d3058a8
commit
d586c41b21
@ -30,6 +30,7 @@
|
||||
;;; Commentary:
|
||||
|
||||
;;; Code:
|
||||
(require 'cl)
|
||||
|
||||
(defcustom origami-parser-alist
|
||||
'((java-mode . origami-c-style-parser)
|
||||
@ -53,12 +54,13 @@
|
||||
(reverse acc))))
|
||||
|
||||
(defun origami-build-pair-tree (create open close positions)
|
||||
(cl-labels ((build (positions)
|
||||
;; this is so horrible, but fast
|
||||
(let (acc beg (should-continue t))
|
||||
(while (and should-continue positions)
|
||||
(cond ((equal (caar positions) open)
|
||||
(if beg ;go down a level
|
||||
(let* ((res (origami-build-pair-tree create open close positions))
|
||||
(let* ((res (build positions))
|
||||
(new-pos (car res))
|
||||
(children (cdr res)))
|
||||
(setq positions (cdr new-pos))
|
||||
@ -74,12 +76,13 @@
|
||||
(setq positions (cdr positions))
|
||||
(setq beg nil))
|
||||
(setq should-continue nil)))))
|
||||
(cons positions (reverse acc))))
|
||||
(cons positions (reverse acc)))))
|
||||
(cdr (build positions))))
|
||||
|
||||
(defun origami-c-style-parser (create)
|
||||
(lambda (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)
|
||||
(lambda (content)
|
||||
|
Loading…
Reference in New Issue
Block a user