Re: [PATCH] lisp/ol.el: Trim search string before attempting to normalize it.

2026-07-15 Thread Ihor Radchenko
Earl Chase  writes:

>> Thanks!
>> Several comments:
>>
>> 1. You copy-paste org-test-with-temp-text-in-file almost in full,
>>removing (org-mode) call. Why not just doing something like
>>(org-test-with-temp-text-in-file ... (fundamental-mode) ...)?
>>
>
> Done.
>
>> 2. Please add Reported-by: and Link: to the report in the commit message.
>>
>
> Done.

Thanks!
Applied, onto main, after removing stray "." in the first line of the
commit message. It should not end with "." by convention
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=d27f01a19


-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH] lisp/ol.el: Trim search string before attempting to normalize it.

2026-07-11 Thread Earl Chase
> Thanks!
> Several comments:
>
> 1. You copy-paste org-test-with-temp-text-in-file almost in full,
>removing (org-mode) call. Why not just doing something like
>(org-test-with-temp-text-in-file ... (fundamental-mode) ...)?
>

Done.

> 2. Please add Reported-by: and Link: to the report in the commit message.
>

Done.

Le sam. 11 juil. 2026 à 03:57, Ihor Radchenko  a écrit :
>
> Earl Chase  writes:
>
> > I wrote the patch that caused this, so this is my bad. We can't just change
> > the order of "(append valid-symbols (list 'contiguous-spaces
> > 'leading-and-trailing-spaces)))" as you suggested since
> > `org-link--remove-statistics-cookies' and 'org-link--remove-pipe-chars' can
> > add spaces to the search string. So instead we just trim twice, before we
> > attempt to normalize the search string and after we finish normalizing the
> > search string. I added new tests to confirm that this approach works.
>
> Thanks!
> Several comments:
>
> 1. You copy-paste org-test-with-temp-text-in-file almost in full,
>removing (org-mode) call. Why not just doing something like
>(org-test-with-temp-text-in-file ... (fundamental-mode) ...)?
>
> 2. Please add Reported-by: and Link: to the report in the commit message.
>
> --
> Ihor Radchenko // yantar92,
> Org mode maintainer,
> 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>
From 52b93e0daa687b3cbaa11f805224a4021a041288 Mon Sep 17 00:00:00 2001
From: ApollonDeParnasse 
Date: Thu, 9 Jul 2026 13:04:44 -0500
Subject: [PATCH] lisp/ol.el: Trim search string before attempting to normalize
 it.

* lisp/ol.el (org-link-normalize-string): Trim search string before
attempting to normalize it.
* testing/lisp/test-ol.el (test-org-link/precise-link-target):
New tests for `org-link-precise-link-target'.

Reported-by: Zhengyi Fu 
Link: https://list.orgmode.org/[email protected]/
---
 lisp/ol.el  |   8 ++-
 testing/lisp/test-ol.el | 148 
 2 files changed, 139 insertions(+), 17 deletions(-)

