浏览代码

Backport commit 123ddec from Emacs master branch

* doc/org.texi (Dynamic blocks):
* lisp/org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling):
* lisp/org-clock.el (org-resolve-clocks, org-clock-get-sum-start)
(org-clock-special-range):
* lisp/org-timer.el (org-timer-seconds):
* lisp/org.el (org-read-date-analyze, org-get-cursor-date):
* lisp/ox-html.el (org-html-format-spec):
* lisp/ox-icalendar.el (org-icalendar--vtodo):
Omit unnecessary call to current-time.
* lisp/org.el (org-get-cursor-date):
Don't call current-time twice to get the current time stamp,
as this can lead to inconsistent results.
* lisp/org-compat.el (org-float-time):
Simplify to an alias because time-to-seconds now behaves like float-time
with respect to nil arg.
* lisp/org-clock.el (org-clock-get-table-data): Omit unnecessary, lossy
conversion from floating point to Emacs time and back.
(org-resolve-clocks): Prefer two-argument floor.

Simplify use of current-time and friends.
123ddec7f807f4bd7400bbbe08219afb02269c00
Paul Eggert
Tue Oct 28 18:42:51 2014 -0700
Paul Eggert 10 年之前
父节点
当前提交
217ad4aafb
共有 8 个文件被更改,包括 23 次插入29 次删除
  1. 2 2
      doc/org.texi
  2. 2 4
      lisp/org-archive.el
  3. 7 9
      lisp/org-clock.el
  4. 3 5
      lisp/org-compat.el
  5. 2 2
      lisp/org-timer.el
  6. 5 4
      lisp/org.el
  7. 1 2
      lisp/ox-html.el
  8. 1 1
      lisp/ox-icalendar.el

+ 2 - 2
doc/org.texi

@@ -13124,7 +13124,7 @@ Here is a thorough example, taken from @inforef{GNU Sample Texts,,texinfo}.
 #+TEXINFO_PRINTED_TITLE: GNU Sample
 #+TEXINFO_PRINTED_TITLE: GNU Sample
 #+SUBTITLE: for version 2.0, last updated 4 March 2014
 #+SUBTITLE: for version 2.0, last updated 4 March 2014
 
 
-* Copying 
+* Copying
   :PROPERTIES:
   :PROPERTIES:
   :COPYING:  t
   :COPYING:  t
   :END:
   :END:
@@ -17536,7 +17536,7 @@ The corresponding block writer function could look like this:
 (defun org-dblock-write:block-update-time (params)
 (defun org-dblock-write:block-update-time (params)
   (let ((fmt (or (plist-get params :format) "%d. %m. %Y")))
   (let ((fmt (or (plist-get params :format) "%d. %m. %Y")))
     (insert "Last block update at: "
     (insert "Last block update at: "
-            (format-time-string fmt (current-time)))))
+            (format-time-string fmt))))
 @end lisp
 @end lisp
 
 
 If you want to make sure that all dynamic blocks are always up-to-date,
 If you want to make sure that all dynamic blocks are always up-to-date,

+ 2 - 4
lisp/org-archive.el

