Bladeren bron

org-compat: Add time-convert compatibility wrappers

* lisp/org-compat.el (org-time-convert-to-integer)
(org-time-convert-to-list): New defsubt's to replace common
invocations of time-convert (new in Emacs 27).
* lisp/org-compat.el (org-current-time-as-list): Drop in favor of
org-time-convert-to-list.

These will be used to port changes from the Emacs repo.
Kyle Meyer 6 jaren geleden
bovenliggende
commit
24ba689506
2 gewijzigde bestanden met toevoegingen van 12 en 8 verwijderingen
  1. 10 6
      lisp/org-compat.el
  2. 2 2
      lisp/org-id.el

+ 10 - 6
lisp/org-compat.el

@@ -90,12 +90,16 @@ is nil)."
   ;; The misspelled variant was made obsolete in Emacs 27.1
   (defalias 'pcomplete-uniquify-list 'pcomplete-uniqify-list))
 
-(defun org-current-time-as-list ()
-  "Compatibility wrapper for `current-time'.
-As of Emacs 27.1, `current-time' callers should not assume a list
-return value."
-  (or (ignore-errors (encode-time nil 'list))
-      (current-time)))
+(if (fboundp 'time-convert)
+    (progn
+      (defsubst org-time-convert-to-integer (time)
+	(time-convert time 'integer))
+      (defsubst org-time-convert-to-list (time)
+	(time-convert time 'list)))
+  (defun org-time-convert-to-integer (time)
+    (floor (float-time time)))
+  (defun org-time-convert-to-list (time)
+    (seconds-to-time (float-time time))))
 
 
 ;;; Emacs < 26.1 compatibility

+ 2 - 2
lisp/org-id.el

@@ -357,7 +357,7 @@ So a typical ID could look like \"Org:4nd91V40HI\"."
   "Return string with random (version 4) UUID."
   (let ((rnd (md5 (format "%s%s%s%s%s%s%s"
 			  (random)
-			  (org-current-time-as-list)
+			  (org-time-convert-to-list nil)
 			  (user-uid)
 			  (emacs-pid)
 			  (user-full-name)
@@ -419,7 +419,7 @@ using `org-id-decode'."
   ;; FIXME: If TIME represents N seconds after the epoch, then
   ;; this encoding assumes 0 <= N < 110075314176 = (* (expt 36 4) 65536),
   ;; i.e., that TIME is from 1970-01-01 00:00:00 to 5458-02-23 20:09:36 UTC.
-  (setq time (or time (org-current-time-as-list)))
+  (setq time (org-time-convert-to-list nil))
   (concat (org-id-int-to-b36 (nth 0 time) 4)
 	  (org-id-int-to-b36 (nth 1 time) 4)
 	  (org-id-int-to-b36 (nth 2 time) 4)))