diff --git a/lisp/org-timer.el b/lisp/org-timer.el index d51140634..0e296820a 100644 --- a/lisp/org-timer.el +++ b/lisp/org-timer.el @@ -145,18 +145,23 @@ With prefix arg STOP, stop it entirely." (org-timer-set-mode-line 'off)) ;;;###autoload -(defun org-timer (&optional restart) +(defun org-timer (&optional restart no-insert-p) "Insert a H:MM:SS string from the timer into the buffer. The first time this command is used, the timer is started. When used with a \\[universal-argument] prefix, force restarting the timer. When used with a double prefix argument \ \\[universal-argument] \\universal-argument], change all the timer string in the region by a fixed amount. This can be used to recalibrate a timer -that was not started at the correct moment." +that was not started at the correct moment. + +If NO-INSERT-P is non-nil, return the string instead of inserting +it in the buffer." (interactive "P") - (if (equal restart '(4)) (org-timer-start)) - (or org-timer-start-time (org-timer-start)) - (insert (org-timer-value-string))) + (when (or (equal restart '(4)) (not org-timer-start-time)) + (org-timer-start)) + (if no-insert-p + (org-timer-value-string) + (insert (org-timer-value-string)))) (defun org-timer-value-string () (format org-timer-format (org-timer-secs-to-hms (floor (org-timer-seconds))))) @@ -196,23 +201,21 @@ that was not started at the correct moment." "Insert a description-type item with the current timer value." (interactive "P") (cond - ;; If we are in a timer list, insert item like `org-insert-item'. + ;; In a timer list, insert with `org-insert-item-internal'. ((and (org-in-item-p) (save-excursion (org-beginning-of-item) (looking-at "[ \t]*[-+*][ \t]+[0-9]+:[0-9]+:[0-9]+ ::"))) - (org-insert-item-internal (point)) - (org-timer (if arg '(4))) - (insert ":: ")) - ;; We are still are in a list, of a wrong type: throw an error. + (org-insert-item-internal (point) nil (concat (org-timer (when arg '(4)) t) ":: "))) + ;; In a list of another type, don't break anything: throw an error. ((org-in-item-p) (error "This is not a timer list")) - ;; Else, go to beginning of line, and insert the timer + ;; Else, insert the timer correctly indented at bol. (t (beginning-of-line) (org-indent-line-function) (insert "- ") - (org-timer (if arg '(4))) + (org-timer (when arg '(4))) (insert ":: ")))) (defun org-timer-fix-incomplete (hms)