Synch with Oort Gnus.
[elisp/gnus.git-] / lisp / nnshimbun.el
index 503f1f7..e961d78 100644 (file)
@@ -1,13 +1,13 @@
 ;;; nnshimbun.el --- interfacing with web newspapers
 
+;; Copyright (C) 2000,2001,2002 TSUCHIYA Masatoshi <tsuchiya@namazu.org>
+
 ;; Authors: TSUCHIYA Masatoshi <tsuchiya@namazu.org>,
 ;;          Akihiro Arisawa    <ari@atesoft.advantest.co.jp>,
 ;;          Katsumi Yamaoka    <yamaoka@jpl.org>,
 ;;          Yuuichi Teranishi  <teranisi@gohome.org>
 ;; Keywords: news
 
-;;; Copyright:
-
 ;; This file is a part of Semi-Gnus.
 
 ;; This program is free software; you can redistribute it and/or modify
@@ -31,7 +31,7 @@
 ;; This module requires the Emacs-W3M and the external command W3M.
 ;; Visit the following pages for more information.
 ;;
-;;     http://namazu.org/~tsuchiya/emacs-w3m/
+;;     http://emacs-w3m.namazu.org/
 ;;     http://ei5nazha.yz.yamagata-u.ac.jp/~aito/w3m/
 
 ;; If you would like to use this module in Gnus (not T-gnus), put this
 ;; '(index-range all prefetch-articles off encapsulate-images on
 ;;               expiry-wait 6)
 
