modified python-parser code for building multi level fold tree.
This commit is contained in:
parent
1f38085c8f
commit
a3b8bac563
@ -192,20 +192,21 @@ position in the CONTENT."
|
|||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert content)
|
(insert content)
|
||||||
(python-mode)
|
(python-mode)
|
||||||
(goto-char (point-min))
|
(defun python-subparser (beg end)
|
||||||
(beginning-of-defun -1)
|
"find all fold block between beg and end."
|
||||||
(let (beg (end (point-max)) offset acc)
|
(goto-char beg)
|
||||||
(while (not (= (point) end))
|
(let (acc)
|
||||||
(setq beg (point))
|
;; iterate all same level children.
|
||||||
(search-forward-regexp ":" nil t)
|
(while (and (beginning-of-defun -1) (<= (point) end)) ;; have children between beg and end?
|
||||||
(setq offset (- (point) beg))
|
(let* ((new-beg (point))
|
||||||
(end-of-defun)
|
(new-offset (progn (search-forward-regexp ":" nil t) (- (point) new-beg)))
|
||||||
(backward-char)
|
(new-end (progn (end-of-defun) (point))))
|
||||||
(setq end (point))
|
(setq acc (cons (funcall create new-beg new-end new-offset
|
||||||
(when (> offset 0)
|
(python-subparser new-beg new-end))
|
||||||
(setq acc (cons (funcall create beg end offset nil) acc)))
|
acc))
|
||||||
(beginning-of-defun -1))
|
(goto-char new-end)))
|
||||||
(reverse acc)))))
|
acc))
|
||||||
|
(python-subparser (point-min) (point-max)))))
|
||||||
|
|
||||||
(defun origami-lisp-parser (create regex)
|
(defun origami-lisp-parser (create regex)
|
||||||
(lambda (content)
|
(lambda (content)
|
||||||
|
Loading…
Reference in New Issue
Block a user