Make parsers create consistent ranges

This commit is contained in:
Greg Sexton 2014-11-15 21:15:28 +00:00
parent e61e3670bc
commit 2e5d1d9126
3 changed files with 13 additions and 12 deletions

View File

@ -159,7 +159,7 @@ function. Best to use an example:
(defun my-amazing-parser (create)
(lambda (content)
(list (funcall create beginning-of-the-fold-node-point-position
end-of-the-fold-node-point-position
(list (funcall create beginning-of-the-fold-node-point-position ; inclusive
end-of-the-fold-node-point-position ; exclusive
offset ; this allows you to show some of the start of the folded text
child-nodes))))

View File

@ -50,7 +50,9 @@
(beginning-of-buffer)
(let (acc)
(while (re-search-forward regex nil t)
(setq acc (cons (cons (match-string 0) (point)) acc)))
(let ((match (match-string 0)))
(setq acc (cons (cons match (- (point) (length match)))
acc))))
(reverse acc))))
(defun origami-build-pair-tree (create open close positions)
@ -64,7 +66,8 @@
(new-pos (car res))
(children (cdr res)))
(setq positions (cdr new-pos))
(setq acc (cons (funcall create beg (cdar new-pos) 0 children) acc))
(setq acc (cons (funcall create beg (cdar new-pos) (length open) children)
acc))
(setq beg nil))
;; begin a new pair
(setq beg (cdar positions))
@ -72,7 +75,8 @@
((equal (caar positions) close)
(if beg
(progn ;close with no children
(setq acc (cons (funcall create beg (cdar positions) 0 nil) acc))
(setq acc (cons (funcall create beg (cdar positions) (length close) nil)
acc))
(setq positions (cdr positions))
(setq beg nil))
(setq should-continue nil)))))
@ -96,8 +100,8 @@
(search-forward-regexp regex nil t)
(setq offset (- (point) beg))
(end-of-defun)
(backward-char)
(setq end (point))
(backward-char) ;move point to one after the last paren
(setq end (1- (point))) ;don't include the last paren in the fold
(when (> offset 0)
(setq acc (cons (funcall create beg end offset nil) acc)))
(beginning-of-defun -1))

View File

@ -41,10 +41,7 @@
(defun origami-create-overlay (beg end offset buffer)
(when (> (- end beg) 0)
;; TODO: need to show the end so offset by 1. Maybe add an
;; end-offset to fold node? The opposite of this is used in
;; origami-fold-end.
(make-overlay (+ beg offset) (- end 1) buffer)))
(make-overlay (+ beg offset) end buffer)))
(defun origami-hide-node-overlay (node)
(-when-let (ov (origami-fold-data node))
@ -120,7 +117,7 @@
(when node
(if (origami-fold-is-root-node? node)
(aref node 1)
(+ (overlay-end (origami-fold-data node)) 1))))
(overlay-end (origami-fold-data node)))))
(defun origami-fold-offset (node) (when node (aref node 2)))