From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder] Date: Mon, 17 Aug 2015 11:16:35 +0200 Message-ID: <87lhda6zrg.fsf@nicolasgoaziou.fr> References: <87a8ufdqte.fsf@free.fr> <871tf89qh8.fsf@fastmail.fm> <87wpwzlmpn.fsf@free.fr> <87lhdftjzy.fsf@fastmail.fm> <871tf690lg.fsf@pierrot.dokosmarshall.org> <878u9ehris.fsf@fastmail.fm> <87vbcg76lq.fsf@free.fr> <87pp2n6t7k.fsf_-_@pierrot.dokosmarshall.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRGVP-0008G3-Pc for emacs-orgmode@gnu.org; Mon, 17 Aug 2015 05:15:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZRGVO-0006Hb-OX for emacs-orgmode@gnu.org; Mon, 17 Aug 2015 05:14:59 -0400 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:60402) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRGVO-0006HX-HN for emacs-orgmode@gnu.org; Mon, 17 Aug 2015 05:14:58 -0400 In-Reply-To: <87pp2n6t7k.fsf_-_@pierrot.dokosmarshall.org> (Nick Dokos's message of "Sun, 16 Aug 2015 13:25:51 -0400") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nick Dokos Cc: emacs-orgmode@gnu.org Hello, Nick Dokos writes: > Here's a patch to add a new function to org-bbdb.el that provides early > warning for upcoming anniversaries; it also adds some documentation to > org.texi. Thank you. Some comments follow. > +(defun org-bbdb-date-list (date n) > + "Return a list of dates in (m d y) format from the given 'date' to n-1 days hence." > + (let ((abs (calendar-absolute-from-gregorian date)) > + ret) > + (reverse (dotimes (i n ret) > + (setq ret (cons (calendar-gregorian-from-absolute (+ abs i)) ret)))))) (dotimes (i n (nreverse ret)) (push (calendar-gregorian-from-absolute (+ abs i)) ret)) > + > +;;;###autoload > +(defun org-bbdb-anniversaries-future (&optional n) > + "Return list of anniversaries for today and the next n-1 days (default n=7)." > + (if (not n) (setq n 7)) (let ((n (or n 7))) (when (<= n 0) (error "...")) (let* (...))) > + (if (<= n 0) nil > + (let* ( > + ;; list of relevant dates. You need to capitalize comments. > + (dates (org-bbdb-date-list date n)) > + ;; Function to annotate text of each element of l with the anniversary date d. > + (annotate-descriptions > + (lambda (d l) > + (let ((modify-description > + (lambda (x) > + ;; The assumption here is that x is a bbdb link of the form > + ;; [[bbdb:name][description]] > + ;; This function rather arbitrarily modifies the description > + ;; by adding the date to it in a fixed format. Missing full stop in first sentence. > + (string-match "]]" x) > + (replace-match (format " -- %d-%02d-%02d\\&" (third d) (first d) (second d)) > + nil nil x)))) > + (mapcar modify-description l)))) Why don't you simply write (mapcar (lambda (x) (string-match "]]" x) ...) l) ? > + ;; Function to generate the list of annotated anniversaries > + ;; for the given date d. > + (gen-anniversaries > + (lambda (d) > + (let ((date d)) > + ;; rebind 'date' so that org-bbdb-anniversaries will be > + ;; fooled into giving us the list for the given date > + ;; and then annotate the descriptions for that date. "Rebind". > + (funcall annotate-descriptions d (org-bbdb-anniversaries)))))) > + ;; map the gen-anniversaries function over the dates > + ;; and nconc the results into a single list Missing capitalization and full stop. > + (apply 'nconc (mapcar gen-anniversaries dates))))) #'nconc (there is also `cl-mapcan'). Also, gen-anniversaries is a one-liner. I don't think it deserves its own name. IOW, wouldn't it be better to use less levels of indirection, i.e., less helper functions? Regards, -- Nicolas Goaziou