emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: "Rüdiger Sonderfeld" <ruediger@c-plusplus.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH 2/3] org-datetree.el: Add support for ISO week trees.
Date: Wed, 02 Sep 2015 21:58:17 +0200	[thread overview]
Message-ID: <87oahk8ug6.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <5814117.7UzEcaoqyZ@descartes> ("Rüdiger Sonderfeld"'s message of "Wed, 02 Sep 2015 09:06:31 +0100")

Rüdiger Sonderfeld <ruediger@c-plusplus.net> writes:

> +(defun org-datetree-find-iso-week-create (date &optional keep-restriction)
> +  "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 &optional 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))
>       ((= (string-to-number (match-string 1)) (or day month year))
>        (goto-char (point-at-bol)))

While you're at it:

  (beginning-of-line)


Regards,

  reply	other threads:[~2015-09-02 19:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1441180730.git.ruediger@c-plusplus.net>
2015-09-02  8:06 ` [PATCH 1/3] org-datetree.el: Code cleanup Rüdiger Sonderfeld
2015-09-02 19:48   ` Nicolas Goaziou
2015-09-02  8:06 ` [PATCH 2/3] org-datetree.el: Add support for ISO week trees Rüdiger Sonderfeld
2015-09-02 19:58   ` Nicolas Goaziou [this message]
2015-09-03  0:14     ` Rüdiger Sonderfeld
2015-09-03  5:55       ` Nicolas Goaziou
2015-09-07 22:24         ` [PATCH v2 1/3] org-datetree.el: Code cleanup Rüdiger Sonderfeld
2015-09-07 22:24         ` [PATCH v2 2/3] org-datetree.el: Add support for ISO week trees Rüdiger Sonderfeld
2015-09-07 22:24         ` [PATCH v2 3/3] org-capture.el: Add support for " Rüdiger Sonderfeld
2015-09-07 22:27         ` [PATCH 2/3] org-datetree.el: Add support for ISO " Rüdiger Sonderfeld
2015-09-08 15:53           ` Nicolas Goaziou
2015-12-29 17:48             ` [PATCH v3 1/3] org-datetree.el: Code cleanup Rüdiger Sonderfeld
2015-12-29 20:58               ` Nicolas Goaziou
2015-12-29 17:49             ` [PATCH v3 2/3] org-datetree.el: Add support for ISO week trees Rüdiger Sonderfeld
2015-12-29 20:59               ` Nicolas Goaziou
2015-12-29 17:49             ` [PATCH v3 3/3] org-capture.el: Add support for " Rüdiger Sonderfeld
2015-12-29 20:59               ` Nicolas Goaziou
2015-09-02  8:06 ` [PATCH " Rüdiger Sonderfeld
2015-09-02 19:59   ` Nicolas Goaziou
     [not found] <cover.1441051750.git.ruediger@c-plusplus.net>
2015-08-31 20:15 ` [PATCH 2/3] org-datetree.el: Add support for ISO " Rüdiger Sonderfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oahk8ug6.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=ruediger@c-plusplus.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).