1 ;;; gnus-diary.el --- Wrapper around the NNDiary Gnus back end
3 ;; Copyright (C) 1999-2014 Free Software Foundation, Inc.
5 ;; Author: Didier Verna <didier@xemacs.org>
6 ;; Maintainer: Didier Verna <didier@xemacs.org>
7 ;; Created: Tue Jul 20 10:42:55 1999
8 ;; Keywords: calendar mail news
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; Contents management by FCM version 0.1.
33 ;; gnus-diary is a utility toolkit used on top of the nndiary back end. It is
34 ;; now fully documented in the Gnus manual.
47 (defgroup gnus-diary nil
48 "Utilities on top of the nndiary back end for Gnus."
52 (defcustom gnus-diary-summary-line-format "%U%R%z %uD: %(%s%) (%ud)\n"
53 "*Summary line format for nndiary groups."
56 :group 'gnus-summary-format)
58 (defcustom gnus-diary-time-format "%a, %b %e %y, %H:%M"
59 "*Time format to display appointments in nndiary summary buffers.
60 Please refer to `format-time-string' for information on possible values."
64 (defcustom gnus-diary-delay-format-function 'gnus-diary-delay-format-english
65 "*Function called to format a diary delay string.
66 It is passed two arguments. The first one is non-nil if the delay is in
67 the past. The second one is of the form ((NUM . UNIT) ...) where NUM is
68 an integer and UNIT is one of 'year 'month 'week 'day 'hour or 'minute.
69 It should return strings like \"In 2 months, 3 weeks\", \"3 hours,
70 1 minute ago\" and so on.
72 There are currently two built-in format functions:
73 `gnus-diary-delay-format-english' (the default)
74 `gnus-diary-delay-format-french'"
75 :type '(choice (const :tag "english" gnus-diary-delay-format-english)
76 (const :tag "french" gnus-diary-delay-format-french)
77 (symbol :tag "other"))
80 (defconst gnus-diary-version nndiary-version
81 "Current Diary back end version.")
84 ;; Compatibility functions ==================================================
87 (if (fboundp 'kill-entire-line)
88 (defalias 'gnus-diary-kill-entire-line 'kill-entire-line)
89 (defun gnus-diary-kill-entire-line ()
91 (let ((kill-whole-line t))
95 ;; Summary line format ======================================================
97 (defun gnus-diary-delay-format-french (past delay)
100 ;; Keep only a precision of two degrees
101 (and (> (length delay) 1) (setcdr (cdr delay) nil))
102 (concat (if past "il y a " "dans ")
105 (while (setq del (pop delay))
106 (setq str (concat str
107 (int-to-string (car del)) " "
108 (cond ((eq (cdr del) 'year)
110 ((eq (cdr del) 'month)
112 ((eq (cdr del) 'week)
116 ((eq (cdr del) 'hour)
118 ((eq (cdr del) 'minute)
120 (unless (or (eq (cdr del) 'month)
127 (defun gnus-diary-delay-format-english (past delay)
130 ;; Keep only a precision of two degrees
131 (and (> (length delay) 1) (setcdr (cdr delay) nil))
132 (concat (unless past "in ")
135 (while (setq del (pop delay))
136 (setq str (concat str
137 (int-to-string (car del)) " "
138 (symbol-name (cdr del))
139 (and (> (car del) 1) "s")
145 (defun gnus-diary-header-schedule (headers)
146 ;; Same as `nndiary-schedule', but given a set of headers HEADERS
149 (let ((head (cdr (assoc (intern (format "X-Diary-%s" (car elt)))
152 (nndiary-parse-schedule-value head (cadr elt) (car (cddr elt))))))
155 ;; #### NOTE: Gnus sometimes gives me a HEADER not corresponding to any
156 ;; message, with all fields set to nil here. I don't know what it is for, and
159 (defun gnus-user-format-function-d (header)
160 ;; Return an approximate delay string for the next occurrence of this
161 ;; message. The delay is given only in the first non zero unit.
162 ;; Code partly stolen from article-make-date-line
163 (let* ((extras (mail-header-extra header))
164 (sched (gnus-diary-header-schedule extras))
165 (occur (nndiary-next-occurence sched (current-time)))
167 (real-time (subtract-time occur now)))
170 (let* ((sec (+ (* (float (car real-time)) 65536) (cadr real-time)))
173 (and past (setq sec (- sec)))
175 ;; This is a bit convoluted, but basically we go through the time
176 ;; units for years, weeks, etc, and divide things to see whether
177 ;; that results in positive answers.
178 (let ((units `((year . ,(* 365.25 24 3600))
179 (month . ,(* 31 24 3600))
180 (week . ,(* 7 24 3600))
185 (while (setq unit (pop units))
186 (unless (zerop (setq num (ffloor (/ sec (cdr unit)))))
187 (setq delay (append delay `((,(floor num) . ,(car unit))))))
188 (setq sec (- sec (* num (cdr unit)))))))
189 (funcall gnus-diary-delay-format-function past delay)))