pico-org / orge.l

(setq Lines '("* ABC" "blah" "blah" "* foo"))
(setq Lines '("* h1" "blah blah blah" "** h1-1" "*** h1-1-1" "** h1-2" "asdfasdf" "* h2"))

(de collectUntil (Lst Func)
	(let (Ret NIL) (find '((X) (if (Func X) T (push 'Ret X) NIL)) Lst) (reverse Ret)))

(de org-parse-level (Line)
 (- (length (split (chop Line) "*")) 1))

(de org-parse-body (Lines)
	(collectUntil Lines '((Line) (> (org-parse-level Line) 0))))

(de org-parse-children (Lines Level)
  (if Lines (org-parse Lines Level)))

(de org-next-sibling (Level Lines)
	(seek '((Line) (org-parse-level Line) (or (= @ 0) (> @ Level))) Lines))

(de org-parse-heading (Line Level Lines)
  (when (> Level 0)
	(Body (org-parse-body Lines)
	 Children (org-parse-children Lines Level)
	 Heading (list 'name Line 'body Body 'children Children)
	 NextPosition (org-next-sibling Level Lines))
      (cons Heading NextPosition))))

(de org-parse (Lines Until)
  (let (Lst '())
       (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 HeadingParse
		   (setq Lst (cons Heading Lst))
		   (setq Lines NextPosition))
	       (setq Lines (cdr Lines))))))
       (reverse Lst)))

# (trace 'org-parse)
# (trace 'org-parse-children)
# (trace 'org-next-sibling)
# (trace 'org-parse-heading)

(printsp (org-parse Lines -1))

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.