Joe Bogner avatar Joe Bogner committed 9129299

add org-to-text method

Comments (0)

Files changed (1)

                   "CLOCKSUM", "CLOCKSUM_T", "BLOCKED", "ITEM", "FILE")))
+(de *Org-hook-parse-body NIL)
+(de *Org-hook-add-heading NIL)
 (de org-parse-level (Line)
  (- (length (split (chop Line) "*")) 1))
 (de org-parse-body (Lines)
-  (collectUntil Lines '((Line) (> (org-parse-level Line) 0))))
+  (collectUntil Lines '((Line) (> (org-parse-level (if *Org-hook-parse-body (*Org-hook-parse-body Line) Line)) 0))))
 (de org-parse-children (Lines Level)
   (let Children (collectUntil Lines '((X) (= Level (org-parse-level X))))
     (if Children (org-parse Children Level))))
+(de passoc (Key Lst) (cadr (seek '((X) (= Key (car X))) Lst)))
+(de org-flatten (Lst)
+   (make
+      (recur (Lst)
+         (for Header Lst
+            (link Header)
+            (recurse (passoc 'children Header))))))
+(de org-header-to-text (Header)
+   (let (Name (passoc 'name Header)
+         Level (passoc 'level Header)
+         Tags (passoc 'tags Header)
+         TagText (mapcar '((X) (if X (pack ":" X))) Tags))
+      (list (need Level "*") " " Name " " TagText)))
+(de org-to-text (Lst)
+   (make
+      (let (Flat (org-flatten Lst))
+         (for X Flat
+            (let (Body (passoc 'body X)
+                  Properties (passoc 'props X))
+               (link (pack (org-header-to-text X) "^J"))
+               (when Properties
+                  (link ":PROPERTIES:^J")
+                  (for (Prop Properties Prop (cddr Prop))
+                     (link ":" (car Prop) ":" " " (cadr Prop)  "^J"))
+                  (! link ":END:^J"))
+               (for Y Body (link Y "^J"))))))))
 (de org-next-sibling (Level Lines)
   (seek '((Line) (= Level (org-parse-level (car Line)))) Lines))
          Tags (cdr ParsedHeader)
          Heading (list 'level Level 'name Header 'tags Tags 'body Body 'props Properties 'children Children)
          NextPosition (org-next-sibling Level Lines))
-     (cons Heading NextPosition))))
+      (if *Org-hook-add-heading (*Org-hook-add-heading Heading))
+      (cons Heading NextPosition))))
 (de org-parse (Lines Until)
   (let Lst NIL
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
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.