diff --git a/lisp/ol.el b/lisp/ol.el
index 96edafa17..3d0e32bcc 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -989,10 +989,14 @@ subset of (statistics-cookies search-syntax pipe-chars):
 - `search-syntax' is # in #heading and enclosing () in (ref)
 - `pipe-chars' are | characters that may clash with table syntax."
   (let* ((valid-symbols (seq-intersection ignored-contents (list 'statistics-cookies 'search-syntax 'pipe-chars)))
- (values-to-remove (append valid-symbols (list 'contiguous-spaces 'leading-and-trailing-spaces
+ (values-to-remove (append valid-symbols (list 'contiguous-spaces 'leading-and-trailing-spaces)))
+ ;; We trim twice: before we run our string normalizers
+ ;; and after in order to remove any spaces that were introduced
+ ;; by the normalization process
+ (trimmed-string (org-trim string)))
 (seq-reduce (lambda (str func) (funcall (map-elt org-link--string-normalizers func) str))
 values-to-remove
-string)))
+trimmed-string)))
 
 (defun org-link--reveal-maybe (region _)
   "Reveal folded link in REGION when needed.
diff --git a/testing/lisp/test-ol.el b/testing/lisp/test-ol.el
index 1487f7d38..7f4f41348 100644
--- a/testing/lisp/test-ol.el
+++ b/testing/lisp/test-ol.el
@@ -713,21 +713,139 @@ See https://github.com/yantar92/org/issues/4.";
 
 (ert-deftest test-org-link/precise-link-target ()
   "Test `org-link-precise-link-target` specifications."
-  (org-test-with-temp-text "* H1\n* H2\n"
-(should
- (equal '("*H1" "H1" 1)
-(org-link-precise-link-target
-  (org-test-with-temp-text "* H1\n#+name: foo\n#+begin_example\nhi\n#+end_example\n"
-(should
- (equal '("foo" "foo" 6)
-(org-link-precise-link-target
-  (org-test-with-temp-text "\nText\n* H1\n"
-(should
- (equal '("Text" nil 2)
-(org-link-precise-link-target
-  (org-test-with-temp-text "\n\n* H1\n"
-(should
- (equal nil (org-link-precise-link-target)
+  (cl-macrolet ((with-text-in-regular-buffer (text &rest body)
+  `(org-test-with-temp-text-in-file ,text
+ (progn
+   (fundamental-mode)
+   ,@body
+(org-test-with-temp-text "* H1\n* H2\n"
+  (should
+   (equal '("*H1" "H1" 1)
+  (org-link-precise-link-target
+(org-test-with-temp-text

Re: [PATCH] lisp/ol.el: Trim search string before attempting to normalize it.

2026-07-11 Thread Ihor Radchenko
Earl Chase  writes:

> I wrote the patch that caused this, so this is my bad. We can't just change
> the order of "(append valid-symbols (list 'contiguous-spaces
> 'leading-and-trailing-spaces)))" as you suggested since
> `org-link--remove-statistics-cookies' and 'org-link--remove-pipe-chars' can
> add spaces to the search string. So instead we just trim twice, before we
> attempt to normalize the search string and after we finish normalizing the
> search string. I added new tests to confirm that this approach works.

Thanks!
Several comments:

1. You copy-paste org-test-with-temp-text-in-file almost in full,
   removing (org-mode) call. Why not just doing something like
   (org-test-with-temp-text-in-file ... (fundamental-mode) ...)?

2. Please add Reported-by: and Link: to the report in the commit message.

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH] lisp/ol.el: Trim search string before attempting to normalize it.

2026-07-10 Thread Zhengyi Fu
Earl Chase  writes:

> I wrote the patch that caused this, so this is my bad. We can't just
> change the order of "(append valid-symbols (list 'contiguous-spaces
> 'leading-and-trailing-spaces)))" as you suggested since
> `org-link--remove-statistics-cookies' and
> 'org-link--remove-pipe-chars' can add spaces to the search string. So
> instead we just trim twice, before we attempt to normalize the search
> string and after we finish normalizing the search string. I added new
> tests to confirm that this approach works.

Thank you.  The patch works for me.



Re: [PATCH] lisp/ol.el: Trim search string before attempting to normalize it.

2026-07-09 Thread Earl Chase
Related-to: https://list.orgmode.org/[email protected]/

Sorry, this was supposed to be a response to the above email.

Le jeu. 9 juil. 2026 à 13:17, Earl Chase  a écrit :

> I wrote the patch that caused this, so this is my bad. We can't just
> change the order of "(append valid-symbols (list 'contiguous-spaces
> 'leading-and-trailing-spaces)))" as you suggested since
> `org-link--remove-statistics-cookies' and 'org-link--remove-pipe-chars' can
> add spaces to the search string. So instead we just trim twice, before we
> attempt to normalize the search string and after we finish normalizing the
> search string. I added new tests to confirm that this approach works.
>


[PATCH] lisp/ol.el: Trim search string before attempting to normalize it.

2026-07-09 Thread Earl Chase
I wrote the patch that caused this, so this is my bad. We can't just change
the order of "(append valid-symbols (list 'contiguous-spaces
'leading-and-trailing-spaces)))" as you suggested since
`org-link--remove-statistics-cookies' and 'org-link--remove-pipe-chars' can
add spaces to the search string. So instead we just trim twice, before we
attempt to normalize the search string and after we finish normalizing the
search string. I added new tests to confirm that this approach works.
From 9b7064c929528f2c6a3709873a3a66a19742f36a Mon Sep 17 00:00:00 2001
From: ApollonDeParnasse 
Date: Thu, 9 Jul 2026 13:04:44 -0500
Subject: [PATCH] lisp/ol.el: Trim search string before attempting to normalize
 it.

* lisp/ol.el (org-link-normalize-string): Trim search string before
attempting to normalize it.
* testing/lisp/test-ol.el (test-org-link/precise-link-target):
New tests for `org-link-precise-link-target'.
---
 lisp/ol.el  |   8 +-
 testing/lisp/test-ol.el | 158 
 2 files changed, 149 insertions(+), 17 deletions(-)

diff --git a/lisp/ol.el b/lisp/ol.el
index 96edafa17..3d0e32bcc 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -989,10 +989,14 @@ subset of (statistics-cookies search-syntax pipe-chars):
 - `search-syntax' is # in #heading and enclosing () in (ref)
 - `pipe-chars' are | characters that may clash with table syntax."
   (let* ((valid-symbols (seq-intersection ignored-contents (list 'statistics-cookies 'search-syntax 'pipe-chars)))
- (values-to-remove (append valid-symbols (list 'contiguous-spaces 'leading-and-trailing-spaces
+ (values-to-remove (append valid-symbols (list 'contiguous-spaces 'leading-and-trailing-spaces)))
+ ;; We trim twice: before we run our string normalizers
+ ;; and after in order to remove any spaces that were introduced
+ ;; by the normalization process
+ (trimmed-string (org-trim string)))
 (seq-reduce (lambda (str func) (funcall (map-elt org-link--string-normalizers func) str))
 values-to-remove
-string)))
+trimmed-string)))
 
 (defun org-link--reveal-maybe (region _)
   "Reveal folded link in REGION when needed.
diff --git a/testing/lisp/test-ol.el b/testing/lisp/test-ol.el
index 1487f7d38..bb0c63a8b 100644
--- a/testing/lisp/test-ol.el
+++ b/testing/lisp/test-ol.el
@@ -713,21 +713,149 @@ See https://github.com/yantar92/org/issues/4.";
 
 (ert-deftest test-org-link/precise-link-target ()
   "Test `org-link-precise-link-target` specifications."
-  (org-test-with-temp-text "* H1\n* H2\n"
-(should
- (equal '("*H1" "H1" 1)
-(org-link-precise-link-target
-  (org-test-with-temp-text "* H1\n#+name: foo\n#+begin_example\nhi\n#+end_example\n"
-(should
- (equal '("foo" "foo" 6)
-(org-link-precise-link-target
-  (org-test-with-temp-text "\nText\n* H1\n"
-(should
- (equal '("Text" nil 2)
-(org-link-precise-link-target
-  (org-test-with-temp-text "\n\n* H1\n"
-(should
- (equal nil (org-link-precise-link-target)
+  (cl-macrolet ((with-text-in-regular-buffer (text &rest body)
+  (org-with-gensyms (file inside-text buffer)
+`(let ((,file (make-temp-file "org-test"))
+   (,inside-text (if (stringp ,text) ,text (eval ,text)))
+   ,buffer)
+   (with-temp-file ,file (insert ,inside-text))
+   (unwind-protect
+   (progn
+ (setq ,buffer (find-file ,file))
+ (when (re-search-forward "" nil t)
+   (replace-match ""))
+ (progn ,@body))
+ (let ((kill-buffer-query-functions nil))
+   (org-test-kill-buffer ,buffer)
+   (delete-file ,file)))
+(org-test-with-temp-text "* H1\n* H2\n"
+  (should
+   (equal '("*H1" "H1" 1)
+  (org-link-precise-link-target
+(org-test-with-temp-text "* H1\n#+name: foo\n#+begin_example\nhi\n#+end_example\n"
+  (should
+   (equal '("foo" "foo" 6)
+  (org-link-precise-link-target
+(org-test-with-temp-text "\nText\n* H1\n"
+  (should
+   (equal '("Text" nil 2)
+  (org-link-precise-link-target
+(org-test-with-temp-text "\n\n* H1\n"
+  (should
+   (equal nil (org-link-precise-link-target
+;; Assert search-syntax is removed
+;;# + no leading spaces
+(with-