Port more time-related changes

* lisp/org-agenda.el (org-agenda-check-clock-gap):
* lisp/org-clock.el (org-clock-get-clocked-time)
(org-clock-resolve-clock, (org-clock-resolve)
(org-resolve-clocks, org-resolve-clocks-if-idle)
(org-clock-in, org-clock-out, org-clock-sum, org-clocktable-steps):
* lisp/org-element.el (org-element-cache-sync-duration)
(org-element--cache-set-timer, org-element--cache-interrupt-p):
(org-element--cache-sync):
* lisp/org-habit.el (org-habit-insert-consistency-graphs):
* lisp/org-indent.el (org-indent-add-properties):
* lisp/org-timer.el (org-timer-start):
(org-timer-pause-or-continue, org-timer-set-timer):
* lisp/org.el (org-today, org-auto-repeat-maybe): Port time-related
changes from the Emacs repo by using compatibility wrappers.

In the Emacs repo, there has been a lot of changes to Org files
involving time-related code.  I've ported some of those changes but
have largely ignored any changes that break compatibility with older
Emacsen that we support.  That, however, isn't a good approach because
it will be hard to do a systematic update once we bump our minimum
Emacs requirement.  Instead use the recently added compatibility
wrappers where needed, which is ugly but more maintainable.

The main time-related changes this leaves unported are changes that
replace (apply #'encode-time args) calls with (encode-time args).
Until the first form is unsupported, adding a compatibility function
doesn't seem worth the churn.

Relevant Emacs commits include
c75f505dea6a560b825384cf3d277690f86840bf,
57c74793c46c6533b63836f00aecaf3ac2accb6d,
988e37fa0f922b852715671d59a0e3f682373411,
476066e89d6f0bb87220da690b8a476bf9655b80,
89c63b3522b62c0fd725f0b348927a2069238452.
This commit is contained in:
Kyle Meyer 2019-08-18 16:47:07 -04:00
parent d72b4af96e
commit 9e1b9fe627
7 changed files with 46 additions and 65 deletions

View File

@ -5924,8 +5924,8 @@ See also the user option `org-agenda-clock-consistency-checks'."
(throw 'exit t))
;; We have a shorter gap.
;; Now we have to get the minute of the day when these times are
(let* ((t1dec (decode-time (seconds-to-time t1)))
(t2dec (decode-time (seconds-to-time t2)))
(let* ((t1dec (org-decode-time t1))
(t2dec (org-decode-time t2))
;; compute the minute on the day
(min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
(min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))

View File

@ -729,8 +729,9 @@ menu\nmouse-2 will jump to task"))
The time returned includes the time spent on this task in
previous clocking intervals."
(let ((currently-clocked-time
(floor (- (float-time)
(float-time org-clock-start-time)) 60)))
(floor (org-time-convert-to-integer
(org-time-since org-clock-start-time))
60)))
(+ currently-clocked-time (or org-clock-total-time 0))))
(defun org-clock-modify-effort-estimate (&optional value)
@ -945,9 +946,7 @@ CLOCK is a cons cell of the form (MARKER START-TIME)."
(org-clock-clock-out clock fail-quietly))
((org-is-active-clock clock) nil)
(t (org-clock-clock-in clock t))))
((pred (time-less-p (current-time)))
;; ^ NOTE: Here and in other `time-less-p' calls, we use
;; (current-time) rather than nil for Emacs 24 compatibility.
((pred (org-time-less-p nil))
(error "RESOLVE-TO must refer to a time in the past"))
(_
(when restart (error "RESTART is not valid here"))
@ -1046,11 +1045,8 @@ to be CLOCKED OUT."))))
nil 45)))
(and (not (memq char-pressed '(?i ?q))) char-pressed)))))
(default
(floor (/ (float-time
;; NOTE: Here and in other `time-subtract'
;; calls, we use (current-time) rather than nil
;; for Emacs 24 compatibility.
(time-subtract (current-time) last-valid)) 60)))
(floor (org-time-convert-to-integer (org-time-since last-valid))
60))
(keep
(and (memq ch '(?k ?K))
(read-number "Keep how many minutes? " default)))
@ -1058,8 +1054,9 @@ to be CLOCKED OUT."))))
(and (memq ch '(?g ?G))
(read-number "Got back how many minutes ago? " default)))
(subtractp (memq ch '(?s ?S)))
(barely-started-p (< (- (float-time last-valid)
(float-time (cdr clock))) 45))
(barely-started-p (org-time-less-p
(org-time-subtract last-valid (cdr clock))
45))
(start-over (and subtractp barely-started-p)))
(cond
((memq ch '(?j ?J))
@ -1085,10 +1082,9 @@ to be CLOCKED OUT."))))
(and gotback (= gotback default)))
'now)
(keep
(time-add last-valid (seconds-to-time (* 60 keep))))
(org-time-add last-valid (* 60 keep)))
(gotback
(time-subtract (current-time)
(seconds-to-time (* 60 gotback))))
(org-time-since (* 60 gotback)))
(t
(error "Unexpected, please report this as a bug")))
(and gotback last-valid)
@ -1118,9 +1114,9 @@ If `only-dangling-p' is non-nil, only ask to resolve dangling
(lambda (clock)
(format
"Dangling clock started %d mins ago"
(floor (- (float-time)
(float-time (cdr clock)))
60)))))
(floor (org-time-convert-to-integer
(org-time-since (cdr clock)))
60)))))
(or last-valid
(cdr clock)))))))))))
@ -1170,7 +1166,7 @@ so long."
org-clock-marker (marker-buffer org-clock-marker))
(let* ((org-clock-user-idle-seconds (org-user-idle-seconds))
(org-clock-user-idle-start
(time-since (seconds-to-time org-clock-user-idle-seconds)))
(org-time-since org-clock-user-idle-seconds))
(org-clock-resolving-clocks-due-to-idleness t))
(if (> org-clock-user-idle-seconds (* 60 org-clock-idle-time))
(org-clock-resolve
@ -1331,9 +1327,10 @@ the default behavior."
(y-or-n-p
(format
"You stopped another clock %d mins ago; start this one from then? "
(/ (- (float-time
(org-current-time org-clock-rounding-minutes t))
(float-time leftover))
(/ (org-time-convert-to-integer
(org-time-subtract
(org-current-time org-clock-rounding-minutes t)
leftover))
60)))
leftover)
start-time
@ -1584,14 +1581,12 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
(delete-region (point) (point-at-eol))
(insert "--")
(setq te (org-insert-time-stamp (or at-time now) 'with-hm 'inactive))
(setq s (- (float-time
(apply #'encode-time (org-parse-time-string te)))
(float-time
(apply #'encode-time (org-parse-time-string ts))))
h (floor (/ s 3600))
s (- s (* 3600 h))
m (floor (/ s 60))
s (- s (* 60 s)))
(setq s (org-time-convert-to-integer
(time-subtract
(org-time-string-to-time te)
(org-time-string-to-time ts)))
h (floor s 3600)
m (floor (mod s 3600) 60))
(insert " => " (format "%2d:%02d" h m))
(move-marker org-clock-marker nil)
(move-marker org-clock-hd-marker nil)
@ -1842,8 +1837,8 @@ PROPNAME lets you set a custom text property instead of :org-clock-minutes."
tend
(>= (float-time org-clock-start-time) tstart)
(<= (float-time org-clock-start-time) tend))
(let ((time (floor (- (float-time)
(float-time org-clock-start-time))
(let ((time (floor (org-time-convert-to-integer
(org-time-since org-clock-start-time))
60)))
(setq t1 (+ t1 time))))
(let* ((headline-forced
@ -2734,7 +2729,7 @@ The TS argument has the same type as the return values of
(te (setq te (org-matcher-time te))))
(setq tsb
(if (eq step0 'week)
(let ((dow (nth 6 (decode-time (seconds-to-time ts)))))
(let ((dow (nth 6 (org-decode-time ts))))
(if (<= dow ws) ts
(float-time (org-clocktable-increment-day ts ; decrement
(- ws dow)))))

View File

@ -4819,13 +4819,13 @@ you want to help debugging the issue.")
(defvar org-element-cache-sync-idle-time 0.6
"Length, in seconds, of idle time before syncing cache.")
(defvar org-element-cache-sync-duration (seconds-to-time 0.04)
(defvar org-element-cache-sync-duration 0.04
"Maximum duration, as a time value, for a cache synchronization.
If the synchronization is not over after this delay, the process
pauses and resumes after `org-element-cache-sync-break'
seconds.")
(defvar org-element-cache-sync-break (seconds-to-time 0.3)
(defvar org-element-cache-sync-break 0.3
"Duration, as a time value, of the pause between synchronizations.
See `org-element-cache-sync-duration' for more information.")
@ -5107,7 +5107,7 @@ Assume ELEMENT belongs to cache and that a cache is active."
(setq org-element--cache-sync-timer
(run-with-idle-timer
(let ((idle (current-idle-time)))
(if idle (time-add idle org-element-cache-sync-break)
(if idle (org-time-add idle org-element-cache-sync-break)
org-element-cache-sync-idle-time))
nil
#'org-element--cache-sync
@ -5118,7 +5118,7 @@ Assume ELEMENT belongs to cache and that a cache is active."
TIME-LIMIT is a time value or nil."
(and time-limit
(or (input-pending-p)
(time-less-p time-limit (current-time)))))
(org-time-less-p time-limit nil))))
(defsubst org-element--cache-shift-positions (element offset &optional props)
"Shift ELEMENT properties relative to buffer positions by OFFSET.
@ -5172,11 +5172,8 @@ updated before current modification are actually submitted."
(and next (aref next 0))
threshold
(and (not threshold)
;; NOTE: Here and in other `time-add' calls, we use
;; (current-time) rather than nil for Emacs 24
;; compatibility.
(time-add (current-time)
org-element-cache-sync-duration))
(org-time-add nil
org-element-cache-sync-duration))
future-change)
;; Request processed. Merge current and next offsets and
;; transfer ending position.

View File

@ -406,8 +406,8 @@ current time."
"Insert consistency graph for any habitual tasks."
(let ((inhibit-read-only t)
(buffer-invisibility-spec '(org-link))
(moment (time-subtract (current-time)
(list 0 (* 3600 org-extend-today-until) 0))))
(moment (org-time-subtract nil
(* 3600 org-extend-today-until))))
(save-excursion
(goto-char (if line (point-at-bol) (point-min)))
(while (not (eobp))

View File

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

View File

@ -139,9 +139,7 @@ the region 0:00:00."
(format "Restart timer with offset [%s]: " def)))
(unless (string-match "\\S-" s) (setq s def))
(setq delta (org-timer-hms-to-secs (org-timer-fix-incomplete s)))))
(setq org-timer-start-time
(seconds-to-time
(- (float-time) delta))))
(setq org-timer-start-time (org-time-since delta)))
(setq org-timer-pause-time nil)
(org-timer-set-mode-line 'on)
(message "Timer start time set to %s, current value is %s"
@ -160,19 +158,14 @@ With prefix arg STOP, stop it entirely."
(org-timer-pause-time
(let ((start-secs (float-time org-timer-start-time))
(pause-secs (float-time org-timer-pause-time)))
;; Note: We pass the result of `current-time' to `time-add' and
;; `float-time' below so that we can easily override the value
;; in tests.
(if org-timer-countdown-timer
(let ((new-secs (- start-secs pause-secs)))
(setq org-timer-countdown-timer
(org-timer--run-countdown-timer
new-secs org-timer-countdown-timer-title))
(setq org-timer-start-time
(time-add (current-time) (seconds-to-time new-secs))))
(setq org-timer-start-time (org-time-add nil new-secs)))
(setq org-timer-start-time
(seconds-to-time (- (float-time)
(- pause-secs start-secs)))))
(org-time-since (- pause-secs start-secs))))
(setq org-timer-pause-time nil)
(org-timer-set-mode-line 'on)
(run-hooks 'org-timer-continue-hook)
@ -453,10 +446,7 @@ using three `C-u' prefix arguments."
(org-timer--run-countdown-timer
secs org-timer-countdown-timer-title))
(run-hooks 'org-timer-set-hook)
;; Pass `current-time' result to `time-add' (instead of nil)
;; for for Emacs 24 compatibility.
(setq org-timer-start-time
(time-add (current-time) (seconds-to-time secs)))
(setq org-timer-start-time (org-time-add nil secs))
(setq org-timer-pause-time nil)
(org-timer-set-mode-line 'on))))))

View File

@ -5649,8 +5649,7 @@ the rounding returns a past time."
(defun org-today ()
"Return today date, considering `org-extend-today-until'."
(time-to-days
(time-subtract (current-time)
(list 0 (* 3600 org-extend-today-until) 0))))
(org-time-since (* 3600 org-extend-today-until))))
;;;; Font-Lock stuff, including the activators
@ -12868,7 +12867,7 @@ This function is run automatically after each state change to a DONE state."
(let ((nshiftmax 10)
(nshift 0))
(while (or (= nshift 0)
(not (time-less-p (current-time) time)))
(not (org-time-less-p nil time)))
(when (= nshiftmax (cl-incf nshift))
(or (y-or-n-p
(format "%d repeater intervals were not \