org-table.el: Fix usage of user-error

* lisp/org-table.el (org-table-convert-region): Don't use `if' because
  Elisp has no concept of continuable errors.
This commit is contained in:
Utkarsh Singh 2021-05-23 13:48:33 +05:30 committed by Bastien
parent bf1c4c7575
commit e626185081
1 changed files with 44 additions and 44 deletions

View File

@ -861,52 +861,52 @@ nil When nil, the command tries to be smart and figure out the
(let* ((beg (min beg0 end0))
(end (max beg0 end0))
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)
(when (equal separator '(64))
(setq separator (read-regexp "Regexp for field separator")))
(when (> (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))
(when (equal separator '(64))
(setq separator (read-regexp "Regexp for field separator")))
(goto-char beg)
(beginning-of-line 1)
(setq beg (point-marker))
(goto-char end)
(if (bolp) (backward-char 1) (end-of-line 1))
(setq end (point-marker))
;; Get the right field separator
(unless separator
(goto-char beg)
(beginning-of-line 1)
(setq beg (point-marker))
(goto-char end)
(if (bolp) (backward-char 1) (end-of-line 1))
(setq end (point-marker))
;; Get the right field separator
(unless separator
(goto-char beg)
(setq separator
(cond
((not (re-search-forward "^[^\n\t]+$" end t)) '(16))
((not (re-search-forward "^[^\n,]+$" end t)) '(4))
(t 1))))
(goto-char beg)
(if (equal separator '(4))
(while (< (point) end)
;; parse the csv stuff
(setq separator
(cond
((looking-at "^") (insert "| "))
((looking-at "[ \t]*$") (replace-match " |") (beginning-of-line 2))
((looking-at "[ \t]*\"\\([^\"\n]*\\)\"")
(replace-match "\\1")
(if (looking-at "\"") (insert "\"")))
((looking-at "[^,\n]+") (goto-char (match-end 0)))
((looking-at "[ \t]*,") (replace-match " | "))
(t (beginning-of-line 2))))
(setq re (cond
((equal separator '(4)) "^\\|\"?[ \t]*,[ \t]*\"?")
((equal separator '(16)) "^\\|\t")
((integerp separator)
(if (< separator 1)
(user-error "Number of spaces in separator must be >= 1")
(format "^ *\\| *\t *\\| \\{%d,\\}" separator)))
((stringp separator)
(format "^ *\\|%s" separator))
(t (error "This should not happen"))))
(while (re-search-forward re end t)
(replace-match "| " t t)))
(goto-char beg)
(org-table-align))))
((not (re-search-forward "^[^\n\t]+$" end t)) '(16))
((not (re-search-forward "^[^\n,]+$" end t)) '(4))
(t 1))))
(goto-char beg)
(if (equal separator '(4))
(while (< (point) end)
;; parse the csv stuff
(cond
((looking-at "^") (insert "| "))
((looking-at "[ \t]*$") (replace-match " |") (beginning-of-line 2))
((looking-at "[ \t]*\"\\([^\"\n]*\\)\"")
(replace-match "\\1")
(if (looking-at "\"") (insert "\"")))
((looking-at "[^,\n]+") (goto-char (match-end 0)))
((looking-at "[ \t]*,") (replace-match " | "))
(t (beginning-of-line 2))))
(setq re (cond
((equal separator '(4)) "^\\|\"?[ \t]*,[ \t]*\"?")
((equal separator '(16)) "^\\|\t")
((integerp separator)
(if (< separator 1)
(user-error "Number of spaces in separator must be >= 1")
(format "^ *\\| *\t *\\| \\{%d,\\}" separator)))
((stringp separator)
(format "^ *\\|%s" separator))
(t (error "This should not happen"))))
(while (re-search-forward re end t)
(replace-match "| " t t)))
(goto-char beg)
(org-table-align)))
;;;###autoload
(defun org-table-import (file separator)