Escape ` and ' in doc
[gnus] / lisp / nndiary.el
index 255c43f..a6e75b7 100644 (file)
@@ -1,7 +1,6 @@
 ;;; nndiary.el --- A diary back end for Gnus
 
-;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2015 Free Software Foundation, Inc.
 
 ;; Author:        Didier Verna <didier@xemacs.org>
 ;; Maintainer:    Didier Verna <didier@xemacs.org>
@@ -10,9 +9,9 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; 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 2 of the License, or
+;; 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,
@@ -21,9 +20,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with this program; if not, write to the Free Software
-;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-;; MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 
 ;;; Commentary:
@@ -58,7 +55,7 @@
 
 ;; * nnoo. NNDiary is very similar to nnml. This makes the idea of using nnoo
 ;;   (to derive nndiary from nnml) natural. However, my experience with nnoo
-;;   is that for reasonably complex back ends like this one, noo is a burden
+;;   is that for reasonably complex back ends like this one, nnoo is a burden
 ;;   rather than an help. It's tricky to use, not everything can be inherited,
 ;;   what can be inherited and when is not very clear, and you've got to be
 ;;   very careful because a little mistake can fuck up your other back ends,
 ;;   IMHO, nnoo is actually badly designed.  A much simpler, and yet more
 ;;   powerful one would be to make *real* functions and variables for a new
 ;;   back end based on another. Lisp is a reflexive language so that's a very
-;;   easy thing to do: inspect the function's form, replace occurences of
+;;   easy thing to do: inspect the function's form, replace occurrences of
 ;;   <nnfrom> (even in strings) with <nnto>, and you're done.
 
 ;; * nndiary-get-new-mail, nndiary-mail-source and nndiary-split-methods:
 ;;   NNDiary has some experimental parts, in the sense Gnus normally uses only
-;;   one mail back ends for mail retreival and splitting. This back end is
-;;   also an attempt to make it behave differently. For Gnus developpers: as
+;;   one mail back ends for mail retrieval and splitting. This back end is
+;;   also an attempt to make it behave differently. For Gnus developers: as
 ;;   you can see if you snarf into the code, that was not a very difficult
 ;;   thing to do. Something should be done about the respooling breakage
 ;;   though.
@@ -131,7 +128,7 @@ non-nil."
 
 
 (defcustom nndiary-reminders '((0 . day))
-  "*Different times when you want to be reminded of your appointements.
+  "*Different times when you want to be reminded of your appointments.
 Diary articles will appear again, as if they'd been just received.
 
 Entries look like (3 . day) which means something like \"Please
@@ -144,8 +141,8 @@ not 'century, sorry).
 
 NOTE: the units of measure actually express dates, not durations: if you
 use 'week, messages will pop up on Sundays at 00:00 (or Mondays if
-`nndiary-week-starts-on-monday' is non nil) and *not* 7 days before the
-appointement, if you use 'month, messages will pop up on the first day of
+`nndiary-week-starts-on-monday' is non-nil) and *not* 7 days before the
+appointment, if you use 'month, messages will pop up on the first day of
 each months, at 00:00 and so on.
 
 If you really want to specify a duration (like 24 hours exactly), you can
@@ -154,16 +151,16 @@ maximum in the reminder is not that painful, I think.  Although this
 scheme might appear somewhat weird at a first glance, it is very powerful.
 In order to make this clear, here are some examples:
 
-- '(0 . day): this is the default value of `nndiary-reminders'.  It means
-  pop up the appointements of the day each morning at 00:00.
+- (0 . day): this is the default value of `nndiary-reminders'.  It means
+  pop up the appointments of the day each morning at 00:00.
 
-- '(1 . day): this means pop up the appointements the day before, at 00:00.
+- (1 . day): this means pop up the appointments the day before, at 00:00.
 
-- '(6 . hour): for an appointement at 18:30, this would pop up the
-  appointement message at 12:00.
+- (6 . hour): for an appointment at 18:30, this would pop up the
+  appointment message at 12:00.
 
-- '(360 . minute): for an appointement at 18:30 and 15 seconds, this would
-  pop up the appointement message at 12:30."
+- (360 . minute): for an appointment at 18:30 and 15 seconds, this would
+  pop up the appointment message at 12:30."
   :group 'nndiary
   :type '(repeat (cons :format "%v\n"
                       (integer :format "%v")
@@ -182,22 +179,28 @@ In order to make this clear, here are some examples:
   :group 'nndiary)
 
 
-(defcustom nndiary-request-create-group-hooks nil
-  "*Hooks to run after `nndiary-request-create-group' is executed.
-The hooks will be called with the full group name as argument."
+(define-obsolete-variable-alias 'nndiary-request-create-group-hooks
+  'nndiary-request-create-group-functions "24.3")
+(defcustom nndiary-request-create-group-functions nil
+  "*Hook run after `nndiary-request-create-group' is executed.
+The hook functions will be called with the full group name as argument."
   :group 'nndiary
   :type 'hook)
 
-(defcustom nndiary-request-update-info-hooks nil
-  "*Hooks to run after `nndiary-request-update-info-group' is executed.
-The hooks will be called with the full group name as argument."
+(define-obsolete-variable-alias 'nndiary-request-update-info-hooks
+  'nndiary-request-update-info-functions "24.3")
+(defcustom nndiary-request-update-info-functions nil
+  "*Hook run after `nndiary-request-update-info-group' is executed.
+The hook functions will be called with the full group name as argument."
   :group 'nndiary
   :type 'hook)
 
-(defcustom nndiary-request-accept-article-hooks nil
-  "*Hooks to run before accepting an article.
+(define-obsolete-variable-alias 'nndiary-request-accept-article-hooks
+  'nndiary-request-accept-article-functions "24.3")
+(defcustom nndiary-request-accept-article-functions nil
+  "*Hook run before accepting an article.
 Executed near the beginning of `nndiary-request-accept-article'.
-The hooks will be called with the article in the current buffer."
+The hook functions will be called with the article in the current buffer."
   :group 'nndiary
   :type 'hook)
 
@@ -227,7 +230,7 @@ The hooks will be called with the article in the current buffer."
 (defvoo nndiary-get-new-mail nil
   "Whether nndiary gets new mail and split it.
 Contrary to traditional mail back ends, this variable can be set to t
-even if your primary mail back end also retreives mail. In such a case,
+even if your primary mail back end also retrieves mail. In such a case,
 NDiary uses its own mail-sources and split-methods.")
 
 (defvoo nndiary-nov-is-evil nil
@@ -356,7 +359,7 @@ all.  This may very well take some time.")
   ;; List of NNDiary headers that specify the time spec. Each header name is
   ;; followed by either two integers (specifying a range of possible values
   ;; for this header) or one list (specifying all the possible values for this
-  ;; header). In the latter case, the list does NOT include the unspecifyed
+  ;; header). In the latter case, the list does NOT include the unspecified
   ;; spec (*).
   ;; For time zone values, we have symbolic time zone names associated with
   ;; the (relative) number of seconds ahead GMT.
@@ -370,7 +373,7 @@ all.  This may very well take some time.")
           (setq head (nth 0 elt))
           (nndiary-parse-schedule (nth 0 elt) (nth 1 elt) (nth 2 elt)))
         nndiary-headers)
-      (t
+      (error
        (nnheader-report 'nndiary "X-Diary-%s header parse error: %s."
                        head (cdr arg))
        nil))
@@ -382,8 +385,7 @@ all.  This may very well take some time.")
 
 (deffoo nndiary-retrieve-headers (sequence &optional group server fetch-old)
   (when (nndiary-possibly-change-directory group server)
-    (save-excursion
-      (set-buffer nntp-server-buffer)
+    (with-current-buffer nntp-server-buffer
       (erase-buffer)
       (let* ((file nil)
             (number (length sequence))
@@ -421,7 +423,7 @@ all.  This may very well take some time.")
                   (> number nnmail-large-newsgroup)
                   (zerop (% count 20))
                   (nnheader-message 6 "nndiary: Receiving headers... %d%%"
-                                    (/ (* count 100) number))))
+                                    (floor (* count 100.0) number))))
 
            (and (numberp nnmail-large-newsgroup)
                 (> number nnmail-large-newsgroup)
@@ -485,7 +487,7 @@ all.  This may very well take some time.")
       (cons (if group-num (car group-num) group)
            (string-to-number (file-name-nondirectory path)))))))
 
-(deffoo nndiary-request-group (group &optional server dont-check)
+(deffoo nndiary-request-group (group &optional server dont-check info)
   (let ((file-name-coding-system nnmail-pathname-coding-system))
     (cond
      ((not (nndiary-possibly-change-directory group server))
@@ -545,7 +547,7 @@ all.  This may very well take some time.")
          (setcar active (apply 'min articles))
          (setcdr active (apply 'max articles))))
       (nnmail-save-active nndiary-group-alist nndiary-active-file)
-      (run-hook-with-args 'nndiary-request-create-group-hooks
+      (run-hook-with-args 'nndiary-request-create-group-functions
                          (gnus-group-prefixed-name group
                                                    (list "nndiary" server)))
       t))
@@ -617,8 +619,7 @@ all.  This may very well take some time.")
      (let (nndiary-current-directory
           nndiary-current-group
           nndiary-article-file-alist)
-       (save-excursion
-        (set-buffer buf)
+       (with-current-buffer buf
         (insert-buffer-substring nntp-server-buffer)
         (setq result (eval accept-form))
         (kill-buffer (current-buffer))
@@ -638,7 +639,7 @@ all.  This may very well take some time.")
 (deffoo nndiary-request-accept-article (group &optional server last)
   (nndiary-possibly-change-directory group server)
   (nnmail-check-syntax)
-  (run-hooks 'nndiary-request-accept-article-hooks)
+  (run-hooks 'nndiary-request-accept-article-functions)
   (when (nndiary-schedule)
     (let (result)
       (when nnmail-cache-accepted-message-ids
@@ -674,8 +675,7 @@ all.  This may very well take some time.")
 
 (deffoo nndiary-request-replace-article (article group buffer)
   (nndiary-possibly-change-directory group)
-  (save-excursion
-    (set-buffer buffer)
+  (with-current-buffer buffer
     (nndiary-possibly-create-directory group)
     (let ((chars (nnmail-insert-lines))
          (art (concat (int-to-string article) "\t"))
@@ -690,8 +690,7 @@ all.  This may very well take some time.")
              t)
        (setq headers (nndiary-parse-head chars article))
        ;; Replace the NOV line in the NOV file.
-       (save-excursion
-         (set-buffer (nndiary-open-nov group))
+       (with-current-buffer (nndiary-open-nov group)
          (goto-char (point-min))
          (if (or (looking-at art)
                  (search-forward (concat "\n" art) nil t))
@@ -811,7 +810,7 @@ all.  This may very well take some time.")
             (gnus-info-set-read info (gnus-update-read-articles
                                       (gnus-info-group info) unread t)))
        ))
-    (run-hook-with-args 'nndiary-request-update-info-hooks
+    (run-hook-with-args 'nndiary-request-update-info-functions
                        (gnus-info-group info))
     t))
 
@@ -844,8 +843,7 @@ all.  This may very well take some time.")
 
 ;; Find an article number in the current group given the Message-ID.
 (defun nndiary-find-group-number (id)
-  (save-excursion
-    (set-buffer (get-buffer-create " *nndiary id*"))
+  (with-current-buffer (get-buffer-create " *nndiary id*")
     (let ((alist nndiary-group-alist)
          number)
       ;; We want to look through all .overview files, but we want to
@@ -890,8 +888,7 @@ all.  This may very well take some time.")
     (let ((nov (expand-file-name nndiary-nov-file-name
                                 nndiary-current-directory)))
       (when (file-exists-p nov)
-       (save-excursion
-         (set-buffer nntp-server-buffer)
+       (with-current-buffer nntp-server-buffer
          (erase-buffer)
          (nnheader-insert-file-contents nov)
          (if (and fetch-old
@@ -991,8 +988,7 @@ all.  This may very well take some time.")
 
 (defun nndiary-add-nov (group article headers)
   "Add a nov line for the GROUP base."
-  (save-excursion
-    (set-buffer (nndiary-open-nov group))
+  (with-current-buffer (nndiary-open-nov group)
     (goto-char (point-max))
     (mail-header-set-number headers article)
     (nnheader-insert-nov headers)))
@@ -1017,8 +1013,7 @@ all.  This may very well take some time.")
   (or (cdr (assoc group nndiary-nov-buffer-alist))
       (let ((buffer (get-buffer-create (format " *nndiary overview %s*"
                                               group))))
-       (save-excursion
-         (set-buffer buffer)
+       (with-current-buffer buffer
          (set (make-local-variable 'nndiary-nov-buffer-file-name)
               (expand-file-name
                nndiary-nov-file-name
@@ -1071,9 +1066,9 @@ all.  This may very well take some time.")
                   (file-directory-p dir))
          (nndiary-generate-nov-databases-1 dir seen))))
     ;; Do this directory.
-    (let ((files (sort (nnheader-article-to-file-alist dir)
+    (let ((nndiary-files (sort (nnheader-article-to-file-alist dir)
                       'car-less-than-car)))
-      (if (not files)
+      (if (not nndiary-files)
          (let* ((group (nnheader-file-to-group
                         (directory-file-name dir) nndiary-directory))
                 (info (cadr (assoc group nndiary-group-alist))))
@@ -1081,11 +1076,11 @@ all.  This may very well take some time.")
              (setcar info (1+ (cdr info)))))
        (funcall nndiary-generate-active-function dir)
        ;; Generate the nov file.
-       (nndiary-generate-nov-file dir files)
+       (nndiary-generate-nov-file dir nndiary-files)
        (unless no-active
          (nnmail-save-active nndiary-group-alist nndiary-active-file))))))
 
-(eval-when-compile (defvar files))
+(defvar nndiary-files) ; dynamically bound in nndiary-generate-nov-databases-1
 (defun nndiary-generate-active-info (dir)
   ;; Update the active info for this group.
   (let* ((group (nnheader-file-to-group
@@ -1094,9 +1089,9 @@ all.  This may very well take some time.")
         (last (or (caadr entry) 0)))
     (setq nndiary-group-alist (delq entry nndiary-group-alist))
     (push (list group
-               (cons (or (caar files) (1+ last))
+               (cons (or (caar nndiary-files) (1+ last))
                      (max last
-                          (or (caar (last files))
+                          (or (caar (last nndiary-files))
                               0))))
          nndiary-group-alist)))
 
@@ -1105,9 +1100,8 @@ all.  This may very well take some time.")
         (nov (concat dir nndiary-nov-file-name))
         (nov-buffer (get-buffer-create " *nov*"))
         chars file headers)
-    (save-excursion
-      ;; Init the nov buffer.
-      (set-buffer nov-buffer)
+    ;; Init the nov buffer.
+    (with-current-buffer nov-buffer
       (buffer-disable-undo)
       (erase-buffer)
       (set-buffer nntp-server-buffer)
@@ -1127,20 +1121,17 @@ all.  This may very well take some time.")
          (unless (zerop (buffer-size))
            (goto-char (point-min))
            (setq headers (nndiary-parse-head chars (caar files)))
-           (save-excursion
-             (set-buffer nov-buffer)
+           (with-current-buffer nov-buffer
              (goto-char (point-max))
              (nnheader-insert-nov headers)))
          (widen))
        (setq files (cdr files)))
-      (save-excursion
-       (set-buffer nov-buffer)
+      (with-current-buffer nov-buffer
        (nnmail-write-region 1 (point-max) nov nil 'nomesg)
        (kill-buffer (current-buffer))))))
 
 (defun nndiary-nov-delete-article (group article)
-  (save-excursion
-    (set-buffer (nndiary-open-nov group))
+  (with-current-buffer (nndiary-open-nov group)
     (when (nnheader-find-nov-line article)
       (delete-region (point) (progn (forward-line 1) (point)))
       (when (bobp)
@@ -1176,11 +1167,11 @@ all.  This may very well take some time.")
 
 (defun nndiary-parse-schedule-value (str min-or-values max)
   ;; Parse the schedule string STR, or signal an error.
-  ;; Signals are caught by `nndary-schedule'.
+  ;; Signals are caught by `nndiary-schedule'.
   (if (string-match "[ \t]*\\*[ \t]*" str)
-      ;; unspecifyed
+      ;; unspecified
       nil
-    ;; specifyed
+    ;; specified
     (if (listp min-or-values)
        ;; min-or-values is values
        ;; #### NOTE: this is actually only a hack for time zones.
@@ -1219,7 +1210,7 @@ all.  This may very well take some time.")
   ;; - Returns nil if `*'
   ;; - Otherwise returns a list of integers and/or ranges (BEG . END)
   ;; The exception is the Timze-Zone value which is always of the form (STR).
-  ;; Signals are caught by `nndary-schedule'.
+  ;; Signals are caught by `nndiary-schedule'.
   (let ((header (format "^X-Diary-%s: \\(.*\\)$" head)))
     (goto-char (point-min))
     (if (not (re-search-forward header nil t))
@@ -1323,8 +1314,10 @@ all.  This may very well take some time.")
        res))
     (sort res 'time-less-p)))
 
+;; FIXME: "occurrence" is misspelled in this function name.
+
 (defun nndiary-last-occurence (sched)
-  ;; Returns the last occurence of schedule SCHED as an Emacs time struct, or
+  ;; Returns the last occurrence of schedule SCHED as an Emacs time struct, or
   ;; nil for permanent schedule or errors.
   (let ((minute (nndiary-max (nth 0 sched)))
        (hour (nndiary-max (nth 1 sched)))
@@ -1335,7 +1328,7 @@ all.  This may very well take some time.")
       (or minute (setq minute 59))
       (or hour (setq hour 23))
       ;; I'll just compute all possible values and test them by decreasing
-      ;; order until one succeeds. This is probably quide rude, but I got
+      ;; order until one succeeds. This is probably quite rude, but I got
       ;; bored in finding a good algorithm for doing that ;-)
       ;; ### FIXME: remove identical entries.
       (let ((dom-list (nth 2 sched))
@@ -1395,7 +1388,7 @@ all.  This may very well take some time.")
                            (encode-time 0 minute hour
                                         (car days) month year time-zone)))
                   )))))
-        ;; There's an upper limit, but we didn't find any last occurence.
+        ;; There's an upper limit, but we didn't find any last occurrence.
         ;; This means that the schedule is undecidable. This can happen if
         ;; you happen to say something like "each Feb 31 until 2038".
         (progn
@@ -1403,9 +1396,11 @@ all.  This may very well take some time.")
           nil))
        ))))
 
+;; FIXME: "occurrence" is misspelled in this function name.
+
 (defun nndiary-next-occurence (sched now)
-  ;; Returns the next occurence of schedule SCHED, starting from time NOW.
-  ;; If there's no next occurence, returns the last one (if any) which is then
+  ;; Returns the next occurrence of schedule SCHED, starting from time NOW.
+  ;; If there's no next occurrence, returns the last one (if any) which is then
   ;; in the past.
   (let* ((today (decode-time now))
         (this-minute (nth 1 today))
@@ -1559,12 +1554,12 @@ all.  This may very well take some time.")
        ;; The article should be re-considered as unread if there's a reminder
        ;; between the group timestamp and the current time.
        (when (and sched (setq sched (nndiary-next-occurence sched now)))
-         (let ((reminders ;; add the next occurence itself at the end.
+         (let ((reminders ;; add the next occurrence itself at the end.
                 (append (nndiary-compute-reminders sched) (list sched))))
            (while (and reminders (time-less-p (car reminders) timestamp))
              (pop reminders))
            ;; The reminders might be empty if the last date is in the past,
-           ;; or we've got at least the next occurence itself left. All past
+           ;; or we've got at least the next occurrence itself left. All past
            ;; dates are renewed.
            (or (not reminders)
                (time-less-p (car reminders) now)))
@@ -1575,19 +1570,15 @@ all.  This may very well take some time.")
 
 ;; The end... ===============================================================
 
-(mapcar
- (lambda (elt)
-   (let ((header (intern (format "X-Diary-%s" (car elt)))))
-     ;; Required for building NOV databases and some other stuff
-     (add-to-list 'gnus-extra-headers header)
-     (add-to-list 'nnmail-extra-headers header)))
- nndiary-headers)
+(dolist (header nndiary-headers)
+  (setq header (intern (format "X-Diary-%s" (car header))))
+  ;; Required for building NOV databases and some other stuff.
+  (add-to-list 'gnus-extra-headers header)
+  (add-to-list 'nnmail-extra-headers header))
 
 (unless (assoc "nndiary" gnus-valid-select-methods)
   (gnus-declare-backend "nndiary" 'post-mail 'respool 'address))
 
 (provide 'nndiary)
 
-
-;;; arch-tag: 9c542b95-92e7-4ace-a038-330ab296e203
 ;;; nndiary.el ends here