summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bastien.guerry@data.gouv.fr>2020-09-13 19:13:05 +0200
committerBastien Guerry <bastien.guerry@data.gouv.fr>2020-09-13 19:13:05 +0200
commit9c31cba002a1ba93053aebea1f778be87f61ba06 (patch)
tree409614e3eeb18bc60a10276b73ff3b21eb68e025
parentb01332c87ec3e031bfab474b801af6148dadb146 (diff)
downloadorg-mode-9c31cba002a1ba93053aebea1f778be87f61ba06.tar.gz
org-table.el: Throw an error when importing a non-csv/tsv/txt file
* lisp/org-table.el (org-table-import): Throw an error when interactively trying to import a non-csv/tsv/txt file. Reported-by: swedebugia <swedebugia@riseup.net> See https://orgmode.org/list/20200912135043.0354bac4@parabola/
-rw-r--r--lisp/org-table.el19
1 files changed, 11 insertions, 8 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 9270f23..ed6e203 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -921,19 +921,22 @@ nil When nil, the command tries to be smart and figure out the
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.
+- 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.
When non-nil, SEPARATOR specifies the field separator in the
lines. It can have the following values:
-(4) Use the comma as a field separator
-(16) Use a TAB as field separator
-(64) Prompt for a regular expression as field separator
-integer When a number, use that many spaces, or a TAB, as field separator
-regexp When a regular expression, use it to match the separator."
+- (4) Use the comma as a field separator.
+- (16) Use a TAB as field separator.
+- (64) Prompt for a regular expression as field separator.
+- integer When a number, use that many spaces, or a TAB, as field separator.
+- regexp When a regular expression, use it to match the separator."
(interactive "f\nP")
+ (when (and (called-interactively-p 'any)
+ (not (string-match-p "\.\\(?:[tc]sv\\|txt\\)$" file)))
+ (user-error "Cannot import such file"))
(unless (bolp) (insert "\n"))
(let ((beg (point))
(pm (point-max)))