@@ -231,8 +231,7 @@ this heading."
 		       (error "No file associated to buffer"))))
 		       (error "No file associated to buffer"))))
 	    (olpath (mapconcat 'identity (org-get-outline-path) "/"))
 	    (olpath (mapconcat 'identity (org-get-outline-path) "/"))
 	    (time (format-time-string
 	    (time (format-time-string
-		   (substring (cdr org-time-stamp-formats) 1 -1)
-		   (current-time)))
+		   (substring (cdr org-time-stamp-formats) 1 -1)))
 	    category todo priority ltags itags atags
 	    category todo priority ltags itags atags
 	    ;; end of variables that will be used for saving context
 	    ;; end of variables that will be used for saving context
 	    location afile heading buffer level newfile-p infile-p visiting
 	    location afile heading buffer level newfile-p infile-p visiting
@@ -441,8 +440,7 @@ sibling does not exist, it will be created at the end of the subtree."
 	(org-set-property
 	(org-set-property
 	 "ARCHIVE_TIME"
 	 "ARCHIVE_TIME"
 	 (format-time-string
 	 (format-time-string
-	  (substring (cdr org-time-stamp-formats) 1 -1)
-	  (current-time)))
+	  (substring (cdr org-time-stamp-formats) 1 -1)))
 	(outline-up-heading 1 t)
 	(outline-up-heading 1 t)
 	(hide-subtree)
 	(hide-subtree)
 	(org-cycle-show-empty-lines 'folded)
 	(org-cycle-show-empty-lines 'folded)

+ 7 - 9
lisp/org-clock.el

@@ -1046,9 +1046,9 @@ If `only-dangling-p' is non-nil, only ask to resolve dangling
 			(lambda (clock)
 			(lambda (clock)
 			  (format
 			  (format
 			   "Dangling clock started %d mins ago"
 			   "Dangling clock started %d mins ago"
-			   (floor
-			    (/ (- (org-float-time (current-time))
-				  (org-float-time (cdr clock))) 60))))))
+			   (floor (- (org-float-time)
+				     (org-float-time (cdr clock)))
+				  60)))))
 		   (or last-valid
 		   (or last-valid
 		       (cdr clock)))))))))))
 		       (cdr clock)))))))))))
 
 
@@ -1370,7 +1370,7 @@ decides which time to use."
       (current-time))
       (current-time))
      ((equal cmt "today")
      ((equal cmt "today")
       (setq org--msg-extra "showing today's task time.")
       (setq org--msg-extra "showing today's task time.")
-      (let* ((dt (decode-time (current-time))))
+      (let* ((dt (decode-time)))
 	(setq dt (append (list 0 0 0) (nthcdr 3 dt)))
 	(setq dt (append (list 0 0 0) (nthcdr 3 dt)))
 	(if org-extend-today-until
 	(if org-extend-today-until
 	    (setf (nth 2 dt) org-extend-today-until))
 	    (setf (nth 2 dt) org-extend-today-until))
@@ -2031,7 +2031,7 @@ If MSTART is non-nil, use this number to specify the starting day of a
 month (1 is the first day of the month).
 month (1 is the first day of the month).
 If you can combine both, the month starting day will have priority."
 If you can combine both, the month starting day will have priority."
   (if (integerp key) (setq key (intern (number-to-string key))))
   (if (integerp key) (setq key (intern (number-to-string key))))
-  (let* ((tm (decode-time (or time (current-time))))
+  (let* ((tm (decode-time time))
 	 (s 0) (m (nth 1 tm)) (h (nth 2 tm))
 	 (s 0) (m (nth 1 tm)) (h (nth 2 tm))
 	 (d (nth 3 tm)) (month (nth 4 tm)) (y (nth 5 tm))
 	 (d (nth 3 tm)) (month (nth 4 tm)) (y (nth 5 tm))
 	 (dow (nth 6 tm))
 	 (dow (nth 6 tm))
@@ -2672,10 +2672,8 @@ TIME:      The sum of all time spend in this tree, in minutes.  This time
     (when (and te (listp te))
     (when (and te (listp te))
       (setq te (format "%4d-%02d-%02d" (nth 2 te) (car te) (nth 1 te))))
       (setq te (format "%4d-%02d-%02d" (nth 2 te) (car te) (nth 1 te))))
     ;; Now the times are strings we can parse.
     ;; Now the times are strings we can parse.
-    (if ts (setq ts (org-float-time
-		     (seconds-to-time (org-matcher-time ts)))))
-    (if te (setq te (org-float-time
-		     (seconds-to-time (org-matcher-time te)))))
+    (if ts (setq ts (org-matcher-time ts)))
+    (if te (setq te (org-matcher-time te)))
     (save-excursion
     (save-excursion
       (org-clock-sum ts te
       (org-clock-sum ts te
 		     (unless (null matcher)
 		     (unless (null matcher)

+ 3 - 5
lisp/org-compat.el

@@ -411,12 +411,10 @@ Pass BUFFER to the XEmacs version of `move-to-column'."
 	 (when focus-follows-mouse
 	 (when focus-follows-mouse
 	   (set-mouse-position frame (1- (frame-width frame)) 0)))))
 	   (set-mouse-position frame (1- (frame-width frame)) 0)))))
 
 
