org-clock.el (org-clock-select-task): Throw a user error when the clock history is empty

* org-clock.el (org-clock-select-task): Throw a user error
when the clock history is empty.
This commit is contained in:
Bastien Guerry 2013-04-10 10:08:45 +02:00
parent 0480d0a0d0
commit ff4b7a4784
1 changed files with 44 additions and 40 deletions

View File

@ -514,9 +514,11 @@ of a different task.")
"Hook called in task selection just before prompting the user.")
(defun org-clock-select-task (&optional prompt)
"Select a task that recently was associated with clocking."
"Select a task that was recently associated with clocking."
(interactive)
(let (sel-list rpl (i 0) s)
(let ((chl (length org-clock-history)) sel-list rpl (i 0) s)
(if (zerop chl)
(user-error "No recent clock")
(save-window-excursion
(org-switch-to-buffer-other-window
(get-buffer-create "*Clock Task Select*"))
@ -547,14 +549,16 @@ of a different task.")
org-clock-history)
(run-hooks 'org-clock-before-select-task-hook)
(goto-char (point-min))
(org-fit-window-to-buffer nil nil (+ 6 (length org-clock-history)))
;; Set min-height relatively to circumvent a possible but in
;; `fit-window-to-buffer'
(fit-window-to-buffer nil nil (if (< chl 10) chl (+ 5 chl)))
(message (or prompt "Select task for clocking:"))
(setq cursor-type nil rpl (read-char-exclusive))
(cond
((eq rpl ?q) nil)
((eq rpl ?x) nil)
((assoc rpl sel-list) (cdr (assoc rpl sel-list)))
(t (error "Invalid task choice %c" rpl))))))
(t (user-error "Invalid task choice %c" rpl)))))))
(defun org-clock-insert-selection-line (i marker)
"Insert a line for the clock selection menu.