Browse Source

New function to convert a table to a lisp structure.

Carsten Dominik 16 years ago
parent
commit
ea71ffc237
2 changed files with 22 additions and 0 deletions
  1. 2 0
      lisp/ChangeLog
  2. 20 0
      lisp/org-table.el

+ 2 - 0
lisp/ChangeLog

@@ -1,5 +1,7 @@
 2008-07-17  Carsten Dominik  <dominik@science.uva.nl>
 
+	* org-table.el (org-table-to-lisp): New function.
+
 	* org.el (org-narrow-to-subtree): Do not include the final newline
 	into the narrowed region.
 

+ 20 - 0
lisp/org-table.el

@@ -3552,6 +3552,26 @@ a radio table."
 	(delete-region beg (point))))
     (insert txt "\n")))
 
+(defun org-table-to-lisp (&optional txt)
+  "Convert the table at point to a Lisp structure.
+The structure will be a list.  Each item is either the symbol `hline'
+for a horizontal separator line, or a list of field values as strings.
+The table is taken from the parameter TXT, or from the buffer at point."
+  (unless txt
+    (unless (org-at-table-p)
+      (error "No table at point")))
+  (let* ((txt (or txt 
+		  (buffer-substring-no-properties (org-table-begin)
+						  (org-table-end))))
+	 (lines (org-split-string txt "[ \t]*\n[ \t]*")))
+
+    (mapcar
+     (lambda (x)
+       (if (string-match org-table-hline-regexp x)
+	   'hline
+	 (org-split-string (org-trim x) "\\s-*|\\s-*")))
+     lines)))
+
 (defun orgtbl-send-table (&optional maybe)
   "Send a tranformed version of this table to the receiver position.
 With argument MAYBE, fail quietly if no transformation is defined for