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

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

[elpa] externals/ebdb 9035da9 4/4: Provide more assistance in automatica


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb 9035da9 4/4: Provide more assistance in automatically creating role fields
Date: Mon, 12 Jul 2021 14:51:38 -0400 (EDT)

branch: externals/ebdb
commit 9035da9421be1da0707e327998b4b37d18ab9a90
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Eric Abrahamsen <eric@ericabrahamsen.net>

    Provide more assistance in automatically creating role fields
    
    * ebdb-com.el (ebdb-create-update-roles): New defcustom controlling
    whether EBDB "helps" or not. Defaults to t.
    (ebdb-com-insert-field): Check this option before running
    `ebdb-record-adopt-role-fields'. Do this work when adding a domain to
    an organization.
    (ebdb-record-insert-field): Also do the work when adding a mail field
    to a record.
    * ebdb.org (Role fields): Document.
    * ebdb.el: Bump to version 0.7.
---
 ebdb-com.el |  90 ++++++++++++++++++++++++++++++++++++++++++++++------
 ebdb.el     |   2 +-
 ebdb.info   | 104 ++++++++++++++++++++++++++++++++----------------------------
 ebdb.org    |  11 +++++--
 ebdb.texi   |  12 +++++--
 5 files changed, 157 insertions(+), 62 deletions(-)

diff --git a/ebdb-com.el b/ebdb-com.el
index 7b29d0d..5aa7807 100644
--- a/ebdb-com.el
+++ b/ebdb-com.el
@@ -93,6 +93,15 @@ Used by `ebdb-mouse-menu'."
   "Hook run after the *EBDB* is filled in."
   :type 'hook)
 
