python parser any block, fix second and next n-level blocks
This commit is contained in:
parent
5538af82c0
commit
f21c701cbe
@ -197,20 +197,26 @@ position in the CONTENT."
|
|||||||
(defun origami-python-parser-one-level-blocks (wrap-beg wrap-end)
|
(defun origami-python-parser-one-level-blocks (wrap-beg wrap-end)
|
||||||
"Parser one level python blocks of codes from WRAP-BEG to WRAP-END."
|
"Parser one level python blocks of codes from WRAP-BEG to WRAP-END."
|
||||||
(goto-char wrap-beg)
|
(goto-char wrap-beg)
|
||||||
(let ((beg wrap-beg) (prev -1) (end wrap-end) (offset 0) children acc)
|
(let (acc last last-on-buffer)
|
||||||
(while (and (< prev beg) (< beg end))
|
(while (and (not last) (not last-on-buffer))
|
||||||
(python-nav-forward-block)
|
(let ((beg wrap-beg) (end wrap-end) (offset 0) children)
|
||||||
(setq prev beg) ;; if prev == beg, region has not next block
|
(setq beg (point))
|
||||||
|
(message "Point: %s Begin %s End %s" (point) wrap-beg wrap-end)
|
||||||
|
(save-excursion
|
||||||
|
(python-nav-forward-block) (python-nav-end-of-block) (setq end (point))
|
||||||
|
(when (>= end wrap-end) (setq last t)))
|
||||||
|
(python-nav-forward-block)
|
||||||
|
(when (= beg (point)) ;; if new beg without change after next block, it is last block on the page
|
||||||
|
(setq last-on-buffer t))
|
||||||
(setq beg (point))
|
(setq beg (point))
|
||||||
|
|
||||||
(save-excursion (python-nav-end-of-block) (setq end (point)))
|
|
||||||
(save-excursion (python-nav-end-of-statement) (setq offset (- (point) beg)))
|
(save-excursion (python-nav-end-of-statement) (setq offset (- (point) beg)))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(python-nav-forward-block)
|
(python-nav-forward-block)
|
||||||
(when (and (< (point) end) (< prev beg)) (setq children t)))
|
(if (< (point) end)
|
||||||
(when (and (< prev beg) (< beg end) (< end wrap-end))
|
(setq children t)
|
||||||
(setq acc (cons (funcall create beg end offset (and children (origami-python-parser-one-level-blocks beg end))) acc)))
|
(setq children nil)))
|
||||||
)
|
(when (and (not last-on-buffer) (<= end wrap-end))
|
||||||
|
(setq acc (cons (funcall create beg end offset (and children (origami-python-parser-one-level-blocks beg end))) acc)))))
|
||||||
(reverse acc)))
|
(reverse acc)))
|
||||||
(origami-python-parser-one-level-blocks (point-min) (point-max)))))
|
(origami-python-parser-one-level-blocks (point-min) (point-max)))))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user