emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BUG] org-compile-prefix-format regexp change breaks eval forms [9.4.6 (9.4.6-gf72a65)]
@ 2021-05-26 23:42 Radon Rosborough
  2021-05-27  3:25 ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Radon Rosborough @ 2021-05-26 23:42 UTC (permalink / raw)
  To: Emacs-orgmode

Hello,

In commit 0260d2fcf603f30210e2b95d37727edd832c12e9 of 2021-04-26, the
regexp used in `org-agenda-prefix-format' was updated to use a
non-greedy regexp, in order to allow multiple %(expression) instances
in `org-agenda-prefix-format'. Unfortunately, this change breaks the
ability to use nested forms in %(expression) instances. For example, I
use the following setting for `org-agenda-prefix-format':

(setf (alist-get 'agenda org-agenda-prefix-format)
          "  %(format-time-string \"%a\" (org-get-deadline-time (point)))  ")

When running `org-agenda', I now receive the error
`org-compile-prefix-format: End of file during parsing'. This is
because of the updated regexp match, which stops at the first closing
parenthesis:

ELISP> myfmt
"  %(format-time-string \"%a\" (org-get-deadline-time (point)))  "
ELISP> (and (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([
.;,:!?=|/<>]?\\)\\([cltseib]\\|(.+?)\\)" myfmt) (match-string 4
myfmt))
"(format-time-string \"%a\" (org-get-deadline-time (point)"

With the previous regexp, it works fine:

ELISP> (and (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([
.;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)" myfmt) (match-string 4 myfmt))
"(format-time-string \"%a\" (org-get-deadline-time (point)))"

Thanks,
Radon Rosborough


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [BUG] org-compile-prefix-format regexp change breaks eval forms [9.4.6 (9.4.6-gf72a65)]
  2021-05-26 23:42 [BUG] org-compile-prefix-format regexp change breaks eval forms [9.4.6 (9.4.6-gf72a65)] Radon Rosborough
@ 2021-05-27  3:25 ` Ihor Radchenko
  2021-05-29 21:18   ` Radon Rosborough
  0 siblings, 1 reply; 6+ messages in thread
From: Ihor Radchenko @ 2021-05-27  3:25 UTC (permalink / raw)
  To: Radon Rosborough; +Cc: Emacs-orgmode

Radon Rosborough <radon.neon@gmail.com> writes:

> Hello,
>
> In commit 0260d2fcf603f30210e2b95d37727edd832c12e9 of 2021-04-26, the
> regexp used in `org-agenda-prefix-format' was updated to use a
> non-greedy regexp, in order to allow multiple %(expression) instances
> in `org-agenda-prefix-format'. Unfortunately, this change breaks the
> ability to use nested forms in %(expression) instances. For example, I
> use the following setting for `org-agenda-prefix-format':

Confirmed.

Sorry, I noticed this problem after sending the patch, but I do not know
an easy way to solve it. To handle sexps properly, we need to do
something more complex than just a simple regexp. Probably, using
org-element--parse-paired-brackets or similar code.

Fixing this is (down) in my todo-list, but patches are welcome.

Best,
Ihor


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [BUG] org-compile-prefix-format regexp change breaks eval forms [9.4.6 (9.4.6-gf72a65)]
  2021-05-27  3:25 ` Ihor Radchenko
@ 2021-05-29 21:18   ` Radon Rosborough
  2021-05-30  8:04     ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Radon Rosborough @ 2021-05-29 21:18 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Emacs-orgmode

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

If you insert the format string into a temporary buffer, then the `read'
function will read up to the closing parenthesis and update point
accordingly. That would be a foolproof way to handle all possible Lisp
forms: use a regexp to find the start, and then use `read' to find the end.
Then proceed with regexp matching, and repeat like that.

