table: Rewrite `org-table-to-lisp'

* lisp/org-table.el (org-table-to-lisp): Rewrite function.

The new implementation can be more than 100 times faster.  This enhances
responsiveness of Babel or Gnuplot blocks handling very large tables.
This commit is contained in:
tbanelwebmin 2020-05-01 00:24:47 +02:00 committed by Nicolas Goaziou
parent a1ad6fe8fe
commit 20f2cd8416
1 changed files with 23 additions and 8 deletions

View File

@ -5466,14 +5466,29 @@ a radio table."
The structure will be a list. Each item is either the symbol `hline' 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. 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." The table is taken from the parameter TXT, or from the buffer at point."
(unless (or txt (org-at-table-p)) (user-error "No table at point")) (if txt
(let ((txt (or txt (with-temp-buffer
(buffer-substring-no-properties (org-table-begin) (insert txt)
(org-table-end))))) (goto-char (point-min))
(mapcar (lambda (x) (org-table-to-lisp))
(if (string-match org-table-hline-regexp x) 'hline (unless (org-at-table-p) (user-error "No table at point"))
(org-split-string (org-trim x) "\\s-*|\\s-*"))) (save-excursion
(org-split-string txt "[ \t]*\n[ \t]*")))) (goto-char (org-table-begin))
(let ((table nil))
(while (search-forward "|" (line-end-position) t)
(let ((row nil))
(if (looking-at "-")
(push 'hline table)
(while (not (progn (skip-chars-forward " \t") (eolp)))
(push
(buffer-substring-no-properties
(point)
(progn (re-search-forward "[ \t]*\\(|\\|$\\)")
(match-beginning 0)))
row))
(push (nreverse row) table)))
(forward-line))
(nreverse table)))))
(defun orgtbl-send-table (&optional maybe) (defun orgtbl-send-table (&optional maybe)
"Send a transformed version of table at point to the receiver position. "Send a transformed version of table at point to the receiver position.