]> code.delx.au - gnu-emacs/blobdiff - lisp/gnus/gnus-sync.el
nnimap.el: Fix inloop if the server dies before the async -finish is called
[gnu-emacs] / lisp / gnus / gnus-sync.el
index c704ed73ff8d37fd7ab5f45f9dec8136d87ddcc8..6efd34e1596b50d5a46d9fc52492d70a91cc4cea 100644 (file)
@@ -1,6 +1,6 @@
 ;;; gnus-sync.el --- synchronization facility for Gnus
 
-;; Copyright (C) 2010  Free Software Foundation, Inc.
+;; Copyright (C) 2010-2012  Free Software Foundation, Inc.
 
 ;; Author: Ted Zlatanov <tzz@lifelogs.com>
 ;; Keywords: news synchronization nntp nnrss
 
 ;; This is the gnus-sync.el package.
 
+;; It's due for a rewrite using gnus-after-set-mark-hook and
+;; gnus-before-update-mark-hook, and my plan is to do this once No
+;; Gnus development is done.  Until then please consider it
+;; experimental.
+
 ;; Put this in your startup file (~/.gnus.el for instance)
 
 ;; possibilities for gnus-sync-backend:
 
 ;; TODO:
 
-;; - after gnus-sync-read, the message counts are wrong
+;; - after gnus-sync-read, the message counts are wrong.  So it's not
+;;   run automatically, you have to call it with M-x gnus-sync-read
+
+;; - use gnus-after-set-mark-hook and gnus-before-update-mark-hook to
+;;   catch the mark updates
 
 ;;; Code:
 
 (eval-when-compile (require 'cl))
+(require 'gnus)
+(require 'gnus-start)
 (require 'gnus-util)
 
 (defgroup gnus-sync nil
@@ -95,20 +106,16 @@ synchronized, I believe).  Also see `gnus-variable-list'."
     ;; populate gnus-sync-newsrc-loader from all but the first dummy
     ;; entry in gnus-newsrc-alist whose group matches any of the
     ;; gnus-sync-newsrc-groups
-    (let* ((loader
-            (loop for entry in (cdr gnus-newsrc-alist)
-                  when (gnus-grep-in-list
-                        (car entry)     ;the group name
-                        gnus-sync-newsrc-groups)
-                  collect (cons (car entry)
-                                (mapcar (lambda (offset)
-                                          (cons offset (nth offset entry)))
-                                        gnus-sync-newsrc-offsets))))
-           (gnus-sync-newsrc-loader
-            (nunion gnus-sync-newsrc-loader
-                    (set-difference gnus-sync-newsrc-loader loader :key 'car)
-                    :key 'car)))
-
+    ;; TODO: keep the old contents for groups we don't have!
+    (let ((gnus-sync-newsrc-loader
+           (loop for entry in (cdr gnus-newsrc-alist)
+                 when (gnus-grep-in-list
+                       (car entry)     ;the group name
+                       gnus-sync-newsrc-groups)
+                 collect (cons (car entry)
+                               (mapcar (lambda (offset)
+                                         (cons offset (nth offset entry)))
+                                       gnus-sync-newsrc-offsets)))))
       (with-temp-file gnus-sync-backend
         (progn
           (let ((coding-system-for-write gnus-ding-file-coding-system)
@@ -128,13 +135,16 @@ synchronized, I believe).  Also see `gnus-variable-list'."
                                     gnus-sync-global-vars))
                    variable)
               (while variables
-                (when (and (boundp (setq variable (pop variables)))
+                (if (and (boundp (setq variable (pop variables)))
                            (symbol-value variable))
-                  (princ "\n(setq ")
-                  (princ (symbol-name variable))
-                  (princ " '")
-                  (prin1 (symbol-value variable))
-                  (princ ")\n"))))
+                    (progn
+                      (princ "\n(setq ")
+                      (princ (symbol-name variable))
+                      (princ " '")
+                      (prin1 (symbol-value variable))
+                      (princ ")\n"))
+                  (princ "\n;;; skipping empty variable ")
+                  (princ (symbol-name variable)))))
             (gnus-message
              7
              "gnus-sync: stored variables %s and %d groups in %s"
@@ -212,13 +222,13 @@ synchronized, I believe).  Also see `gnus-variable-list'."
   "Install the sync hooks."
   (interactive)
   ;; (add-hook 'gnus-get-new-news-hook 'gnus-sync-read)
-  (add-hook 'gnus-save-newsrc-hook 'gnus-sync-save)
-  (add-hook 'gnus-read-newsrc-el-hoo4a 'gnus-sync-read))
+  ;; (add-hook 'gnus-read-newsrc-el-hook 'gnus-sync-read)
+  (add-hook 'gnus-save-newsrc-hook 'gnus-sync-save))
 
 (defun gnus-sync-unload-hook ()
   "Uninstall the sync hooks."
   (interactive)
-  ;; (remove-hook 'gnus-get-new-news-hook 'gnus-sync-read)
+  (remove-hook 'gnus-get-new-news-hook 'gnus-sync-read)
   (remove-hook 'gnus-save-newsrc-hook 'gnus-sync-save)
   (remove-hook 'gnus-read-newsrc-el-hook 'gnus-sync-read))