annotate lisp/gnus/gnus-sync.el @ 110995:29c951d93e6d

Merge changes made in Gnus trunk. gnus-group.el (gnus-group-insert-group-line): Fix group argument to `gnus-group-get-icon'. nnimap.el (nnimap-open-connection): tls-program should be a list of programs.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Thu, 14 Oct 2010 10:16:59 +0000
parents d2b45bb936b6
children b1eac6d41a93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
1 ;;; gnus-sync.el --- synchronization facility for Gnus
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
2
109774
7a46ef068de4 * lisp/gnus/gnus-sync.el (gnus-sync): Fix defgroup version.
Glenn Morris <rgm@gnu.org>
parents: 109769
diff changeset
3 ;; Copyright (C) 2010 Free Software Foundation, Inc.
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
4
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
5 ;; Author: Ted Zlatanov <tzz@lifelogs.com>
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
6 ;; Keywords: news synchronization nntp nnrss
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
7
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
9
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
13 ;; (at your option) any later version.
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
14
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
19
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
22
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
23 ;;; Commentary:
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
24
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
25 ;; This is the gnus-sync.el package.
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
26
110799
d2b45bb936b6 gnus-int.el, gnus-util.el: Gnus hooks for the mark get/set operations.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109811
diff changeset
27 ;; It's due for a rewrite using gnus-after-set-mark-hook and
d2b45bb936b6 gnus-int.el, gnus-util.el: Gnus hooks for the mark get/set operations.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109811
diff changeset
28 ;; gnus-before-update-mark-hook. Until then please consider it
d2b45bb936b6 gnus-int.el, gnus-util.el: Gnus hooks for the mark get/set operations.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109811
diff changeset
29 ;; experimental.
d2b45bb936b6 gnus-int.el, gnus-util.el: Gnus hooks for the mark get/set operations.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109811
diff changeset
30
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
31 ;; Put this in your startup file (~/.gnus.el for instance)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
32
109769
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
33 ;; possibilities for gnus-sync-backend:
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
34 ;; Tramp over SSH: /ssh:user@host:/path/to/filename
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
35 ;; Tramp over IMAP: /imaps:user@yourhosthere.com:/INBOX.test/filename
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
36 ;; ...or any other file Tramp and Emacs can handle...
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
37
109777
729aca322fce Doc fixes and keep unknown groups.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109774
diff changeset
38 ;; (setq gnus-sync-backend "/remote:/path.gpg" ; will use Tramp+EPA if loaded
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
39 ;; gnus-sync-global-vars `(gnus-newsrc-last-checked-date)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
40 ;; gnus-sync-newsrc-groups `("nntp" "nnrss")
109777
729aca322fce Doc fixes and keep unknown groups.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109774
diff changeset
41 ;; gnus-sync-newsrc-offsets `(2 3))
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
42
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
43 ;; TODO:
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
44
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
45 ;; - after gnus-sync-read, the message counts are wrong
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
46
110799
d2b45bb936b6 gnus-int.el, gnus-util.el: Gnus hooks for the mark get/set operations.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109811
diff changeset
47 ;; - use gnus-after-set-mark-hook and gnus-before-update-mark-hook to
d2b45bb936b6 gnus-int.el, gnus-util.el: Gnus hooks for the mark get/set operations.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109811
diff changeset
48 ;; catch the mark updates
d2b45bb936b6 gnus-int.el, gnus-util.el: Gnus hooks for the mark get/set operations.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109811
diff changeset
49
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
50 ;;; Code:
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
51
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
52 (eval-when-compile (require 'cl))
109811
d06b7ff1ea84 Silence more Gnus compiler warnings.
Glenn Morris <rgm@gnu.org>
parents: 109783
diff changeset
53 (require 'gnus)
d06b7ff1ea84 Silence more Gnus compiler warnings.
Glenn Morris <rgm@gnu.org>
parents: 109783
diff changeset
54 (require 'gnus-start)
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
55 (require 'gnus-util)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
56
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
57 (defgroup gnus-sync nil
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
58 "The Gnus synchronization facility."
109774
7a46ef068de4 * lisp/gnus/gnus-sync.el (gnus-sync): Fix defgroup version.
Glenn Morris <rgm@gnu.org>
parents: 109769
diff changeset
59 :version "24.1"
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
60 :group 'gnus)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
61
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
62 (defcustom gnus-sync-newsrc-groups `("nntp" "nnrss")
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
63 "List of groups to be synchronized in the gnus-newsrc-alist.
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
64 The group names are matched, they don't have to be fully
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
65 qualified. Typically you would choose all of these. That's the
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
66 default because there is no active sync backend by default, so
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
67 this setting is harmless until the user chooses a sync backend."
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
68 :group 'gnus-sync
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
69 :type '(repeat regexp))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
70
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
71 (defcustom gnus-sync-newsrc-offsets '(2 3)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
72 "List of per-group data to be synchronized."
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
73 :group 'gnus-sync
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
74 :type '(set (const :tag "Read ranges" 2)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
75 (const :tag "Marks" 3)))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
76
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
77 (defcustom gnus-sync-global-vars nil
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
78 "List of global variables to be synchronized.
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
79 You may want to sync `gnus-newsrc-last-checked-date' but pretty
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
80 much any symbol is fair game. You could additionally sync
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
81 `gnus-newsrc-alist', `gnus-server-alist', `gnus-topic-topology',
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
82 and `gnus-topic-alist' to cover all the variables in
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
83 newsrc.eld (except for `gnus-format-specs' which should not be
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
84 synchronized, I believe). Also see `gnus-variable-list'."
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
85 :group 'gnus-sync
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
86 :type '(repeat (choice (variable :tag "A known variable")
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
87 (symbol :tag "Any symbol"))))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
88
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
89 (defcustom gnus-sync-backend nil
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
90 "The synchronization backend."
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
91 :group 'gnus-sync
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
92 :type '(radio (const :format "None" nil)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
93 (string :tag "Sync to a file")))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
94
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
95 (defvar gnus-sync-newsrc-loader nil
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
96 "Carrier for newsrc data")
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
97
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
98 (defun gnus-sync-save ()
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
99 "Save the Gnus sync data to the backend."
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
100 (interactive)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
101 (cond
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
102 ((stringp gnus-sync-backend)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
103 (gnus-message 7 "gnus-sync: saving to backend %s" gnus-sync-backend)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
104 ;; populate gnus-sync-newsrc-loader from all but the first dummy
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
105 ;; entry in gnus-newsrc-alist whose group matches any of the
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
106 ;; gnus-sync-newsrc-groups
109783
43f98127e0f3 Typo fix "hoo4a" -> "hook".
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109778
diff changeset
107 ;; TODO: keep the old contents for groups we don't have!
43f98127e0f3 Typo fix "hoo4a" -> "hook".
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109778
diff changeset
108 (let ((gnus-sync-newsrc-loader
43f98127e0f3 Typo fix "hoo4a" -> "hook".
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109778
diff changeset
109 (loop for entry in (cdr gnus-newsrc-alist)
43f98127e0f3 Typo fix "hoo4a" -> "hook".
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109778
diff changeset
110 when (gnus-grep-in-list
43f98127e0f3 Typo fix "hoo4a" -> "hook".
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109778
diff changeset
111 (car entry) ;the group name
43f98127e0f3 Typo fix "hoo4a" -> "hook".
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109778
diff changeset
112 gnus-sync-newsrc-groups)
43f98127e0f3 Typo fix "hoo4a" -> "hook".
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109778
diff changeset
113 collect (cons (car entry)
43f98127e0f3 Typo fix "hoo4a" -> "hook".
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109778
diff changeset
114 (mapcar (lambda (offset)
43f98127e0f3 Typo fix "hoo4a" -> "hook".
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109778
diff changeset
115 (cons offset (nth offset entry)))
43f98127e0f3 Typo fix "hoo4a" -> "hook".
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109778
diff changeset
116 gnus-sync-newsrc-offsets)))))
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
117 (with-temp-file gnus-sync-backend
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
118 (progn
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
119 (let ((coding-system-for-write gnus-ding-file-coding-system)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
120 (standard-output (current-buffer)))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
121 (princ (format ";; -*- mode:emacs-lisp; coding: %s; -*-\n"
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
122 gnus-ding-file-coding-system))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
123 (princ ";; Gnus sync data v. 0.0.1\n")
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
124 (let* ((print-quoted t)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
125 (print-readably t)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
126 (print-escape-multibyte nil)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
127 (print-escape-nonascii t)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
128 (print-length nil)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
129 (print-level nil)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
130 (print-circle nil)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
131 (print-escape-newlines t)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
132 (variables (cons 'gnus-sync-newsrc-loader
109767
f7cd57edb2ca Minor bug fixes for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109766
diff changeset
133 gnus-sync-global-vars))
f7cd57edb2ca Minor bug fixes for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109766
diff changeset
134 variable)
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
135 (while variables
109778
e253995f955c Ammended for bug fix on the loader nunion.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109777
diff changeset
136 (if (and (boundp (setq variable (pop variables)))
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
137 (symbol-value variable))
109778
e253995f955c Ammended for bug fix on the loader nunion.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109777
diff changeset
138 (progn
e253995f955c Ammended for bug fix on the loader nunion.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109777
diff changeset
139 (princ "\n(setq ")
e253995f955c Ammended for bug fix on the loader nunion.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109777
diff changeset
140 (princ (symbol-name variable))
e253995f955c Ammended for bug fix on the loader nunion.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109777
diff changeset
141 (princ " '")
e253995f955c Ammended for bug fix on the loader nunion.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109777
diff changeset
142 (prin1 (symbol-value variable))
e253995f955c Ammended for bug fix on the loader nunion.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109777
diff changeset
143 (princ ")\n"))
e253995f955c Ammended for bug fix on the loader nunion.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109777
diff changeset
144 (princ "\n;;; skipping empty variable ")
e253995f955c Ammended for bug fix on the loader nunion.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109777
diff changeset
145 (princ (symbol-name variable)))))
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
146 (gnus-message
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
147 7
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
148 "gnus-sync: stored variables %s and %d groups in %s"
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
149 gnus-sync-global-vars
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
150 (length gnus-sync-newsrc-loader)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
151 gnus-sync-backend)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
152
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
153 ;; Idea from Dan Christensen <jdc@chow.mat.jhu.edu>
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
154 ;; Save the .eld file with extra line breaks.
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
155 (gnus-message 8 "gnus-sync: adding whitespace to %s"
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
156 gnus-sync-backend)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
157 (save-excursion
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
158 (goto-char (point-min))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
159 (while (re-search-forward "^(\\|(\\\"" nil t)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
160 (replace-match "\n\\&" t))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
161 (goto-char (point-min))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
162 (while (re-search-forward " $" nil t)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
163 (replace-match "" t t))))))))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
164 ;; the pass-through case: gnus-sync-backend is not a known choice
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
165 (nil)))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
166
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
167 (defun gnus-sync-read ()
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
168 "Load the Gnus sync data from the backend."
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
169 (interactive)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
170 (when gnus-sync-backend
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
171 (gnus-message 7 "gnus-sync: loading from backend %s" gnus-sync-backend)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
172 (cond ((stringp gnus-sync-backend)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
173 ;; read data here...
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
174 (if (or debug-on-error debug-on-quit)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
175 (load gnus-sync-backend nil t)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
176 (condition-case var
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
177 (load gnus-sync-backend nil t)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
178 (error
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
179 (error "Error in %s: %s" gnus-sync-backend (cadr var)))))
109769
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
180 (let ((valid-count 0)
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
181 invalid-groups)
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
182 (dolist (node gnus-sync-newsrc-loader)
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
183 (if (gnus-gethash (car node) gnus-newsrc-hashtb)
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
184 (progn
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
185 (incf valid-count)
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
186 (loop for store in (cdr node)
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
187 do (setf (nth (car store)
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
188 (assoc (car node) gnus-newsrc-alist))
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
189 (cdr store))))
109769
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
190 (push (car node) invalid-groups)))
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
191 (gnus-message
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
192 7
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
193 "gnus-sync: loaded %d groups (out of %d) from %s"
109769
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
194 valid-count (length gnus-sync-newsrc-loader)
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
195 gnus-sync-backend)
109769
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
196 (when invalid-groups
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
197 (gnus-message
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
198 7
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
199 "gnus-sync: skipped %d groups (out of %d) from %s"
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
200 (length invalid-groups)
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
201 (length gnus-sync-newsrc-loader)
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
202 gnus-sync-backend)
fe81389a263d Optimizations for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109768
diff changeset
203 (gnus-message 9 "gnus-sync: skipped groups: %s"
109777
729aca322fce Doc fixes and keep unknown groups.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109774
diff changeset
204 (mapconcat 'identity invalid-groups ", ")))))
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
205 (nil))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
206 ;; make the hashtable again because the newsrc-alist may have been modified
109767
f7cd57edb2ca Minor bug fixes for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109766
diff changeset
207 (when gnus-sync-newsrc-offsets
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
208 (gnus-message 9 "gnus-sync: remaking the newsrc hashtable")
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
209 (gnus-make-hashtable-from-newsrc-alist))))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
210
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
211 ;;;###autoload
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
212 (defun gnus-sync-initialize ()
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
213 "Initialize the Gnus sync facility."
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
214 (interactive)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
215 (gnus-message 5 "Initializing the sync facility")
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
216 (gnus-sync-install-hooks))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
217
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
218 ;;;###autoload
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
219 (defun gnus-sync-install-hooks ()
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
220 "Install the sync hooks."
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
221 (interactive)
109768
9c65ce5bc0db Minor bug fixes for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109767
diff changeset
222 ;; (add-hook 'gnus-get-new-news-hook 'gnus-sync-read)
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
223 (add-hook 'gnus-save-newsrc-hook 'gnus-sync-save)
109783
43f98127e0f3 Typo fix "hoo4a" -> "hook".
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109778
diff changeset
224 (add-hook 'gnus-read-newsrc-el-hook 'gnus-sync-read))
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
225
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
226 (defun gnus-sync-unload-hook ()
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
227 "Uninstall the sync hooks."
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
228 (interactive)
109768
9c65ce5bc0db Minor bug fixes for gnus-sync.el.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 109767
diff changeset
229 ;; (remove-hook 'gnus-get-new-news-hook 'gnus-sync-read)
109766
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
230 (remove-hook 'gnus-save-newsrc-hook 'gnus-sync-save)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
231 (remove-hook 'gnus-read-newsrc-el-hook 'gnus-sync-read))
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
232
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
233 (add-hook 'gnus-sync-unload-hook 'gnus-sync-unload-hook)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
234
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
235 ;; this is harmless by default, until the gnus-sync-backend is set
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
236 (gnus-sync-initialize)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
237
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
238 (provide 'gnus-sync)
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
239
af33651be88b add lisp/gnus/gnus-sync.el
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
240 ;;; gnus-sync.el ends here