This is a trick. It has minimal error checking.
The interface to use is the software interface:
(org-table-to-sexp <location-of-beginning-of-table> <location-of-end-of-table>)
In this case, he will return sexp to you.
If you want to use interactive use, you can call the following command to work on a table in a region . So, set the label at the beginning of the table, go to the end and enter:
Mx insert-org-table-to-sexp
This will insert the desired sexp immediately after the table in the current buffer.
Here is the code:
(defun org-table-to-sexp-parse-line () "Helper, returns the current line as a list of strings" (save-excursion (save-match-data (let ((result nil) (end-of-line (save-excursion (end-of-line) (point)))) (beginning-of-line) (while (re-search-forward "\\([^|]*\\)|" end-of-line t) (let ((match (mapconcat 'identity (split-string (match-string-no-properties 1)) " "))) (if (< 0 (length match)) ;; really want to strip spaces from front and back (push match result)))) (reverse result))))) (require 'cl) (defun org-table-to-sexp (be) "Parse an org-mode table to sexp" (save-excursion (save-match-data (goto-char b) (let ((headers (mapcar (lambda (str) (make-symbol (concat ":" (upcase str)))) (org-table-to-sexp-parse-line))) (sexp nil)) (forward-line 1) ;skip |
source share