diff --git a/README.md b/README.md index 88672d4..6aec846 100644 --- a/README.md +++ b/README.md @@ -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)))) diff --git a/origami-parsers.el b/origami-parsers.el index 5ca6cff..325a23e 100644 --- a/origami-parsers.el +++ b/origami-parsers.el @@ -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)) diff --git a/origami.el b/origami.el index a30db4b..1c2ce76 100644 --- a/origami.el +++ b/origami.el @@ -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)))