Commits

Joe Bogner  committed 4e3cb34

fix parsing issue with dupes

  • Participants
  • Parent commits 343c86e

Comments (0)

Files changed (1)

 
 (setq Lines '("* ABC" "blah" "blah" "* foo"))
-(setq Lines '("* h1" "blah blah blah" "** h1-1" "*** h1-1-1" "** h1-2" "asdfasdf" "* h2"))
+(setq Lines '("* h1" "blah blah blah" "** h1-1" "* h3" "** h3-1" "asdfasdf" "* h2"))
 
 
 
 	(collectUntil Lines '((Line) (> (org-parse-level Line) 0))))
 
 (de org-parse-children (Lines Level)
-  (if Lines (org-parse Lines Level)))
+	(let Children (collectUntil Lines '((X) (= Level (org-parse-level X))))
+  	(if Children (org-parse Children Level))))
 
 (de org-next-sibling (Level Lines)
-	(seek '((Line) (org-parse-level Line) (or (= @ 0) (> @ Level))) Lines))
+	(seek '((Line) (= Level (org-parse-level (car Line)))) Lines))
 
 (de org-parse-heading (Line Level Lines)
   (when (> Level 0)
 		 (cons Heading NextPosition))))
 
 (de org-parse (Lines Until)
-	(let (Lst NIL)
+	(let Lst NIL
 		(while Lines 
 			(let (Line (car Lines)
 						Level (org-parse-level Line)
-						HeadingParse (if (and (>= Level Until) (> Level 0)) (org-parse-heading Line Level (cdr Lines)))
-						Heading (car HeadingParse)
-						NextPosition (cdr HeadingParse))
-			 (if (and (<= Level Until) (not (= 0 Level))) (setq Lines NIL))
-	     (if (and Lines HeadingParse)
+						IsBody (= 0 Level)
+						Sibling (<= Level Until)
+						ShouldParse (and (not Sibling) (not IsBody)) 
+						ParsedHeading (if ShouldParse (org-parse-heading Line Level (cdr Lines)))
+						Heading (car ParsedHeading)
+						NextPosition (cdr ParsedHeading))
+			 (if (and Sibling (not IsBody)) (setq Lines NIL))
+	     (if (and Lines ParsedHeading)
 				 (prog
 					 (setq Lst (cons Heading Lst))
 					 (setq Lines NextPosition))
 				 (setq Lines (cdr Lines)))))
        (reverse Lst)))
 
-(printsp (org-parse Lines -1))
-(bye)
+(printsp (org-parse Lines 0))
+
+