mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-08-21 12:48:36 +00:00
org-table: introduce an upper bound on `org-table-convert-region-max-lines'.
* lisp/org-table.el (org-table-convert-region-max-lines): New defcustom. (org-table-convert-region): Use it. This is useful primarily for babel results. If a large table-like object is returned by a code block, this function will become bogged down in trying to read it, and hang emacs (necessitating a C-g). This situation most commonly arises when a :results none header has been omitted. With the patch, the user will not experience a hang, but rather an error message.
This commit is contained in:
parent
7c86747881
commit
b8d790a076
|
@ -380,6 +380,16 @@ available parameters."
|
||||||
:group 'org-table-import-export
|
:group 'org-table-import-export
|
||||||
:type 'string)
|
:type 'string)
|
||||||
|
|
||||||
|
(defcustom org-table-convert-region-max-lines 999
|
||||||
|
"Max lines that `org-table-convert-region' will attempt to process.
|
||||||
|
|
||||||
|
The function can be slow on larger regions; this safety feature
|
||||||
|
prevents it from hanging emacs."
|
||||||
|
:group 'org-table-import-export
|
||||||
|
:type 'integer
|
||||||
|
:version "25.1"
|
||||||
|
:package-version '(Org . "8.3"))
|
||||||
|
|
||||||
(defconst org-table-auto-recalculate-regexp "^[ \t]*| *# *\\(|\\|$\\)"
|
(defconst org-table-auto-recalculate-regexp "^[ \t]*| *# *\\(|\\|$\\)"
|
||||||
"Detects a table line marked for automatic recalculation.")
|
"Detects a table line marked for automatic recalculation.")
|
||||||
(defconst org-table-recalculate-regexp "^[ \t]*| *[#*] *\\(|\\|$\\)"
|
(defconst org-table-recalculate-regexp "^[ \t]*| *[#*] *\\(|\\|$\\)"
|
||||||
|
@ -546,6 +556,9 @@ nil When nil, the command tries to be smart and figure out the
|
||||||
(let* ((beg (min beg0 end0))
|
(let* ((beg (min beg0 end0))
|
||||||
(end (max beg0 end0))
|
(end (max beg0 end0))
|
||||||
re)
|
re)
|
||||||
|
(if (> (count-lines beg end) org-table-convert-region-max-lines)
|
||||||
|
(user-error "Region is longer than `org-table-convert-region-max-lines' (%s) lines; not converting"
|
||||||
|
org-table-convert-region-max-lines)
|
||||||
(if (equal separator '(64))
|
(if (equal separator '(64))
|
||||||
(setq separator (read-regexp "Regexp for field separator")))
|
(setq separator (read-regexp "Regexp for field separator")))
|
||||||
(goto-char beg)
|
(goto-char beg)
|
||||||
|
@ -588,7 +601,7 @@ nil When nil, the command tries to be smart and figure out the
|
||||||
(while (re-search-forward re end t)
|
(while (re-search-forward re end t)
|
||||||
(replace-match "| " t t)))
|
(replace-match "| " t t)))
|
||||||
(goto-char beg)
|
(goto-char beg)
|
||||||
(org-table-align)))
|
(org-table-align))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun org-table-import (file arg)
|
(defun org-table-import (file arg)
|
||||||
|
|
Loading…
Reference in a new issue