emacs-orgmode
[Top][All Lists]
Advanced

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

Re: clock-table and hooking that into org-capture file+olp+datetree


From: Christopher Causer
Subject: Re: clock-table and hooking that into org-capture file+olp+datetree
Date: Sat, 30 Jan 2021 22:40:22 +0000
User-agent: Cyrus-JMAP/3.5.0-alpha0-84-gfc141fe8b8-fm-20210125.001-gfc141fe8

Thanks again Richard. I now have a working solution which I share below, warts 
and all.

One snag I hit that I feel I should mention is what I believe to be a mistake 
in the documentation[1]. I was scratching my head as why 
org-clocktable-defaults wasn't working, but it was only when I brought up the 
inline documentation that I see that this probably is some vestigial 
variableand it has since moved to org-clock-clocktable-default-properties. Is 
mentioning this here on the list enough or should I report it somewhere else?

Christopher 

#+BEGIN_SRC emacs-lisp
(defun org-date-to-list ()
  "Run `org-read-date' and return it in the form '(mm dd YYYY).

This form is more useful for functions that require it in
this format, such as `org-datetree-find-date-create'."

  (let* ((date-string (org-read-date))
         (year (substring date-string 0 4))
         (month (substring date-string 5 7))
         (day (substring date-string 8 10)))
    (mapcar 'string-to-number (list month day year))))

(defun org-update-clocktable-on-date (date)
  (let* ((year (number-to-string (nth 2 date)))
         (month (number-to-string (nth 0 date)))
         (day (number-to-string (nth 1 date)))
         (org-clock-clocktable-default-properties
          (list :scope 'agenda :maxlevel 6 :block (concat year "-" month "-" 
day))))
         (save-excursion
           ;; open the file containing the datetree:
           (find-file (concat org-directory "/diary.org"))
           ;; jump to the subtree for the given date:
           ;; note: date must look like (m d y) where all three values are 
integers
           (org-datetree-find-date-create date)
           ;; narrow to the subtree for this date, so we don't update
           ;; any other clocktables
           (org-narrow-to-subtree)
           ;; update the clock report, or create it if it doesn't exist
           ;; note: we pass a prefix argument to tell org-clock-report to
           ;; update the first clocktable it finds in the (narrowed) buffer
           (org-clock-report t)
           ;; widen to the whole buffer again
           (widen))))


;; Usage
; (org-update-clocktable-on-date (org-date-to-list))
#+END_SRC

[1] Variable org-clocktable-defaults is mentioned here 
https://orgmode.org/manual/The-clock-table.html



reply via email to

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