branch: externals/org
commit f7238772eb6cfdc96f6ac9ee45aa72ab93f42664
Author: Ihor Radchenko <[email protected]>
Commit: Ihor Radchenko <[email protected]>
org-timestamp-translate: Fix regression causing unconditional <> brackets
* lisp/org.el (org-time-stamp-format): Allow INACTIVE to be
'keep-format to preserve the format as is without stripping/adding
brackets.
(org-timestamp-translate): Use custom timestamp format as is. It is
indentical to Org 9.5.5 and earlier. Org 9.6 introduced a regression.
(org-timestamp-custom-formats): Document that brackets are preserved
on export in the docstring. Clarify that [...] is also stripped.
Mention that variable has no effect on export when
`org-display-custom-times' is nil.
* testing/lisp/test-org.el (test-org/timestamp-translate): Add test
case.
Reported-by: Zeremonienmeister Berber Aab <[email protected]>
Link:
https://orgmode.org/list/[email protected]
---
lisp/org.el | 25 +++++++++++++++----------
testing/lisp/test-org.el | 7 +++++++
2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index 802f966f00..d0b349487a 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -2566,10 +2566,12 @@ These are overlaid over the default ISO format if the
variable
end of the second format. The custom formats are also honored by export
commands, if custom time display is turned on at the time of export.
-This variable also affects how timestamps are exported.
+This variable also affects how timestamps are exported when
+`org-display-custom-times' is set.
-Leading \"<\" and trailing \">\" pair will be stripped from the format
-strings."
+Leading \"<\" or \"[\" and trailing \">\" or \"]\" pair will be
+stripped from the format strings in Emacs buffers. The brackets
+will be preserved on export."
:group 'org-time
:package-version '(Org . "9.6")
:type '(cons string string))
@@ -2585,20 +2587,23 @@ time.
When optional argument INACTIVE is nil, format active timestamp.
When `no-brackets', strip timestamp brackets.
+When `keep-format', keep as is.
Otherwise, format inactive timestamp."
(let ((format (funcall
(if with-time #'cdr #'car)
(if custom
org-timestamp-custom-formats
org-timestamp-formats))))
- ;; Strip brackets, if any.
- (when (or (and (string-prefix-p "<" format)
- (string-suffix-p ">" format))
- (and (string-prefix-p "[" format)
- (string-suffix-p "]" format)))
- (setq format (substring format 1 -1)))
+ (unless (eq inactive 'keep-format)
+ ;; Strip brackets, if any.
+ (when (or (and (string-prefix-p "<" format)
+ (string-suffix-p ">" format))
+ (and (string-prefix-p "[" format)
+ (string-suffix-p "]" format)))
+ (setq format (substring format 1 -1))))
(pcase inactive
(`no-brackets format)
+ (`keep-format format)
(`nil (concat "<" format ">"))
(_ (concat "[" format "]")))))
@@ -20598,7 +20603,7 @@ it has a `diary' type."
(if (or (not org-display-custom-times) (eq type 'diary))
(org-element-interpret-data timestamp)
(let ((fmt (org-time-stamp-format
- (org-timestamp-has-time-p timestamp) nil 'custom)))
+ (org-timestamp-has-time-p timestamp) 'keep-format 'custom)))
(if (and (not boundary) (memq type '(active-range inactive-range)))
(concat (org-format-timestamp timestamp fmt)
"--"
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 76b2a58fb7..f0aff2287b 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -9447,6 +9447,13 @@ CLOSED: %s
(ert-deftest test-org/timestamp-translate ()
"Test `org-timestamp-translate' specifications."
;; Translate whole date range.
+ (should
+ (equal "29"
+ (org-test-with-temp-text "<2012-03-29 Thu>"
+ (let ((org-display-custom-times t)
+ (org-timestamp-custom-formats '("%d" . "%d")))
+ (org-timestamp-translate (org-element-context))))))
+ ;; Translate whole date range.
(should
(equal "<29>--<30>"
(org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"