emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Morgan Smith <morgan.j.smith@outlook.com>
Cc: emacs-orgmode@gnu.org, Sanel Zukan <sanelz@gmail.com>
Subject: Re: Parse malformed clocklines (was: Re: [PATCH] lisp/org-clock.el (org-clock-sum): Rewrite regex using rx)
Date: Wed, 26 Jun 2024 09:02:35 +0000	[thread overview]
Message-ID: <87ikxw3wlw.fsf@localhost> (raw)
In-Reply-To: <CH3PR84MB34243D1F564538B01F270DE5C5D42@CH3PR84MB3424.NAMPRD84.PROD.OUTLOOK.COM>

Morgan Smith <morgan.j.smith@outlook.com> writes:

>> I think that the best course of action when a problematic timestamp
>> without opening/closing time is encountered is:
>>
>> 1. Warn user
>> 2. Still calculate the duration, assuming 0s in time (simply because
>>    previous versions of Org mode did it)
>>
>> (2) is kind of debatable, but I can imagine some users might make use of
>>
>> such feature by putting clocks by hand:
>> CLOCK: [2023-11-15 Wed]--[2023-11-16 Thu] => 24:00
>>
>> These users may then simply suppress the warning.
>
> I'm very tempted to just make it hard rule that clocklines need to be
> fully specified.  If you take a look at the attached patch, it shows one
> way we could do this.
>
> First, I modify the timestamp parser so the ":*-end" variables don't
> always inherit the ":*-start" variables.  They can be nil independent of
> the start.

> -	    (setq year-end (or (nth 5 date) year-start)
> -		  month-end (or (nth 4 date) month-start)
> -		  day-end (or (nth 3 date) day-start)
> -		  hour-end (or (nth 2 date) (car time-range) hour-start)
> -		  minute-end (or (nth 1 date) (cdr time-range) minute-start))))
> +	    (setq year-end (or (nth 5 date) (and time-range year-start))
> +		  month-end (or (nth 4 date) (and time-range month-start))
> +		  day-end (or (nth 3 date) (and time-range day-start))
> +		  hour-end (or (nth 2 date) (car time-range))
> +		  minute-end (or (nth 1 date) (cdr time-range)))))

This is harmless, but also does nothing - if there is no year, month,
and date specified, `date-end' would never match.

> 1. Will changing the timestamp parser have far-reaching implications?
> Is this something I should avoid?

Clock lines and timestamps are not only used to calculate clock
sums. They can, for example, be exported. Or they can be used manually,
by reading them as text. So, any kind of change in the parser should be
considered extremely carefully.

> Then in the clockline parser I ensure that every single field is set.
> If it isn't, then I set the timestamp to nil so it won't be used.

> 2. Is there a way to give user errors in the parser code?  I'm using
> `org-element--cache-warn' in my patch but I'm not sure that's the right
> thing to do.  (if it is the right thing then we need to define it
> earlier in the file)

This is not acceptable.
org-element is a _parser_. It has nothing to do with interpretation of
timestamps. Moreover, there is no notion of "invalid" syntax in Org mode
- any text is a valid Org syntax, although it may be interpreted as
plain text if it does not fit any existing markup.

I still insist that it is a job of the Elisp code that interprets the
clock lines (the clock sum function) to display warnings and otherwise
analyze the timestamp components. We may also hint potential problems in
org-lint.

-- 
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:[~2024-06-26  9:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11 17:20 [PATCH] lisp/org-clock.el (org-clock-sum): Rewrite regex using rx Morgan Smith
2024-04-13 14:49 ` Ihor Radchenko
2024-04-13 16:08   ` Morgan Smith
2024-04-13 16:48     ` Ihor Radchenko
2024-04-13 17:46       ` Morgan Smith
2024-06-18  7:39         ` Ihor Radchenko
2024-06-19 14:57           ` Morgan Smith
2024-06-19 15:46             ` Ihor Radchenko
2024-06-19 18:24               ` Morgan Smith
2024-06-20  9:07                 ` Ihor Radchenko
2024-06-24 12:09                   ` Parse malformed clocklines (was: Re: [PATCH] lisp/org-clock.el (org-clock-sum): Rewrite regex using rx) Morgan Smith
2024-06-26  9:02                     ` Ihor Radchenko [this message]
2024-04-14 12:53       ` [PATCH] lisp/org-clock.el (org-clock-sum): Rewrite regex using rx 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

  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=87ikxw3wlw.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=morgan.j.smith@outlook.com \
    --cc=sanelz@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 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).