summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2010-07-16 11:20:05 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2010-09-01 19:05:47 +0200
commit53c4b53e8f8f9955ea1acea118fa355deffa64c2 (patch)
tree4c50b8c4a424c4b226659428775270767cc42267
parent8eece59f9e635a397f3c1338fb9b65abd3d6e935 (diff)
downloadorg-mode-53c4b53e8f8f9955ea1acea118fa355deffa64c2.tar.gz
Less latency in org-timer-item.
* org-timer.el (org-timer-item): Refactoring. Compute timer string before inserting it in the buffer * org-timer.el (org-timer): added an optional argument to return timer string instead of inserting it.
-rw-r--r--lisp/org-timer.el27
1 files changed, 15 insertions, 12 deletions
diff --git a/lisp/org-timer.el b/lisp/org-timer.el
index d511406..0e29682 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)