From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [PATCH 2/3] org-datetree.el: Add support for ISO week trees. Date: Wed, 02 Sep 2015 21:58:17 +0200 Message-ID: <87oahk8ug6.fsf@nicolasgoaziou.fr> References: <5814117.7UzEcaoqyZ@descartes> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXE9B-00041F-OY for emacs-orgmode@gnu.org; Wed, 02 Sep 2015 15:56:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZXE9A-0007co-Ps for emacs-orgmode@gnu.org; Wed, 02 Sep 2015 15:56:41 -0400 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:37800) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXE9A-0007cA-JT for emacs-orgmode@gnu.org; Wed, 02 Sep 2015 15:56:40 -0400 In-Reply-To: <5814117.7UzEcaoqyZ@descartes> (=?utf-8?Q?=22R=C3=BCdiger?= Sonderfeld"'s message of "Wed, 02 Sep 2015 09:06:31 +0100") 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: =?utf-8?Q?R=C3=BCdiger?= Sonderfeld Cc: emacs-orgmode@gnu.org R=C3=BCdiger Sonderfeld writes: > +(defun org-datetree-find-iso-week-create (date &optional keep-restrictio= n) > + "Find or create an ISO week entry for DATE. > +Compared to `org-datetree-find-date-create' this function creates > +entries ordered by week instead of months. > +If KEEP-RESTRICTION is non-nil, do not widen the buffer. When it > +is nil, the buffer will be widened to make sure an existing date > +tree can be found." > + (org-set-local 'org-datetree-base-level 1) > + (or keep-restriction (widen)) > + (save-restriction > + (let ((prop (org-find-property "DATE_WEEK_TREE"))) I don't think we need to introduce a new property for that. DATE_TREE is enough. > + (when prop > + (goto-char prop) > + (org-set-local 'org-datetree-base-level > + (org-get-valid-level (org-current-level) 1)) > + (org-narrow-to-subtree))) > + (goto-char (point-min)) > + (require 'cal-iso) > + (let* ((year (calendar-extract-year date)) > + (month (calendar-extract-month date)) > + (day (calendar-extract-day date)) > + (time (encode-time 0 0 0 day month year)) > + (iso-date (calendar-iso-from-absolute > + (calendar-absolute-from-gregorian date))) > + (weekyear (nth 2 iso-date)) > + (week (car iso-date)) > + (weekday (cadr iso-date))) Nitpick, since you used (nth 2 ...): car -> nth 0 cadr -> nth 1 > + ;; ISO 8601 week format is %G-W%V(-%u) > + (org-datetree--find-create "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\= s-*?\\([ \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)" Isn't this line too long? > + weekyear nil nil > + (format-time-string "%G" time)) > + (org-datetree--find-create "^\\*+[ \t]+%d-W\\([0-5][0-9]\\)$" > + weekyear week nil > + (format-time-string "%G-W%V" time)) > + ;; For the actual day we use the regular date instead of ISO week. > + (org-datetree--find-create "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \= \w+$" > + year month day)))) > + > +(defun org-datetree--find-create (regex year &optional month day insert) > + "Find the datetree matched by REGEX for YEAR, MONTH, or DAY. Here you have expectations about REGEX, since you use (format regex year month day) Could you clarify that it should have three format placeholders in the docstring? > +If INSERT is non-nil insert the text if not found." Insert where? What text? Could you tweak docstring to specify that INSERT is a string and where it is going to be inserted? > (let ((re (format regex year month day)) > match) > (goto-char (point-min)) > @@ -86,25 +126,27 @@ (defun org-datetree--find-create (regex year &option= al month day) > ((not match) > (goto-char (point-max)) > (unless (bolp) (newline)) > - (org-datetree-insert-line year month day)) > + (org-datetree-insert-line year month day insert)) > ((=3D (string-to-number (match-string 1)) (or day month year)) > (goto-char (point-at-bol))) While you're at it: (beginning-of-line) Regards,