all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Ilya Chernyshov <ichernyshovvv@gmail.com>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] org-element-timestamp-interpreter: Return daterange anyway, if DATERANGE is non-nil
Date: Sun, 02 Jul 2023 08:46:08 +0000	[thread overview]
Message-ID: <87wmzi4s6n.fsf@localhost> (raw)
In-Reply-To: <CAGEwbGU9bmg=jAAX5OTrcrjV0q67Nd2yR3aVM4Z-yOUv1Pz1sQ@mail.gmail.com>

Ilya Chernyshov <ichernyshovvv@gmail.com> writes:

> In the new patch I added :range-type timestamp property, adjusted
> interpreter,
> parser functions, added tests for the property.

Thanks!

Some general stylistic comments:

1. You left some whitespace-only blank lines and spaces at the end of
   lines. Please, clean them up.
2. Please, use double space between sentences in the commit message and
   link to this thread. See
   https://orgmode.org/worg/org-contribute.html#commit-messages
3. I noticed some (let((...) forms. Please put spaces between sexps like
   (let ((...)
       ^ space here

> * lisp/org-element (org-element-timestamp-parser): Add :range-type property

Dot is missing at the end of the sentence here.

>  (defun org-element-timestamp-interpreter (timestamp _)
>    "Interpret TIMESTAMP object as Org syntax."
> ...
> +	         (concat
> +                  "<" start-date (and start-time (concat " " start-time))
> +                  (if date-range-p
> +                      (concat ">--<" end-date (and end-time (concat " " end-time)))
> +                    (if time-range-p (concat "-" end-time)))
> +                  ">")))

Here, you are manually constructing time part of the timestamp,
bypassing `org-time-stamp-format' and `org-timestamp-formats'. Please,
use `org-time-stamp-format' for times as well.
If necessary, feed free to extend `org-time-stamp-format' and the value
of `org-timestamp-formats' constant.

> +	    (dolist (s (list repeat-string warning-string))
> +	      (when (org-string-nw-p s)
> +	        (setq ts (string-replace ">" (concat " " s ">") ts))))
> +	    (pcase (org-element-property :type timestamp)
> +              ((or `active `active-range)
> +               ts)
> +              ((or `inactive `inactive-range)
> +               (string-replace
> +                "<" "["
> +                (string-replace ">" "]" ts)))))))

`string-replace' is fragile here. If we ever need to put "<" or ">"
inside timestamp, random breakages may happen. Please, rewrite.



>    (should
>     (string-match
> -    "\\[2012-03-29 .* 16:40\\]--\\[2012-03-29 .* 16:41\\]"
> +    "\\[2012-03-29 .* 16:40-16:41\\]"
>      (org-element-timestamp-interpreter
>       '(timestamp
>         (:type inactive-range :year-start 2012 :month-start 3 :day-start 29
>  	      :hour-start 16 :minute-start 40 :year-end 2012 :month-end 3
>  	      :day-end 29 :hour-end 16 :minute-end 41)) nil)))
> +  
>    ;; Diary.
>    (should (equal (org-test-parse-and-interpret "<%%diary-float t 4 2>")
>  		 "<%%diary-float t 4 2>\n"))
> -- 
> 2.40.1

> * lisp/org-element (org-element-timestamp-interpreter): For ranges:
> When :range-type is nil or `timerange', return timerange (<YYYY-mm-DD
> HH:MM-HH:MM>) if date-start and date-end are equal; return
> daterange(<...>--<...>) otherwise. When :range-type is `daterange',
> return daterange anyway. Refactor the code.

Interpreting timestamps with :time-range nil and
:day-end/:year-end/:month-end non-nil as timerange is a breaking change.
Let's avoid it.

With the new version of the parser, the test example will never happen,
but the tested AST structure might happen in the wild - we do not want
to break anything when it is not necessary.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


  reply	other threads:[~2023-07-02  8:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-19 12:25 [PATCH] org-element-timestamp-interpreter: Return daterange anyway, if DATERANGE is non-nil Ilya Chernyshov
2023-02-19 14:11 ` Ilya Chernyshov
2023-02-20 11:07 ` Ihor Radchenko
2023-02-20 16:36   ` Ilya Chernyshov
2023-02-22 11:21     ` Ihor Radchenko
2023-07-01 19:47       ` Ilya Chernyshov
2023-07-02  8:46         ` Ihor Radchenko [this message]
2023-07-07  7:24           ` Ilya Chernyshov
2023-07-08  8:35             ` Ihor Radchenko
2023-07-10 18:19               ` Ilya Chernyshov
2023-07-11  9:02                 ` Ihor Radchenko
2023-07-11 13:16                   ` Ilya Chernyshov
2023-07-12  8:16                     ` Ihor Radchenko

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

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

  git send-email \
    --in-reply-to=87wmzi4s6n.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=ichernyshovvv@gmail.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.