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'
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 (or txt (org-at-table-p)) (user-error "No table at point"))
(let ((txt (or txt
(buffer-substring-no-properties (org-table-begin)
(org-table-end)))))
(mapcar (lambda (x)
(if (string-match org-table-hline-regexp x) 'hline
(org-split-string (org-trim x) "\\s-*|\\s-*")))
(org-split-string txt "[ \t]*\n[ \t]*"))))
(if txt
(with-temp-buffer
(insert txt)
(goto-char (point-min))
(org-table-to-lisp))
(unless (org-at-table-p) (user-error "No table at point"))
(save-excursion
(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)
"Send a transformed version of table at point to the receiver position.