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

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

[elpa] externals/gnorb 6653b6c 187/449: Fix gnorb-tracking-initialize


From: Stefan Monnier
Subject: [elpa] externals/gnorb 6653b6c 187/449: Fix gnorb-tracking-initialize
Date: Fri, 27 Nov 2020 23:15:36 -0500 (EST)

branch: externals/gnorb
commit 6653b6cf1dbf4f383e9b8c396671c52bf6d15327
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Eric Abrahamsen <eric@ericabrahamsen.net>

    Fix gnorb-tracking-initialize
    
    * lisp/gnorb-utils.el (gnorb-tracking-initialize): Needs to be put into
      the gnus-started-hook in order to work properly.
---
 lisp/gnorb-registry.el | 18 +++++++++++++++++-
 lisp/gnorb-utils.el    | 15 ++++++++++-----
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/lisp/gnorb-registry.el b/lisp/gnorb-registry.el
index 95f24c5..3c4da22 100644
--- a/lisp/gnorb-registry.el
+++ b/lisp/gnorb-registry.el
@@ -88,15 +88,31 @@ to the message's registry entry, under the 'gnorb-ids key."
               (memq major-mode '(gnus-summary-mode gnus-article-mode)))
             (not org-note-abort))
     (let* ((msg-id
-           (concat "<" (plist-get org-store-link-plist :message-id) ">"))
+           (format "<%s>" (plist-get org-store-link-plist :message-id)))
           (entry (gnus-registry-get-or-make-entry msg-id))
           (org-ids
            (gnus-registry-get-id-key msg-id 'gnorb-ids))
           (new-org-id (org-id-get-create)))
+      (plist-put org-capture-plist :gnorb-id new-org-id)
       (setq org-ids (cons new-org-id org-ids))
       (setq org-ids (delete-dups org-ids))
       (gnus-registry-set-id-key msg-id 'gnorb-ids org-ids))))
 
+
+(defun gnorb-registry-capture-abort-cleanup ()
+  (when (and (org-capture-get :gnorb-id)
+            org-note-abort)
+    (condition-case error
+       (let* ((msg-id (format "<%s>" (plist-get org-store-link-plist 
:message-id)))
+              (existing-org-ids (gnus-registry-get-id-key msg-id 'gnorb-ids))
+              (org-id (org-capture-get :gnorb-id)))
+         (when (member org-id existing-org-ids)
+           (gnus-registry-set-id-key msg-id 'gnorb-ids
+                                     (remove org-id existing-org-ids)))
+         (setq abort-note 'clean))
+      (error
+       (setq abort-note 'dirty)))))
+
 (defun gnorb-find-visit-candidates (ids)
   "For all message-ids in IDS (which should be a list of
 Message-ID strings, with angle brackets), produce a list of Org
diff --git a/lisp/gnorb-utils.el b/lisp/gnorb-utils.el
index 7d598a8..669763f 100644
--- a/lisp/gnorb-utils.el
+++ b/lisp/gnorb-utils.el
@@ -262,11 +262,16 @@ Gnus messages and Org headings. This requires that the 
Gnus
 registry be in use, and should be called after the call to
 `gnus-registry-initialize'."
   (require 'gnorb-registry)
-  (unless (gnus-registry-install-p)
-    (user-error "Gnorb tracking requires that the Gnus registry be 
installed."))
-  (add-to-list 'gnus-registry-extra-entries-precious 'gnorb-ids)
-  (add-hook 'org-capture-prepare-finalize-hook 'gnorb-registry-capture)
-  (setq gnorb-tracking-enabled t))
+  (add-hook
+   'gnus-started-hook
+   (lambda ()
+     (unless (gnus-registry-install-p)
+       (user-error "Gnorb tracking requires that the Gnus registry be 
installed."))
+     (add-to-list 'gnus-registry-extra-entries-precious 'gnorb-ids)
+     (add-to-list 'gnus-registry-track-extra 'gnorb-ids)
+     (add-hook 'org-capture-mode-hook 'gnorb-registry-capture)
+     (add-hook 'org-capture-prepare-finalize-hook 
'gnorb-registry-capture-abort-cleanup)
+     (setq gnorb-tracking-enabled t))))
 
 (provide 'gnorb-utils)
 ;;; gnorb-utils.el ends here



reply via email to

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