[Top][All Lists]

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

[elpa] externals/ebdb 7a5ce18 13/15: Handle mail priority after customiz

From: Eric Abrahamsen
Subject: [elpa] externals/ebdb 7a5ce18 13/15: Handle mail priority after customization edits
Date: Sun, 1 Apr 2018 06:02:49 -0400 (EDT)

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

    Handle mail priority after customization edits
    * ebdb-com.el (eieio-done-customizing): New :after method to set
      record's mail priorities based on edits to this mail address. Split
      redisplay out into its own :after method, so it runs after this, as well.
 ebdb-com.el | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/ebdb-com.el b/ebdb-com.el
index ff6d447..ac96ad2 100644
--- a/ebdb-com.el
+++ b/ebdb-com.el
@@ -1733,8 +1733,29 @@ commands, called from an *EBDB* buffer, and the 
 (cl-defmethod eieio-done-customizing ((f ebdb-field))
   (let ((rec ebdb-custom-field-record))
     (when rec
-      (ebdb-record-insert-field rec f)
-      (ebdb-redisplay-records rec 'reformat t))))
+      (ebdb-record-insert-field rec f))))
+(cl-defmethod eieio-done-customizing :after ((f ebdb-field))
+  (ebdb-redisplay-records rec 'reformat t))
+(cl-defmethod eieio-done-customizing :after ((mail ebdb-field-mail))
+  "Handle mail priority after customizing.
+Check that some mail is marked as primary after MAIL is edited."
+  (let* ((rec ebdb-custom-field-record)
+        (all-mails (remove mail (ebdb-record-mail rec)))
+        (primaries (when rec (seq-filter
+                              (lambda (m)
+                                (eq (slot-value m 'priority) 'primary))
+                              all-mails)))
+        (prim (eq (slot-value mail 'priority) 'primary)))
+    (cond ((and prim primaries)
+          (dolist (p primaries)
+            (ebdb-record-change-field rec p (clone p :priority 'normal))))
+         ((and (null (or prim primaries))
+               (car-safe all-mails))
+          (ebdb-record-change-field
+           rec (car all-mails)
+           (clone (car all-mails) :priority 'primary))))))
 (defun ebdb-edit-foo (record field)

reply via email to

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