emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: Anders Johansson <mejlaandersj@gmail.com>
Cc: org-mode-email <emacs-orgmode@gnu.org>
Subject: Re: Bug: Changed behaviour of org-at-timestamp-p after recent change
Date: Fri, 15 Apr 2022 16:45:44 +0800	[thread overview]
Message-ID: <87tuau20qv.fsf@localhost> (raw)
In-Reply-To: <CAKJdtO8bqdbW5N6pRFNQRATjm2daEBDCpJj0njwcd4fmhSJSKQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2447 bytes --]


Anders Johansson <mejlaandersj@gmail.com> writes:
> Hi,
> I noticed that this commit:
> b1a570b3b  org-agenda: Fix regression when diary sexp timestamps are ignored
>
> made a call like (org-at-timestamp-p 'agenda) match against the regexp
> `org-element--timestamp-regexp`. However, this regexp doesn’t have the
> match groups setup as the others (`org-ts-regexp3` and `org-ts-regexp2`) so
> the last part of the docstring for org-at-timestamp-p doesn’t hold anymore
> (that the timestamp parts should now be put in match groups).

Confirmed.
Can you try the attached patch?

Also, unless I miss something, docstring was not fully obeyed even in
the past. Consider the following timestamp:

 <2022-04-15 Fri 11:40>

I ran the following code with point at the timestamp:
(progn (org-at-timestamp-p ) (mapcar #'substring-no-properties (list (match-string 0) (match-string 1) (match-string 2) (match-string 3) (match-string 4) (match-string 5) (match-string 6) (match-string 7))))

The output is:
("<2022-04-15 Fri 11:40>" "2022-04-15 Fri 11:40" "2022" "04" "15" "Fri" " 11:40" "11" "40")

There are two extra groups (group 1 and group 6), presumably due to
earlier changes in org-ts-regexp1.

> I was using this in some code of mine, but I also realize that this doesn’t
> feel all that clean anyway. I am not sure if this is used elsewhere in org
> though.

I am currently working on an alternative concept of analyzing arbitrary
org element components. Instead of named groups, I plan to provide named
match groups:

(progn (org-element-match 'timestamp) (org-element-match-data))

((:minute-start 314 316)
 (:hour-start 311 313)
 (:day-start 304 306)
 (:month-start 301 303)
 (:year-start 296 300)
 (:date-start 296 316)
 (:timestamp-start 295 317)
 (:end-marker 316 317)
 (:begin-marker 295 296)
 (:full 295 317)
 (:full-no-blank 295 317)
 (:full-no-affiliated 295 317))

The current WIP implementation is in
https://github.com/yantar92/org/blob/feature/org-font-lock-element/lisp/org-element-match.el

The match groups set by org-at-timestamp-p are currently being used by
the following functions: org-mouse-delete-timestamp,
org-follow-timestamp-link, org-time-stamp, org-toggle-timestamp-type

However, all but one of them are only using group 0 and
org-follow-timestamp-link is using group 1 as currently set by
org-at-timestamp-p against the docstring.

Best,
Ihor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-at-timestamp-p-Fix-invalid-regexp-groups-for-age.patch --]
[-- Type: text/x-patch, Size: 2080 bytes --]

From d9a5cb8b7d7b12aca389331f4817130420d2d744 Mon Sep 17 00:00:00 2001
Message-Id: <d9a5cb8b7d7b12aca389331f4817130420d2d744.1650012068.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Fri, 15 Apr 2022 15:05:39 +0800
Subject: [PATCH] org-at-timestamp-p: Fix invalid regexp groups for 'agenda
 scope

* lisp/org.el (org-at-timestamp-p): Make sure that match groups follow
the docstring in `agenda' scope.  Update docstring explaining return
values for sexp timestamps.

Reported in https://orgmode.org/list/CAKJdtO8bqdbW5N6pRFNQRATjm2daEBDCpJj0njwcd4fmhSJSKQ@mail.gmail.com
---
 lisp/org.el | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 3cc8a5036..b736a3824 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15248,20 +15248,24 @@ (defun org-at-timestamp-p (&optional extended)
 When at a timestamp, return the position of the point as a symbol
 among `bracket', `after', `year', `month', `hour', `minute',
 `day' or a number of character from the last know part of the
-time stamp.
+time stamp.  If diary sexp timestamps, any point inside the timestamp
+is considered `day' (i.e. only `bracket', `day', and `after' return
+values are possible).
 
 When matching, the match groups are the following:
-  group 1: year
-  group 2: month
-  group 3: day number
-  group 4: day name
+  group 1: year, if any
+  group 2: month, if any
+  group 3: day number, if any
+  group 4: day name, if any
   group 5: hours, if any
   group 6: minutes, if any"
-  (let* ((regexp (if extended
-                     (if (eq extended 'agenda)
-                         org-element--timestamp-regexp
-		       org-ts-regexp3)
-                   org-ts-regexp2))
+  (let* ((regexp
+          (if extended
+              (if (eq extended 'agenda)
+                  (rx (or (regexp org-ts-regexp3)
+                          (regexp org-element--timestamp-regexp)))
+		org-ts-regexp3)
+            org-ts-regexp2))
 	 (pos (point))
 	 (match?
 	  (let ((boundaries (org-in-regexp regexp)))
-- 
2.35.1


      reply	other threads:[~2022-04-15  8:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-11 11:55 Bug: Changed behaviour of org-at-timestamp-p after recent change Anders Johansson
2022-04-15  8:45 ` Ihor Radchenko [this message]

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=87tuau20qv.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mejlaandersj@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).