org-clock-timestamps-change: Preserve point position

* lisp/org-clock.el (org-clock-timestamps-change): Try harder to
preserve point position.  `save-excursion' is not sufficient here,
when the timestamp gets deleted in the process.

Reported-by: Johannes Dahl <muusik@gmail.com>
Link: https://orgmode.org/list/CAHuokSbJxM4kqjdT94aHmjnKqzOvpJpq3tJqOEqdswaBC=JnfA@mail.gmail.com
This commit is contained in:
Ihor Radchenko 2023-01-13 11:57:19 +03:00
parent cd967ce006
commit 97a235cf1c
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 19 additions and 11 deletions

View File

@ -1800,17 +1800,25 @@ Optional argument N tells to change by that many units."
(time-subtract
(org-time-string-to-time org-last-changed-timestamp)
(org-time-string-to-time ts)))
(save-excursion
(goto-char begts)
(org-timestamp-change
(round (/ (float-time tdiff)
(pcase timestamp?
(`minute 60)
(`hour 3600)
(`day (* 24 3600))
(`month (* 24 3600 31))
(`year (* 24 3600 365.2)))))
timestamp? 'updown)))))))
;; `save-excursion' won't work because
;; `org-timestamp-change' deletes and re-inserts the
;; timestamp.
(let ((origin (point)))
(save-excursion
(goto-char begts)
(org-timestamp-change
(round (/ (float-time tdiff)
(pcase timestamp?
(`minute 60)
(`hour 3600)
(`day (* 24 3600))
(`month (* 24 3600 31))
(`year (* 24 3600 365.2)))))
timestamp? 'updown))
;; Move back to initial position, but never beyond updated
;; clock.
(unless (< (point) origin)
(goto-char origin))))))))
;;;###autoload
(defun org-clock-cancel ()