Backport commit c75f505de from Emacs

* lisp/org-agenda.el (org-agenda-to-appt):
* lisp/org-clock.el (org-clock-resolve-clock)
(org-clock-resolve, org-resolve-clocks-if-idle):
* lisp/org-colview.el (org-columns-edit-value, org-columns)
(org-agenda-columns):
* lisp/org-element.el (org-element--cache-interrupt-p)
(org-element--cache-sync):
* lisp/org-habit.el (org-habit-get-faces)
(org-habit-insert-consistency-graphs):
* lisp/org-indent.el (org-indent-add-properties):
* lisp/org-timer.el ((org-timer-show-remaining-time):
* lisp/org.el (org-babel-load-file, org-current-time)
(org-today, org-auto-repeat-maybe)
(org-small-year-to-year, org-goto-calendar):
* lisp/ox.el (org-export-insert-default-template):
Use nil instead of (current-time) where either will do, as nil is
a bit more efficient and should have less timing error.

Prefer nil to (current-time) when either works
c75f505dea6a560b825384cf3d277690f86840bf
Paul Eggert
Fri Oct 20 19:42:23 2017 -0700

Note(km): The changes that will reverted in the next commit have been
dropped from the ChangeLog entries above.
This commit is contained in:
Paul Eggert 2017-10-20 19:40:09 -07:00 committed by Kyle Meyer
parent d4a295e46a
commit eb10ad9360
9 changed files with 34 additions and 38 deletions

View File

@ -10201,7 +10201,7 @@ to override `appt-message-warning-time'."
;; time and without date as argument, so it may pass wrong ;; time and without date as argument, so it may pass wrong
;; information otherwise ;; information otherwise
(today (org-date-to-gregorian (today (org-date-to-gregorian
(time-to-days (current-time)))) (time-to-days nil)))
(org-agenda-restrict nil) (org-agenda-restrict nil)
(files (org-agenda-files 'unrestricted)) entries file (files (org-agenda-files 'unrestricted)) entries file
(org-agenda-buffer nil)) (org-agenda-buffer nil))

View File

@ -943,7 +943,7 @@ CLOCK is a cons cell of the form (MARKER START-TIME)."
(org-clock-clock-out clock fail-quietly)) (org-clock-clock-out clock fail-quietly))
((org-is-active-clock clock) nil) ((org-is-active-clock clock) nil)
(t (org-clock-clock-in clock t)))) (t (org-clock-clock-in clock t))))
((pred (time-less-p (current-time))) ((pred (time-less-p nil))
(error "RESOLVE-TO must refer to a time in the past")) (error "RESOLVE-TO must refer to a time in the past"))
(_ (_
(when restart (error "RESTART is not valid here")) (when restart (error "RESTART is not valid here"))
@ -1043,7 +1043,7 @@ to be CLOCKED OUT."))))
(and (not (memq char-pressed '(?i ?q))) char-pressed))))) (and (not (memq char-pressed '(?i ?q))) char-pressed)))))
(default (default
(floor (/ (float-time (floor (/ (float-time
(time-subtract (current-time) last-valid)) 60))) (time-subtract nil last-valid)) 60)))
(keep (keep
(and (memq ch '(?k ?K)) (and (memq ch '(?k ?K))
(read-number "Keep how many minutes? " default))) (read-number "Keep how many minutes? " default)))
@ -1080,8 +1080,7 @@ to be CLOCKED OUT."))))
(keep (keep
(time-add last-valid (seconds-to-time (* 60 keep)))) (time-add last-valid (seconds-to-time (* 60 keep))))
(gotback (gotback
(time-subtract (current-time) (time-subtract nil (seconds-to-time (* 60 gotback))))
(seconds-to-time (* 60 gotback))))
(t (t
(error "Unexpected, please report this as a bug"))) (error "Unexpected, please report this as a bug")))
(and gotback last-valid) (and gotback last-valid)
@ -1163,7 +1162,7 @@ so long."
org-clock-marker (marker-buffer org-clock-marker)) org-clock-marker (marker-buffer org-clock-marker))
(let* ((org-clock-user-idle-seconds (org-user-idle-seconds)) (let* ((org-clock-user-idle-seconds (org-user-idle-seconds))
(org-clock-user-idle-start (org-clock-user-idle-start
(time-subtract (current-time) (time-subtract nil
(seconds-to-time org-clock-user-idle-seconds))) (seconds-to-time org-clock-user-idle-seconds)))
(org-clock-resolving-clocks-due-to-idleness t)) (org-clock-resolving-clocks-due-to-idleness t))
(if (> org-clock-user-idle-seconds (* 60 org-clock-idle-time)) (if (> org-clock-user-idle-seconds (* 60 org-clock-idle-time))
@ -1173,8 +1172,7 @@ so long."
(lambda (_) (lambda (_)
(format "Clocked in & idle for %.1f mins" (format "Clocked in & idle for %.1f mins"
(/ (float-time (/ (float-time
(time-subtract (current-time) (time-subtract nil org-clock-user-idle-start))
org-clock-user-idle-start))
60.0))) 60.0)))
org-clock-user-idle-start))))) org-clock-user-idle-start)))))

View File

@ -579,7 +579,7 @@ Where possible, use the standard interface for changing this line."
(eol (line-end-position)) (eol (line-end-position))
(pom (or (get-text-property bol 'org-hd-marker) (point))) (pom (or (get-text-property bol 'org-hd-marker) (point)))
(key (or key (get-char-property (point) 'org-columns-key))) (key (or key (get-char-property (point) 'org-columns-key)))
(org-columns--time (float-time (current-time))) (org-columns--time (float-time))
(action (action
(pcase key (pcase key
("CLOCKSUM" ("CLOCKSUM"
@ -830,7 +830,7 @@ When COLUMNS-FMT-STRING is non-nil, use it as the column format."
(org-columns-goto-top-level) (org-columns-goto-top-level)
;; Initialize `org-columns-current-fmt' and ;; Initialize `org-columns-current-fmt' and
;; `org-columns-current-fmt-compiled'. ;; `org-columns-current-fmt-compiled'.
(let ((org-columns--time (float-time (current-time)))) (let ((org-columns--time (float-time)))
(org-columns-get-format columns-fmt-string) (org-columns-get-format columns-fmt-string)
(unless org-columns-inhibit-recalculation (org-columns-compute-all)) (unless org-columns-inhibit-recalculation (org-columns-compute-all))
(save-restriction (save-restriction
@ -1224,7 +1224,7 @@ column specification."
"Compute all columns that have operators defined." "Compute all columns that have operators defined."
(with-silent-modifications (with-silent-modifications
(remove-text-properties (point-min) (point-max) '(org-summaries t))) (remove-text-properties (point-min) (point-max) '(org-summaries t)))
(let ((org-columns--time (float-time (current-time))) (let ((org-columns--time (float-time))
seen) seen)
(dolist (spec org-columns-current-fmt-compiled) (dolist (spec org-columns-current-fmt-compiled)
(let ((property (car spec))) (let ((property (car spec)))
@ -1560,7 +1560,7 @@ PARAMS is a property list of parameters:
(if (markerp org-columns-begin-marker) (if (markerp org-columns-begin-marker)
(move-marker org-columns-begin-marker (point)) (move-marker org-columns-begin-marker (point))
(setq org-columns-begin-marker (point-marker))) (setq org-columns-begin-marker (point-marker)))
(let* ((org-columns--time (float-time (current-time))) (let* ((org-columns--time (float-time))
(fmt (fmt
(cond (cond
((bound-and-true-p org-agenda-overriding-columns-format)) ((bound-and-true-p org-agenda-overriding-columns-format))

View File

@ -5114,7 +5114,7 @@ Assume ELEMENT belongs to cache and that a cache is active."
TIME-LIMIT is a time value or nil." TIME-LIMIT is a time value or nil."
(and time-limit (and time-limit
(or (input-pending-p) (or (input-pending-p)
(time-less-p time-limit (current-time))))) (time-less-p time-limit nil))))
(defsubst org-element--cache-shift-positions (element offset &optional props) (defsubst org-element--cache-shift-positions (element offset &optional props)
"Shift ELEMENT properties relative to buffer positions by OFFSET. "Shift ELEMENT properties relative to buffer positions by OFFSET.
@ -5168,7 +5168,7 @@ updated before current modification are actually submitted."
(and next (aref next 0)) (and next (aref next 0))
threshold threshold
(and (not threshold) (and (not threshold)
(time-add (current-time) (time-add nil
org-element-cache-sync-duration)) org-element-cache-sync-duration))
future-change) future-change)
;; Request processed. Merge current and next offsets and ;; Request processed. Merge current and next offsets and

View File

@ -288,7 +288,7 @@ Habits are assigned colors on the following basis:
(deadline (if scheduled-days (deadline (if scheduled-days
(+ scheduled-days (- d-repeat s-repeat)) (+ scheduled-days (- d-repeat s-repeat))
(org-habit-deadline habit))) (org-habit-deadline habit)))
(m-days (or now-days (time-to-days (current-time))))) (m-days (or now-days (time-to-days nil))))
(cond (cond
((< m-days scheduled) ((< m-days scheduled)
'(org-habit-clear-face . org-habit-clear-future-face)) '(org-habit-clear-face . org-habit-clear-future-face))
@ -406,7 +406,7 @@ current time."
"Insert consistency graph for any habitual tasks." "Insert consistency graph for any habitual tasks."
(let ((inhibit-read-only t) (let ((inhibit-read-only t)
(buffer-invisibility-spec '(org-link)) (buffer-invisibility-spec '(org-link))
(moment (time-subtract (current-time) (moment (time-subtract nil
(list 0 (* 3600 org-extend-today-until) 0)))) (list 0 (* 3600 org-extend-today-until) 0))))
(save-excursion (save-excursion
(goto-char (if line (point-at-bol) (point-min))) (goto-char (if line (point-at-bol) (point-min)))

View File

@ -326,7 +326,7 @@ stopped."
(let* ((case-fold-search t) (let* ((case-fold-search t)
(limited-re (org-get-limited-outline-regexp)) (limited-re (org-get-limited-outline-regexp))
(level (or (org-current-level) 0)) (level (or (org-current-level) 0))
(time-limit (and delay (time-add (current-time) delay)))) (time-limit (and delay (time-add nil delay))))
;; For each line, set `line-prefix' and `wrap-prefix' ;; For each line, set `line-prefix' and `wrap-prefix'
;; properties depending on the type of line (headline, inline ;; properties depending on the type of line (headline, inline
;; task, item or other). ;; task, item or other).
@ -339,7 +339,7 @@ stopped."
;; In asynchronous mode, take a break of ;; In asynchronous mode, take a break of
;; `org-indent-agent-resume-delay' every DELAY to avoid ;; `org-indent-agent-resume-delay' every DELAY to avoid
;; blocking any other idle timer or process output. ;; blocking any other idle timer or process output.
((and delay (time-less-p time-limit (current-time))) ((and delay (time-less-p time-limit nil))
(setq org-indent-agent-resume-timer (setq org-indent-agent-resume-timer
(run-with-idle-timer (run-with-idle-timer
(time-add (current-idle-time) org-indent-agent-resume-delay) (time-add (current-idle-time) org-indent-agent-resume-delay)

View File

@ -144,7 +144,7 @@ the region 0:00:00."
;; Pass `current-time' result to `float-time' (instead ;; Pass `current-time' result to `float-time' (instead
;; of calling without arguments) so that only ;; of calling without arguments) so that only
;; `current-time' has to be overridden in tests. ;; `current-time' has to be overridden in tests.
(- (float-time (current-time)) delta)))) (- (float-time) delta))))
(setq org-timer-pause-time nil) (setq org-timer-pause-time nil)
(org-timer-set-mode-line 'on) (org-timer-set-mode-line 'on)
(message "Timer start time set to %s, current value is %s" (message "Timer start time set to %s, current value is %s"
@ -169,12 +169,12 @@ With prefix arg STOP, stop it entirely."
(org-timer--run-countdown-timer (org-timer--run-countdown-timer
new-secs org-timer-countdown-timer-title)) new-secs org-timer-countdown-timer-title))
(setq org-timer-start-time (setq org-timer-start-time
(time-add (current-time) (seconds-to-time new-secs)))) (time-add nil (seconds-to-time new-secs))))
(setq org-timer-start-time (setq org-timer-start-time
;; Pass `current-time' result to `float-time' (instead ;; Pass `current-time' result to `float-time' (instead
;; of calling without arguments) so that only ;; of calling without arguments) so that only
;; `current-time' has to be overridden in tests. ;; `current-time' has to be overridden in tests.
(seconds-to-time (- (float-time (current-time)) (seconds-to-time (- (float-time)
(- pause-secs start-secs))))) (- pause-secs start-secs)))))
(setq org-timer-pause-time nil) (setq org-timer-pause-time nil)
(org-timer-set-mode-line 'on) (org-timer-set-mode-line 'on)
@ -240,8 +240,8 @@ it in the buffer."
;; overridden in tests. ;; overridden in tests.
(if org-timer-countdown-timer (if org-timer-countdown-timer
(- (float-time org-timer-start-time) (- (float-time org-timer-start-time)
(float-time (or org-timer-pause-time (current-time)))) (float-time org-timer-pause-time))
(- (float-time (or org-timer-pause-time (current-time))) (- (float-time org-timer-pause-time)
(float-time org-timer-start-time)))) (float-time org-timer-start-time))))
;;;###autoload ;;;###autoload
@ -402,7 +402,7 @@ VALUE can be `on', `off', or `paused'."
(message "No timer set") (message "No timer set")
(let* ((rtime (decode-time (let* ((rtime (decode-time
(time-subtract (timer--time org-timer-countdown-timer) (time-subtract (timer--time org-timer-countdown-timer)
(current-time)))) nil)))
(rsecs (nth 0 rtime)) (rsecs (nth 0 rtime))
(rmins (nth 1 rtime))) (rmins (nth 1 rtime)))
(message "%d minute(s) %d seconds left before next time out" (message "%d minute(s) %d seconds left before next time out"
@ -466,7 +466,7 @@ using three `C-u' prefix arguments."
secs org-timer-countdown-timer-title)) secs org-timer-countdown-timer-title))
(run-hooks 'org-timer-set-hook) (run-hooks 'org-timer-set-hook)
(setq org-timer-start-time (setq org-timer-start-time
(time-add (current-time) (seconds-to-time secs))) (time-add nil (seconds-to-time secs)))
(setq org-timer-pause-time nil) (setq org-timer-pause-time nil)
(org-timer-set-mode-line 'on)))))) (org-timer-set-mode-line 'on))))))

View File

@ -252,7 +252,7 @@ file to byte-code before it is loaded."
(interactive "fFile to load: \nP") (interactive "fFile to load: \nP")
(let* ((age (lambda (file) (let* ((age (lambda (file)
(float-time (float-time
(time-subtract (current-time) (time-subtract nil
(nth 5 (or (file-attributes (file-truename file)) (nth 5 (or (file-attributes (file-truename file))
(file-attributes file))))))) (file-attributes file)))))))
(base-name (file-name-sans-extension file)) (base-name (file-name-sans-extension file))
@ -5637,15 +5637,14 @@ the rounding returns a past time."
(apply 'encode-time (apply 'encode-time
(append (list 0 (* r (floor (+ .5 (/ (float (nth 1 time)) r))))) (append (list 0 (* r (floor (+ .5 (/ (float (nth 1 time)) r)))))
(nthcdr 2 time)))) (nthcdr 2 time))))
(if (and past (< (float-time (time-subtract (current-time) res)) 0)) (if (and past (< (float-time (time-subtract nil res)) 0))
(seconds-to-time (- (float-time res) (* r 60))) (seconds-to-time (- (float-time res) (* r 60)))
res)))) res))))
(defun org-today () (defun org-today ()
"Return today date, considering `org-extend-today-until'." "Return today date, considering `org-extend-today-until'."
(time-to-days (time-to-days
(time-subtract (current-time) (time-subtract nil (list 0 (* 3600 org-extend-today-until) 0))))
(list 0 (* 3600 org-extend-today-until) 0))))
;;;; Font-Lock stuff, including the activators ;;;; Font-Lock stuff, including the activators
@ -12792,8 +12791,7 @@ This function is run automatically after each state change to a DONE state."
(while (re-search-forward org-clock-line-re end t) (while (re-search-forward org-clock-line-re end t)
(when (org-at-clock-log-p) (throw :clock t)))))) (when (org-at-clock-log-p) (throw :clock t))))))
(org-entry-put nil "LAST_REPEAT" (format-time-string (org-entry-put nil "LAST_REPEAT" (format-time-string
(org-time-stamp-format t t) (org-time-stamp-format t t))))
(current-time))))
(when org-log-repeat (when org-log-repeat
(if (or (memq 'org-add-log-note (default-value 'post-command-hook)) (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
(memq 'org-add-log-note post-command-hook)) (memq 'org-add-log-note post-command-hook))
@ -12848,7 +12846,7 @@ This function is run automatically after each state change to a DONE state."
(let ((nshiftmax 10) (let ((nshiftmax 10)
(nshift 0)) (nshift 0))
(while (or (= nshift 0) (while (or (= nshift 0)
(not (time-less-p (current-time) time))) (not (time-less-p nil time)))
(when (= nshiftmax (cl-incf nshift)) (when (= nshiftmax (cl-incf nshift))
(or (y-or-n-p (or (y-or-n-p
(format "%d repeater intervals were not \ (format "%d repeater intervals were not \
@ -16401,7 +16399,7 @@ user."
;; overridden in tests. ;; overridden in tests.
(let ((org-def def) (let ((org-def def)
(org-defdecode defdecode) (org-defdecode defdecode)
(nowdecode (decode-time (current-time))) (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-date futurep kill-year) iso-year iso-weekday iso-week iso-date futurep kill-year)
@ -16567,7 +16565,7 @@ user."
; (when (and org-read-date-prefer-future ; (when (and org-read-date-prefer-future
; (not iso-year) ; (not iso-year)
; (< (calendar-absolute-from-gregorian iso-date) ; (< (calendar-absolute-from-gregorian iso-date)
; (time-to-days (current-time)))) ; (time-to-days nil)))
; (setq year (1+ year) ; (setq year (1+ year)
; iso-date (calendar-gregorian-from-absolute ; iso-date (calendar-gregorian-from-absolute
; (calendar-iso-to-absolute ; (calendar-iso-to-absolute
@ -16581,7 +16579,7 @@ user."
;; Pass `current-time' result to `decode-time' (instead of ;; Pass `current-time' result to `decode-time' (instead of
;; calling without arguments) so that only `current-time' has ;; calling without arguments) so that only `current-time' has
;; to be overridden in tests. ;; to be overridden in tests.
(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))))
@ -17055,7 +17053,7 @@ signaled."
YEAR is expanded into one of the 30 next years, if possible, or YEAR is expanded into one of the 30 next years, if possible, or
into a past one. Any year larger than 99 is returned unchanged." into a past one. Any year larger than 99 is returned unchanged."
(if (>= year 100) year (if (>= year 100) year
(let* ((current (string-to-number (format-time-string "%Y" (current-time)))) (let* ((current (string-to-number (format-time-string "%Y")))
(century (/ current 100)) (century (/ current 100))
(offset (- year (% current 100)))) (offset (- year (% current 100))))
(cond ((> offset 30) (+ (* (1- century) 100) year)) (cond ((> offset 30) (+ (* (1- century) 100) year))
@ -17552,7 +17550,7 @@ A prefix ARG can be used to force the current date."
diff) diff)
(when (or (org-at-timestamp-p 'lax) (when (or (org-at-timestamp-p 'lax)
(org-match-line (concat ".*" org-ts-regexp))) (org-match-line (concat ".*" org-ts-regexp)))
(let ((d1 (time-to-days (current-time))) (let ((d1 (time-to-days nil))
(d2 (time-to-days (org-time-string-to-time (match-string 1))))) (d2 (time-to-days (org-time-string-to-time (match-string 1)))))
(setq diff (- d2 d1)))) (setq diff (- d2 d1))))
(calendar) (calendar)

View File

@ -3230,7 +3230,7 @@ locally for the subtree through node properties."
(let ((val (cond ((equal (car key) "DATE") (let ((val (cond ((equal (car key) "DATE")
(or (cdr key) (or (cdr key)
(with-temp-buffer (with-temp-buffer
(org-insert-time-stamp (current-time))))) (org-insert-time-stamp nil))))
((equal (car key) "TITLE") ((equal (car key) "TITLE")
(or (let ((visited-file (or (let ((visited-file
(buffer-file-name (buffer-base-buffer)))) (buffer-file-name (buffer-base-buffer))))