org-table.el: Enhanced table parsing
* lisp/org-table.el (org-table-to-lisp): Refactored. * etc/ORG-NEWS: Document changes. `org-table-to-lisp' is significantly faster. It no longer uses regexps, nor clobbers the global regexp state.
This commit is contained in:
parent
af9100382c
commit
407a55c1c0
|
@ -1285,6 +1285,12 @@ For symmetry with =\S= and =\sect= for the section symbol, =\P= has
|
||||||
been added as an another form for the pilcrow symbol currently
|
been added as an another form for the pilcrow symbol currently
|
||||||
available as =\para=.
|
available as =\para=.
|
||||||
|
|
||||||
|
*** ~org-table-to-lisp~ no longer clobbers the regexp global state
|
||||||
|
|
||||||
|
It does no longer use regexps.
|
||||||
|
|
||||||
|
It is also faster. Large tables can be read quickly.
|
||||||
|
|
||||||
* Version 9.6
|
* Version 9.6
|
||||||
|
|
||||||
** Important announcements and breaking changes
|
** Important announcements and breaking changes
|
||||||
|
|
|
@ -5494,25 +5494,36 @@ 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."
|
||||||
(if txt
|
(if txt
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
|
(buffer-disable-undo)
|
||||||
(insert txt)
|
(insert txt)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(org-table-to-lisp))
|
(org-table-to-lisp))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char (org-table-begin))
|
(goto-char (org-table-begin))
|
||||||
(let ((table nil))
|
(let (table)
|
||||||
(while (re-search-forward "\\=[ \t]*|" nil t)
|
(while (progn (skip-chars-forward " \t")
|
||||||
(let ((row nil))
|
(eq (following-char) ?|))
|
||||||
(if (looking-at "-")
|
(forward-char)
|
||||||
(push 'hline table)
|
(push
|
||||||
(while (not (progn (skip-chars-forward " \t") (eolp)))
|
(if (eq (following-char) ?-)
|
||||||
(push (buffer-substring
|
'hline
|
||||||
(point)
|
(let (row)
|
||||||
(progn (re-search-forward "[ \t]*\\(|\\|$\\)")
|
(while (progn
|
||||||
(match-beginning 0)))
|
(skip-chars-forward " \t")
|
||||||
row))
|
(not (eolp)))
|
||||||
(push (nreverse row) table)))
|
(let ((q (point)))
|
||||||
|
(skip-chars-forward "^|\n")
|
||||||
|
(goto-char
|
||||||
|
(prog1
|
||||||
|
(let ((p (point)))
|
||||||
|
(unless (eolp) (setq p (1+ p)))
|
||||||
|
p)
|
||||||
|
(skip-chars-backward " \t" q)
|
||||||
|
(push (buffer-substring-no-properties q (point)) row)))))
|
||||||
|
(nreverse row)))
|
||||||
|
table)
|
||||||
(forward-line))
|
(forward-line))
|
||||||
(nreverse table)))))
|
(nreverse table)))))
|
||||||
|
|
||||||
(defun org-table-collapse-header (table &optional separator max-header-lines)
|
(defun org-table-collapse-header (table &optional separator max-header-lines)
|
||||||
"Collapse the lines before `hline' into a single header.
|
"Collapse the lines before `hline' into a single header.
|
||||||
|
|
Loading…
Reference in New Issue