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 16:32:42 +0000
User-agent: Cyrus-JMAP/3.5.0-alpha0-84-gfc141fe8b8-fm-20210125.001-gfc141fe8

On Sat, 30 Jan 2021, at 12:53, Richard Lawrence wrote:
> #+begin_src emacs-lisp
> (defun org-update-clocktable-on-date (date)
>   (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)))
> #+end_src

This is wonderful Richard, and a great help to me. I had no idea of the 
org-datree-find-date-create, and the argument to org-clock-report cuts out a 
lot of my code. 

> Note that org-datetree-find-date has a slightly annoying interface, in
> that you need to provide a list of three integers representing a
> calendar date. 

Yes, that is a little awkward. What I did think of using was substrings to 
extract the date from the picker interface.

#+BEGIN_SRC emacs-lisp
(defun org-date-picker-to-list ()
  (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))))
#+END_SRC

Does that look sensible? 

My two next things to tackle are 

1. A hook to run the function when I run org-capture.
2. Changing the org-clock-report options in your function above, but not the 
defaults.

For the second point, is there some trick to swap a global variable for the run 
of a function? The variable in this case would be org-clocktable-defaults.

Thank you so much Richard. You've probably saved me days of going through the 
org-mode documentation and source. 



reply via email to

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