emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [PATCH 2/3] org-datetree.el: Add support for ISO week trees.


From: Nicolas Goaziou
Subject: Re: [O] [PATCH 2/3] org-datetree.el: Add support for ISO week trees.
Date: Wed, 02 Sep 2015 21:58:17 +0200

Rüdiger Sonderfeld <address@hidden> 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:]:address@hidden:\\)?\\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 via email to

[Prev in Thread] Current Thread [Next in Thread]