+(defcustom ebdb-create-update-roles t
+  "When non-nil, offer to create and/or update role fields for records.
+For instance, note when the domain field of a newly-created
+organization matches existing records' mail fields, and offer to
+create roles for those records, etc."
+  :group 'ebdb-record-edit
+  :type 'boolean
+  :version "0.7")
+
 ;; Faces for font-lock
 (defgroup ebdb-faces nil
   "Faces used by EBDB."
@@ -1852,18 +1861,81 @@ SLOTS, if present, is passed to any subsequent call to
 (cl-defmethod ebdb-com-insert-field :after ((record ebdb-record-person)
                                            (field ebdb-field-role)
                                            &optional _slots)
-  (let ((org (ebdb-gethash (slot-value field 'org-uuid) 'uuid)))
-    (when org
-      (ebdb-record-adopt-role-fields record org t))))
+  (when ebdb-create-update-roles
+    (let ((org (ebdb-gethash (slot-value field 'org-uuid) 'uuid)))
+      (when org
+       (ebdb-record-adopt-role-fields record org t)))))
 
 (cl-defmethod ebdb-com-insert-field :after ((org ebdb-record-organization)
-                                           (_field ebdb-field-domain)
+                                           (domain ebdb-field-domain)
                                            &optional _slot)
-  (let ((roles (gethash (ebdb-record-uuid org) ebdb-org-hashtable))
-       rec)
-    (dolist (r roles)
-      (setq rec (ebdb-gethash (slot-value r 'record-uuid) 'uuid))
-      (ebdb-record-adopt-role-fields rec org t))))
+  (when ebdb-create-update-roles
+    (let ((roles (gethash (ebdb-record-uuid org) ebdb-org-hashtable))
+         (matching-records (ebdb-search
+                            (ebdb-records)
+                            `((ebdb-field-mail
+                               ,(concat "@"
+                                        (regexp-quote (ebdb-string domain))
+                                        "\\'")))))
+         rec mail)
+      (dolist (r roles)
+       (setq rec (ebdb-gethash (slot-value r 'record-uuid) 'uuid)
+             matching-records (delete rec matching-records))
+       (ebdb-record-adopt-role-fields rec org t))
+      (dolist (m matching-records)
+       (when (y-or-n-p (format "Add role for %s at %s?"
+                               (ebdb-string m)
+                               (ebdb-string org)))
+         (setq mail (seq-find (lambda (m)
+                                (string-suffix-p (ebdb-string domain)
+                                                 (ebdb-string m)))
+                              (ebdb-record-mail m)))
+         (ebdb-record-insert-field
+          m (ebdb-read 'ebdb-field-role
+                       (list :org-uuid (ebdb-record-uuid org)
+                             :record-uuid (ebdb-record-uuid m)
+                             :mail mail)))
+         (ebdb-record-delete-field m mail 'mail))))))
+
+;; This is an `ebdb-record-insert-field', while the reverse action
+;; (creating role fields when an organization gets a new domain field)
+;; happens above as part of an `ebdb-com-insert-field' method.  The
+;; reason being, there are no automated procedures that might add a
+;; domain field to an organization: it can currently only happen in an
+;; ebdb-mode buffer as the result of an interactive command.  But mail
+;; fields can be added to person records during MUA updating or
+;; snarfing (which is when this automated process is really helpful),
+;; so it needs to happen on a lower-level method.  We keep the
+;; definition here, though, so as not to pollute ebdb.el with
+;; user-prompting behavior.
+(cl-defmethod ebdb-record-insert-field :around ((record ebdb-record-person)
+                                               (mail ebdb-field-mail)
+                                               &optional _slot)
+  "Maybe add role fields to RECORD.
+If the domain part of MAIL matches any the domain field of any
+existing organization, ask the user if they want to create a role
+field."
+  (if ebdb-create-update-roles
+      (let ((orgs (ebdb-search (ebdb-records)
+                              `((ebdb-field-domain
+                                 ,(nth 1 (split-string
+                                          (ebdb-string mail)
+                                          "@")))))))
+       (unless (seq-find
+                (lambda (org)
+                  (when (y-or-n-p
+                         (format "Add role for %s at %s?"
+                                 (ebdb-string record)
+                                 (ebdb-string org)))
+                    (ebdb-record-insert-field
+                     record (ebdb-read
+                             'ebdb-field-role
+                             (list :org-uuid (ebdb-record-uuid org)
+                                   :record-uuid (ebdb-record-uuid record)
+                                   :mail mail)))))
+                orgs)
+         (cl-call-next-method)))
+    (cl-call-next-method)))
 
 ;;;###autoload
 (defun ebdb-edit-field (record field)
diff --git a/ebdb.el b/ebdb.el
index 82742d0..7501a9e 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2016-2020  Free Software Foundation, Inc.
 
-;; Version: 0.6.24
+;; Version: 0.7
 ;; Package-Requires: ((emacs "25.1") (cl-lib "0.5") (seq "2.15"))
 
 ;; Maintainer: Eric Abrahamsen <eric@ericabrahamsen.net>
diff --git a/ebdb.info b/ebdb.info
index b727b36..9f5c9de 100644
--- a/ebdb.info
+++ b/ebdb.info
@@ -564,10 +564,17 @@ very welcome.
    It can often feel a little clunky creating a new organization to
 associate with a person, or vice versa.  EBDB provides a convenience
 function to create a new person or organization record, and associate it
-with the existing record under point, in one step, using the ‘F’.  This
-will create a new organization if point is on a person record, or a new
+with the existing record under point, in one step, using ‘R’.  This will
+create a new organization if point is on a person record, or a new
 person if point is on an organization.
 
+   Lastly, EBDB will try to assist in creating role fields where it
+seems helpful.  When adding mail fields to person records, or domain
+fields to organization records, it will check if the mail or domain
+seems to match any existing records, and offer to create the
+corresponding role fields.  This behavior is enabled by default; set
+‘ebdb-create-update-roles’ to nil to disable it.
+
 
 File: ebdb.info,  Node: Tag field,  Next: Mail folder field,  Prev: Role 
fields,  Up: Field Types
 
@@ -2453,6 +2460,7 @@ File: ebdb.info,  Node: Index,  Prev: Hacking EBDB,  Up: 
Top
 * ebdb-create-record-extended:           Creating Records.    (line  14)
 * ebdb-create-record-extended <1>:       The Basics of ebdb-mode.
                                                               (line  26)
+* ebdb-create-update-roles:              Role fields.         (line  40)
 * ebdb-dedicated-window:                 Customizing Record Display.
                                                               (line  19)
 * ebdb-default-address-class:            Hacking EBDB.        (line  43)
@@ -2763,52 +2771,52 @@ Node: Editing Existing Fields14916
 Node: Deleting Records and Fields15516
 Node: Field Types15912
 Node: Role fields18198
-Node: Tag field20179
-Node: Mail folder field20748
-Node: MUA Interaction21076
-Node: Loading MUA Code21629
-Node: Display and Updating22342
-Node: Pop-up Buffers23108
-Node: Auto-Updating Records25958
-Node: Noticing and Automatic Rules30752
-Node: Interactive Commands32574
-Node: EBDB and MUA summary buffers35048
-Node: Sender name display35566
-Node: Summary buffer marks36793
-Node: Mail Address Completion37972
-Node: A Note on Completion40481
-Node: Specific MUAs41104
-Node: Gnus41252
-Node: Posting Styles41474
-Node: EBDB Buffers43030
-Node: Searching44241
-Node: Changing Search Behavior45955
-Node: The Basics of ebdb-mode47202
-Node: Customizing Record Display51550
-Node: Marking55870
-Node: Exporting/Formatting56297
-Node: Completion57232
-Node: Snarfing58028
-Node: Internationalization60045
-Node: Diary Integration62746
-Node: Mail Aliases63611
-Node: vCard Support64325
-Node: Org Integration64824
-Node: Citing Records66722
-Node: Hacking EBDB67480
-Node: Field Classes70073
-Node: Init and Delete Methods73254
-Node: Manipulating Field Data Programmatically74778
-Node: The Labeled Field Class76490
-Node: The Singleton Field Class77361
-Node: Actions77799
-Node: Custom Field Searching78471
-Node: Fast Lookups81338
-Node: Formatting in the EBDB Buffer83148
-Node: Writing Internationalization Libraries85224
-Node: Writing Integration For New MUAs89640
-Node: Article snarfing93088
-Node: Index93806
+Node: Tag field20564
+Node: Mail folder field21133
+Node: MUA Interaction21461
+Node: Loading MUA Code22014
+Node: Display and Updating22727
+Node: Pop-up Buffers23493
+Node: Auto-Updating Records26343
+Node: Noticing and Automatic Rules31137
+Node: Interactive Commands32959
+Node: EBDB and MUA summary buffers35433
+Node: Sender name display35951
+Node: Summary buffer marks37178
+Node: Mail Address Completion38357
+Node: A Note on Completion40866
+Node: Specific MUAs41489
+Node: Gnus41637
+Node: Posting Styles41859
+Node: EBDB Buffers43415
+Node: Searching44626
+Node: Changing Search Behavior46340
+Node: The Basics of ebdb-mode47587
+Node: Customizing Record Display51935
+Node: Marking56255
+Node: Exporting/Formatting56682
+Node: Completion57617
+Node: Snarfing58413
+Node: Internationalization60430
+Node: Diary Integration63131
+Node: Mail Aliases63996
+Node: vCard Support64710
+Node: Org Integration65209
+Node: Citing Records67107
+Node: Hacking EBDB67865
+Node: Field Classes70458
+Node: Init and Delete Methods73639
+Node: Manipulating Field Data Programmatically75163
+Node: The Labeled Field Class76875
+Node: The Singleton Field Class77746
+Node: Actions78184
+Node: Custom Field Searching78856
+Node: Fast Lookups81723
+Node: Formatting in the EBDB Buffer83533
+Node: Writing Internationalization Libraries85609
+Node: Writing Integration For New MUAs90025
+Node: Article snarfing93473
+Node: Index94191
 
 End Tag Table
 
diff --git a/ebdb.org b/ebdb.org
index 6db0225..e58a8b3 100644
--- a/ebdb.org
+++ b/ebdb.org
@@ -407,10 +407,17 @@ Suggestions are very welcome.
 It can often feel a little clunky creating a new organization to
 associate with a person, or vice versa.  EBDB provides a convenience
 function to create a new person or organization record, and associate
-it with the existing record under point, in one step, using the
-{{{kbd(F)}}}.  This will create a new organization if point is on a
+it with the existing record under point, in one step, using
+{{{kbd(R)}}}.  This will create a new organization if point is on a
 person record, or a new person if point is on an organization.
 
+#+VINDEX: ebdb-create-update-roles
+Lastly, EBDB will try to assist in creating role fields where it seems
+helpful.  When adding mail fields to person records, or domain fields
+to organization records, it will check if the mail or domain seems to
+match any existing records, and offer to create the corresponding role
+fields.  This behavior is enabled by default; set
+~ebdb-create-update-roles~ to nil to disable it.
 *** Tag field
 :PROPERTIES:
 :ID:       d9073bc7-8731-4919-9fc0-7d1dcf98426e
diff --git a/ebdb.texi b/ebdb.texi
index fa44a31..be21c45 100644
--- a/ebdb.texi
+++ b/ebdb.texi
@@ -602,10 +602,18 @@ Suggestions are very welcome.
 It can often feel a little clunky creating a new organization to
 associate with a person, or vice versa.  EBDB provides a convenience
 function to create a new person or organization record, and associate
-it with the existing record under point, in one step, using the
-@kbd{F}.  This will create a new organization if point is on a
+it with the existing record under point, in one step, using
+@kbd{R}.  This will create a new organization if point is on a
 person record, or a new person if point is on an organization.
 
+@vindex ebdb-create-update-roles
+Lastly, EBDB will try to assist in creating role fields where it seems
+helpful.  When adding mail fields to person records, or domain fields
+to organization records, it will check if the mail or domain seems to
+match any existing records, and offer to create the corresponding role
+fields.  This behavior is enabled by default; set
+@code{ebdb-create-update-roles} to nil to disable it.
+
 @node Tag field
 @subsection Tag field
 



reply via email to

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