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

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

[elpa] externals/ebdb bbe407e 257/350: Code tweaks and re-arrangments


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb bbe407e 257/350: Code tweaks and re-arrangments
Date: Mon, 14 Aug 2017 11:46:49 -0400 (EDT)

branch: externals/ebdb
commit bbe407eaafaff072e6833b1fc5bc5a0175265ffe
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>

    Code tweaks and re-arrangments
    
    Inspired by the compiler, and tumashu's bug report. Make sure all
    functions and variables are required, autoloaded, defvar'd, or
    otherwise available.
    
    Fixes #41.
    
    * ebdb.el (ebdb-canonicalize-mail-function,
      ebdb-message-clean-name-function): Biggest change is that these two
      customization options have been moved here from ebdb-mua.el, and
      switched to the 'ebdb-utilities defgroup. They aren't MUA
      specific (we should use them in snarfing, for one thing), and the
      functions they point to by default are already in ebdb.el.
---
 ebdb-com.el   |  5 ++---
 ebdb-mua.el   | 66 ++++++++++++++++++++++-------------------------------------
 ebdb-snarf.el |  2 +-
 ebdb.el       | 23 ++++++++++++++++++++-
 4 files changed, 50 insertions(+), 46 deletions(-)

diff --git a/ebdb-com.el b/ebdb-com.el
index 10f1d4c..ad341e2 100644
--- a/ebdb-com.el
+++ b/ebdb-com.el
@@ -27,7 +27,6 @@
 
 (require 'ebdb)
 (require 'ebdb-format)
-(require 'ebdb-snarf)
 (require 'mailabbrev)
 
 (eval-and-compile
@@ -2575,7 +2574,7 @@ of all of these people."
               (ebdb-dwim-mail (if (stringp (car e))
                                   (ebdb-gethash e 'uuid)
                                 (car e))
-                              (second e)))
+                              (cl-second e)))
             (cdr entry) ", "))
           f-alias)
 
