branch: externals/org commit 89c68683f9dae12c65680b0451d9bc74abac178a Author: Ihor Radchenko <yanta...@posteo.net> Commit: Ihor Radchenko <yanta...@posteo.net>
org-babel-import-elisp-from-file: Fix detecting delimiter in single-line data * lisp/org-table.el (org-table-convert-region): When detecting delimiter in, do not unconditionally fall back to CSV parser. Only do it when the line contains commas and use a simple single tab/space split otherwise. Add new special delimeter-detection strategy when SEPARATOR is 'babel-auto - convert to | full line | table instead of falling back to tab/space split when the region contains a single line. * lisp/ob-core.el (org-babel-import-elisp-from-file): Force special strategy when converting data to lisp. The commit fixes the problem with first `re-search-forward' in the `cond' moving point to end of the region, making the third `cond' branch never match. A special strategy specific to babel is necessary to preserve the historic behavior with lines like : single line with spaces being converted to a single table cell : | single line with space | Reported-by: Matt <m...@excalamus.com> Link: https://orgmode.org/list/18f24d87b62.d55e94e24743657.3252620114689708...@excalamus.com --- lisp/ob-core.el | 4 +++- lisp/org-table.el | 14 ++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 8dfc07a4e2..73fb70c26a 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -3389,7 +3389,9 @@ SEPARATOR is passed to `org-table-convert-region', which see." ;; If the file was empty, don't bother trying to ;; convert the table. (when (> pmax 1) - (org-table-convert-region (point-min) pmax separator) + (org-table-convert-region + (point-min) pmax + (or separator 'babel-auto)) (delq nil (mapcar (lambda (row) (and (not (eq row 'hline)) diff --git a/lisp/org-table.el b/lisp/org-table.el index b5387e418e..0c2dc27ed6 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -892,7 +892,10 @@ nil When nil, the command tries to be smart and figure out the separator in the following way: - when each line contains a TAB, assume TAB-separated material - when each line contains a comma, assume CSV material - - else, assume one or more SPACE characters as separator." + - else, assume one or more SPACE characters as separator. +`babel-auto' + Use the same rules as nil, but do not try any separator when + the region contains a single line and has no commas or tabs." (interactive "r\nP") (let* ((beg (min beg0 end0)) (end (max beg0 end0)) @@ -909,12 +912,15 @@ nil When nil, the command tries to be smart and figure out the (if (bolp) (backward-char 1) (end-of-line 1)) (setq end (point-marker)) ;; Get the right field separator - (unless separator + (when (or (not separator) (eq separator 'babel-auto)) (goto-char beg) (setq separator (cond - ((not (re-search-forward "^[^\n\t]+$" end t)) '(16)) - ((not (re-search-forward "^[^\n,]+$" end t)) '(4)) + ((not (save-excursion (re-search-forward "^[^\n\t]+$" end t))) '(16)) + ((not (save-excursion (re-search-forward "^[^\n,]+$" end t))) '(4)) + ((and (eq separator 'babel-auto) + (= 1 (count-lines beg end))) + (rx unmatchable)) (t 1)))) (goto-char beg) (if (equal separator '(4))