[-- Attachment #2: Type: text/html, Size: 373 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [BUG] org-compile-prefix-format regexp change breaks eval forms [9.4.6 (9.4.6-gf72a65)]
  2021-05-29 21:18   ` Radon Rosborough
@ 2021-05-30  8:04     ` Ihor Radchenko
  2021-05-30 16:48       ` Radon Rosborough
  2021-09-26  7:12       ` Bastien
  0 siblings, 2 replies; 6+ messages in thread
From: Ihor Radchenko @ 2021-05-30  8:04 UTC (permalink / raw)
  To: Radon Rosborough; +Cc: Emacs-orgmode

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

Radon Rosborough <radon.neon@gmail.com> writes:

> If you insert the format string into a temporary buffer, then the `read'
> function will read up to the closing parenthesis and update point
> accordingly. That would be a foolproof way to handle all possible Lisp
> forms: use a regexp to find the start, and then use `read' to find the end.
> Then proceed with regexp matching, and repeat like that.

Thanks for the suggestion! The patch is attached.

Best,
Ihor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-sexps-with-nested-parenthesis-in-org-agenda-pr.patch --]
[-- Type: text/x-diff, Size: 1862 bytes --]

From ffbf7fe29913e33e3f20544be49b6cc2c0ef6409 Mon Sep 17 00:00:00 2001
Message-Id: <ffbf7fe29913e33e3f20544be49b6cc2c0ef6409.1622361756.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Sun, 30 May 2021 16:00:07 +0800
Subject: [PATCH] Allow sexps with nested parenthesis in
 org-agenda-prefix-format

* lisp/org-agenda.el (org-compile-prefix-format): Use `read' instead
of pure regexp matching to determine bounds of %(sexp) expressions in
`org-agenda-prefix-format'.

Fixes https://orgmode.org/list/87fsy8yi1e.fsf@localhost/
---
 lisp/org-agenda.el | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index f49a24f88..fcfcd872e 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -6942,7 +6942,7 @@ (defun org-compile-prefix-format (key)
 		  (and (string-match "\\.[0-9]+" x)
 		       (string-to-number (substring (match-string 0 x) 1)))))))
       (if (eq var 'eval)
-	  (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
+	  (setq varform `(format ,f (org-eval ,(read (substring s (match-beginning 4))))))
 	(if opt
 	    (setq varform
 		  `(if (member ,var '("" nil))
@@ -6951,7 +6951,12 @@ (defun org-compile-prefix-format (key)
 	  (setq varform
 		`(format ,f (if (member ,var '("" nil)) ""
 			      (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
-      (setq s (replace-match "%s" t nil s))
+      (if (eq var 'eval)
+          (setf (substring s (match-beginning 0)
+                           (+ (match-beginning 4)
+                              (length (format "%S" (read (substring s (match-beginning 4)))))))
+                "%s")
+        (setq s (replace-match "%s" t nil s)))
       (push varform vars))
     (setq vars (nreverse vars))
     (with-current-buffer (or org-agenda-buffer (current-buffer))
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [BUG] org-compile-prefix-format regexp change breaks eval forms [9.4.6 (9.4.6-gf72a65)]
  2021-05-30  8:04     ` Ihor Radchenko
@ 2021-05-30 16:48       ` Radon Rosborough
  2021-09-26  7:12       ` Bastien
  1 sibling, 0 replies; 6+ messages in thread
From: Radon Rosborough @ 2021-05-30 16:48 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Emacs-orgmode

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

Ah yes, you can also check the length of the form that was read. Good call,
I didn't think of that option, which is clearly better than using a
temporary buffer. Thanks!

[-- Attachment #2: Type: text/html, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [BUG] org-compile-prefix-format regexp change breaks eval forms [9.4.6 (9.4.6-gf72a65)]
  2021-05-30  8:04     ` Ihor Radchenko
  2021-05-30 16:48       ` Radon Rosborough
@ 2021-09-26  7:12       ` Bastien
  1 sibling, 0 replies; 6+ messages in thread
From: Bastien @ 2021-09-26  7:12 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Radon Rosborough, Emacs-orgmode

Ihor Radchenko <yantar92@gmail.com> writes:

> Thanks for the suggestion! The patch is attached.

Applied, thanks.

-- 
 Bastien


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-09-26  7:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-26 23:42 [BUG] org-compile-prefix-format regexp change breaks eval forms [9.4.6 (9.4.6-gf72a65)] Radon Rosborough
2021-05-27  3:25 ` Ihor Radchenko
2021-05-29 21:18   ` Radon Rosborough
2021-05-30  8:04     ` Ihor Radchenko
2021-05-30 16:48       ` Radon Rosborough
2021-09-26  7:12       ` Bastien

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).