emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Sławomir Grochowski" <slawomir.grochowski@gmail.com>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: [BUG] colview.el regexp - capture operator when title is empty
Date: Sun, 25 Aug 2024 14:59:50 +0200	[thread overview]
Message-ID: <8734msbvw9.fsf@gmail.com> (raw)
In-Reply-To: <8734ms6ake.fsf@localhost>

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

Ihor Radchenko <yantar92@posteo.net> writes:
> There is no patch attached.


[-- Attachment #2: 0001-lisp-org-colview.el-org-columns-compile-format-regex.patch --]
[-- Type: text/x-diff, Size: 3702 bytes --]

From 987f66774db4ad1e515cac4b9fc5ba46bd627c27 Mon Sep 17 00:00:00 2001
From: Slawomir Grochowski <slawomir.grochowski@gmail.com>
Date: Sat, 24 Aug 2024 18:47:09 +0200
Subject: [PATCH] lisp/org-colview.el: org-columns-compile-format regexp bugfix
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/org-colview.el (org-columns-compile-format): Refactor
string-based regexp to `rx' form. Fix regexp: When an empty
parentheses `()` is in the column format string then the regexp
can't capture the operator which is in curly brackets `{}`.
(org-columns-new): prevent adding empty parantheses '()' to 'column
format string' when 'column title' is empty.
* testing/lisp.test-org-colview.el (test-org-colview/compile-format):
add new case to test: check if operator will be captured when there is
empty parantheses '()' in 'column format string'.

Reported-by: Sławomir Grochowski <slawomir.grochowski@gmail.com>
Link: https://list.orgmode.org/orgmode/877ccczt83.fsf@gmail.com/
---
 lisp/org-colview.el              | 19 ++++++++++++-------
 testing/lisp/test-org-colview.el |  7 ++++++-
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index bc93941e4..b111c1676 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -935,8 +935,9 @@ details."
 			 (mapcar #'list (org-buffer-property-keys t nil t))
 			 nil nil (nth 0 spec))))
 		   (list prop
-			 (read-string (format "Column title [%s]: " prop)
-				      (nth 1 spec))
+			 (org-string-nw-p
+                          (read-string (format "Column title [%s]: " prop)
+				       (nth 1 spec)))
 			 ;; Use `read-string' instead of `read-number'
 			 ;; to allow empty width.
 			 (let ((w (read-string
@@ -1183,14 +1184,18 @@ This function updates `org-columns-current-fmt-compiled'."
   (setq org-columns-current-fmt-compiled nil)
   (let ((start 0))
     (while (string-match
-	    "%\\([0-9]+\\)?\\([[:alnum:]_-]+\\)\\(?:(\\([^)]+\\))\\)?\
-\\(?:{\\([^}]+\\)}\\)?\\s-*"
-	    fmt start)
+            (rx "%"
+                (optional (group (+ digit)))
+                (group (one-or-more (in alnum "_-")))
+                (optional "(" (group (zero-or-more (not (any ")")))) ")")
+                (optional "{" (group (zero-or-more (not (any "}")))) "}")
+                (zero-or-more space))
+    	    fmt start)
       (setq start (match-end 0))
       (let* ((width (and (match-end 1) (string-to-number (match-string 1 fmt))))
 	     (prop (match-string-no-properties 2 fmt))
-	     (title (or (match-string-no-properties 3 fmt) prop))
-	     (operator (match-string-no-properties 4 fmt)))
+	     (title (or (org-string-nw-p (match-string-no-properties 3 fmt)) prop))
+	     (operator (org-string-nw-p (match-string-no-properties 4 fmt))))
 	(push (if (not operator) (list (upcase prop) title width nil nil)
 		(let (printf)
 		  (when (string-match ";" operator)
diff --git a/testing/lisp/test-org-colview.el b/testing/lisp/test-org-colview.el
index 6b603c31b..623ee6283 100644
--- a/testing/lisp/test-org-colview.el
+++ b/testing/lisp/test-org-colview.el
@@ -90,7 +90,12 @@
   (should
    (equal `(("ITEM" "ITEM" nil "+" "%.1f"))
           (org-columns-compile-format
-           "%ITEM{+;%.1f}"))))
+           "%ITEM{+;%.1f}")))
+  (should
+   ;; Bug https://list.orgmode.org/orgmode/877ccczt83.fsf@gmail.com/
+   (equal '(("ITEM" "ITEM" nil "X" nil))
+          (org-columns-compile-format
+           "%ITEM(){X}"))))
 
 (ert-deftest test-org-colview/substring-below-width ()
   "Test `org-columns--truncate-below-width'."
-- 
2.30.2


[-- Attachment #3: Type: text/plain, Size: 25 bytes --]


-- 
Slawomir Grochowski

  reply	other threads:[~2024-08-25 13:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-19 10:45 [BUG] colview.el regexp - capture operator when title is empty Sławomir Grochowski
2024-08-20 18:21 ` Ihor Radchenko
2024-08-21  8:27   ` Sławomir Grochowski
2024-08-25 12:35     ` Sławomir Grochowski
2024-08-25 12:39       ` Ihor Radchenko
2024-08-25 12:59         ` Sławomir Grochowski [this message]
2024-08-31 13:34           ` 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=8734msbvw9.fsf@gmail.com \
    --to=slawomir.grochowski@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@posteo.net \
    /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).