aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Winkler2020-12-04 14:00:49 -0600
committerRoland Winkler2020-12-04 14:00:49 -0600
commit335018f663fa76abadd8e5ea7c267ae3eb3cd059 (patch)
tree1437e356908f818aae40fef755224638cb8731e7
parent81fe928a769d9a63078aa1144335c204a2541595 (diff)
downloademacs-335018f663fa76abadd8e5ea7c267ae3eb3cd059.tar.gz
emacs-335018f663fa76abadd8e5ea7c267ae3eb3cd059.zip
* lisp/textmodes/bibtex.el: Use user-error.
-rw-r--r--lisp/textmodes/bibtex.el85
1 files changed, 43 insertions, 42 deletions
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el
index cb0b95bc20b..0a0a58244d0 100644
--- a/lisp/textmodes/bibtex.el
+++ b/lisp/textmodes/bibtex.el
@@ -1739,7 +1739,7 @@ BibTeX field as necessary."
1739 ;; It can be confusing if non-editing commands try to 1739 ;; It can be confusing if non-editing commands try to
1740 ;; modify the buffer. 1740 ;; modify the buffer.
1741 (if buffer-read-only 1741 (if buffer-read-only
1742 (error "Comma missing at buffer position %s" (point))) 1742 (user-error "Comma missing at buffer position %s" (point)))
1743 (insert ",") 1743 (insert ",")
1744 (forward-char -1) 1744 (forward-char -1)
1745 ;; Now try again. 1745 ;; Now try again.
@@ -2263,7 +2263,7 @@ On success return bounds, nil otherwise. Do not move point."
2263 (>= (bibtex-end-of-field bounds) (point))) 2263 (>= (bibtex-end-of-field bounds) (point)))
2264 bounds) 2264 bounds)
2265 ((not noerr) 2265 ((not noerr)
2266 (error "Can't find enclosing BibTeX field")))))) 2266 (user-error "Can't find enclosing BibTeX field"))))))
2267 2267
2268(defun bibtex-beginning-first-field (&optional beg) 2268(defun bibtex-beginning-first-field (&optional beg)
2269 "Move point to beginning of first field. 2269 "Move point to beginning of first field.
@@ -2275,7 +2275,7 @@ Optional arg BEG is beginning of entry."
2275(defun bibtex-insert-kill (n &optional comma) 2275(defun bibtex-insert-kill (n &optional comma)
2276 "Reinsert the Nth stretch of killed BibTeX text (field or entry). 2276 "Reinsert the Nth stretch of killed BibTeX text (field or entry).
2277Optional arg COMMA is as in `bibtex-enclosing-field'." 2277Optional arg COMMA is as in `bibtex-enclosing-field'."
2278 (unless bibtex-last-kill-command (error "BibTeX kill ring is empty")) 2278 (unless bibtex-last-kill-command (user-error "BibTeX kill ring is empty"))
2279 (let ((fun (lambda (kryp kr) ; adapted from `current-kill' 2279 (let ((fun (lambda (kryp kr) ; adapted from `current-kill'
2280 (car (set kryp (nthcdr (mod (- n (length (symbol-value kryp))) 2280 (car (set kryp (nthcdr (mod (- n (length (symbol-value kryp)))
2281 (length kr)) 2281 (length kr))
@@ -2354,7 +2354,7 @@ Formats current entry according to variable `bibtex-entry-format'."
2354 ;; identify entry type 2354 ;; identify entry type
2355 (goto-char (point-min)) 2355 (goto-char (point-min))
2356 (or (re-search-forward bibtex-entry-type nil t) 2356 (or (re-search-forward bibtex-entry-type nil t)
2357 (error "Not inside a BibTeX entry")) 2357 (user-error "Not inside a BibTeX entry"))
2358 (let* ((beg-type (1+ (match-beginning 0))) 2358 (let* ((beg-type (1+ (match-beginning 0)))
2359 (end-type (match-end 0)) 2359 (end-type (match-end 0))
2360 (entry-list (assoc-string (buffer-substring-no-properties 2360 (entry-list (assoc-string (buffer-substring-no-properties
@@ -2564,7 +2564,7 @@ Formats current entry according to variable `bibtex-entry-format'."
2564 (memq 'required-fields format) 2564 (memq 'required-fields format)
2565 (assoc-string field-name req-field-list t)) 2565 (assoc-string field-name req-field-list t))
2566 (setq error-field-name field-name) 2566 (setq error-field-name field-name)
2567 (error "Mandatory field `%s' is empty" field-name)) 2567 (user-error "Mandatory field `%s' is empty" field-name))
2568 2568
2569 ;; unify case of field name 2569 ;; unify case of field name
2570 (when (memq 'unify-case format) 2570 (when (memq 'unify-case format)
@@ -2595,20 +2595,20 @@ Formats current entry according to variable `bibtex-entry-format'."
2595 ;; we have deleted by now. Nonetheless we can 2595 ;; we have deleted by now. Nonetheless we can
2596 ;; move point on this empty field. 2596 ;; move point on this empty field.
2597 (setq error-field-name (car fname)) 2597 (setq error-field-name (car fname))
2598 (error "Mandatory field `%s' is missing" 2598 (user-error "Mandatory field `%s' is missing"
2599 (car fname))))) 2599 (car fname)))))
2600 (dotimes (idx num-alt) 2600 (dotimes (idx num-alt)
2601 (cond ((= 0 (aref alt-found idx)) 2601 (cond ((= 0 (aref alt-found idx))
2602 (setq error-field-name 2602 (setq error-field-name
2603 (car (last (aref alt-fields idx)))) 2603 (car (last (aref alt-fields idx))))
2604 (error "Alternative mandatory field `%s' is missing" 2604 (user-error "Alternative mandatory field `%s' is missing"
2605 (aref alt-expect idx))) 2605 (aref alt-expect idx)))
2606 ((< 1 (aref alt-found idx)) 2606 ((< 1 (aref alt-found idx))
2607 (setq error-field-name 2607 (setq error-field-name
2608 (car (last (aref alt-fields idx)))) 2608 (car (last (aref alt-fields idx))))
2609 (error "Alternative fields `%s' are defined %s times" 2609 (user-error "Alternative fields `%s' are defined %s times"
2610 (aref alt-expect idx) 2610 (aref alt-expect idx)
2611 (length (aref alt-fields idx)))))))) 2611 (length (aref alt-fields idx))))))))
2612 2612
2613 ;; update comma after last field 2613 ;; update comma after last field
2614 (if (memq 'last-comma format) 2614 (if (memq 'last-comma format)
@@ -2754,7 +2754,8 @@ and `bibtex-autokey-names-stretch'."
2754 ;; name is of the form "First Middle Last" or "Last" 2754 ;; name is of the form "First Middle Last" or "Last"
2755 ;; --> take the last token 2755 ;; --> take the last token
2756 (match-string 1 fullname)) 2756 (match-string 1 fullname))
2757 (t (error "Name `%s' is incorrectly formed" fullname))))) 2757 (t (user-error "Name `%s' is incorrectly formed"
2758 fullname)))))
2758 (funcall bibtex-autokey-name-case-convert-function 2759 (funcall bibtex-autokey-name-case-convert-function
2759 (bibtex-autokey-abbrev name bibtex-autokey-name-length)))) 2760 (bibtex-autokey-abbrev name bibtex-autokey-name-length))))
2760 2761
@@ -3052,15 +3053,15 @@ Use `bibtex-predefined-strings' and BibTeX files `bibtex-string-files'."
3052 (if (file-name-absolute-p filename) 3053 (if (file-name-absolute-p filename)
3053 (if (file-readable-p filename) 3054 (if (file-readable-p filename)
3054 (push filename string-files) 3055 (push filename string-files)
3055 (error "BibTeX strings file %s not found" filename)) 3056 (user-error "BibTeX strings file %s not found" filename))
3056 (dolist (dir dirlist) 3057 (dolist (dir dirlist)
3057 (when (file-readable-p 3058 (when (file-readable-p
3058 (setq fullfilename (expand-file-name filename dir))) 3059 (setq fullfilename (expand-file-name filename dir)))
3059 (push fullfilename string-files) 3060 (push fullfilename string-files)
3060 (setq found t))) 3061 (setq found t)))
3061 (unless found 3062 (unless found
3062 (error "File %s not in paths defined via bibtex-string-file-path" 3063 (user-error "File %s not in paths defined via bibtex-string-file-path"
3063 filename)))) 3064 filename))))
3064 ;; parse string files 3065 ;; parse string files
3065 (dolist (filename string-files) 3066 (dolist (filename string-files)
3066 (with-temp-buffer 3067 (with-temp-buffer
@@ -3135,11 +3136,11 @@ does not use `bibtex-mode'."
3135 (push expanded-file-name file-list) 3136 (push expanded-file-name file-list)
3136 (setq found t))) 3137 (setq found t)))
3137 (unless found 3138 (unless found
3138 (error "File `%s' not in paths defined via bibtex-file-path" 3139 (user-error "File `%s' not in paths defined via bibtex-file-path"
3139 file)))))) 3140 file))))))
3140 (dolist (file file-list) 3141 (dolist (file file-list)
3141 (unless (file-readable-p file) 3142 (unless (file-readable-p file)
3142 (error "BibTeX file `%s' not found" file))) 3143 (user-error "BibTeX file `%s' not found" file)))
3143 ;; expand dir-list 3144 ;; expand dir-list
3144 (dolist (dir dir-list) 3145 (dolist (dir dir-list)
3145 (setq file-list 3146 (setq file-list
@@ -3216,7 +3217,7 @@ that is generated by calling `bibtex-url'."
3216 (bibtex-beginning-of-entry) 3217 (bibtex-beginning-of-entry)
3217 (if (looking-at bibtex-entry-maybe-empty-head) 3218 (if (looking-at bibtex-entry-maybe-empty-head)
3218 (kill-new (message "%s" (funcall bibtex-summary-function))) 3219 (kill-new (message "%s" (funcall bibtex-summary-function)))
3219 (error "No entry found"))))) 3220 (user-error "No entry found")))))
3220 3221
3221(defun bibtex-summary () 3222(defun bibtex-summary ()
3222 "Return summary of current BibTeX entry. 3223 "Return summary of current BibTeX entry.
@@ -3248,7 +3249,7 @@ Used as default value of `bibtex-summary-function'."
3248 `((" " . ,names) (" " . ,year) (": " . ,title) 3249 `((" " . ,names) (" " . ,year) (": " . ,title)
3249 (", " . ,journal) (" " . ,volume) (":" . ,pages)) 3250 (", " . ,journal) (" " . ,volume) (":" . ,pages))
3250 "")) 3251 ""))
3251 (error "Entry not found"))) 3252 (user-error "Entry not found")))
3252 3253
3253(defun bibtex-pop (arg direction) 3254(defun bibtex-pop (arg direction)
3254 "Fill current field from the ARGth same field's text in DIRECTION. 3255 "Fill current field from the ARGth same field's text in DIRECTION.
@@ -3282,8 +3283,8 @@ Generic function used by `bibtex-pop-previous' and `bibtex-pop-next'."
3282 (goto-char (bibtex-end-of-field bounds)) 3283 (goto-char (bibtex-end-of-field bounds))
3283 (setq failure t)))) 3284 (setq failure t))))
3284 (if failure 3285 (if failure
3285 (error "No %s matching BibTeX field" 3286 (user-error "No %s matching BibTeX field"
3286 (if (eq direction 'previous) "previous" "next")) 3287 (if (eq direction 'previous) "previous" "next"))
3287 ;; Found a matching field. Remember boundaries. 3288 ;; Found a matching field. Remember boundaries.
3288 (let ((new-text (bibtex-text-in-field-bounds bounds)) 3289 (let ((new-text (bibtex-text-in-field-bounds bounds))
3289 (nbeg (copy-marker (bibtex-start-of-field bounds))) 3290 (nbeg (copy-marker (bibtex-start-of-field bounds)))
@@ -3499,7 +3500,7 @@ if that value is non-nil.
3499 entry-alist) 3500 entry-alist)
3500 (if (boundp var) 3501 (if (boundp var)
3501 (setq entry-alist (symbol-value var)) 3502 (setq entry-alist (symbol-value var))
3502 (error "BibTeX dialect `%s' undefined" dialect)) 3503 (user-error "BibTeX dialect `%s' undefined" dialect))
3503 (if (not (consp (nth 1 (car entry-alist)))) 3504 (if (not (consp (nth 1 (car entry-alist))))
3504 ;; new format 3505 ;; new format
3505 entry-alist 3506 entry-alist
@@ -3553,8 +3554,8 @@ LOCAL is t for interactive calls."
3553 bibtex-dialect)))) 3554 bibtex-dialect))))
3554 (if (boundp var) 3555 (if (boundp var)
3555 (symbol-value var) 3556 (symbol-value var)
3556 (error "Field types for BibTeX dialect `%s' undefined" 3557 (user-error "Field types for BibTeX dialect `%s' undefined"
3557 bibtex-dialect)))) 3558 bibtex-dialect))))
3558 (funcall setfun 'bibtex-entry-type 3559 (funcall setfun 'bibtex-entry-type
3559 (concat "@[ \t]*\\(?:" 3560 (concat "@[ \t]*\\(?:"
3560 (regexp-opt (mapcar #'car bibtex-entry-alist)) "\\)")) 3561 (regexp-opt (mapcar #'car bibtex-entry-alist)) "\\)"))
@@ -3625,7 +3626,7 @@ and `bibtex-user-optional-fields'."
3625 (let ((e-list (assoc-string entry-type bibtex-entry-alist t)) 3626 (let ((e-list (assoc-string entry-type bibtex-entry-alist t))
3626 required optional) 3627 required optional)
3627 (unless e-list 3628 (unless e-list
3628 (error "Fields for BibTeX entry type %s not defined" entry-type)) 3629 (user-error "Fields for BibTeX entry type %s not defined" entry-type))
3629 (if (member-ignore-case entry-type bibtex-include-OPTcrossref) 3630 (if (member-ignore-case entry-type bibtex-include-OPTcrossref)
3630 (setq required (nth 2 e-list) 3631 (setq required (nth 2 e-list)
3631 optional (append (nth 3 e-list) (nth 4 e-list))) 3632 optional (append (nth 3 e-list) (nth 4 e-list)))
@@ -3656,7 +3657,7 @@ is non-nil."
3656 (bibtex-read-key (format "%s key: " entry-type)))) 3657 (bibtex-read-key (format "%s key: " entry-type))))
3657 (field-list (bibtex-field-list entry-type))) 3658 (field-list (bibtex-field-list entry-type)))
3658 (unless (bibtex-prepare-new-entry (list key nil entry-type)) 3659 (unless (bibtex-prepare-new-entry (list key nil entry-type))
3659 (error "Entry with key `%s' already exists" key)) 3660 (user-error "Entry with key `%s' already exists" key))
3660 (indent-to-column bibtex-entry-offset) 3661 (indent-to-column bibtex-entry-offset)
3661 (insert "@" entry-type (bibtex-entry-left-delimiter)) 3662 (insert "@" entry-type (bibtex-entry-left-delimiter))
3662 (if key (insert key)) 3663 (if key (insert key))
@@ -3868,7 +3869,7 @@ INIT is surrounded by field delimiters, unless NODELIM is non-nil."
3868 (let ((init (nth 2 field))) 3869 (let ((init (nth 2 field)))
3869 (if (not init) (setq init "") 3870 (if (not init) (setq init "")
3870 (if (functionp init) (setq init (funcall init))) 3871 (if (functionp init) (setq init (funcall init)))
3871 (unless (stringp init) (error "`%s' is not a string" init))) 3872 (unless (stringp init) (user-error "`%s' is not a string" init)))
3872 ;; NODELIM is required by `bibtex-insert-kill' 3873 ;; NODELIM is required by `bibtex-insert-kill'
3873 (if nodelim (insert init) 3874 (if nodelim (insert init)
3874 (insert (bibtex-field-left-delimiter) init 3875 (insert (bibtex-field-left-delimiter) init
@@ -3906,7 +3907,7 @@ Return the new location of point."
3906 (goto-char (bibtex-end-of-string bounds))) 3907 (goto-char (bibtex-end-of-string bounds)))
3907 ((looking-at bibtex-any-valid-entry-type) 3908 ((looking-at bibtex-any-valid-entry-type)
3908 ;; Parsing of entry failed 3909 ;; Parsing of entry failed
3909 (error "Syntactically incorrect BibTeX entry starts here")) 3910 (user-error "Syntactically incorrect BibTeX entry starts here"))
3910 (t (if (called-interactively-p 'interactive) 3911 (t (if (called-interactively-p 'interactive)
3911 (message "Not on a known BibTeX entry.")) 3912 (message "Not on a known BibTeX entry."))
3912 (goto-char pnt))) 3913 (goto-char pnt)))
@@ -3981,7 +3982,7 @@ If mark is active count entries in region, if not in whole buffer."
3981 (if bounds 3982 (if bounds
3982 (ispell-region (bibtex-start-of-text-in-field bounds) 3983 (ispell-region (bibtex-start-of-text-in-field bounds)
3983 (bibtex-end-of-text-in-field bounds)) 3984 (bibtex-end-of-text-in-field bounds))
3984 (error "No abstract in entry")))) 3985 (user-error "No abstract in entry"))))
3985 3986
3986(defun bibtex-narrow-to-entry () 3987(defun bibtex-narrow-to-entry ()
3987 "Narrow buffer to current BibTeX entry." 3988 "Narrow buffer to current BibTeX entry."
@@ -4098,7 +4099,7 @@ for a crossref key, t otherwise."
4098 (let* ((pnt (point)) 4099 (let* ((pnt (point))
4099 (_ (bibtex-beginning-of-entry)) 4100 (_ (bibtex-beginning-of-entry))
4100 (end (cdr (bibtex-valid-entry t))) 4101 (end (cdr (bibtex-valid-entry t)))
4101 (_ (unless end (error "Not inside valid entry"))) 4102 (_ (unless end (user-error "Not inside valid entry")))
4102 (beg (match-end 0)) ; set by `bibtex-valid-entry' 4103 (beg (match-end 0)) ; set by `bibtex-valid-entry'
4103 (bounds (bibtex-search-forward-field "\\(OPT\\)?crossref" end)) 4104 (bounds (bibtex-search-forward-field "\\(OPT\\)?crossref" end))
4104 case-fold-search best temp crossref-key) 4105 case-fold-search best temp crossref-key)
@@ -4138,7 +4139,7 @@ for a crossref key, t otherwise."
4138 (bibtex-reposition-window pos) 4139 (bibtex-reposition-window pos)
4139 (beginning-of-line) 4140 (beginning-of-line)
4140 (if (and eqb (> pnt pos) (not noerror)) 4141 (if (and eqb (> pnt pos) (not noerror))
4141 (error "The referencing entry must precede the crossrefed entry!")))) 4142 (user-error "The referencing entry must precede the crossrefed entry"))))
4142 ;; `bibtex-search-crossref' is called noninteractively during 4143 ;; `bibtex-search-crossref' is called noninteractively during
4143 ;; clean-up of an entry. Then it is not possible to check 4144 ;; clean-up of an entry. Then it is not possible to check
4144 ;; whether the current entry and the crossrefed entry have 4145 ;; whether the current entry and the crossrefed entry have
@@ -4559,7 +4560,7 @@ interactive calls."
4559 (if (memq (preceding-char) '(?} ?\")) 4560 (if (memq (preceding-char) '(?} ?\"))
4560 (forward-char -1))) 4561 (forward-char -1)))
4561 (if help (bibtex-print-help-message (car bounds)))) 4562 (if help (bibtex-print-help-message (car bounds))))
4562 ((not noerror) (error "Not on BibTeX field"))))) 4563 ((not noerror) (user-error "Not on BibTeX field")))))
4563 4564
4564(defun bibtex-find-text-internal (&optional noerror subfield comma) 4565(defun bibtex-find-text-internal (&optional noerror subfield comma)
4565 "Find text part of current BibTeX field or entry head. 4566 "Find text part of current BibTeX field or entry head.
@@ -4635,8 +4636,8 @@ Optional arg COMMA is as in `bibtex-enclosing-field'."
4635 (cond ((not failure) 4636 (cond ((not failure)
4636 (list name start-text end-text end string-const)) 4637 (list name start-text end-text end string-const))
4637 ((and no-sub (not noerror)) 4638 ((and no-sub (not noerror))
4638 (error "Not on text part of BibTeX field")) 4639 (user-error "Not on text part of BibTeX field"))
4639 ((not noerror) (error "Not on BibTeX field")))))) 4640 ((not noerror) (user-error "Not on BibTeX field"))))))
4640 4641
4641(defun bibtex-remove-OPT-or-ALT (&optional comma) 4642(defun bibtex-remove-OPT-or-ALT (&optional comma)
4642 "Remove the string starting optional/alternative fields. 4643 "Remove the string starting optional/alternative fields.
@@ -4774,7 +4775,7 @@ The sequence of kills wraps around, so that after the oldest one
4774comes the newest one." 4775comes the newest one."
4775 (interactive "*p") 4776 (interactive "*p")
4776 (unless (eq last-command 'bibtex-yank) 4777 (unless (eq last-command 'bibtex-yank)
4777 (error "Previous command was not a BibTeX yank")) 4778 (user-error "Previous command was not a BibTeX yank"))
4778 (setq this-command 'bibtex-yank) 4779 (setq this-command 'bibtex-yank)
4779 (let ((inhibit-read-only t) key) 4780 (let ((inhibit-read-only t) key)
4780 ;; point is at end of yanked entry 4781 ;; point is at end of yanked entry
@@ -4832,12 +4833,12 @@ At end of the cleaning process, the functions in
4832 (let ((case-fold-search t) 4833 (let ((case-fold-search t)
4833 (start (bibtex-beginning-of-entry)) 4834 (start (bibtex-beginning-of-entry))
4834 (_ (or (looking-at bibtex-any-entry-maybe-empty-head) 4835 (_ (or (looking-at bibtex-any-entry-maybe-empty-head)
4835 (error "Not inside a BibTeX entry"))) 4836 (user-error "Not inside a BibTeX entry")))
4836 (entry-type (bibtex-type-in-head)) 4837 (entry-type (bibtex-type-in-head))
4837 (key (bibtex-key-in-head))) 4838 (key (bibtex-key-in-head)))
4838 (cond ((bibtex-string= entry-type "preamble") 4839 (cond ((bibtex-string= entry-type "preamble")
4839 ;; (bibtex-format-preamble) 4840 ;; (bibtex-format-preamble)
4840 (error "No clean up of @Preamble entries")) 4841 (user-error "No clean up of @Preamble entries"))
4841 ((bibtex-string= entry-type "string") 4842 ((bibtex-string= entry-type "string")
4842 (setq entry-type 'string)) 4843 (setq entry-type 'string))
4843 ;; (bibtex-format-string) 4844 ;; (bibtex-format-string)
@@ -4887,11 +4888,11 @@ At end of the cleaning process, the functions in
4887 (setq error (or (/= (point) start) 4888 (setq error (or (/= (point) start)
4888 (bibtex-search-entry key nil end)))) 4889 (bibtex-search-entry key nil end))))
4889 (if error 4890 (if error
4890 (error "New inserted entry yields duplicate key")) 4891 (user-error "New inserted entry yields duplicate key"))
4891 (dolist (buffer (bibtex-initialize)) 4892 (dolist (buffer (bibtex-initialize))
4892 (with-current-buffer buffer 4893 (with-current-buffer buffer
4893 (if (cdr (assoc-string key bibtex-reference-keys)) 4894 (if (cdr (assoc-string key bibtex-reference-keys))
4894 (error "Duplicate key in %s" (buffer-file-name))))) 4895 (user-error "Duplicate key in %s" (buffer-file-name)))))
4895 4896
4896 ;; Only update `bibtex-strings' and `bibtex-reference-keys' 4897 ;; Only update `bibtex-strings' and `bibtex-reference-keys'
4897 ;; if they have been built already. 4898 ;; if they have been built already.
@@ -5193,7 +5194,7 @@ entries from minibuffer."
5193 bibtex-maintain-sorted-entries)) 5194 bibtex-maintain-sorted-entries))
5194 endpos) 5195 endpos)
5195 (unless (bibtex-prepare-new-entry (list key nil "String")) 5196 (unless (bibtex-prepare-new-entry (list key nil "String"))
5196 (error "Entry with key `%s' already exists" key)) 5197 (user-error "Entry with key `%s' already exists" key))
5197 (if (zerop (length key)) (setq key nil)) 5198 (if (zerop (length key)) (setq key nil))
5198 (indent-to-column bibtex-entry-offset) 5199 (indent-to-column bibtex-entry-offset)
5199 (insert "@String" 5200 (insert "@String"