Merge branch 'master' of http://git.gnus.org/gnus into SYgnus
[gnus] / lisp / legacy-gnus-agent.el
index 16b0cf6..7293e33 100644 (file)
@@ -1,10 +1,37 @@
+;;; gnus-agent.el --- Legacy unplugged support for Gnus
+
+;; Copyright (C) 2004-2016 Free Software Foundation, Inc.
+
+;; Author: Kevin Greiner <kgreiner@xpediantsolutions.com>
+;; Keywords: news
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Conversion functions for the Agent.
+
+;;; Code:
 (require 'gnus-start)
 (require 'gnus-util)
 (require 'gnus-range)
 (require 'gnus-agent)
 
 (require 'gnus-start)
 (require 'gnus-util)
 (require 'gnus-range)
 (require 'gnus-agent)
 
-; Oort Gnus v0.08 - This release updated agent to no longer use
-;                   history file and to support a compressed alist.
+;; Oort Gnus v0.08 - This release updated agent to no longer use
+;;                   history file and to support a compressed alist.
 
 (defvar gnus-agent-compressed-agentview-search-only nil)
 
 
 (defvar gnus-agent-compressed-agentview-search-only nil)
 
@@ -25,7 +52,7 @@ converted to the compressed format."
              ((file-directory-p member)
               (push member search-in))
               ((equal (file-name-nondirectory member) ".agentview")
              ((file-directory-p member)
               (push member search-in))
               ((equal (file-name-nondirectory member) ".agentview")
-               (setq converted-something 
+               (setq converted-something
                      (or (gnus-agent-convert-agentview member)
                          converted-something))))))
 
                      (or (gnus-agent-convert-agentview member)
                          converted-something))))))
 
@@ -81,23 +108,20 @@ converted to the compressed format."
            (throw 'found-file-to-convert t))
 
           (erase-buffer)
            (throw 'found-file-to-convert t))
 
           (erase-buffer)
-          (let ((compressed nil))
-            (mapcar (lambda (pair)
-                      (let* ((article-id (car pair))
-                             (day-of-download (cdr pair))
-                             (comp-list (assq day-of-download compressed)))
-                        (if comp-list
-                            (setcdr comp-list
-                                    (cons article-id (cdr comp-list)))
-                          (setq compressed
-                                (cons (list day-of-download article-id)
-                                      compressed)))
-                        nil)) alist)
-            (mapcar (lambda (comp-list)
-                      (setcdr comp-list
-                              (gnus-compress-sequence
-                               (nreverse (cdr comp-list)))))
-                    compressed)
+          (let (article-id day-of-download comp-list compressed)
+           (while alist
+             (setq article-id (caar alist)
+                   day-of-download (cdar alist)
+                   comp-list (assq day-of-download compressed)
+                   alist (cdr alist))
+             (if comp-list
+                 (setcdr comp-list (cons article-id (cdr comp-list)))
+               (push (list day-of-download article-id) compressed)))
+           (setq alist compressed)
+           (while alist
+             (setq comp-list (pop alist))
+             (setcdr comp-list
+                     (gnus-compress-sequence (nreverse (cdr comp-list)))))
             (princ compressed (current-buffer)))
           (insert "\n2\n")
           (write-file file)
             (princ compressed (current-buffer)))
           (insert "\n2\n")
           (write-file file)
@@ -123,14 +147,19 @@ converted to the compressed format."
             (insert "The definition of gnus-agent-expire-days has been changed.\nYou currently have it set to the list:\n  ")
             (gnus-pp gnus-agent-expire-days)
 
             (insert "The definition of gnus-agent-expire-days has been changed.\nYou currently have it set to the list:\n  ")
             (gnus-pp gnus-agent-expire-days)
 
-            (insert "\nIn order to use version '" converting-to "' of gnus, you will need to set\n")
+           (insert
+            (gnus-format-message
+             "\nIn order to use version `%s' of gnus, you will need to set\n"
+             converting-to))
             (insert "gnus-agent-expire-days to an integer. If you still wish to set different\n")
             (insert "expiration days to individual groups, you must instead set the\n")
             (insert "gnus-agent-expire-days to an integer. If you still wish to set different\n")
             (insert "expiration days to individual groups, you must instead set the\n")
-            (insert "'agent-days-until-old group and/or topic parameter.\n")
+            (insert (gnus-format-message
+                    "`agent-days-until-old' group and/or topic parameter.\n"))
             (insert "\n")
             (insert "If you would like, gnus can iterate over every group comparing its name to the\n")
             (insert "regular expressions that you currently have in gnus-agent-expire-days.  When\n")
             (insert "\n")
             (insert "If you would like, gnus can iterate over every group comparing its name to the\n")
             (insert "regular expressions that you currently have in gnus-agent-expire-days.  When\n")
-            (insert "gnus finds a match, it will update that group's 'agent-days-until-old group\n")
+            (insert (gnus-format-message
+                    "gnus finds a match, it will update that group's `agent-days-until-old' group\n"))
             (insert "parameter to the value associated with the regular expression.\n")
             (insert "\n")
             (insert "Whether gnus assigns group parameters, or not, gnus will terminate with an\n")
             (insert "parameter to the value associated with the regular expression.\n")
             (insert "\n")
             (insert "Whether gnus assigns group parameters, or not, gnus will terminate with an\n")
@@ -162,7 +191,7 @@ converted to the compressed format."
                                                                (when (eq 0 (string-match
                                                                             (caar days)
                                                                             group))
                                                                (when (eq 0 (string-match
                                                                             (caar days)
                                                                             group))
-                                                                 (throw 'found (cadar days)))
+                                                                 (throw 'found (cadr (car days))))
                                                                (setq days (cdr days)))
                                                              nil)))
                                                  (when day
                                                                (setq days (cdr days)))
                                                              nil)))
                                                  (when day
@@ -175,36 +204,38 @@ converted to the compressed format."
                                   (t
                                    t))))))
         (kill-buffer buffer))
                                   (t
                                    t))))))
         (kill-buffer buffer))
