branch: externals/org-contacts
commit 3a592c71b5352f36d3584b393841b4c6a2adb638
Author: stardiviner <numbch...@gmail.com>
Commit: stardiviner <numbch...@gmail.com>

    Contacts may be unintentionally excluded from the database
    
    if a diary sexp calls `org-contacts-db' when a skip function is set.
---
 org-contacts.el      |  2 +-
 test-org-contacts.el | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/org-contacts.el b/org-contacts.el
index fdc4130935..8c0e815ae5 100644
--- a/org-contacts.el
+++ b/org-contacts.el
@@ -268,7 +268,7 @@ buffer."
   "Return the latest Org Contacts Database."
   (let* ((org--matcher-tags-todo-only nil)
          (contacts-matcher (cdr (org-make-tags-matcher org-contacts-matcher)))
-         result)
+         result org-agenda-skip-function org-agenda-skip-function-global)
     (when (org-contacts-db-need-update-p)
       (let ((progress-reporter
              (make-progress-reporter "Updating Org Contacts Database..." 0 
(length (org-contacts-files))))
diff --git a/test-org-contacts.el b/test-org-contacts.el
index a2de7493c2..7d59906781 100644
--- a/test-org-contacts.el
+++ b/test-org-contacts.el
@@ -63,6 +63,43 @@
 ;;       (match-string 1 pvalue)
 ;;     pvalue))
 
+(ert-deftest ert-test-org-contacts-do-not-skip-during-update ()
+  "The value of `org-agenda-skip-function-global' should not cause
+org-contacts to skip contacts while updating the database."
+  (let ((org-contacts-files (list (make-temp-file "ert-test-org-contacts" nil 
".org")))
+        (org-agenda-skip-function-global
+         (lambda ()
+           (org-agenda-skip-entry-if 'regexp "Smith")))
+        (org-agenda-skip-function
+         (lambda ()
+           (org-agenda-skip-entry-if 'regexp "Henry"))))
+    (with-temp-file (car org-contacts-files)
+      (insert "\
+* John Doe
+:PROPERTIES:
+:EMAIL: j...@example.com
+:END:\n")
+      (insert "\
+* John Smith
+:PROPERTIES:
+:EMAIL: jsm...@example.com
+:END:\n")
+      (insert "\
+* Jon Henry
+:PROPERTIES:
+:EMAIL: jhe...@example.com
+:END:\n"))
+    (should
+     (seq-some (lambda (contact)
+                 (string= "John Smith"
+                          (car contact)))
+               (org-contacts-db)))
+    (should
+     (seq-some (lambda (contact)
+                 (string= "Jon Henry"
+                          (car contact)))
+               (org-contacts-db)))))
+
 
 
 (provide 'test-org-contacts)

Reply via email to