Hi,

Today I found that test-org/auto-repeat-maybe fails on my system
(LANG=zh_CN.UTF-8):

    make BTEST_RE='^test-org/auto-repeat-maybe$$' test

    FAILED test-org/auto-repeat-maybe "Not at a timestamp"

while it passes under the C locale:

    LANG=C make BTEST_RE='^test-org/auto-repeat-maybe$$' test

The cause is in org-timestamp-change. It deletes the timestamp and
inserts a new one, writing the weekday name in the current locale, then
puts point back in the part of the timestamp it was in. The test
timestamps spell weekday names in English, and Chinese names are one
character long, so "Mon" becomes "一" and the timestamp gets two
characters shorter. org-auto-repeat-maybe calls org-timestamp-change
with point on the closing bracket. For that position, however,
org-timestamp-change puts point back at its old position, which is now
after the timestamp, so the next call fails ("Not at a timestamp").

The same happens with other locales whose weekday names are one
character long, such as Japanese or Korean, and in C locale with a
timestamp like <2026-11-18 Wednesday .+1d>, whose weekday name is longer
than the one of the locale.

Commit 58dbdb25a fixed a similar problem for point right after the
timestamp (/after/ position), but not on the closing bracket. The
attached patch puts point on the closing bracket of the new timestamp,
like /after/ does with its end. It also adds tests to
test-org/org-timestamp-change, which fail without the fix in any locale.
With the patch, test-org/auto-repeat-maybe passes with LANG=zh_CN.UTF-8.

-- 
Mingzhe Chen // hxppdv
>From 9a41933e565f59204917a7fd0854a948ccef3cd7 Mon Sep 17 00:00:00 2001
From: Mingzhe Chen <[email protected]>
Date: Sun, 22 Nov 2026 05:08:48 +0000
Subject: [PATCH] org-timestamp-change: Handle `bracket' position

* lisp/org-timestamp.el (org-timestamp-change):
Handle `bracket' position.
* testing/lisp/test-org.el (test-org/org-timestamp-change): Add tests.
---
 lisp/org-timestamp.el    |  5 +++++
 testing/lisp/test-org.el | 15 ++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/lisp/org-timestamp.el b/lisp/org-timestamp.el
index e3a22d1e8..032fb911a 100644
--- a/lisp/org-timestamp.el
+++ b/lisp/org-timestamp.el
@@ -408,6 +408,11 @@ When SUPPRESS-TMP-DELAY is non-nil, suppress delays like
 	   (`hour (min (match-end 7) origin))
 	   (`minute (min (1- (match-end 8)) origin))
 	   ((pred integerp) (min (1- (match-end 0)) origin))
+           ;; Point was on a bracket.  However, the timestamp length
+           ;; might have changed, so refer to (match-end 0) for the
+           ;; closing one.
+           (`bracket (if (> origin (match-beginning 0)) (1- (match-end 0))
+                       origin))
 	   ;; Point was right after the timestamp.  However, the
 	   ;; timestamp length might have changed, so refer to
 	   ;; (match-end 0) instead.
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 17668cef4..892dffb74 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -9877,7 +9877,20 @@ SCHEDULED: <2026-10-01 +1d>
                                 (concat "12:0" (number-to-string (1+ i)))))
     (dotimes (i 9)
       (test-time-stamp-rounding "<2026-03-14 12:00>" (1+ i) -1
-                                (concat "11:5" (number-to-string (- 9 i)))))))
+                                (concat "11:5" (number-to-string (- 9 i))))))
+  ;; Point on the closing bracket stays on it when rewriting the
+  ;; weekday name makes the timestamp shorter or longer.
+  (let ((system-time-locale "C"))
+    (should
+     (eq 'bracket
+         (org-test-with-temp-text "<2026-03-18 Wednesday<point>>"
+                                  (org-timestamp-change 1 'day)
+                                  (org-at-timestamp-p 'lax))))
+    (should
+     (eq 'bracket
+         (org-test-with-temp-text "<2026-03-18 三<point>>"
+                                  (org-timestamp-change 1 'day)
+                                  (org-at-timestamp-p 'lax))))))
 
 (ert-deftest test-org/org-timestamp-change/bad ()
   "Promises that are currently broken in `org-timestamp-change'."

base-commit: 1221cb4ab1129e5bd9c3ece797eaf6bd1005f29d

Reply via email to