emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org 7ddc86a2ca: Merge branch 'bugfix'


From: ELPA Syncer
Subject: [elpa] externals/org 7ddc86a2ca: Merge branch 'bugfix'
Date: Mon, 1 May 2023 07:05:47 -0400 (EDT)

branch: externals/org
commit 7ddc86a2ca27d3e33f3f1c8db29e98d301bba6b6
Merge: e5ae9c0ce7 08077812ef
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    Merge branch 'bugfix'
---
 lisp/org-clock.el              | 103 +++++++++++++++++++++--------------------
 testing/lisp/test-org-clock.el |  14 ++++++
 2 files changed, 66 insertions(+), 51 deletions(-)

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index c34db443c7..3aafec67ef 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -3108,57 +3108,58 @@ PROPERTIES: The list properties specified in the 
`:properties' parameter
 Otherwise, return nil."
   (interactive)
   (let ((origin (point))) ;; `save-excursion' may not work when deleting.
-    (save-excursion
-      (beginning-of-line 1)
-      (skip-chars-forward " \t")
-      (when (looking-at org-clock-string)
-        (let ((re (concat "[ \t]*" org-clock-string
-                         " *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]"
-                         "\\([ \t]*=>.*\\)?\\)?"))
-             ts te h m s neg)
-          (cond
-          ((not (looking-at re))
-           nil)
-          ((not (match-end 2))
-           (when (and (equal (marker-buffer org-clock-marker) (current-buffer))
-                      (> org-clock-marker (point))
-                       (<= org-clock-marker (line-end-position)))
-             ;; The clock is running here
-             (setq org-clock-start-time
-                   (org-time-string-to-time (match-string 1)))
-             (org-clock-update-mode-line)))
-          (t
-            ;; Prevent recursive call from `org-timestamp-change'.
-            (cl-letf (((symbol-function 'org-clock-update-time-maybe) 
#'ignore))
-              ;; Update timestamps.
-              (save-excursion
-                (goto-char (match-beginning 1)) ; opening timestamp
-                (save-match-data (org-timestamp-change 0 'day)))
-              ;; Refresh match data.
-              (looking-at re)
-              (save-excursion
-                (goto-char (match-beginning 3)) ; closing timestamp
-                (save-match-data (org-timestamp-change 0 'day))))
-            ;; Refresh match data.
-            (looking-at re)
-            (and (match-end 4) (delete-region (match-beginning 4) (match-end 
4)))
-            (end-of-line 1)
-            (setq ts (match-string 1)
-                  te (match-string 3))
-            (setq s (- (org-time-string-to-seconds te)
-                      (org-time-string-to-seconds ts))
-                  neg (< s 0)
-                  s (abs s)
-                  h (floor (/ s 3600))
-                  s (- s (* 3600 h))
-                  m (floor (/ s 60))
-                  s (- s (* 60 s)))
-           (insert " => " (format (if neg "-%d:%02d" "%2d:%02d") h m))
-           t)))))
-    ;; Move back to initial position, but never beyond updated
-    ;; clock.
-    (unless (< (point) origin)
-      (goto-char origin))))
+    (prog1
+        (save-excursion
+          (beginning-of-line 1)
+          (skip-chars-forward " \t")
+          (when (looking-at org-clock-string)
+            (let ((re (concat "[ \t]*" org-clock-string
+                             " *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]"
+                             "\\([ \t]*=>.*\\)?\\)?"))
+                 ts te h m s neg)
+              (cond
+              ((not (looking-at re))
+               nil)
+              ((not (match-end 2))
+               (when (and (equal (marker-buffer org-clock-marker) 
(current-buffer))
+                          (> org-clock-marker (point))
+                           (<= org-clock-marker (line-end-position)))
+                 ;; The clock is running here
+                 (setq org-clock-start-time
+                       (org-time-string-to-time (match-string 1)))
+                 (org-clock-update-mode-line)))
+              (t
+                ;; Prevent recursive call from `org-timestamp-change'.
+                (cl-letf (((symbol-function 'org-clock-update-time-maybe) 
#'ignore))
+                  ;; Update timestamps.
+                  (save-excursion
+                    (goto-char (match-beginning 1)) ; opening timestamp
+                    (save-match-data (org-timestamp-change 0 'day)))
+                  ;; Refresh match data.
+                  (looking-at re)
+                  (save-excursion
+                    (goto-char (match-beginning 3)) ; closing timestamp
+                    (save-match-data (org-timestamp-change 0 'day))))
+                ;; Refresh match data.
+                (looking-at re)
+                (and (match-end 4) (delete-region (match-beginning 4) 
(match-end 4)))
+                (end-of-line 1)
+                (setq ts (match-string 1)
+                      te (match-string 3))
+                (setq s (- (org-time-string-to-seconds te)
+                          (org-time-string-to-seconds ts))
+                      neg (< s 0)
+                      s (abs s)
+                      h (floor (/ s 3600))
+                      s (- s (* 3600 h))
+                      m (floor (/ s 60))
+                      s (- s (* 60 s)))
+               (insert " => " (format (if neg "-%d:%02d" "%2d:%02d") h m))
+               t)))))
+      ;; Move back to initial position, but never beyond updated
+      ;; clock.
+      (unless (< (point) origin)
+        (goto-char origin)))))
 
 (defun org-clock-save ()
   "Persist various clock-related data to disk.
diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el
index 7d8123e1f9..911161277b 100644
--- a/testing/lisp/test-org-clock.el
+++ b/testing/lisp/test-org-clock.el
@@ -113,6 +113,20 @@ the buffer."
       (org-clock-timestamps-change 'up 1)
       (buffer-string)))))
 
+(ert-deftest test-org-clok/org-clock-update-time-maybe ()
+  "Test `org-clock-update-time-maybe' specifications."
+  (should
+   (equal
+    "CLOCK: [2023-04-29 Sat 00:00]--[2023-05-04 Thu 01:00] => 121:00"
+    (org-test-with-temp-text
+        "CLOCK: [2023-04-29 Sat 00:00]--[2023-05-04 Thu 01:00]"
+      (should (org-clock-update-time-maybe))
+      (buffer-string))))
+  (should-not
+   (org-test-with-temp-text
+       "[2023-04-29 Sat 00:00]--[2023-05-04 Thu 01:00]"
+     (org-clock-update-time-maybe))))
+
 
 ;;; Clock drawer
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]