org-table.el: Use user-error' instead of error' for user errors

* org-table.el (org-table-convert-region, org-table-export)
(org-table-align, org-table-beginning-of-field)
(org-table-copy-down, org-table-check-inside-data-field)
(org-table-insert-column, org-table-find-dataline)
(org-table-delete-column, org-table-move-column)
(org-table-insert-row, org-table-insert-hline)
(org-table-kill-row, org-table-paste-rectangle)
(org-table-wrap-region, org-table-sum, org-table-get-formula)
(org-table-get-formula, org-table-get-stored-formulas)
(org-table-fix-formulas, org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks, org-table-eval-formula)
(org-table-get-range, org-table-get-descriptor-line)
(org-table-find-row-type, org-table-recalculate)
(org-table-iterate, org-table-iterate-buffer-tables)
(org-table-formula-handle-first/last-rc)
(org-table-edit-formulas, org-table-fedit-shift-reference)
(org-rematch-and-replace, org-table-shift-refpart)
(org-table-fedit-finish, org-table-fedit-lisp-indent)
(org-table-show-reference, org-table-show-reference)
(org-table-show-reference, org-table-show-reference)
(org-table-force-dataline, orgtbl-error, orgtbl-export)
(orgtbl-send-replace-tbl, org-table-to-lisp)
(orgtbl-send-table, orgtbl-send-table, orgtbl-send-table)
(orgtbl-toggle-comment, orgtbl-insert-radio-table)
(orgtbl-to-unicode, org-table-get-remote-range)
(org-table-get-remote-range, org-table-copy-dow)
(org-table-check-inside-data-field, org-table-insert-colum)
(org-table-find-dataline, org-table-delete-colum)
(org-table-move-column, org-table-insert-ro)
(org-table-insert-hline, org-table-kill-ro)
(org-table-paste-rectangle, org-table-wrap-regio)
(org-table-sum, org-table-get-formul)
(org-table-get-stored-formulas, org-table-fix-formula)
(org-table-maybe-eval-formul, org-table-rotate-recalc-marks)
(org-table-eval-formul, org-table-get-range)
(org-table-get-descriptor-lin, org-table-find-row-type)
(org-table-recalculat, org-table-iterate)
(org-table-iterate-buffer-table)
(org-table-formula-handle-first/last-r)
(org-table-edit-formulas, org-table-fedit-shift-referenc)
(org-rematch-and-replace, org-table-shift-refpar)
(org-table-fedit-finish, org-table-fedit-lisp-inden)
(org-table-show-reference, org-table-force-datalin)
(orgtbl-error, orgtbl-export, orgtbl-send-replace-tb)
(org-table-to-lisp, orgtbl-send-tabl, orgtbl-toggle-comment)
(orgtbl-insert-radio-tabl, orgtbl-to-unicode)
(org-table-get-remote-range): Use `user-error' instead of
`error' for user errors.
This commit is contained in:
Bastien Guerry 2013-03-02 15:40:09 +01:00
parent 2d2913ce4f
commit bd89d6a02f

View file

