Skip to content

Commit d3a9c42

Browse files
committed
org-encode-time: Refactor into top-level `defmacro'
* lisp/org-macs.el (org-encode-time): Rewrite, avoiding top-level `if' statement that triggers https://debbugs.gnu.org/cgi/bugreport.cgi?bug=56746 Also, fix the docstring warnings.
1 parent 3303a54 commit d3a9c42

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

lisp/org-macs.el

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,40 +1363,38 @@ nil, just return 0."
13631363
(b (org-2ft b)))
13641364
(and (> a 0) (> b 0) (\= a b))))
13651365

1366-
(if (version< emacs-version "27.1")
1367-
(defmacro org-encode-time (&rest time)
1366+
(defmacro org-encode-time (&rest time)
1367+
"Compatibility and convenience helper for `encode-time'.
1368+
TIME may be a 9 components list (SECONDS ... YEAR IGNORED DST ZONE)
1369+
as the recommended way since Emacs-27 or 6 or 9 separate arguments
1370+
similar to the only possible variant for Emacs-26 and earlier.
1371+
6 elements list as the only argument causes wrong type argument till
1372+
Emacs-29.
1373+
1374+
Warning: use -1 for DST to guess the actual value, nil means no
1375+
daylight saving time and may be wrong at particular time.
1376+
1377+
DST value is ignored prior to Emacs-27. Since Emacs-27 DST value matters
1378+
even when multiple arguments is passed to this macro and such
1379+
behavior is different from `encode-time'. See
1380+
Info node `(elisp)Time Conversion' for details and caveats,
1381+
preferably the latest version."
1382+
(if (version< emacs-version "27.1")
13681383
(if (cdr time)
13691384
`(encode-time ,@time)
1370-
`(apply #'encode-time ,@time)))
1371-
(if (ignore-errors (with-no-warnings (encode-time '(0 0 0 1 1 1971))))
1372-
(defmacro org-encode-time (&rest time)
1385+
`(apply #'encode-time ,@time))
1386+
(if (ignore-errors (with-no-warnings (encode-time '(0 0 0 1 1 1971))))
13731387
(pcase (length time) ; Emacs-29 since d75e2c12eb
13741388
(1 `(encode-time ,@time))
13751389
((or 6 9) `(encode-time (list ,@time)))
13761390
(_ (error "`org-encode-time' may be called with 1, 6, or 9 arguments but %d given"
1377-
(length time)))))
1378-
(defmacro org-encode-time (&rest time)
1391+
(length time))))
13791392
(pcase (length time)
13801393
(1 `(encode-time ,@time))
13811394
(6 `(encode-time (list ,@time nil -1 nil)))
13821395
(9 `(encode-time (list ,@time)))
13831396
(_ (error "`org-encode-time' may be called with 1, 6, or 9 arguments but %d given"
13841397
(length time)))))))
1385-
(put 'org-encode-time 'function-documentation
1386-
"Compatibility and convenience helper for `encode-time'.
1387-
May be called with 9 components list (SECONDS ... YEAR IGNORED DST ZONE)
1388-
as the recommended way since Emacs-27 or with 6 or 9 separate arguments
1389-
similar to the only possible variant for Emacs-26 and earlier.
1390-
6 elements list as the only argument causes wrong type argument till Emacs-29.
1391-
1392-
Warning: use -1 for DST to guess the actual value, nil means no
1393-
daylight saving time and may be wrong at particular time.
1394-
1395-
DST value is ignored prior to Emacs-27. Since Emacs-27 DST value matters
1396-
even when multiple arguments is passed to this macro and such
1397-
behavior is different from `encode-time'. See
1398-
Info node `(elisp)Time Conversion' for details and caveats,
1399-
preferably the latest version.")
14001398

14011399
(defun org-parse-time-string (s &optional nodefault)
14021400
"Parse Org time string S.

0 commit comments

Comments
 (0)