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

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

[elpa] externals/gnorb a370e64 372/449: Rename msg-id-to-group to msg-id


From: Stefan Monnier
Subject: [elpa] externals/gnorb a370e64 372/449: Rename msg-id-to-group to msg-id-request-head, refactor
Date: Fri, 27 Nov 2020 23:16:14 -0500 (EST)

branch: externals/gnorb
commit a370e64d2813d0273e9784cdb79879bab28d9170
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    Rename msg-id-to-group to msg-id-request-head, refactor
    
    * packages/gnorb/gnorb-utils.el (gnorb-msg-id-request-head): Renaming
      because it now always calls gnus-request-head, and always returns
      the full return value of that call (as well as setting the registry
      group key). Callers that don't want to use Gnus to verify
      group/article can just access the group key. Also now calls
      gnus-activate-group in an attempt to get it to quit querying about
      number of articles to get from group.
      (gnorb-msg-id-to-link): Change call. This is one of the functions
      that might just use the group key instead of doing the full lookup.
    * packages/gnorb/nngnorb.el (nnir-run-gnorb): Refactor and simplify.
      Now we aren't calling gnus-request-head twice for each message.
---
 gnorb-registry.el |  2 +-
 gnorb-utils.el    | 39 +++++++++++++++++++--------------------
 nngnorb.el        | 33 +++++++++++----------------------
 3 files changed, 31 insertions(+), 43 deletions(-)

diff --git a/gnorb-registry.el b/gnorb-registry.el
index 2b3912c..05f91f5 100644
--- a/gnorb-registry.el
+++ b/gnorb-registry.el
@@ -297,7 +297,7 @@ your Org files."
            ;; and set that value on the registry entry if it can find
            ;; it.
            (unless (gnus-registry-get-id-key p 'group)
-             (gnorb-msg-id-to-group p))
+             (gnorb-msg-id-request-head p))
            (cl-incf count)))))
      gnorb-org-find-candidates-match
      'agenda 'archive 'comment)
diff --git a/gnorb-utils.el b/gnorb-utils.el
index f4a0aff..ae51a59 100644
--- a/gnorb-utils.el
+++ b/gnorb-utils.el
@@ -488,14 +488,14 @@ and 'gnus."
 (defun gnorb-msg-id-to-link (msg-id)
   "Given a message id, try to create a full org link to the
 message."
-  (let ((server-group (gnorb-msg-id-to-group msg-id)))
+  (let ((server-group (car (gnorb-msg-id-request-head msg-id))))
     (when server-group
       (org-link-escape
        (concat server-group "#"
               (gnorb-unbracket-message-id msg-id))))))
 
-(defun gnorb-msg-id-to-group (msg-id)
-  "Given a message id, try to find the group it's in.
+(defun gnorb-msg-id-request-head (msg-id)
+  "Given a message id, try to find its group and article number.
 
 So far we're checking the registry, then the groups in
 `gnorb-gnus-sent-groups'. Use search engines? Other clever
@@ -504,23 +504,22 @@ methods?"
     (setq msg-id (gnorb-bracket-message-id msg-id))
     (catch 'found
       (when gnorb-tracking-enabled
-       (setq candidates (gnus-registry-get-id-key msg-id 'group))
-       (if (= 1 (length candidates))
-           (throw 'found (car candidates))
-         (setq candidates (append candidates gnorb-gnus-sent-groups))
-         (while (setq server-group (pop candidates))
-           (when (and (stringp server-group)
-                      (string-match-p "+" server-group)
-                      (not
-                       (string-match-p
-                        "\\(nnir\\|nnvirtual\\|UNKNOWN\\)"
-                        server-group))
-                      (setq check
-                            (ignore-errors
-                              (gnus-request-head msg-id server-group))))
-
-             (gnus-registry-set-id-key msg-id 'group (list server-group))
-             (throw 'found (car check))))))
+       (setq candidates (append (gnus-registry-get-id-key msg-id 'group)
+                                gnorb-gnus-sent-groups))
+       (while (setq server-group (pop candidates))
+         (when (and (stringp server-group)
+                    (string-match-p "+" server-group)
+                    (not
+                     (string-match-p
+                      "\\(nnir\\|nnvirtual\\|UNKNOWN\\)"
+                      server-group))
+                    (gnus-activate-group server-group)
+                    (setq check
+                          (ignore-errors
+                            (gnus-request-head msg-id server-group))))
+
+           (gnus-registry-set-id-key msg-id 'group (list server-group))
+           (throw 'found (cons server-group (cdr check))))))
       nil)))
 
 (defun gnorb-collect-ids (&optional id)
diff --git a/nngnorb.el b/nngnorb.el
index 172dbab..a0e8f8c 100644
--- a/nngnorb.el
+++ b/nngnorb.el
@@ -78,7 +78,7 @@ be scanned for gnus messages, and those messages displayed."
   (save-window-excursion
     (let ((q (cdr (assq 'query query)))
          (buf (get-buffer-create nnir-tmp-buffer))
-         msg-ids org-ids links messages vectors)
+         msg-ids org-ids links vectors)
       (with-current-buffer buf
        (erase-buffer)
        (setq nngnorb-attachment-file-list nil))
@@ -139,34 +139,23 @@ be scanned for gnus messages, and those messages 
displayed."
                     (nth 1 (split-string link "#"))))
              messages))
 
+      (unless (gnus-alive-p)
+       (gnus))
+
       ;; Then use the registry to turn list of org-ids into list of
       ;; msg-ids.
       (dolist (i (delq nil (delete-dups org-ids)))
        (when-let ((rel-msg-id (gnorb-registry-org-id-search i)))
          (setq msg-ids (append (delq nil rel-msg-id) msg-ids))))
 
-      ;; Then find the group for each msg-id, and add the results to
-      ;; messages.
+      ;; Then find the group and article number for each msg-id, and
+      ;; push that onto our return value "vectors".
       (when msg-ids
-       (dolist (id (delete-dups msg-ids))
-         (when-let ((group (gnorb-msg-id-to-group id)))
-           (push (list group id) messages))))
-
-      (setq messages (sort messages (lambda (l r)
-                                     (string< (car l) (car r)))))
-
-      (unless (gnus-alive-p)
-       (gnus))
-
-      (dolist (m messages (when vectors
-                           (reverse vectors)))
-       (let ((artno
-              (cdr-safe (ignore-errors
-                          (gnus-request-head
-                           (nth 1 m) (car m))))))
-
-         (when (and artno (integerp artno) (> artno 0))
-           (push (vector (car m) artno 100) vectors)))))))
+       (dolist (id (delete-dups msg-ids) (when vectors
+                                           (nreverse vectors)))
+         (pcase-let ((`(,group . ,artno) (gnorb-msg-id-request-head id)))
+           (when (and artno (integerp artno) (> artno 0))
+             (push (vector group artno 100) vectors))))))))
 
 (defvar gnorb-summary-minor-mode-map (make-sparse-keymap)
   "Keymap for use in Gnorb's *Summary* minor mode.")



reply via email to

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