@ -601,7 +601,7 @@ nil When nil, the command tries to be smart and figure out the
((equal separator '(16)) "^\\|\t") ((equal separator '(16)) "^\\|\t")
((integerp separator) ((integerp separator)
(if (< separator 1) (if (< separator 1)
(error "Number of spaces in separator must be >= 1") (user-error "Number of spaces in separator must be >= 1")
(format "^ *\\| *\t *\\| \\{%d,\\}" separator))) (format "^ *\\| *\t *\\| \\{%d,\\}" separator)))
(t (error "This should not happen")))) (t (error "This should not happen"))))
(while (re-search-forward re end t) (while (re-search-forward re end t)
@ -641,7 +641,7 @@ whether it is set locally or up in the hierarchy, then on the
extension of the given file name, and finally on the variable extension of the given file name, and finally on the variable
`org-table-export-default-format'." `org-table-export-default-format'."
(interactive) (interactive)
(unless (org-at-table-p) (error "No table at point")) (unless (org-at-table-p) (user-error "No table at point"))
(org-table-align) ;; make sure we have everything we need (org-table-align) ;; make sure we have everything we need
(let* ((beg (org-table-begin)) (let* ((beg (org-table-begin))
(end (org-table-end)) (end (org-table-end))
@ -658,13 +658,13 @@ extension of the given file name, and finally on the variable
(setq file (read-file-name "Export table to: ")) (setq file (read-file-name "Export table to: "))
(unless (or (not (file-exists-p file)) (unless (or (not (file-exists-p file))
(y-or-n-p (format "Overwrite file %s? " file))) (y-or-n-p (format "Overwrite file %s? " file)))
(error "Abort"))) (user-error "File not written")))
(if (file-directory-p file) (if (file-directory-p file)
(error "This is a directory path, not a file")) (user-error "This is a directory path, not a file"))
(if (and (buffer-file-name) (if (and (buffer-file-name)
(equal (file-truename file) (equal (file-truename file)
(file-truename (buffer-file-name)))) (file-truename (buffer-file-name))))
(error "Please specify a file name that is different from current")) (user-error "Please specify a file name that is different from current"))
(setq fileext (concat (file-name-extension file) "$")) (setq fileext (concat (file-name-extension file) "$"))
(unless format (unless format
(setq deffmt-readable (setq deffmt-readable
@ -701,7 +701,7 @@ extension of the given file name, and finally on the variable
skipcols i0))) skipcols i0)))
(unless (fboundp transform) (unless (fboundp transform)
(error "No such transformation function %s" transform)) (user-error "No such transformation function %s" transform))
(setq txt (funcall transform table params)) (setq txt (funcall transform table params))
(with-current-buffer (find-file-noselect file) (with-current-buffer (find-file-noselect file)
@ -712,7 +712,7 @@ extension of the given file name, and finally on the variable
(save-buffer)) (save-buffer))
(kill-buffer buf) (kill-buffer buf)
(message "Export done.")) (message "Export done."))
(error "TABLE_EXPORT_FORMAT invalid")))) (user-error "TABLE_EXPORT_FORMAT invalid"))))
(defvar org-table-aligned-begin-marker (make-marker) (defvar org-table-aligned-begin-marker (make-marker)
"Marker at the beginning of the table last aligned. "Marker at the beginning of the table last aligned.
@ -820,7 +820,7 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
(error (error
(kill-region beg end) (kill-region beg end)
(org-table-create org-table-default-size) (org-table-create org-table-default-size)
(error "Empty table - created default table"))) (user-error "Empty table - created default table")))
;; A list of empty strings to fill any short rows on output ;; A list of empty strings to fill any short rows on output
(setq emptystrings (make-list maxfields "")) (setq emptystrings (make-list maxfields ""))
;; Check for special formatting. ;; Check for special formatting.
@ -847,7 +847,7 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
(concat "Clipped table field, use C-c ` to edit. Full value is:\n" (org-no-properties (copy-sequence xx)))) (concat "Clipped table field, use C-c ` to edit. Full value is:\n" (org-no-properties (copy-sequence xx))))
(setq f1 (min fmax (or (string-match org-bracket-link-regexp xx) fmax))) (setq f1 (min fmax (or (string-match org-bracket-link-regexp xx) fmax)))
(unless (> f1 1) (unless (> f1 1)
(error "Cannot narrow field starting with wide link \"%s\"" (user-error "Cannot narrow field starting with wide link \"%s\""
(match-string 0 xx))) (match-string 0 xx)))
(add-text-properties f1 (length xx) (list 'org-cwidth t) xx) (add-text-properties f1 (length xx) (list 'org-cwidth t) xx)
(add-text-properties (- f1 2) f1 (add-text-properties (- f1 2) f1
@ -1055,7 +1055,7 @@ With numeric argument N, move N-1 fields forward first."
(setq n (1- n)) (setq n (1- n))
(org-table-previous-field)) (org-table-previous-field))
(if (not (re-search-backward "|" (point-at-bol 0) t)) (if (not (re-search-backward "|" (point-at-bol 0) t))
(error "No more table fields before the current") (user-error "No more table fields before the current")
(goto-char (match-end 0)) (goto-char (match-end 0))
(and (looking-at " ") (forward-char 1))) (and (looking-at " ") (forward-char 1)))
(if (>= (point) pos) (org-table-beginning-of-field 2)))) (if (>= (point) pos) (org-table-beginning-of-field 2))))
@ -1152,7 +1152,7 @@ copying. In the case of a timestamp, increment by one day."
(org-table-maybe-recalculate-line)) (org-table-maybe-recalculate-line))
(org-table-align) (org-table-align)
(org-move-to-column col)) (org-move-to-column col))
(error "No non-empty field found")))) (user-error "No non-empty field found"))))
(defun org-table-check-inside-data-field (&optional noerror) (defun org-table-check-inside-data-field (&optional noerror)
"Is point inside a table data field? "Is point inside a table data field?
@ -1164,7 +1164,7 @@ This actually throws an error, so it aborts the current command."
(looking-at "[ \t]*$")) (looking-at "[ \t]*$"))
(if noerror (if noerror
nil nil
(error "Not in table data field")) (user-error "Not in table data field"))
t)) t))
(defvar org-table-clip nil (defvar org-table-clip nil
@ -1347,7 +1347,7 @@ However, when FORCE is non-nil, create new columns if necessary."
"Insert a new column into the table." "Insert a new column into the table."
(interactive) (interactive)
(if (not (org-at-table-p)) (if (not (org-at-table-p))
(error "Not at a table")) (user-error "Not at a table"))
(org-table-find-dataline) (org-table-find-dataline)
(let* ((col (max 1 (org-table-current-column))) (let* ((col (max 1 (org-table-current-column)))
(beg (org-table-begin)) (beg (org-table-begin))
@ -1387,7 +1387,7 @@ However, when FORCE is non-nil, create new columns if necessary."
(if (and (org-at-table-p) (if (and (org-at-table-p)
(not (org-at-table-hline-p))) (not (org-at-table-hline-p)))
t t
(error (user-error
"Please position cursor in a data line for column operations"))))) "Please position cursor in a data line for column operations")))))
(defun org-table-line-to-dline (line &optional above) (defun org-table-line-to-dline (line &optional above)
@ -1417,7 +1417,7 @@ first dline below it is used. When ABOVE is non-nil, the one above is used."
"Delete a column from the table." "Delete a column from the table."
(interactive) (interactive)
(if (not (org-at-table-p)) (if (not (org-at-table-p))
(error "Not at a table")) (user-error "Not at a table"))
(org-table-find-dataline) (org-table-find-dataline)
(org-table-check-inside-data-field) (org-table-check-inside-data-field)
(let* ((col (org-table-current-column)) (let* ((col (org-table-current-column))
@ -1461,7 +1461,7 @@ first dline below it is used. When ABOVE is non-nil, the one above is used."
"Move the current column to the right. With arg LEFT, move to the left." "Move the current column to the right. With arg LEFT, move to the left."
(interactive "P") (interactive "P")
(if (not (org-at-table-p)) (if (not (org-at-table-p))
(error "Not at a table")) (user-error "Not at a table"))
(org-table-find-dataline) (org-table-find-dataline)
(org-table-check-inside-data-field) (org-table-check-inside-data-field)
(let* ((col (org-table-current-column)) (let* ((col (org-table-current-column))
@ -1547,7 +1547,7 @@ first dline below it is used. When ABOVE is non-nil, the one above is used."
With prefix ARG, insert below the current line." With prefix ARG, insert below the current line."
(interactive "P") (interactive "P")
(if (not (org-at-table-p)) (if (not (org-at-table-p))
(error "Not at a table")) (user-error "Not at a table"))
(let* ((line (buffer-substring (point-at-bol) (point-at-eol))) (let* ((line (buffer-substring (point-at-bol) (point-at-eol)))
(new (org-table-clean-line line))) (new (org-table-clean-line line)))
;; Fix the first field if necessary ;; Fix the first field if necessary
@ -1569,7 +1569,7 @@ With prefix ARG, insert below the current line."
With prefix ABOVE, insert above the current line." With prefix ABOVE, insert above the current line."
(interactive "P") (interactive "P")
(if (not (org-at-table-p)) (if (not (org-at-table-p))
(error "Not at a table")) (user-error "Not at a table"))
(when (eobp) (insert "\n") (backward-char 1)) (when (eobp) (insert "\n") (backward-char 1))
(if (not (string-match "|[ \t]*$" (org-current-line-string))) (if (not (string-match "|[ \t]*$" (org-current-line-string)))
(org-table-align)) (org-table-align))
@ -1619,7 +1619,7 @@ In particular, this does handle wide and invisible characters."
"Delete the current row or horizontal line from the table." "Delete the current row or horizontal line from the table."
(interactive) (interactive)
(if (not (org-at-table-p)) (if (not (org-at-table-p))
(error "Not at a table")) (user-error "Not at a table"))
(let ((col (current-column)) (let ((col (current-column))
(dline (org-table-current-dline))) (dline (org-table-current-dline)))
(kill-region (point-at-bol) (min (1+ (point-at-eol)) (point-max))) (kill-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
@ -1771,7 +1771,7 @@ the table is enlarged as needed. The process ignores horizontal separator
lines." lines."
(interactive) (interactive)
(unless (and org-table-clip (listp org-table-clip)) (unless (and org-table-clip (listp org-table-clip))
(error "First cut/copy a region to paste!")) (user-error "First cut/copy a region to paste!"))
(org-table-check-inside-data-field) (org-table-check-inside-data-field)
(let* ((clip org-table-clip) (let* ((clip org-table-clip)
(line (org-current-line)) (line (org-current-line))
@ -1900,7 +1900,7 @@ blank, and the content is appended to the field above."
nlines) nlines)
(org-table-cut-region (region-beginning) (region-end)) (org-table-cut-region (region-beginning) (region-end))
(if (> (length (car org-table-clip)) 1) (if (> (length (car org-table-clip)) 1)
(error "Region must be limited to single column")) (user-error "Region must be limited to single column"))
(setq nlines (if arg (setq nlines (if arg
(if (< arg 1) (if (< arg 1)
(+ (length org-table-clip) arg) (+ (length org-table-clip) arg)
@ -2069,12 +2069,12 @@ If NLAST is a number, only the NLAST fields will actually be summed."
(setq col (org-table-current-column)) (setq col (org-table-current-column))
(goto-char (org-table-begin)) (goto-char (org-table-begin))
(unless (re-search-forward "^[ \t]*|[^-]" nil t) (unless (re-search-forward "^[ \t]*|[^-]" nil t)
(error "No table data")) (user-error "No table data"))
(org-table-goto-column col) (org-table-goto-column col)
(setq beg (point)) (setq beg (point))
(goto-char (org-table-end)) (goto-char (org-table-end))
(unless (re-search-backward "^[ \t]*|[^-]" nil t) (unless (re-search-backward "^[ \t]*|[^-]" nil t)
(error "No table data")) (user-error "No table data"))
(org-table-goto-column col) (org-table-goto-column col)
(setq end (point)))) (setq end (point))))
(let* ((items (apply 'append (org-table-copy-region beg end))) (let* ((items (apply 'append (org-table-copy-region beg end)))
@ -2159,7 +2159,7 @@ When NAMED is non-nil, look for a named equation."
(int-to-string (org-table-current-column)))) (int-to-string (org-table-current-column))))
(dummy (and (or nameass refass) (not named) (dummy (and (or nameass refass) (not named)
(not (y-or-n-p "Replace existing field formula with column formula? " )) (not (y-or-n-p "Replace existing field formula with column formula? " ))
(error "Abort"))) (message "Formula not replaced")))
(name (or name ref)) (name (or name ref))
(org-table-may-need-update nil) (org-table-may-need-update nil)
(stored (cdr (assoc scol stored-list))) (stored (cdr (assoc scol stored-list)))
@ -2183,7 +2183,7 @@ When NAMED is non-nil, look for a named equation."
;; remove formula ;; remove formula
(setq stored-list (delq (assoc scol stored-list) stored-list)) (setq stored-list (delq (assoc scol stored-list) stored-list))
(org-table-store-formulas stored-list) (org-table-store-formulas stored-list)
(error "Formula removed")) (user-error "Formula removed"))
(if (string-match "^ *=?" eq) (setq eq (replace-match "" t t eq))) (if (string-match "^ *=?" eq) (setq eq (replace-match "" t t eq)))
(if (string-match " *$" eq) (setq eq (replace-match "" t t eq))) (if (string-match " *$" eq) (setq eq (replace-match "" t t eq)))
(if (and name (not named)) (if (and name (not named))
@ -2268,7 +2268,7 @@ When NAMED is non-nil, look for a named equation."
(message "Double definition `$%s=' in TBLFM line, please fix by hand" scol) (message "Double definition `$%s=' in TBLFM line, please fix by hand" scol)
(ding) (ding)
(sit-for 2)) (sit-for 2))
(error "Double definition `$%s=' in TBLFM line, please fix by hand" scol)) (user-error "Double definition `$%s=' in TBLFM line, please fix by hand" scol))
(push scol seen)))))) (push scol seen))))))
(nreverse eq-alist))) (nreverse eq-alist)))
@ -2292,7 +2292,7 @@ For all numbers larger than LIMIT, shift them by DELTA."
(while (re-search-forward re2 (point-at-eol) t) (while (re-search-forward re2 (point-at-eol) t)
(unless (save-match-data (org-in-regexp "remote([^)]+?)")) (unless (save-match-data (org-in-regexp "remote([^)]+?)"))
(if (equal (char-before (match-beginning 0)) ?.) (if (equal (char-before (match-beginning 0)) ?.)
(error "Change makes TBLFM term %s invalid, use undo to recover" (user-error "Change makes TBLFM term %s invalid, use undo to recover"
(match-string 0)) (match-string 0))
(replace-match ""))))) (replace-match "")))))
(while (re-search-forward re (point-at-eol) t) (while (re-search-forward re (point-at-eol) t)
@ -2399,7 +2399,7 @@ If yes, store the formula and apply it."
(equal (substring eq 0 (min 2 (length eq))) "'(")) (equal (substring eq 0 (min 2 (length eq))) "'("))
(org-table-eval-formula (if named '(4) nil) (org-table-eval-formula (if named '(4) nil)
(org-table-formula-from-user eq)) (org-table-formula-from-user eq))
(error "Calc does not seem to be installed, and is needed to evaluate the formula")))))) (user-error "Calc does not seem to be installed, and is needed to evaluate the formula"))))))
(defvar org-recalc-commands nil (defvar org-recalc-commands nil
"List of commands triggering the recalculation of a line. "List of commands triggering the recalculation of a line.
@ -2424,7 +2424,7 @@ after prompting for the marking character.
After each change, a message will be displayed indicating the meaning After each change, a message will be displayed indicating the meaning
of the new mark." of the new mark."
(interactive) (interactive)
(unless (org-at-table-p) (error "Not at a table")) (unless (org-at-table-p) (user-error "Not at a table"))
(let* ((marks (append (mapcar 'car org-recalc-marks) '(" "))) (let* ((marks (append (mapcar 'car org-recalc-marks) '(" ")))
(beg (org-table-begin)) (beg (org-table-begin))
(end (org-table-end)) (end (org-table-end))
@ -2443,13 +2443,13 @@ of the new mark."
(setq newchar (char-to-string (read-char-exclusive)) (setq newchar (char-to-string (read-char-exclusive))
forcenew (car (assoc newchar org-recalc-marks)))) forcenew (car (assoc newchar org-recalc-marks))))
(if (and newchar (not forcenew)) (if (and newchar (not forcenew))
(error "Invalid NEWCHAR `%s' in `org-table-rotate-recalc-marks'" (user-error "Invalid NEWCHAR `%s' in `org-table-rotate-recalc-marks'"
newchar)) newchar))
(if l1 (org-goto-line l1)) (if l1 (org-goto-line l1))
(save-excursion (save-excursion
(beginning-of-line 1) (beginning-of-line 1)
(unless (looking-at org-table-dataline-regexp) (unless (looking-at org-table-dataline-regexp)
(error "Not at a table data line"))) (user-error "Not at a table data line")))
(unless have-col (unless have-col
(org-table-goto-column 1) (org-table-goto-column 1)
(org-table-insert-column) (org-table-insert-column)
@ -2544,7 +2544,7 @@ not overwrite the stored one."
(or suppress-analysis (org-table-get-specials)) (or suppress-analysis (org-table-get-specials))
(if (equal arg '(16)) (if (equal arg '(16))
(let ((eq (org-table-current-field-formula))) (let ((eq (org-table-current-field-formula)))
(or eq (error "No equation active for current field")) (or eq (user-error "No equation active for current field"))
(org-table-get-field nil eq) (org-table-get-field nil eq)
(org-table-align) (org-table-align)
(setq org-table-may-need-update t)) (setq org-table-may-need-update t))
@ -2676,7 +2676,7 @@ not overwrite the stored one."
(if (not (save-match-data (if (not (save-match-data
(string-match (regexp-quote form) formrpl))) (string-match (regexp-quote form) formrpl)))
(setq form (replace-match formrpl t t form)) (setq form (replace-match formrpl t t form))
(error "Spreadsheet error: invalid reference \"%s\"" form))) (user-error "Spreadsheet error: invalid reference \"%s\"" form)))
;; Insert simple ranges ;; Insert simple ranges
(while (string-match "\\$\\([0-9]+\\)\\.\\.\\$\\([0-9]+\\)" form) (while (string-match "\\$\\([0-9]+\\)\\.\\.\\$\\([0-9]+\\)" form)
(setq form (setq form
@ -2694,7 +2694,7 @@ not overwrite the stored one."
(setq n (+ (string-to-number (match-string 1 form)) (setq n (+ (string-to-number (match-string 1 form))
(if (match-end 2) n0 0)) (if (match-end 2) n0 0))
x (nth (1- (if (= n 0) n0 (max n 1))) fields)) x (nth (1- (if (= n 0) n0 (max n 1))) fields))
(unless x (error "Invalid field specifier \"%s\"" (unless x (user-error "Invalid field specifier \"%s\""
(match-string 0 form))) (match-string 0 form)))
(setq form (replace-match (setq form (replace-match
(save-match-data (save-match-data
@ -2705,13 +2705,13 @@ not overwrite the stored one."
(if lispp (if lispp
(setq ev (condition-case nil (setq ev (condition-case nil
(eval (eval (read form))) (eval (eval (read form)))
(error "#ERROR")) (user-error "#ERROR"))
ev (if (numberp ev) (number-to-string ev) ev) ev (if (numberp ev) (number-to-string ev) ev)
ev (if duration (org-table-time-seconds-to-string ev (if duration (org-table-time-seconds-to-string
(string-to-number ev) (string-to-number ev)
duration-output-format) ev)) duration-output-format) ev))
(or (fboundp 'calc-eval) (or (fboundp 'calc-eval)
(error "Calc does not seem to be installed, and is needed to evaluate the formula")) (user-error "Calc does not seem to be installed, and is needed to evaluate the formula"))
;; Use <...> time-stamps so that Calc can handle them ;; Use <...> time-stamps so that Calc can handle them
(setq form (replace-regexp-in-string org-ts-regexp3 "<\\1>" form)) (setq form (replace-regexp-in-string org-ts-regexp3 "<\\1>" form))
;; I18n-ize local time-stamps by setting (system-time-locale "C") ;; I18n-ize local time-stamps by setting (system-time-locale "C")
@ -2754,7 +2754,7 @@ $1-> %s\n" orig formula form0 form))
(unless (let (inhibit-redisplay) (unless (let (inhibit-redisplay)
(y-or-n-p "Debugging Formula. Continue to next? ")) (y-or-n-p "Debugging Formula. Continue to next? "))
(org-table-align) (org-table-align)
(error "Abort")) (user-error "Abort"))
(delete-window bw) (delete-window bw)
(message ""))) (message "")))
(if (listp ev) (setq fmt nil ev "#ERROR")) (if (listp ev) (setq fmt nil ev "#ERROR"))
@ -2792,7 +2792,7 @@ in the buffer and column1 and column2 are table column numbers."
(let ((thisline (org-current-line)) (let ((thisline (org-current-line))
beg end c1 c2 r1 r2 rangep tmp) beg end c1 c2 r1 r2 rangep tmp)
(unless (string-match org-table-range-regexp desc) (unless (string-match org-table-range-regexp desc)
(error "Invalid table range specifier `%s'" desc)) (user-error "Invalid table range specifier `%s'" desc))
(setq rangep (match-end 3) (setq rangep (match-end 3)
r1 (and (match-end 1) (match-string 1 desc)) r1 (and (match-end 1) (match-string 1 desc))
r2 (and (match-end 4) (match-string 4 desc)) r2 (and (match-end 4) (match-string 4 desc))
@ -2860,7 +2860,7 @@ and TABLE is a vector with line types."
;; 1 2 3 4 5 6 ;; 1 2 3 4 5 6
(and (not (match-end 3)) (not (match-end 6))) (and (not (match-end 3)) (not (match-end 6)))
(and (match-end 3) (match-end 6) (not (match-end 5)))) (and (match-end 3) (match-end 6) (not (match-end 5))))
(error "Invalid row descriptor `%s'" desc)) (user-error "Invalid row descriptor `%s'" desc))
(let* ((hdir (and (match-end 2) (match-string 2 desc))) (let* ((hdir (and (match-end 2) (match-string 2 desc)))
(hn (if (match-end 3) (- (match-end 3) (match-beginning 3)) nil)) (hn (if (match-end 3) (- (match-end 3) (match-beginning 3)) nil))
(odir (and (match-end 5) (match-string 5 desc))) (odir (and (match-end 5) (match-string 5 desc)))
@ -2874,7 +2874,7 @@ and TABLE is a vector with line types."
(setq i 0 hdir "+") (setq i 0 hdir "+")
(if (eq (aref table 0) 'hline) (setq hn (1- hn))))) (if (eq (aref table 0) 'hline) (setq hn (1- hn)))))
(if (and (not hn) on (not odir)) (if (and (not hn) on (not odir))
(error "Should never happen");;(aref org-table-dlines on) (user-error "Should never happen");;(aref org-table-dlines on)
(if (and hn (> hn 0)) (if (and hn (> hn 0))
(setq i (org-table-find-row-type table i 'hline (equal hdir "-") (setq i (org-table-find-row-type table i 'hline (equal hdir "-")
nil hn cline desc))) nil hn cline desc)))
@ -2894,20 +2894,20 @@ and TABLE is a vector with line types."
(cond (cond
((eq org-table-relative-ref-may-cross-hline t) t) ((eq org-table-relative-ref-may-cross-hline t) t)
((eq org-table-relative-ref-may-cross-hline 'error) ((eq org-table-relative-ref-may-cross-hline 'error)
(error "Row descriptor %s used in line %d crosses hline" desc cline)) (user-error "Row descriptor %s used in line %d crosses hline" desc cline))
(t (setq i (- i (if backwards -1 1)) (t (setq i (- i (if backwards -1 1))
n 1) n 1)
nil)) nil))
t))) t)))
(setq n (1- n))) (setq n (1- n)))
(if (or (< i 0) (>= i l)) (if (or (< i 0) (>= i l))
(error "Row descriptor %s used in line %d leads outside table" (user-error "Row descriptor %s used in line %d leads outside table"
desc cline) desc cline)
i))) i)))
(defun org-table-rewrite-old-row-references (s) (defun org-table-rewrite-old-row-references (s)
(if (string-match "&[-+0-9I]" s) (if (string-match "&[-+0-9I]" s)
(error "Formula contains old &row reference, please rewrite using @-syntax") (user-error "Formula contains old &row reference, please rewrite using @-syntax")
s)) s))
(defun org-table-make-reference (elements keep-empty numbers lispp) (defun org-table-make-reference (elements keep-empty numbers lispp)
@ -2971,7 +2971,7 @@ known that the table will be realigned a little later anyway."
(interactive "P") (interactive "P")
(or (memq this-command org-recalc-commands) (or (memq this-command org-recalc-commands)
(setq org-recalc-commands (cons this-command org-recalc-commands))) (setq org-recalc-commands (cons this-command org-recalc-commands)))
(unless (org-at-table-p) (error "Not at a table")) (unless (org-at-table-p) (user-error "Not at a table"))
(if (or (eq all 'iterate) (equal all '(16))) (if (or (eq all 'iterate) (equal all '(16)))
(org-table-iterate) (org-table-iterate)
(org-table-get-specials) (org-table-get-specials)
@ -2994,7 +2994,7 @@ known that the table will be realigned a little later anyway."
(car x)) 1) (car x)) 1)
(cdr x))) (cdr x)))
(if (assoc (car x) eqlist1) (if (assoc (car x) eqlist1)
(error "\"%s=\" formula tries to overwrite existing formula for column %s" (user-error "\"%s=\" formula tries to overwrite existing formula for column %s"
lhs1 (car x)))) lhs1 (car x))))
(cons (cons
(org-table-formula-handle-first/last-rc (car x)) (org-table-formula-handle-first/last-rc (car x))
@ -3039,7 +3039,7 @@ known that the table will be realigned a little later anyway."
(if a (setq name1 (format "@%d$%d" (org-table-line-to-dline (nth 1 a)) (if a (setq name1 (format "@%d$%d" (org-table-line-to-dline (nth 1 a))
(nth 2 a)))) (nth 2 a))))
(when (member name1 seen-fields) (when (member name1 seen-fields)
(error "Several field/range formulas try to set %s" name1)) (user-error "Several field/range formulas try to set %s" name1))
(push name1 seen-fields) (push name1 seen-fields)
(and (not a) (and (not a)
@ -3048,7 +3048,7 @@ known that the table will be realigned a little later anyway."
(condition-case nil (condition-case nil
(aref org-table-dlines (aref org-table-dlines
(string-to-number (match-string 1 name))) (string-to-number (match-string 1 name)))
(error (error "Invalid row number in %s" (error (user-error "Invalid row number in %s"
name))) name)))
(string-to-number (match-string 2 name))))) (string-to-number (match-string 2 name)))))
(when (and a (or all (equal (nth 1 a) thisline))) (when (and a (or all (equal (nth 1 a) thisline)))
@ -3118,7 +3118,7 @@ with the prefix ARG."
(message "Convergence after %d iterations" i) (message "Convergence after %d iterations" i)
(message "Table was already stable")) (message "Table was already stable"))
(throw 'exit t))) (throw 'exit t)))
(error "No convergence after %d iterations" i)))) (user-error "No convergence after %d iterations" i))))
;;;###autoload ;;;###autoload
(defun org-table-recalculate-buffer-tables () (defun org-table-recalculate-buffer-tables ()
@ -3149,7 +3149,7 @@ with the prefix ARG."
(message "Convergence after %d iterations" (- imax i)) (message "Convergence after %d iterations" (- imax i))
(throw 'exit t)) (throw 'exit t))
(setq checksum c1))) (setq checksum c1)))
(error "No convergence after %d iterations" imax)))))) (user-error "No convergence after %d iterations" imax))))))
(defun org-table-expand-lhs-ranges (equations) (defun org-table-expand-lhs-ranges (equations)
"Expand list of formulas. "Expand list of formulas.
@ -3207,7 +3207,7 @@ borders of the table using the @< @> $< $> makers."
len len
(- nmax len -1))) (- nmax len -1)))
(if (or (< n 1) (> n nmax)) (if (or (< n 1) (> n nmax))
(error "Reference \"%s\" in expression \"%s\" points outside table" (user-error "Reference \"%s\" in expression \"%s\" points outside table"
(match-string 0 s) s)) (match-string 0 s) s))
(setq start (match-beginning 0)) (setq start (match-beginning 0))
(setq s (replace-match (format "%s%d" (match-string 1 s) n) t t s))))) (setq s (replace-match (format "%s%d" (match-string 1 s) n) t t s)))))
@ -3306,7 +3306,7 @@ Parameters get priority."
(interactive) (interactive)
(when (save-excursion (beginning-of-line 1) (let ((case-fold-search t)) (looking-at "[ \t]*#\\+TBLFM"))) (when (save-excursion (beginning-of-line 1) (let ((case-fold-search t)) (looking-at "[ \t]*#\\+TBLFM")))
(beginning-of-line 0)) (beginning-of-line 0))
(unless (org-at-table-p) (error "Not at a table")) (unless (org-at-table-p) (user-error "Not at a table"))
(org-table-get-specials) (org-table-get-specials)
(let ((key (org-table-current-field-formula 'key 'noerror)) (let ((key (org-table-current-field-formula 'key 'noerror))
(eql (sort (org-table-get-stored-formulas 'noerror) (eql (sort (org-table-get-stored-formulas 'noerror)
@ -3528,7 +3528,7 @@ minutes or seconds."
((org-at-regexp-p "\\(\\<[a-zA-Z]\\)&") ((org-at-regexp-p "\\(\\<[a-zA-Z]\\)&")
(if (memq dir '(left right)) (if (memq dir '(left right))
(org-rematch-and-replace 1 (eq dir 'left)) (org-rematch-and-replace 1 (eq dir 'left))
(error "Cannot shift reference in this direction"))) (user-error "Cannot shift reference in this direction")))
((org-at-regexp-p "\\(\\<[a-zA-Z]\\{1,2\\}\\)\\([0-9]+\\)") ((org-at-regexp-p "\\(\\<[a-zA-Z]\\{1,2\\}\\)\\([0-9]+\\)")
;; A B3-like reference ;; A B3-like reference
(if (memq dir '(up down)) (if (memq dir '(up down))
@ -3543,7 +3543,7 @@ minutes or seconds."
(defun org-rematch-and-replace (n &optional decr hline) (defun org-rematch-and-replace (n &optional decr hline)
"Re-match the group N, and replace it with the shifted reference." "Re-match the group N, and replace it with the shifted reference."
(or (match-end n) (error "Cannot shift reference in this direction")) (or (match-end n) (user-error "Cannot shift reference in this direction"))
(goto-char (match-beginning n)) (goto-char (match-beginning n))
(and (looking-at (regexp-quote (match-string n))) (and (looking-at (regexp-quote (match-string n)))
(replace-match (org-table-shift-refpart (match-string 0) decr hline) (replace-match (org-table-shift-refpart (match-string 0) decr hline)
@ -3579,7 +3579,7 @@ a translation reference."
(org-number-to-letters (org-number-to-letters
(max 1 (+ (org-letters-to-number ref) (if decr -1 1))))) (max 1 (+ (org-letters-to-number ref) (if decr -1 1)))))
(t (error "Cannot shift reference")))))) (t (user-error "Cannot shift reference"))))))
(defun org-table-fedit-toggle-coordinates () (defun org-table-fedit-toggle-coordinates ()
"Toggle the display of coordinates in the referenced table." "Toggle the display of coordinates in the referenced table."
@ -3611,14 +3611,14 @@ With prefix ARG, apply the new formulas to the table."
(while (string-match "[ \t]*\n[ \t]*" form) (while (string-match "[ \t]*\n[ \t]*" form)
(setq form (replace-match " " t t form))) (setq form (replace-match " " t t form)))
(when (assoc var eql) (when (assoc var eql)
(error "Double formulas for %s" var)) (user-error "Double formulas for %s" var))
(push (cons var form) eql))) (push (cons var form) eql)))
(setq org-pos nil) (setq org-pos nil)
(set-window-configuration org-window-configuration) (set-window-configuration org-window-configuration)
(select-window sel-win) (select-window sel-win)
(goto-char pos) (goto-char pos)
(unless (org-at-table-p) (unless (org-at-table-p)
(error "Lost table position - cannot install formulas")) (user-error "Lost table position - cannot install formulas"))
(org-table-store-formulas eql) (org-table-store-formulas eql)
(move-marker pos nil) (move-marker pos nil)
(kill-buffer "*Edit Formulas*") (kill-buffer "*Edit Formulas*")
@ -3648,14 +3648,14 @@ With prefix ARG, apply the new formulas to the table."
(call-interactively 'lisp-indent-line)) (call-interactively 'lisp-indent-line))
((looking-at "[$&@0-9a-zA-Z]+ *= *[^ \t\n']") (goto-char pos)) ((looking-at "[$&@0-9a-zA-Z]+ *= *[^ \t\n']") (goto-char pos))
((not (fboundp 'pp-buffer)) ((not (fboundp 'pp-buffer))
(error "Cannot pretty-print. Command `pp-buffer' is not available")) (user-error "Cannot pretty-print. Command `pp-buffer' is not available"))
((looking-at "[$&@0-9a-zA-Z]+ *= *'(") ((looking-at "[$&@0-9a-zA-Z]+ *= *'(")
(goto-char (- (match-end 0) 2)) (goto-char (- (match-end 0) 2))
(setq beg (point)) (setq beg (point))
(setq ind (make-string (current-column) ?\ )) (setq ind (make-string (current-column) ?\ ))
(condition-case nil (forward-sexp 1) (condition-case nil (forward-sexp 1)
(error (error
(error "Cannot pretty-print Lisp expression: Unbalanced parenthesis"))) (user-error "Cannot pretty-print Lisp expression: Unbalanced parenthesis")))
(setq end (point)) (setq end (point))
(save-restriction (save-restriction
(narrow-to-region beg end) (narrow-to-region beg end)
@ -3707,7 +3707,7 @@ With prefix ARG, apply the new formulas to the table."
((org-at-regexp-p "\\$[a-zA-Z][a-zA-Z0-9]*") 'name) ((org-at-regexp-p "\\$[a-zA-Z][a-zA-Z0-9]*") 'name)
((org-at-regexp-p "\\$[0-9]+") 'column) ((org-at-regexp-p "\\$[0-9]+") 'column)
((not local) nil) ((not local) nil)
(t (error "No reference at point"))) (t (user-error "No reference at point")))
match (and what (or match (match-string 0)))) match (and what (or match (match-string 0))))
(when (and match (not (equal (match-beginning 0) (point-at-bol)))) (when (and match (not (equal (match-beginning 0) (point-at-bol))))
(org-table-add-rectangle-overlay (match-beginning 0) (match-end 0) (org-table-add-rectangle-overlay (match-beginning 0) (match-end 0)
@ -3774,7 +3774,7 @@ With prefix ARG, apply the new formulas to the table."
(goto-char (match-beginning 1)) (goto-char (match-beginning 1))
(org-table-highlight-rectangle) (org-table-highlight-rectangle)
(message "Named column (column %s)" (cdr e))) (message "Named column (column %s)" (cdr e)))
(error "Column name not found"))) (user-error "Column name not found")))
((eq what 'column) ((eq what 'column)
;; column number ;; column number
(org-table-goto-column (string-to-number (substring match 1))) (org-table-goto-column (string-to-number (substring match 1)))
@ -3787,10 +3787,10 @@ With prefix ARG, apply the new formulas to the table."
(goto-char (match-beginning 1)) (goto-char (match-beginning 1))
(org-table-highlight-rectangle) (org-table-highlight-rectangle)
(message "Local parameter.")) (message "Local parameter."))
(error "Parameter not found"))) (user-error "Parameter not found")))
(t (t
(cond (cond
((not var) (error "No reference at point")) ((not var) (user-error "No reference at point"))
((setq e (assoc var org-table-formula-constants-local)) ((setq e (assoc var org-table-formula-constants-local))
(message "Local Constant: $%s=%s in #+CONSTANTS line." (message "Local Constant: $%s=%s in #+CONSTANTS line."
var (cdr e))) var (cdr e)))
@ -3800,7 +3800,7 @@ With prefix ARG, apply the new formulas to the table."
((setq e (and (fboundp 'constants-get) (constants-get var))) ((setq e (and (fboundp 'constants-get) (constants-get var)))
(message "Constant: $%s=%s, from `constants.el'%s." (message "Constant: $%s=%s, from `constants.el'%s."
var e (format " (%s units)" constants-unit-system))) var e (format " (%s units)" constants-unit-system)))
(t (error "Undefined name $%s" var))))) (t (user-error "Undefined name $%s" var)))))
(goto-char pos) (goto-char pos)
(when (and org-show-positions (when (and org-show-positions
(not (memq this-command '(org-table-fedit-scroll (not (memq this-command '(org-table-fedit-scroll
@ -3826,7 +3826,7 @@ With prefix ARG, apply the new formulas to the table."
(goto-char (if (< (abs (- p1 (point))) (abs (- p2 (point)))) (goto-char (if (< (abs (- p1 (point))) (abs (- p2 (point))))
p1 p2))) p1 p2)))
((or p1 p2) (goto-char (or p1 p2))) ((or p1 p2) (goto-char (or p1 p2)))
(t (error "No table dataline around here")))))) (t (user-error "No table dataline around here"))))))
(defun org-table-fedit-line-up () (defun org-table-fedit-line-up ()
"Move cursor one line up in the window showing the table." "Move cursor one line up in the window showing the table."
@ -4091,7 +4091,7 @@ to execute outside of tables."
(defun orgtbl-error () (defun orgtbl-error ()
"Error when there is no default binding for a table key." "Error when there is no default binding for a table key."
(interactive) (interactive)
(error "This key has no function outside tables")) (user-error "This key has no function outside tables"))
(defun orgtbl-setup () (defun orgtbl-setup ()
"Setup orgtbl keymaps." "Setup orgtbl keymaps."
@ -4362,7 +4362,7 @@ overwritten, and the table is not marked as requiring realignment."
org-table-last-alignment org-table-last-column-widths org-table-last-alignment org-table-last-column-widths
maxcol column) maxcol column)
(if (not (fboundp func)) (if (not (fboundp func))
(error "Cannot export orgtbl table to %s" target)) (user-error "Cannot export orgtbl table to %s" target))
(setq lines (org-table-clean-before-export lines)) (setq lines (org-table-clean-before-export lines))
(setq table (setq table
(mapcar (mapcar
@ -4403,14 +4403,14 @@ a radio table."
(goto-char (point-min)) (goto-char (point-min))
(unless (re-search-forward (unless (re-search-forward
(concat "BEGIN RECEIVE ORGTBL +" name "\\([ \t]\\|$\\)") nil t) (concat "BEGIN RECEIVE ORGTBL +" name "\\([ \t]\\|$\\)") nil t)
(error "Don't know where to insert translated table")) (user-error "Don't know where to insert translated table"))
(goto-char (match-beginning 0)) (goto-char (match-beginning 0))
(beginning-of-line 2) (beginning-of-line 2)
(save-excursion (save-excursion
(let ((beg (point))) (let ((beg (point)))
(unless (re-search-forward (unless (re-search-forward
(concat "END RECEIVE ORGTBL +" name) nil t) (concat "END RECEIVE ORGTBL +" name) nil t)
(error "Cannot find end of insertion region")) (user-error "Cannot find end of insertion region"))
(beginning-of-line 1) (beginning-of-line 1)
(delete-region beg (point)))) (delete-region beg (point))))
(insert txt "\n"))) (insert txt "\n")))
@ -4423,7 +4423,7 @@ 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."
(unless txt (unless txt
(unless (org-at-table-p) (unless (org-at-table-p)
(error "No table at point"))) (user-error "No table at point")))
(let* ((txt (or txt (let* ((txt (or txt
(buffer-substring-no-properties (org-table-begin) (buffer-substring-no-properties (org-table-begin)
(org-table-end)))) (org-table-end))))
@ -4442,7 +4442,7 @@ With argument MAYBE, fail quietly if no transformation is defined for
this table." this table."
(interactive) (interactive)
(catch 'exit (catch 'exit
(unless (org-at-table-p) (error "Not at a table")) (unless (org-at-table-p) (user-error "Not at a table"))
;; when non-interactive, we assume align has just happened. ;; when non-interactive, we assume align has just happened.
(when (org-called-interactively-p 'any) (org-table-align)) (when (org-called-interactively-p 'any) (org-table-align))
(let ((dests (orgtbl-gather-send-defs)) (let ((dests (orgtbl-gather-send-defs))
@ -4450,7 +4450,7 @@ this table."
(org-table-end))) (org-table-end)))
(ntbl 0)) (ntbl 0))
(unless dests (if maybe (throw 'exit nil) (unless dests (if maybe (throw 'exit nil)
(error "Don't know how to transform this table"))) (user-error "Don't know how to transform this table")))
(dolist (dest dests) (dolist (dest dests)
(let* ((name (plist-get dest :name)) (let* ((name (plist-get dest :name))
(transform (plist-get dest :transform)) (transform (plist-get dest :transform))
@ -4483,7 +4483,7 @@ this table."
skipcols i0)) skipcols i0))
(txt (if (fboundp transform) (txt (if (fboundp transform)
(funcall transform table params) (funcall transform table params)
(error "No such transformation function %s" transform)))) (user-error "No such transformation function %s" transform))))
(orgtbl-send-replace-tbl name txt)) (orgtbl-send-replace-tbl name txt))
(setq ntbl (1+ ntbl))) (setq ntbl (1+ ntbl)))
(message "Table converted and installed at %d receiver location%s" (message "Table converted and installed at %d receiver location%s"
@ -4513,7 +4513,7 @@ First element has index 0, or I0 if given."
(commented (save-excursion (beginning-of-line 1) (commented (save-excursion (beginning-of-line 1)
(cond ((looking-at re1) t) (cond ((looking-at re1) t)
((looking-at re2) nil) ((looking-at re2) nil)
(t (error "Not at an org table"))))) (t (user-error "Not at an org table")))))
(re (if commented re1 re2)) (re (if commented re1 re2))
beg end) beg end)
(save-excursion (save-excursion
@ -4531,7 +4531,7 @@ First element has index 0, or I0 if given."
(let* ((e (assq major-mode orgtbl-radio-table-templates)) (let* ((e (assq major-mode orgtbl-radio-table-templates))
(txt (nth 1 e)) (txt (nth 1 e))
name pos) name pos)
(unless e (error "No radio table setup defined for %s" major-mode)) (unless e (user-error "No radio table setup defined for %s" major-mode))
(setq name (read-string "Table name: ")) (setq name (read-string "Table name: "))
(while (string-match "%n" txt) (while (string-match "%n" txt)
(setq txt (replace-match name t t txt))) (setq txt (replace-match name t t txt)))
@ -4898,7 +4898,7 @@ it here: http://gnuvola.org/software/j/aa2u/ascii-art-to-unicode.el."
(unless (delq nil (mapcar (lambda (l) (string-match "aa2u" (car l))) org-stored-links)) (unless (delq nil (mapcar (lambda (l) (string-match "aa2u" (car l))) org-stored-links))
(push '("http://gnuvola.org/software/j/aa2u/ascii-art-to-unicode.el" (push '("http://gnuvola.org/software/j/aa2u/ascii-art-to-unicode.el"
"Link to ascii-art-to-unicode.el") org-stored-links)) "Link to ascii-art-to-unicode.el") org-stored-links))
(error "Please download ascii-art-to-unicode.el (use C-c C-l to insert the link to it)")) (user-error "Please download ascii-art-to-unicode.el (use C-c C-l to insert the link to it)"))
(buffer-string))) (buffer-string)))
(defun org-table-get-remote-range (name-or-id form) (defun org-table-get-remote-range (name-or-id form)
@ -4939,7 +4939,7 @@ list of the fields in the rectangle ."
(setq buffer (current-buffer) loc (match-beginning 0)) (setq buffer (current-buffer) loc (match-beginning 0))
(setq id-loc (org-id-find name-or-id 'marker)) (setq id-loc (org-id-find name-or-id 'marker))
(unless (and id-loc (markerp id-loc)) (unless (and id-loc (markerp id-loc))
(error "Can't find remote table \"%s\"" name-or-id)) (user-error "Can't find remote table \"%s\"" name-or-id))
(setq buffer (marker-buffer id-loc) (setq buffer (marker-buffer id-loc)
loc (marker-position id-loc)) loc (marker-position id-loc))
(move-marker id-loc nil))) (move-marker id-loc nil)))
@ -4951,7 +4951,7 @@ list of the fields in the rectangle ."
(forward-char 1) (forward-char 1)
(unless (and (re-search-forward "^\\(\\*+ \\)\\|[ \t]*|" nil t) (unless (and (re-search-forward "^\\(\\*+ \\)\\|[ \t]*|" nil t)
(not (match-beginning 1))) (not (match-beginning 1)))
(error "Cannot find a table at NAME or ID %s" name-or-id)) (user-error "Cannot find a table at NAME or ID %s" name-or-id))
(setq tbeg (point-at-bol)) (setq tbeg (point-at-bol))
(org-table-get-specials) (org-table-get-specials)
(setq form (org-table-formula-substitute-names (setq form (org-table-formula-substitute-names