-(defun org-float-time (&optional time)
+(defalias 'org-float-time
+  (if (featurep 'xemacs) 'time-to-seconds 'float-time)
   "Convert time value TIME to a floating point number.
   "Convert time value TIME to a floating point number.
-TIME defaults to the current time."
-  (if (featurep 'xemacs)
-      (time-to-seconds (or time (current-time)))
-    (float-time time)))
+TIME defaults to the current time.")
 
 
 ;; `user-error' is only available from 24.2.50 on
 ;; `user-error' is only available from 24.2.50 on
 (unless (fboundp 'user-error)
 (unless (fboundp 'user-error)

+ 2 - 2
lisp/org-timer.el

@@ -195,8 +195,8 @@ it in the buffer."
 (defun org-timer-seconds ()
 (defun org-timer-seconds ()
   (if org-timer-timer-is-countdown
   (if org-timer-timer-is-countdown
       (- (org-float-time org-timer-start-time)
       (- (org-float-time org-timer-start-time)
-	 (org-float-time (current-time)))
-    (- (org-float-time (or org-timer-pause-time (current-time)))
+	 (org-float-time))
+    (- (org-float-time org-timer-pause-time)
        (org-float-time org-timer-start-time))))
        (org-float-time org-timer-start-time))))
 
 
 ;;;###autoload
 ;;;###autoload

+ 5 - 4
lisp/org.el

@@ -16494,7 +16494,7 @@ user."
 (defun org-read-date-analyze (ans org-def org-defdecode)
 (defun org-read-date-analyze (ans org-def org-defdecode)
   "Analyze the combined answer of the date prompt."
   "Analyze the combined answer of the date prompt."
   ;; FIXME: cleanup and comment
   ;; FIXME: cleanup and comment
-  (let ((nowdecode (decode-time (current-time)))
+  (let ((nowdecode (decode-time))
 	delta deltan deltaw deltadef year month day
 	delta deltan deltaw deltadef year month day
 	hour minute second wday pm h2 m2 tl wday1
 	hour minute second wday pm h2 m2 tl wday1
 	iso-year iso-weekday iso-week iso-year iso-date futurep kill-year)
 	iso-year iso-weekday iso-week iso-year iso-date futurep kill-year)
@@ -16652,7 +16652,7 @@ user."
      (deltan
      (deltan
       (setq futurep nil)
       (setq futurep nil)
       (unless deltadef
       (unless deltadef
-	(let ((now (decode-time (current-time))))
+	(let ((now (decode-time)))
 	  (setq day (nth 3 now) month (nth 4 now) year (nth 5 now))))
 	  (setq day (nth 3 now) month (nth 4 now) year (nth 5 now))))
       (cond ((member deltaw '("d" "")) (setq day (+ day deltan)))
       (cond ((member deltaw '("d" "")) (setq day (+ day deltan)))
 	    ((equal deltaw "w") (setq day (+ day (* 7 deltan))))
 	    ((equal deltaw "w") (setq day (+ day (* 7 deltan))))
@@ -22066,8 +22066,9 @@ the agenda) or the current time of the day."
       (when (and tp (string-match "\\([0-9][0-9]\\):\\([0-9][0-9]\\)" tp))
       (when (and tp (string-match "\\([0-9][0-9]\\):\\([0-9][0-9]\\)" tp))
 	(setq hod (string-to-number (match-string 1 tp))
 	(setq hod (string-to-number (match-string 1 tp))
 	      mod (string-to-number (match-string 2 tp))))
 	      mod (string-to-number (match-string 2 tp))))
-      (or tp (setq hod (nth 2 (decode-time (current-time)))
-		   mod (nth 1 (decode-time (current-time))))))
+      (or tp (let ((now (decode-time)))
+	       (setq hod (nth 2 now)
+		     mod (nth 1 now)))))
     (cond
     (cond
      ((eq major-mode 'calendar-mode)
      ((eq major-mode 'calendar-mode)
       (setq date (calendar-cursor-to-date)
       (setq date (calendar-cursor-to-date)

+ 1 - 2
lisp/ox-html.el

@@ -1630,8 +1630,7 @@ used in the preamble or postamble."
     (?c . ,(plist-get info :creator))
     (?c . ,(plist-get info :creator))
     (?C . ,(let ((file (plist-get info :input-file)))
     (?C . ,(let ((file (plist-get info :input-file)))
 	     (format-time-string org-html-metadata-timestamp-format
 	     (format-time-string org-html-metadata-timestamp-format
-				 (if file (nth 5 (file-attributes file))
-				   (current-time)))))
+				 (if file (nth 5 (file-attributes file))))))
     (?v . ,(or org-html-validation-link ""))))
     (?v . ,(or org-html-validation-link ""))))
 
 
 (defun org-html--build-pre/postamble (type info)
 (defun org-html--build-pre/postamble (type info)

+ 1 - 1
lisp/ox-icalendar.el

@@ -678,7 +678,7 @@ Return VTODO component as a string."
 			(org-element-property :scheduled entry))
 			(org-element-property :scheduled entry))
 		   ;; If we can't use a scheduled time for some
 		   ;; If we can't use a scheduled time for some
 		   ;; reason, start task now.
 		   ;; reason, start task now.
-		   (let ((now (decode-time (current-time))))
+		   (let ((now (decode-time)))
 		     (list 'timestamp
 		     (list 'timestamp
 			   (list :type 'active
 			   (list :type 'active
 				 :minute-start (nth 1 now)
 				 :minute-start (nth 1 now)