+(unless (fboundp 'gnus-define-group-parameter)
+  (defmacro gnus-define-group-parameter (&rest args) nil)
+  (defun nnshimbun-find-group-parameters (name)
+    "Return a nnshimbun GROUP's group parameters."
+    (when name
+      (or (gnus-group-find-parameter name 'nnshimbun-group-parameters t)
+         (assoc-default name
+                        (and (boundp 'nnshimbun-group-parameters-alist)
+                             (symbol-value 'nnshimbun-group-parameters-alist))
+                        (function string-match))))))
+
 (gnus-define-group-parameter
  nnshimbun-group-parameters
  :type list
@@ -172,17 +183,17 @@ but it has a preference.")
 
 (defvoo nnshimbun-nov-file-name ".overview")
 
-(defvoo nnshimbun-pre-fetch-article nil
-  "*Non nil means that nnshimbun fetch unread articles when scanning
-groups.  Note that this variable has just a default value for all the
-nnshimbun groups.  You can specify the nnshimbun group parameter
-`prefecth-articles' for each nnshimbun group.")
+(defvoo nnshimbun-pre-fetch-article 'off
+  "*If it is neither `off' nor nil, nnshimbun fetch unread articles when
+scanning groups.  Note that this variable has just a default value for
+all the nnshimbun groups.  You can specify the nnshimbun group
+parameter `prefecth-articles' for each nnshimbun group.")
 
 (defvoo nnshimbun-encapsulate-images shimbun-encapsulate-images
-  "*If non-nil, inline images will be encapsulated in the articles.
-Note that this variable has just a default value for all the nnshimbun
-groups.  You can specify the nnshimbun group parameter
-`encapsulate-images' for each nnshimbun group.")
+  "*If it is neither `off' nor nil, inline images will be encapsulated in
+the articles.  Note that this variable has just a default value for
+all the nnshimbun groups.  You can specify the nnshimbun group
+parameter `encapsulate-images' for each nnshimbun group.")
 
 (defvoo nnshimbun-index-range nil
   "*Range of indices to detect new pages.  Note that this variable has
@@ -236,15 +247,19 @@ GROUP has a full name."
                           'index-range)
                nnshimbun-index-range))
          ((eq 'prefetch-articles (eval symbol))
-          `(let ((v (or (plist-get (nnshimbun-find-group-parameters ,name)
-                                   'prefetch-articles)
-                        nnshimbun-pre-fetch-article)))
-             (if (eq v 'off) nil v)))
+          `(let ((val (or (plist-get (nnshimbun-find-group-parameters ,name)
+                                     'prefetch-articles)
+                          nnshimbun-pre-fetch-article)))
+             (if (eq 'off val)
+                 nil
+               val)))
          ((eq 'encapsulate-images (eval symbol))
-          `(let ((v (or (plist-get (nnshimbun-find-group-parameters ,name)
-                                   'encapsulate-images)
-                        nnshimbun-encapsulate-images)))
-             (if (eq v 'off) nil v)))
+          `(let ((val (or (plist-get (nnshimbun-find-group-parameters ,name)
+                                     'encapsulate-images)
+                          nnshimbun-encapsulate-images)))
+             (if (eq 'off val)
+                 nil
+               val)))
          ((eq 'expiry-wait (eval symbol))
           (if full-name-p
               `(or (plist-get (nnshimbun-find-group-parameters ,group)
@@ -385,7 +400,14 @@ GROUP has a full name."
 (deffoo nnshimbun-request-article (article &optional group server to-buffer)
   (when (nnshimbun-possibly-change-group group server)
     (when (stringp article)
-      (setq article (nnshimbun-search-id group article)))
+      (let ((num (when (or group (setq group nnshimbun-current-group))
+                  (nnshimbun-search-id group article))))
+       (unless num
+         (let ((groups (shimbun-groups (shimbun-open server))))
+           (while (and (not num) groups)
+             (setq group (pop groups)
+                   num (nnshimbun-search-id group article)))))
+       (setq article num)))
     (if (integerp article)
        (nnshimbun-request-article-1 article group server to-buffer)
       (nnheader-report 'nnshimbun "Couldn't retrieve article: %s"
@@ -633,19 +655,20 @@ also be nil."
     (when (buffer-live-p buffer)
       (save-excursion
        (set-buffer buffer)
-       (buffer-modified-p)
-       (nnmail-write-region 1 (point-max) nnshimbun-nov-buffer-file-name
-                            nil 'nomesg)))))
+       (and (> (buffer-size) 0)
+            (buffer-modified-p)
+            (nnmail-write-region 1 (point-max) nnshimbun-nov-buffer-file-name
+                                 nil 'nomesg))))))
 
 (defun nnshimbun-save-nov ()
   (save-excursion
     (while nnshimbun-nov-buffer-alist
       (when (buffer-name (cdar nnshimbun-nov-buffer-alist))
        (set-buffer (cdar nnshimbun-nov-buffer-alist))
-       (when (buffer-modified-p)
-         (nnmail-write-region 1 (point-max) nnshimbun-nov-buffer-file-name
-                              nil 'nomesg))
-       (set-buffer-modified-p nil)
+       (and (> (buffer-size) 0)
+            (buffer-modified-p)
+            (nnmail-write-region 1 (point-max) nnshimbun-nov-buffer-file-name
+                                 nil 'nomesg))
        (kill-buffer (current-buffer)))
       (setq nnshimbun-nov-buffer-alist (cdr nnshimbun-nov-buffer-alist)))))
 
@@ -664,15 +687,20 @@ and the NOV is open.  The optional fourth argument FORCE is ignored."
        (let* ((expirable (copy-sequence articles))
               (name (concat "nnshimbun+" server ":" group))
               ;; If the group's parameter `expiry-wait' is non-nil,
-              ;; `nnmail-expiry-wait' is bound to that value, and
-              ;; `nnmail-expiry-wait-function' is bound to nil.
-              ;; See the source code of `gnus-summary-expire-articles'.
-              ;; Prefer the shimbun's default to `nnmail-expiry-wait'
-              ;; only when the group's parameter is nil.
-              (nnmail-expiry-wait
+              ;; the value of the option `nnmail-expiry-wait' will be
+              ;; bound to that value, and the value of the option
+              ;; `nnmail-expiry-wait-function' will be bound to nil.
+              ;; See the source code of `gnus-summary-expire-articles'
+              ;; how does it work.  If the group's parameter is not
+              ;; specified by user, the shimbun's default value will
+              ;; be used.
+              (expiry-wait
                (or (nnshimbun-find-parameter name 'expiry-wait t)
-                   (shimbun-article-expiration-days nnshimbun-shimbun)
-                   nnmail-expiry-wait))
+                   (shimbun-article-expiration-days nnshimbun-shimbun)))
+              (nnmail-expiry-wait (or expiry-wait nnmail-expiry-wait))
+              (nnmail-expiry-wait-function (if expiry-wait
+                                               nil
+                                             nnmail-expiry-wait-function))
               article end time)
          (save-excursion
            (set-buffer buffer)
@@ -787,14 +815,13 @@ and the NOV is open.  The optional fourth argument FORCE is ignored."
                  'nnshimbun-server-history))
         (groups)
         (nnshimbun-pre-fetch-article))
-    (require (intern (concat "sb-" server)))
-    (when (setq groups (intern-soft (concat "shimbun-" server "-groups")))
-      (gnus-group-make-group
-       (completing-read "Group name: "
-                       (mapcar 'list (symbol-value groups))
-                       nil t nil)
-       (list 'nnshimbun server)))))
+    (if (setq groups (shimbun-groups (shimbun-open server)))
+       (gnus-group-make-group
+        (completing-read "Group name: " (mapcar 'list groups) nil t nil)
+        (list 'nnshimbun server))
+      (error "%s" "Can't find group"))))
 
 
 (provide 'nnshimbun)
-;;; nnshimbun.el ends here.
+
+;;; nnshimbun.el ends here