-      (error "Change gnus-agent-expire-days to an integer for gnus to start."))))
+      (error "Change gnus-agent-expire-days to an integer for gnus to start"))))
 
 ;; The gnus-agent-unlist-expire-days has its own conversion prompt.
 ;; Therefore, hide the default prompt.
 (gnus-convert-mark-converter-prompt 'gnus-agent-unlist-expire-days t)
 
 (defun gnus-agent-unhook-expire-days (converting-to)
 
 ;; The gnus-agent-unlist-expire-days has its own conversion prompt.
 ;; Therefore, hide the default prompt.
 (gnus-convert-mark-converter-prompt 'gnus-agent-unlist-expire-days t)
 
 (defun gnus-agent-unhook-expire-days (converting-to)
-  "Remove every lambda from gnus-group-prepare-hook that mention the
-symbol gnus-agent-do-once in their definition.  This should NOT be
+  "Remove every lambda from `gnus-group-prepare-hook' that mention the
+symbol `gnus-agent-do-once' in their definition.  This should NOT be
 necessary as gnus-agent.el no longer adds them.  However, it is
 possible that the hook was persistently saved."
 necessary as gnus-agent.el no longer adds them.  However, it is
 possible that the hook was persistently saved."
-    (let ((h t)) ; iterate from bgn of hook
+    (let ((h t)) ; Iterate from bgn of hook.
       (while h
         (let ((func (progn (when (eq h t)
       (while h
         (let ((func (progn (when (eq h t)
-                             ;; init h to list of functions
+                             ;; Init h to list of functions.
                              (setq h (cond ((listp gnus-group-prepare-hook)
                                             gnus-group-prepare-hook)
                                            ((boundp 'gnus-group-prepare-hook)
                                             (list gnus-group-prepare-hook)))))
                            (pop h))))
 
                              (setq h (cond ((listp gnus-group-prepare-hook)
                                             gnus-group-prepare-hook)
                                            ((boundp 'gnus-group-prepare-hook)
                                             (list gnus-group-prepare-hook)))))
                            (pop h))))
 
-          (when (cond ((eq (type-of func) 'compiled-function)
-                       ;; Search def. of compiled function for gnus-agent-do-once string
-                       (let* (definition 
-                               print-level 
+          (when (cond ((byte-code-function-p func)
+                       ;; Search def. of compiled function for
+                       ;; gnus-agent-do-once string.
+                       (let* (definition
+                               print-level
                                print-length
                                (standard-output
                                 (lambda (char)
                                   (setq definition (cons char definition)))))
                                print-length
                                (standard-output
                                 (lambda (char)
                                   (setq definition (cons char definition)))))
-                         (princ func) ; populates definition with reversed list of characters
+                         (princ func) ; Populates definition with reversed list
+                                     ; of characters.
                          (let* ((i (length definition))
                                 (s (make-string i 0)))
                            (while definition
                          (let* ((i (length definition))
                                 (s (make-string i 0)))
                            (while definition
@@ -212,7 +243,7 @@ possible that the hook was persistently saved."
 
                            (string-match "\\bgnus-agent-do-once\\b" s))))
                       ((listp func)
 
                            (string-match "\\bgnus-agent-do-once\\b" s))))
                       ((listp func)
-                       (eq (cadr (nth 2 func)) 'gnus-agent-do-once) ; handles eval'd lambda
+                       (eq (cadr (nth 2 func)) 'gnus-agent-do-once) ; Handles eval'd lambda.
                        ))
 
             (remove-hook 'gnus-group-prepare-hook func)
                        ))
 
             (remove-hook 'gnus-group-prepare-hook func)
@@ -224,4 +255,6 @@ possible that the hook was persistently saved."
 ;; the .newsrc.eld file.
 (gnus-convert-mark-converter-prompt 'gnus-agent-unhook-expire-days t)
 
 ;; the .newsrc.eld file.
 (gnus-convert-mark-converter-prompt 'gnus-agent-unhook-expire-days t)
 
-;;; arch-tag: 845c7b8a-88f7-4468-b8d7-94e8fc72cf1a
+(provide 'legacy-gnus-agent)
+
+;;; legacy-gnus-agent.el ends here