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: Richard Lawrence
Subject: Re: clock-table and hooking that into org-capture file+olp+datetree
Date: Sat, 30 Jan 2021 18:09:36 +0100

Hi Christopher and all,

"Christopher Causer" <ml-emacs-orgmode@chyc.co.uk> writes:

>> 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? 

As sensible as anything :) 

I recently added my version, using decode-time and nth, as a helper
function to my .emacs. I feel sure that it must already exist
*somewhere* in Emacs but I searched quite a while for it and didn't find
it. I will use this again below:

#+begin_src emacs-lisp 
  (defun time-as-calendar-date (time)
    "Convert time in Emacs' time format to a calendar date list (MONTH DAY 
YEAR)"
    (let ((parsed-time (decode-time time)))
      (list
       (nth 4 parsed-time)
       (nth 3 parsed-time)
       (nth 5 parsed-time))))
#+end_src

> My two next things to tackle are 
>
> 1. A hook to run the function when I run org-capture.

Here you might find it useful to grab the value of the :default-time key
from org-capture-plist (which should contain either the time you entered
at the date prompt during capture, or the current time, in Emacs' time
format). Then, using the functions above, you can say something like
this in your hook:

#+being_src emacs-lisp
(let* ((default-time (plist-get org-capture-plist :default-time))
       (date (time-as-calendar-date default-time)))
  (org-update-clocktable-on-date date))
#+end_src

> 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.

Emacs Lisp has dynamic scope by default, which makes this is pretty easy
in general: just set the value you want to use in a let form around the
code that uses this variable, like:

(let ((org-clocktable-defaults your-custom-value-here))
  ...)

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

No problem! That's what this list is for. I recently spent a fair amount
of time digging through the datetree stuff myself, so I was glad to have
a chance to share what I learned.

-- 
Best,
Richard



reply via email to

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