浏览代码

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.
Ihor Radchenko 2 年之前
父节点
当前提交
d3a9c424ba
共有 1 个文件被更改,包括 20 次插入22 次删除
  1. 20 22
      lisp/org-macs.el

+ 20 - 22
lisp/org-macs.el

@@ -1363,40 +1363,38 @@ nil, just return 0."
 	(b (org-2ft b)))
     (and (> a 0) (> b 0) (\= a b))))
 
-(if (version< emacs-version "27.1")
-    (defmacro org-encode-time (&rest time)
+(defmacro org-encode-time (&rest time)
+  "Compatibility and convenience helper for `encode-time'.
+TIME may be a 9 components list (SECONDS ... YEAR IGNORED DST ZONE)
+as the recommended way since Emacs-27 or 6 or 9 separate arguments
+similar to the only possible variant for Emacs-26 and earlier.
+6 elements list as the only argument causes wrong type argument till
+Emacs-29.
+
+Warning: use -1 for DST to guess the actual value, nil means no
+daylight saving time and may be wrong at particular time.
+
+DST value is ignored prior to Emacs-27.  Since Emacs-27 DST value matters
+even when multiple arguments is passed to this macro and such
+behavior is different from `encode-time'.  See
+Info node `(elisp)Time Conversion' for details and caveats,
+preferably the latest version."
+  (if (version< emacs-version "27.1")
       (if (cdr time)
           `(encode-time ,@time)
-        `(apply #'encode-time ,@time)))
-  (if (ignore-errors (with-no-warnings (encode-time '(0 0 0 1 1 1971))))
-      (defmacro org-encode-time (&rest time)
+        `(apply #'encode-time ,@time))
+    (if (ignore-errors (with-no-warnings (encode-time '(0 0 0 1 1 1971))))
         (pcase (length time) ; Emacs-29 since d75e2c12eb
           (1 `(encode-time ,@time))
           ((or 6 9) `(encode-time (list ,@time)))
           (_ (error "`org-encode-time' may be called with 1, 6, or 9 arguments but %d given"
-                    (length time)))))
-    (defmacro org-encode-time (&rest time)
+                    (length time))))
       (pcase (length time)
         (1 `(encode-time ,@time))
         (6 `(encode-time (list ,@time nil -1 nil)))
         (9 `(encode-time (list ,@time)))
         (_ (error "`org-encode-time' may be called with 1, 6, or 9 arguments but %d given"
                   (length time)))))))
-(put 'org-encode-time 'function-documentation
-     "Compatibility and convenience helper for `encode-time'.
-May be called with 9 components list (SECONDS ... YEAR IGNORED DST ZONE)
-as the recommended way since Emacs-27 or with 6 or 9 separate arguments
-similar to the only possible variant for Emacs-26 and earlier.
-6 elements list as the only argument causes wrong type argument till Emacs-29.
-
-Warning: use -1 for DST to guess the actual value, nil means no
-daylight saving time and may be wrong at particular time.
-
-DST value is ignored prior to Emacs-27.  Since Emacs-27 DST value matters
-even when multiple arguments is passed to this macro and such
-behavior is different from `encode-time'. See
-Info node `(elisp)Time Conversion' for details and caveats,
-preferably the latest version.")
 
 (defun org-parse-time-string (s &optional nodefault)
   "Parse Org time string S.