I'm drowning in parenthesis here. I want to write a function which returns in a string the time and the effort estimate of the current clocked task.
I first looked in org-mode checking I wasn't re-doing the wheel, I found org-clock-get-clock-string
which does what I want but it appends things I don't need making the string unusable for what I want. I took a look at the source code and tried to adapt it to do what I want, however, I fail miserably, I did this mess:
(defun shackra/task-clocked-time ()
"Return a string with the clocked time and effort, if any"
(let* ((clocked-time (org-clock-get-clocked-time))
(h (floor clocked-time 60))
(m (- clocked-time (* 60 h))))
(if org-clock-effort
(let* ((effort-in-minutes
(org-duration-string-to-minutes org-clock-effort))
(effort-h (floor effort-in-minutes 60))
(effort-m (- effort-in-minutes (* effort-h 60)))
(work-done-str (format org-time-clocksum-format h m))
(effort-str (format org-time-clocksum-format effort-h effort-m))
(clockstr (concat " [%s/" effort-str
"] (" (replace-regexp-in-string "%" "%%" org-clock-heading) ")"))))
(format clockstr work-done-str))
(format
(concat "[" org-time-clocksum-format " (%s)]")
h m org-clock-heading)))
but executing the function for testing yells this error:
Debugger entered--Lisp error: (wrong-type-argument stringp (:days "%dd " :hours "%d" :require-hours t :minutes ":%02d" :require-minutes t))
format((:days "%dd " :hours "%d" :require-hours t :minutes ":%02d" :require-minutes t) 0 12)
(let* ((effort-in-minutes (org-duration-string-to-minutes org-clock-effort)) (effort-h (floor effort-in-minutes 60)) (effort-m (- effort-in-minutes (* effort-h 60)))) (format org-time-clocksum-format h m))
(if org-clock-effort (let* ((effort-in-minutes (org-duration-string-to-minutes org-clock-effort)) (effort-h (floor effort-in-minutes 60)) (effort-m (- effort-in-minutes (* effort-h 60)))) (format org-time-clocksum-format h m)))
(let* ((clocked-time (org-clock-get-clocked-time)) (h (floor clocked-time 60)) (m (- clocked-time (* 60 h)))) (if org-clock-effort (let* ((effort-in-minutes (org-duration-string-to-minutes org-clock-effort)) (effort-h (floor effort-in-minutes 60)) (effort-m (- effort-in-minutes (* effort-h 60)))) (format org-time-clocksum-format h m))))
shackra/task-clocked-time()
eval((shackra/task-clocked-time) nil)
eval-last-sexp-1(nil)
eval-last-sexp(nil)
call-interactively(eval-last-sexp nil nil)
command-execute(eval-last-sexp)
To be honest, I don't know what I'm doing and I neither know how to read the code of org-clock-get-clock-string
(the lacks of documentation in that code kills me)
org-time-clocksum-format
isn't string but alist, andformat
needs string as its first argument.