Browse Source

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 years ago
parent
commit
217ad4aafb
8 changed files with 23 additions and 29 deletions
  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
 #+SUBTITLE: for version 2.0, last updated 4 March 2014
 
-* Copying 
+* Copying
   :PROPERTIES:
   :COPYING:  t
   :END:
@@ -17536,7 +17536,7 @@ The corresponding block writer function could look like this:
 (defun org-dblock-write:block-update-time (params)
   (let ((fmt (or (plist-get params :format) "%d. %m. %Y")))
     (insert "Last block update at: "
-            (format-time-string fmt (current-time)))))
+            (format-time-string fmt))))
 @end lisp
 
 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"))))
 	    (olpath (mapconcat 'identity (org-get-outline-path) "/"))
 	    (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
 	    ;; end of variables that will be used for saving context
 	    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
 	 "ARCHIVE_TIME"
 	 (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)
 	(hide-subtree)
 	(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)
 			  (format
 			   "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
 		       (cdr clock)))))))))))
 
@@ -1370,7 +1370,7 @@ decides which time to use."
       (current-time))
      ((equal cmt "today")
       (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)))
 	(if 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).
 If you can combine both, the month starting day will have priority."
   (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))
 	 (d (nth 3 tm)) (month (nth 4 tm)) (y (nth 5 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))
       (setq te (format "%4d-%02d-%02d" (nth 2 te) (car te) (nth 1 te))))
     ;; 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
       (org-clock-sum ts te
 		     (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
 	   (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.
-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
 (unless (fboundp 'user-error)

+ 2 - 2
lisp/org-timer.el

@@ -195,8 +195,8 @@ it in the buffer."
 (defun org-timer-seconds ()
   (if org-timer-timer-is-countdown
       (- (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))))
 
 ;;;###autoload

+ 5 - 4
lisp/org.el

@@ -16494,7 +16494,7 @@ user."
 (defun org-read-date-analyze (ans org-def org-defdecode)
   "Analyze the combined answer of the date prompt."
   ;; FIXME: cleanup and comment
-  (let ((nowdecode (decode-time (current-time)))
+  (let ((nowdecode (decode-time))
 	delta deltan deltaw deltadef year month day
 	hour minute second wday pm h2 m2 tl wday1
 	iso-year iso-weekday iso-week iso-year iso-date futurep kill-year)
@@ -16652,7 +16652,7 @@ user."
      (deltan
       (setq futurep nil)
       (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))))
       (cond ((member deltaw '("d" "")) (setq day (+ day 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))
 	(setq hod (string-to-number (match-string 1 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
      ((eq major-mode 'calendar-mode)
       (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 . ,(let ((file (plist-get info :input-file)))
 	     (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 ""))))
 
 (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))
 		   ;; If we can't use a scheduled time for some
 		   ;; reason, start task now.
-		   (let ((now (decode-time (current-time))))
+		   (let ((now (decode-time)))
 		     (list 'timestamp
 			   (list :type 'active
 				 :minute-start (nth 1 now)