@@ -2633,7 +2632,7 @@ actions."
                       (cdar actions))
                 (let ((alst (mapcar
                              (lambda (a)
-                               (cons (first a) (cdr a)))
+                               (cons (cl-first a) (cdr a)))
                              actions)))
                   (cdr
                    (assoc (completing-read "Action: " alst)
diff --git a/ebdb-mua.el b/ebdb-mua.el
index 5ad668f..f859411 100644
--- a/ebdb-mua.el
+++ b/ebdb-mua.el
@@ -45,9 +45,13 @@
 (require 'ebdb)
 (require 'ebdb-com)
 
+(autoload 'ebdb-snarf "ebdb-snarf")
+
 (eval-and-compile
   (autoload 'mail-decode-encoded-word-string "mail-parse"))
 
+(defvar message-alternative-emails)
+
 ;;; MUA interface
 
 (defvar ebdb-offer-to-create nil
@@ -244,7 +248,8 @@ accordingly."
                 (regexp-opt (slot-value
                              (ebdb-record-cache self-rec)
                              'mail-canon)))))
-       ((eq ebdb-user-mail-address-re 'message)
+       ((and (eq ebdb-user-mail-address-re 'message)
+             (boundp 'message-alternative-emails))
         (setq ebdb-user-mail-address-re
               message-alternative-emails))
        (t ebdb-user-mail-address-re)))
@@ -315,18 +320,6 @@ See also `ebdb-ignore-redundant-mails'."
                  (function :tag "Function for analyzing name handling")
                  (regexp :tag "If the new address matches this regexp ignore 
it.")))
 
-(defcustom ebdb-canonicalize-mail-function nil
-  "If non-nil, it should be a function of one arg: a mail address string.
-When EBDB \"notices\" a message, the corresponding mail addresses are passed
-to this function first.  It acts as a kind of \"filter\" to transform
-the mail addresses before they are compared against or added to the database.
-See `ebdb-canonicalize-mail-1' for a more complete example.
-If this function returns nil, EBDB assumes that there is no mail address.
-
-See also `ebdb-ignore-redundant-mails'."
-  :group 'ebdb-mua
-  :type 'function)
-
 (defcustom ebdb-ignore-redundant-mails 'query
   "How to handle redundant mail addresses for existing EBDB records.
 For example, \"address@hidden" is redundant w.r.t. \"address@hidden".
@@ -352,15 +345,6 @@ See also `ebdb-add-mails' and 
`ebdb-canonicalize-mail-function'."
                  (number :tag "Number of seconds to display redundant 
addresses")
                  (function :tag "Function for handling redundant mail 
addresses")
                  (regexp :tag "If the new address matches this regexp never 
ignore it.")))
-(define-obsolete-variable-alias 'ebdb-canonicalize-redundant-mails
-  'ebdb-ignore-redundant-mails)
-
-(defcustom ebdb-message-clean-name-function 'ebdb-message-clean-name-default
-  "Function to clean up the name in the header of a message.
-It takes one argument, the name as extracted by
-`mail-extract-address-components'."
-  :group 'ebdb-mua
-  :type 'function)
 
 (defcustom ebdb-message-mail-as-name t
   "If non-nil use mail address of message as fallback for name of new records."
@@ -627,6 +611,25 @@ Currently no other MUAs support this EBDB feature."
     (when (and val (string-match regexp val))
       (throw 'done t))))
 
+(defsubst ebdb-mua-check-header (header-type address-parts &optional invert)
+  (let ((rest (if invert
+                 ebdb-ignore-header-alist
+               ebdb-accept-header-alist))
+       h-type)
+    (catch 'done
+      (dolist (elt rest)
+       (setq h-type (car elt))
+       (cond ((and (eq h-type 'subject)
+                   (eq header-type 'subject))
+              (when (ebdb-message-header-re "Subject" (cdr elt))
+                (throw 'done (if invert nil t))))
+             ((or (eq h-type header-type)
+                  (and (eq h-type 'any)
+                       (memq header-type '(sender recipients))))
+              (when (string-match-p (cdr elt) (cl-second address-parts))
+                (throw 'done (if invert nil t))))))
+      (throw 'done t))))
+
 (defun ebdb-mua-test-headers (header-type address-parts &optional 
ignore-address)
   "Decide if the address in ADDRESS-PARTS should be ignored or
   acted upon.  Return t if the header \"passes\".
@@ -656,25 +659,6 @@ variables `ebdb-user-mail-address-re',
                (and (ebdb-mua-check-header header-type address-parts)
                     (ebdb-mua-check-header header-type address-parts t)))))))
 
-(defsubst ebdb-mua-check-header (header-type address-parts &optional invert)
-  (let ((rest (if invert
-                 ebdb-ignore-header-alist
-               ebdb-accept-header-alist))
-       h-type)
-    (catch 'done
-      (dolist (elt rest)
-       (setq h-type (car elt))
-       (cond ((and (eq h-type 'subject)
-                   (eq header-type 'subject))
-              (when (ebdb-message-header-re "Subject" (cdr elt))
-                (throw 'done (if invert nil t))))
-             ((or (eq h-type header-type)
-                  (and (eq h-type 'any)
-                       (memq header-type '(sender recipients))))
-              (when (string-match-p (cdr elt) (second address-parts))
-                (throw 'done (if invert nil t))))))
-      (throw 'done t))))
-
 ;; How are you supposed to do the &context arglist for a defgeneric?
 (cl-defgeneric ebdb-message-header (header)
   "Get value of HEADER for the mua keyed to major-mode.")
diff --git a/ebdb-snarf.el b/ebdb-snarf.el
index b05c735..6b238f1 100644
--- a/ebdb-snarf.el
+++ b/ebdb-snarf.el
@@ -39,7 +39,7 @@
 
 ;;; Code:
 
-(require 'ebdb)
+(require 'ebdb-com)
 
 (defcustom ebdb-snarf-routines
   '((ebdb-field-mail 
"[[:blank:]([<\"]*\\([^[:space:]\":\n<address@hidden:[:space:])>\"\n]+\\)"))
diff --git a/ebdb.el b/ebdb.el
index dbf07a7..9c89fdc 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -4221,9 +4221,30 @@ If the domain part of a mail address matches this 
regexp, the domain
 is replaced by the substring that actually matched this address.
 
 Used by  `ebdb-canonicalize-mail-1'.  See also `ebdb-ignore-redundant-mails'."
-  :group 'ebdb-mua
+  :group 'ebdb-utilities
   :type '(regexp :tag "Regexp matching sites"))
 
+
+(defcustom ebdb-canonicalize-mail-function nil
+  "If non-nil, it should be a function of one arg: a mail address string.
+When EBDB is parsing mail addresses, the corresponding mail
+addresses are passed to this function first.  It acts as a kind
+of \"filter\" to transform the mail addresses before they are
+compared against or added to the database.  See
+`ebdb-canonicalize-mail-1' for a more complete example.  If this
+function returns nil, EBDB assumes that there is no mail address.
+
+See also `ebdb-ignore-redundant-mails'."
+  :group 'ebdb-utilities
+  :type 'function)
+
+(defcustom ebdb-message-clean-name-function 'ebdb-message-clean-name-default
+  "Function to clean up the name in the header of a message.
+It takes one argument, the name as extracted by
+`mail-extract-address-components'."
+  :group 'ebdb-utilities
+  :type 'function)
+
 (defun ebdb-canonicalize-mail-1 (address)
   "Example of `ebdb-canonicalize-mail-function'.
 However, this function is too specific to be useful for the general user.



reply via email to

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