Make parsers create consistent ranges
This commit is contained in:
		@@ -159,7 +159,7 @@ function. Best to use an example:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
     (defun my-amazing-parser (create)
 | 
					     (defun my-amazing-parser (create)
 | 
				
			||||||
       (lambda (content)
 | 
					       (lambda (content)
 | 
				
			||||||
         (list (funcall create beginning-of-the-fold-node-point-position
 | 
					         (list (funcall create beginning-of-the-fold-node-point-position ; inclusive
 | 
				
			||||||
                               end-of-the-fold-node-point-position
 | 
					                               end-of-the-fold-node-point-position ; exclusive
 | 
				
			||||||
                               offset  ; this allows you to show some of the start of the folded text
 | 
					                               offset  ; this allows you to show some of the start of the folded text
 | 
				
			||||||
                               child-nodes))))
 | 
					                               child-nodes))))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,7 +50,9 @@
 | 
				
			|||||||
    (beginning-of-buffer)
 | 
					    (beginning-of-buffer)
 | 
				
			||||||
    (let (acc)
 | 
					    (let (acc)
 | 
				
			||||||
      (while (re-search-forward regex nil t)
 | 
					      (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))))
 | 
					      (reverse acc))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun origami-build-pair-tree (create open close positions)
 | 
					(defun origami-build-pair-tree (create open close positions)
 | 
				
			||||||
@@ -64,7 +66,8 @@
 | 
				
			|||||||
                                           (new-pos (car res))
 | 
					                                           (new-pos (car res))
 | 
				
			||||||
                                           (children (cdr res)))
 | 
					                                           (children (cdr res)))
 | 
				
			||||||
                                      (setq positions (cdr new-pos))
 | 
					                                      (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))
 | 
					                                      (setq beg nil))
 | 
				
			||||||
                                  ;; begin a new pair
 | 
					                                  ;; begin a new pair
 | 
				
			||||||
                                  (setq beg (cdar positions))
 | 
					                                  (setq beg (cdar positions))
 | 
				
			||||||
@@ -72,7 +75,8 @@
 | 
				
			|||||||
                               ((equal (caar positions) close)
 | 
					                               ((equal (caar positions) close)
 | 
				
			||||||
                                (if beg
 | 
					                                (if beg
 | 
				
			||||||
                                    (progn                 ;close with no children
 | 
					                                    (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 positions (cdr positions))
 | 
				
			||||||
                                      (setq beg nil))
 | 
					                                      (setq beg nil))
 | 
				
			||||||
                                  (setq should-continue nil)))))
 | 
					                                  (setq should-continue nil)))))
 | 
				
			||||||
@@ -96,8 +100,8 @@
 | 
				
			|||||||
          (search-forward-regexp regex nil t)
 | 
					          (search-forward-regexp regex nil t)
 | 
				
			||||||
          (setq offset (- (point) beg))
 | 
					          (setq offset (- (point) beg))
 | 
				
			||||||
          (end-of-defun)
 | 
					          (end-of-defun)
 | 
				
			||||||
          (backward-char)
 | 
					          (backward-char)               ;move point to one after the last paren
 | 
				
			||||||
          (setq end (point))
 | 
					          (setq end (1- (point)))       ;don't include the last paren in the fold
 | 
				
			||||||
          (when (> offset 0)
 | 
					          (when (> offset 0)
 | 
				
			||||||
            (setq acc (cons (funcall create beg end offset nil) acc)))
 | 
					            (setq acc (cons (funcall create beg end offset nil) acc)))
 | 
				
			||||||
          (beginning-of-defun -1))
 | 
					          (beginning-of-defun -1))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,10 +41,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
(defun origami-create-overlay (beg end offset buffer)
 | 
					(defun origami-create-overlay (beg end offset buffer)
 | 
				
			||||||
  (when (> (- end beg) 0)
 | 
					  (when (> (- end beg) 0)
 | 
				
			||||||
    ;; TODO: need to show the end so offset by 1. Maybe add an
 | 
					    (make-overlay (+ beg offset) end buffer)))
 | 
				
			||||||
    ;; end-offset to fold node? The opposite of this is used in
 | 
					 | 
				
			||||||
    ;; origami-fold-end.
 | 
					 | 
				
			||||||
    (make-overlay (+ beg offset) (- end 1) buffer)))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
(defun origami-hide-node-overlay (node)
 | 
					(defun origami-hide-node-overlay (node)
 | 
				
			||||||
  (-when-let (ov (origami-fold-data node))
 | 
					  (-when-let (ov (origami-fold-data node))
 | 
				
			||||||
@@ -120,7 +117,7 @@
 | 
				
			|||||||
  (when node
 | 
					  (when node
 | 
				
			||||||
    (if (origami-fold-is-root-node? node)
 | 
					    (if (origami-fold-is-root-node? node)
 | 
				
			||||||
        (aref node 1)
 | 
					        (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)))
 | 
					(defun origami-fold-offset (node) (when node (aref node 2)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user