emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/bbdb 120abeff25 1/4: Use user-error where appropriate


From: Roland Winkler
Subject: [elpa] externals/bbdb 120abeff25 1/4: Use user-error where appropriate
Date: Sun, 27 Mar 2022 00:17:14 -0400 (EDT)

branch: externals/bbdb
commit 120abeff25c2f3914b5816a92dea4f2a1ce1f4fa
Author: Roland Winkler <winkler@gnu.org>
Commit: Roland Winkler <winkler@gnu.org>

    Use user-error where appropriate
---
 lisp/bbdb-com.el  | 62 +++++++++++++++++++++++++++----------------------------
 lisp/bbdb-mua.el  |  8 +++----
 lisp/bbdb-site.el |  4 ++--
 lisp/bbdb-tex.el  |  2 +-
 lisp/bbdb.el      | 41 ++++++++++++++++++------------------
 5 files changed, 59 insertions(+), 58 deletions(-)

diff --git a/lisp/bbdb-com.el b/lisp/bbdb-com.el
index 5d60ead4dc..1e7207d53d 100644
--- a/lisp/bbdb-com.el
+++ b/lisp/bbdb-com.el
@@ -1051,7 +1051,7 @@ A non-nil prefix arg is passed on to `bbdb-read-field' as 
FLAG (see there)."
   (interactive
    (let* ((_ (bbdb-editable))
           (record (or (bbdb-current-record)
-                      (error "Point not on a record")))
+                      (user-error "Point not on a record")))
           (list (append bbdb-xfield-label-list
                         '(affix organization aka phone address mail)))
           (field "")
@@ -1068,20 +1068,20 @@ A non-nil prefix arg is passed on to `bbdb-read-field' 
as FLAG (see there)."
        (setq field (downcase (completing-read "Insert Field: " list))))
      (setq field (intern field))
      (if (memq field present)
-         (error "Field \"%s\" already exists" field))
+         (user-error "Field \"%s\" already exists" field))
      (list record field (bbdb-read-field record field current-prefix-arg))))
 
   (cond (;; affix
          (eq field 'affix)
          (if (bbdb-record-affix record)
-             (error "Affix field exists already"))
+             (user-error "Affix field exists already"))
          (if (stringp value)
              (setq value (bbdb-split 'affix value)))
          (bbdb-record-set-field record 'affix value))
         ;; organization
         ((eq field 'organization)
          (if (bbdb-record-organization record)
-             (error "Organization field exists already"))
+             (user-error "Organization field exists already"))
          (if (stringp value)
              (setq value (bbdb-split 'organization value)))
          (bbdb-record-set-field record 'organization value))
@@ -1098,20 +1098,20 @@ A non-nil prefix arg is passed on to `bbdb-read-field' 
as FLAG (see there)."
         ;; mail
         ((eq field 'mail)
          (if (bbdb-record-mail record)
-             (error "Mail field exists already"))
+             (user-error "Mail field exists already"))
          (if (stringp value)
              (setq value (bbdb-split 'mail value)))
          (bbdb-record-set-field record 'mail value))
         ;; AKA
         ((eq field 'aka)
          (if (bbdb-record-aka record)
-             (error "Alternate names field exists already"))
+             (user-error "Alternate names field exists already"))
          (if (stringp value)
              (setq value (bbdb-split 'aka value)))
          (bbdb-record-set-field record 'aka value))
         ;; xfields
         ((assq field (bbdb-record-xfields record))
-         (error "Xfield \"%s\" already exists" field))
+         (user-error "Xfield \"%s\" already exists" field))
         (t
          (bbdb-record-set-xfield record field value)))
   (unless (bbdb-change-record record)
@@ -1157,7 +1157,7 @@ A non-nil prefix arg is passed on to `bbdb-read-field' as 
FLAG (see there)."
                ;; New xfield
                (y-or-n-p
                 (format "\"%s\" is an unknown field name.  Define it? " field))
-               (error "Aborted"))
+               (user-error "Aborted"))
            (bbdb-read-xfield field init flag)))))
 
 ;;;###autoload
@@ -1180,7 +1180,7 @@ a phone number or address with VALUE being nil.
      (let* ((field-l (bbdb-current-field))
             (field (car field-l))
             (value (nth 1 field-l)))
-       (unless field (error "Point not in a field"))
+       (unless field (user-error "Point not in a field"))
        (list (bbdb-current-record)
              (if (memq field '(name affix organization aka mail phone address
                                     uuid creation-date timestamp))
@@ -1190,7 +1190,7 @@ a phone number or address with VALUE being nil.
   (let (edit-str)
     (cond ((memq field '(firstname lastname xfields))
            ;; FIXME: We could also edit first and last names.
-           (error "Field `%s' not editable this way." field))
+           (user-error "Field `%s' not editable this way." field))
           ((eq field 'name)
            (bbdb-error-retry
             (bbdb-record-set-field
@@ -1207,7 +1207,7 @@ a phone number or address with VALUE being nil.
               (bbdb-record-lastname record)))))
 
           ((eq field 'phone)
-           (unless value (error "No phone specified"))
+           (unless value (user-error "No phone specified"))
            (bbdb-record-set-field
             record field
             ;; Splice new phone value into list of phones.
@@ -1216,7 +1216,7 @@ a phone number or address with VALUE being nil.
                       (bbdb-record-edit-phone value))
               phones)))
           ((eq field 'address)
-           (unless value (error "No address specified"))
+           (unless value (user-error "No address specified"))
            (bbdb-record-edit-address value nil flag)
            (bbdb-record-set-field record field (bbdb-record-address record)))
           ((eq field 'organization)
@@ -1317,13 +1317,13 @@ to select the field."
                                (string-to-number nvalue))))))
 
   (if (memq field '(firstname lastname name-lf aka-all mail-aka mail-canon))
-      (error "Field `%s' illegal" field))
+      (user-error "Field `%s' illegal" field))
   (let ((value (if (numberp nvalue)
                    (nth nvalue (cond ((eq field 'phone) (bbdb-record-phone 
record))
                                      ((eq field 'address) (bbdb-record-address 
record))
-                                     (t (error "%s: nvalue %s meaningless" 
field nvalue)))))))
+                                     (t (user-error "%s: nvalue %s 
meaningless" field nvalue)))))))
     (if (and (numberp nvalue) (not value))
-        (error "%s: nvalue %s out of range" field nvalue))
+        (user-error "%s: nvalue %s out of range" field nvalue))
     (if (or (memq field '(name uuid creation-date))
             (and (eq field 'affix) (bbdb-record-affix record))
             (and (eq field 'organization) (bbdb-record-organization record))
@@ -1385,7 +1385,7 @@ Otherwise, use the default rule according to 
`bbdb-address-format-list'."
               (setq edit (nth 1 elt))))))
     (unless edit
       (setq edit (nth 1 (assq t bbdb-address-format-list))))
-    (unless edit (error "No address editing function defined"))
+    (unless edit (user-error "No address editing function defined"))
     (if (functionp edit)
         (setq new-addr (funcall edit address))
       (setq new-addr (make-vector 5 ""))
@@ -1557,9 +1557,9 @@ irrespective of the value of ARG."
          (record (and (car ident) (car (nth (car ident) bbdb-records))))
          num1 num2)
     (cond ((not (car ident))
-           (error "Point not in BBDB record"))
+           (user-error "Point not in BBDB record"))
           ((not (nth 1 ident))
-           (error "Point not in BBDB field"))
+           (user-error "Point not in BBDB field"))
           ((eq 'name (nth 1 ident))
            ;; Transpose firstname and lastname
            (bbdb-record-set-name record (bbdb-record-lastname record)
@@ -1567,15 +1567,15 @@ irrespective of the value of ARG."
           ((not (integerp arg))
            (error "Arg `%s' not an integer" arg))
           ((not (nth 2 ident))
-           (error "Point not in a transposable field"))
+           (user-error "Point not in a transposable field"))
           (t
            (if (or (use-region-p) (zerop arg))
                (let ((ident2 (bbdb-ident-point
-                              (or (mark) (error "No mark set in this 
buffer")))))
+                              (or (mark) (user-error "No mark set in this 
buffer")))))
                  (unless (and (eq (car ident) (car ident2))
                               (eq (cadr ident) (cadr ident2))
                               (integerp (nth 2 ident2)))
-                   (error "Mark (or point) not on transposable field"))
+                   (user-error "Mark (or point) not on transposable field"))
                  (setq num1 (nth 2 ident)
                        num2 (nth 2 ident2)))
              (setq num1 (1- (nth 2 ident))
@@ -1583,7 +1583,7 @@ irrespective of the value of ARG."
              (if (or (< (min num1 num2) 0)
                      (>= (max num1 num2) (length (bbdb-record-field
                                                   record (nth 1 ident)))))
-                 (error "Cannot transpose fields of different types")))
+                 (user-error "Cannot transpose fields of different types")))
            (bbdb-record-set-field
             record (nth 1 ident)
             (bbdb-list-transpose (bbdb-record-field record (nth 1 ident))
@@ -1604,7 +1604,7 @@ If prefix NOPROMPT is non-nil, do not confirm deletion."
   (interactive
    (list (bbdb-do-records) (bbdb-current-field) current-prefix-arg))
   (bbdb-editable)
-  (unless field (error "Not a field"))
+  (unless field (user-error "Not a field"))
   (setq records (bbdb-record-list records))
   (let* ((type (car field))
          (type-x (if (eq type 'xfields)
@@ -1613,7 +1613,7 @@ If prefix NOPROMPT is non-nil, do not confirm deletion."
     (if (eq type 'name)
         (bbdb-delete-records records noprompt)
       (if (memq type '(firstname lastname))
-          (error "Cannot delete field `%s'" type))
+          (user-error "Cannot delete field `%s'" type))
       (dolist (record records)
         (when (or noprompt
                   (y-or-n-p (format "delete this `%s' field (of %s)? "
@@ -1787,8 +1787,8 @@ With prefix, RECORD2 defaults to the first record with 
the same name."
                 (list record1))))))
 
   (bbdb-editable)
-  (cond ((eq record1 record2) (error "Records are equal"))
-        ((null record2) (error "No record to merge with")))
+  (cond ((eq record1 record2) (user-error "Records are equal"))
+        ((null record2) (user-error "No record to merge with")))
 
   ;; Merge names
   (let* ((new-name (bbdb-record-name record2))
@@ -1928,7 +1928,7 @@ If MAIL is nil use the first mail address of RECORD."
     (let ((mails (bbdb-record-mail record)))
       (setq mail (or (and (integerp mail) (nth mail mails))
                      (car mails)))))
-  (unless mail (error "Record has no mail addresses"))
+  (unless mail (user-error "Record has no mail addresses"))
   (let (name fn ln)
     (cond ((let ((address (bbdb-decompose-bbdb-address mail)))
              ;; We need to know whether we should quote the name part of MAIL
@@ -2592,7 +2592,7 @@ Rebuilding the aliases is enforced if prefix 
FORCE-REBUILT is t."
             (bbdb-pushnew (cons alias expansion) mail-aliases)
 
             (define-mail-abbrev alias expansion)
-            
+
             (unless (setq f-alias (abbrev-symbol alias mail-abbrevs))
               (error "Cannot find the alias"))
 
@@ -2725,7 +2725,7 @@ is non-nil.  Do not dial the extension."
       (setq phone (car (bbdb-record-phone (bbdb-current-record)))))
   (if (eq (car-safe phone) 'phone)
       (setq phone (car (cdr phone))))
-  (or (bbdb-phone-p phone) (error "Not on a phone field"))
+  (or (bbdb-phone-p phone) (user-error "Not on a phone field"))
 
   (let ((number (bbdb-phone-string phone))
         shortnumber)
@@ -2785,7 +2785,7 @@ Default is the first URL."
 (defun bbdb-grab-url (record url)
   "Grab URL and store it in RECORD."
   (interactive (let ((url (browse-url-url-at-point)))
-                 (unless url (error "No URL at point"))
+                 (unless url (user-error "No URL at point"))
                  (list (bbdb-completing-read-record
                         (format "Add `%s' for: " url))
                        url)))
@@ -2823,7 +2823,7 @@ Interactively, use BBDB prefix \
    (list (bbdb-do-records t) (bbdb-current-field)
          (and current-prefix-arg
               (prefix-numeric-value current-prefix-arg))))
-  (unless field (error "Not a field"))
+  (unless field (user-error "Not a field"))
   (let* ((type (if (eq (car field) 'xfields)
                    (car (nth 1 field))
                  (car field)))
diff --git a/lisp/bbdb-mua.el b/lisp/bbdb-mua.el
index f9d141dfdb..3c44393c56 100644
--- a/lisp/bbdb-mua.el
+++ b/lisp/bbdb-mua.el
@@ -89,7 +89,7 @@ Return values include
       (if (memq major-mode (cdr elt))
           (setq mua (car elt)
                 mm-alist nil)))
-    (or mua (error "BBDB: MUA `%s' not supported" major-mode))))
+    (or mua (user-error "BBDB: MUA `%s' not supported" major-mode))))
 
 ;;;###autoload
 (defun bbdb-message-header (header)
@@ -244,7 +244,7 @@ Usually this function is called by the wrapper 
`bbdb-mua-update-records'."
   (cond ((eq t action)
          (setq action 'create))
         ((not (memq action '(search update query create nil)))
-         (error "Illegal value of arg action: %s" action)))
+         (user-error "Illegal value of arg action: %s" action)))
 
   (let (records-alist records elt)
     ;; association list: records -> addresses
@@ -739,7 +739,7 @@ FIELD defaults to `bbdb-annotate-field'.
 If REPLACE is non-nil, ANNOTATION replaces the content of FIELD.
 If ANNOTATION is an empty string and REPLACE is non-nil, delete FIELD."
   (if (memq field '(name firstname lastname phone address xfields))
-      (error "Field `%s' illegal" field))
+      (user-error "Field `%s' illegal" field))
   (setq annotation (bbdb-string-trim annotation))
   (cond ((memq field '(affix organization mail aka))
          (setq annotation (list annotation)))
@@ -825,7 +825,7 @@ HEADER-CLASS is defined in `bbdb-message-headers'.  If it 
is nil,
 use all classes in `bbdb-message-headers'."
   (interactive (bbdb-mua-edit-field-interactive))
   (cond ((memq field '(firstname lastname address phone xfields))
-         (error "Field `%s' not editable this way" field))
+         (user-error "Field `%s' not editable this way" field))
         ((not field)
          (setq field bbdb-mua-edit-field)))
   (bbdb-mua-wrapper
diff --git a/lisp/bbdb-site.el b/lisp/bbdb-site.el
index dcaf0969ba..563db95bae 100644
--- a/lisp/bbdb-site.el
+++ b/lisp/bbdb-site.el
@@ -1,6 +1,6 @@
 ;;; bbdb-site.el --- site-specific variables for BBDB -*- lexical-binding: t 
-*-
 
-;; Copyright (C) 2010-2017  Free Software Foundation, Inc.
+;; Copyright (C) 2010-2022  Free Software Foundation, Inc.
 
 ;; This file is part of the Insidious Big Brother Database (aka BBDB),
 
@@ -22,7 +22,7 @@
 (defconst bbdb-version "@PACKAGE_VERSION@" "Version of BBDB.")
 
 (if (< emacs-major-version 24)
-  (error "BBDB %s requires GNU Emacs 24 or later" bbdb-version))
+  (user-error "BBDB %s requires GNU Emacs 24 or later" bbdb-version))
 
 (defcustom bbdb-tex-path
   (let* ((default "@pkgdatadir@")
diff --git a/lisp/bbdb-tex.el b/lisp/bbdb-tex.el
index e87d4b85d0..12e4f2a6cc 100644
--- a/lisp/bbdb-tex.el
+++ b/lisp/bbdb-tex.el
@@ -479,7 +479,7 @@ RULE should be an element of `bbdb-tex-alist'."
                                     (insert (format fmt (car first-last) (cadr 
first-last))))
                                    ((eq 1 (length first-last))
                                     (insert (format fmt "" (car first-last))))
-                                   (t (error "TeX name %s cannot be split" 
tex-name))))
+                                   (t (user-error "TeX name %s cannot be 
split" tex-name))))
                          (insert (format fmt
                                          (bbdb-tex-field 'firstname firstname)
                                          (bbdb-tex-field 'lastname  
lastname))))))
diff --git a/lisp/bbdb.el b/lisp/bbdb.el
index a7fb8a89bb..3ea2bb18f1 100644
--- a/lisp/bbdb.el
+++ b/lisp/bbdb.el
@@ -677,7 +677,7 @@ This variable also affects dialing."
                  (integerp val)
                  (null val))
              (set symb val)
-           (error "%s must contain digits only." symb))))
+           (user-error "%s must contain digits only." symb))))
 
 (defcustom bbdb-allow-duplicates nil
   "When non-nil BBDB allows records with duplicate names and email addresses.
@@ -1102,7 +1102,7 @@ Allowed values are:
  a regexp    If the new mail address matches this regexp never ignore
                this mail address.  Otherwise query to ignore it.
 See also `bbdb-add-mails', `bbdb-message-clean-mail-function',
-and 'bbdb-message-ignore-mail-re'."
+and `bbdb-message-ignore-mail-re'."
   :group 'bbdb-mua
   :type '(choice (const :tag "Automatically ignore redundant mail addresses" t)
                  (const :tag "Query whether to ignore them" query)
@@ -2099,18 +2099,18 @@ The return value is the new value of LISTNAME."
   "Return the record point is at.
 If FULL is non-nil record includes the display information."
   (unless (eq major-mode 'bbdb-mode)
-    (error "This only works while in BBDB buffers."))
+    (user-error "This only works while in BBDB buffers."))
   (let ((num (get-text-property (if (and (not (bobp)) (eobp))
                                     (1- (point)) (point))
                                 'bbdb-record-number))
         record)
-    (unless num (error "Not a BBDB record"))
+    (unless num (user-error "Not a BBDB record"))
     (setq record (nth num bbdb-records))
     (if full record (car record))))
 
 (defun bbdb-current-field ()
   "Return current field point is on."
-  (unless (bbdb-current-record) (error "Not a BBDB record"))
+  (unless (bbdb-current-record) (user-error "Not a BBDB record"))
   (get-text-property (point) 'bbdb-field))
 
 (defmacro bbdb-debug (&rest body)
@@ -2202,7 +2202,8 @@ Used with variable `bbdb-add-name' and friends."
          (funcall spec record string))
         ((stringp spec)
          (unless (let ((case-fold-search t))
-                   (string-match spec string) 'query))) ; be least aggressive
+                   (string-match spec string))
+           'query)) ; be least aggressive
         (spec)))
 
 (defsubst bbdb-eval-spec (spec prompt)
@@ -2602,7 +2603,7 @@ If WARN is non-nil, issue a warning instead of raising an 
error."
                                             name (mapconcat #'bbdb-record-name
                                                             records ", "))))
                            (if (not warn)
-                               (error msg)
+                               (user-error msg)
                              (message msg)
                              (sit-for 1)))))))
       (cond ((stringp name)
@@ -2629,7 +2630,7 @@ If WARN is non-nil, issue a warning instead of raising an 
error."
             (let ((msg (format "Mail `%s' is already in BBDB: %s" m
                                (mapconcat #'bbdb-record-name records ", "))))
               (if (not warn)
-                  (error msg)
+                  (user-error msg)
                 (message msg)
                 (sit-for 1))))))))
 
@@ -2738,7 +2739,7 @@ Return VALUE."
   ;; Yet the actual code would get rather confused.  So we throw an error.
   (if (memq label '(name firstname lastname affix organization
                          mail aka phone address xfields))
-      (error "xfield label `%s' illegal" label))
+      (user-error "xfield label `%s' illegal" label))
   (if (eq label 'mail-alias)
       (setq bbdb-mail-aliases-need-rebuilt 'edit))
   (if (stringp value) (setq value (bbdb-string-trim value t)))
@@ -2929,7 +2930,7 @@ Then VALUE is the value of this xfield.
 See also `bbdb-record-field'."
   (bbdb-editable)
   (if (memq field '(name-lf mail-aka mail-canon aka-all))
-      (error "`%s' is not allowed as the name of a field" field))
+      (user-error "`%s' is not allowed as the name of a field" field))
   ;; FIXME: Use something like `bbdb-record--make' i.s.o `vector'.
   (let ((record-type (apply #'vector (cdr bbdb-record-type))))
     (cond ((eq field 'firstname) ; First name
@@ -3167,7 +3168,7 @@ Do this only if `bbdb-check-postcode' is non-nil."
           (if (string-match re string)
               (setq done t postcodes nil)))
         (if done string
-          (error "not a valid postcode.")))
+          (user-error "not a valid postcode.")))
     string))
 
 (defun bbdb-phone-string (phone)
@@ -3177,11 +3178,11 @@ Do this only if `bbdb-check-postcode' is non-nil."
       ;; (1) ["where" "the number"]
       (if (stringp (aref phone 1))
           (aref phone 1)
-        (error "Not a valid phone number: %s" (aref phone 1)))
+        (user-error "Not a valid phone number: %s" (aref phone 1)))
     ;; (2) ["where" 415 555 1212 99]
     (unless (and (integerp (aref phone 2))
                  (integerp (aref phone 3)))
-      (error "Not an NANP number: %s %s" (aref phone 2) (aref phone 3)))
+      (user-error "Not an NANP number: %s %s" (aref phone 2) (aref phone 3)))
     (concat (if (/= 0 (bbdb-phone-area phone))
                 (format "(%03d) " (bbdb-phone-area phone))
                 "")
@@ -3319,7 +3320,7 @@ that window has been scrolled to the record we have just 
modified."
   "Ensure that BBDB is editable, otherwise throw an error.
 If BBDB is out of sync try to revert.
 BBDB is not editable if it is read-only."
-  (if bbdb-read-only (error "BBDB is read-only"))
+  (if bbdb-read-only (user-error "BBDB is read-only"))
   (let ((buffer (bbdb-buffer))) ; this reverts if necessary / possible
     ;; Is the following possible?  Superfluous tests do not hurt.
     ;; It is relevant only for editing commands in a BBDB buffer,
@@ -3378,7 +3379,7 @@ Return nil otherwise."
                     (or noconfirm
                         (yes-or-no-p "Flush your changes and revert BBDB? "))))
            (unless (file-exists-p bbdb-file)
-             (error "BBDB: file %s no longer exists" bbdb-file))
+             (user-error "BBDB: file %s no longer exists" bbdb-file))
            (kill-all-local-variables)  ; clear database
            ;; `revert-buffer-function' has the permanent-local property
            ;; So to avoid looping, we need to bind it to nil explicitly.
@@ -3596,7 +3597,7 @@ They are present only for backward compatibility."
     (sit-for 2))
 
   (if bbdb-read-only
-      (error "The Insidious Big Brother Database is read-only."))
+      (user-error "The Insidious Big Brother Database is read-only."))
   ;; The call of `bbdb-records' checks file synchronization.
   ;; If RECORD refers to an existing record that has been changed,
   ;; yet in the meanwhile we reverted the BBDB file, then RECORD
@@ -3857,8 +3858,8 @@ The formatting rules are defined in 
`bbdb-address-format-list'."
                          ((string-match "%C" form) ; country
                           (unless (or (not country) (string= ""  country))
                             (setq string (concat string (format 
(replace-regexp-in-string "%C" "%s" form t) country)))))
-                         (t (error "Malformed address format element %s" 
form)))))
-                (t (error "Malformed address format %s" format))))))
+                         (t (user-error "Malformed address format element %s" 
form)))))
+                (t (user-error "Malformed address format %s" format))))))
     (unless string
       (error "No match of `bbdb-address-format-list'"))
     string))
@@ -4700,7 +4701,7 @@ With prefix N move forward N records."
   (interactive "p")
   (let ((npoint (bbdb-scan-property 'bbdb-record-number 'integerp n)))
     (if npoint (goto-char npoint)
-      (error "No %s record" (if (< 0 n) "next" "previous")))))
+      (user-error "No %s record" (if (< 0 n) "next" "previous")))))
 
 (defun bbdb-prev-record (n)
   "Move point to the beginning of the previous BBDB record.
@@ -4718,7 +4719,7 @@ With prefix N move forward N (sub)fields."
                                   (not (eq (nth 2 p) 'field-label))))
                  n)))
     (if npoint (goto-char npoint)
-      (error "No %s field" (if (< 0 n) "next" "previous")))))
+      (user-error "No %s field" (if (< 0 n) "next" "previous")))))
 
 (defun bbdb-prev-field (n)
   "Move point to previous (sub)field.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]