branch: externals/ebdb commit 4bb77e377f04ac26ab0b743a9d0a46fd2d14ab1a Author: Eric Abrahamsen <e...@ericabrahamsen.net> Commit: Eric Abrahamsen <e...@ericabrahamsen.net>
Add mail deletion behavior * ebdb.el (ebdb-record-delete-field): If deleting a record mail leaves no primary mail address, set the first of the remaining mails as primary. --- ebdb.el | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ebdb.el b/ebdb.el index 613660b..e23e294 100644 --- a/ebdb.el +++ b/ebdb.el @@ -3025,9 +3025,21 @@ If FIELD doesn't specify a year, use the current year." "Possibly set the priority of a newly-added mail address. If RECORD has no other primary mail, set MAIL's priority to primary." - (when (null (object-assoc 'primary 'priority (ebdb-record-mail record))) + (when (null (object-assoc 'primary 'priority (ebdb-record-mail record t))) (setf (slot-value mail 'priority) 'primary))) +(cl-defmethod ebdb-record-delete-field :after ((record ebdb-record-entity) + (mail ebdb-field-mail) + &optional _slot) + "Possibly alter the priority of RECORD's remaining mails. +If there aren't any other primary mails, make the first of the +remaining mails primary." + (let* ((mails (remove mail (ebdb-record-mail record))) + (clone (unless (object-assoc 'primary 'priority mails) + (clone (car mails))))) + (when clone + (ebdb-record-change-field record (car mails) clone)))) + (defun ebdb-compose-mail (&rest args) "Start composing a mail message to send. ARGS is passed to `compose-mail'."