emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How do you get the LOGBOOK information from the current heading at point?
@ 2018-08-05 16:48 Cody Goodman
  2018-08-05 22:41 ` John Kitchin
  0 siblings, 1 reply; 4+ messages in thread
From: Cody Goodman @ 2018-08-05 16:48 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1302 bytes --]

Given a TODO that looks like this:

*** DONE put into spacemacs file
    CLOSED: [2018-08-04 Sat 21:18]
   :LOGBOOK:
    CLOCK: [2018-08-04 Sat 21:16]--[2018-08-04 Sat 12:18] =>  0:02
   :END:

What function will get me the parts in CLOCK: [2018-08-04 Sat
21:16]--[2018-08-04 Sat 12:18] =>  0:02, preferably in plist format like
the closed timestamp org-element-at-point gives back of:

(timestamp (:type inactive :raw-value "[2018-08-04 Sat 21:18]" :year-start
2018 :month-start 8 :day-start 4 :hour-start 21 :minute-start 18 :year-end
2018 :month-end 8 :day-end 4 :hour-end 21 :minute-end 18 :begin 46 :end 68
:post-blank 0)

Note org-element-at-point doesn't give back logbook information:

(headline (:raw-value "put into spacemacs file" :begin 1 :end 157
:pre-blank 0 :contents-begin 34 :contents-end 157 :level 3 :priority nil
:tags nil :todo-keyword #("DONE" 0 4 (fontified t face org-done))
:todo-type done :post-blank 0 :footnote-section-p nil :archivedp nil
:commentedp nil :post-affiliated 1 :closed (timestamp (:type inactive
:raw-value "[2018-08-04 Sat 21:18]" :year-start 2018 :month-start 8
:day-start 4 :hour-start 21 :minute-start 18 :year-end 2018 :month-end 8
:day-end 4 :hour-end 21 :minute-end 18 :begin 46 :end 68 :post-blank 0))
:title "put into spacemacs file"))

Thanks,

Cody

[-- Attachment #2: Type: text/html, Size: 1547 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How do you get the LOGBOOK information from the current heading at point?
  2018-08-05 16:48 How do you get the LOGBOOK information from the current heading at point? Cody Goodman
@ 2018-08-05 22:41 ` John Kitchin
  2018-08-06  2:56   ` Cody Goodman
  0 siblings, 1 reply; 4+ messages in thread
From: John Kitchin @ 2018-08-05 22:41 UTC (permalink / raw)
  To: Cody Goodman; +Cc: emacs-orgmode

I think something like this is what you are looking for:

#+BEGIN_SRC emacs-lisp
(defun get-clock-lines ()
  "Return org-element representations of clock lines in a logbook drawer."
  (interactive)
  (save-excursion
    (goto-char (org-log-beginning))
    (let ((logbook (org-element-at-point))
	  (clock-entries '())
	  (current-element))
      (goto-char (org-element-property :contents-begin logbook))
      (setq current-element (org-element-at-point))
      (while (eq 'clock (car current-element))
	(push current-element clock-entries)
	(forward-line)
	(setq current-element (org-element-at-point)))
      (reverse clock-entries))))

(get-clock-lines)
#+END_SRC


Cody Goodman <codygman.consulting@gmail.com> writes:

> Given a TODO that looks like this:
>
> *** DONE put into spacemacs file
>     CLOSED: [2018-08-04 Sat 21:18]
>    :LOGBOOK:
>     CLOCK: [2018-08-04 Sat 21:16]--[2018-08-04 Sat 12:18] =>  0:02
>    :END:
>
> What function will get me the parts in CLOCK: [2018-08-04 Sat
> 21:16]--[2018-08-04 Sat 12:18] =>  0:02, preferably in plist format like
> the closed timestamp org-element-at-point gives back of:
>
> (timestamp (:type inactive :raw-value "[2018-08-04 Sat 21:18]" :year-start
> 2018 :month-start 8 :day-start 4 :hour-start 21 :minute-start 18 :year-end
> 2018 :month-end 8 :day-end 4 :hour-end 21 :minute-end 18 :begin 46 :end 68
> :post-blank 0)
>
> Note org-element-at-point doesn't give back logbook information:
>
> (headline (:raw-value "put into spacemacs file" :begin 1 :end 157
> :pre-blank 0 :contents-begin 34 :contents-end 157 :level 3 :priority nil
> :tags nil :todo-keyword #("DONE" 0 4 (fontified t face org-done))
> :todo-type done :post-blank 0 :footnote-section-p nil :archivedp nil
> :commentedp nil :post-affiliated 1 :closed (timestamp (:type inactive
> :raw-value "[2018-08-04 Sat 21:18]" :year-start 2018 :month-start 8
> :day-start 4 :hour-start 21 :minute-start 18 :year-end 2018 :month-end 8
> :day-end 4 :hour-end 21 :minute-end 18 :begin 46 :end 68 :post-blank 0))
> :title "put into spacemacs file"))
>
> Thanks,
>
> Cody


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How do you get the LOGBOOK information from the current heading at point?
  2018-08-05 22:41 ` John Kitchin
@ 2018-08-06  2:56   ` Cody Goodman
  2018-08-06  3:10     ` John Kitchin
  0 siblings, 1 reply; 4+ messages in thread
From: Cody Goodman @ 2018-08-06  2:56 UTC (permalink / raw)
  To: jkitchin; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 4950 bytes --]

Thanks! I think that's going to be what I'm looking for, but I got an error:

let: Wrong type argument: integer-or-marker-p, nil

I traced it down to the =org-element-property :contents-begin= call which
essentially ends up looking like this:

(org-element-property :contents-begin '((clock (:status closed :value
(timestamp (:type inactive-range :raw-value "[2018-08-05 Sun
02:35]--[2018-08-05 Sun 03:06]" :year-start 2018 :month-start 8 :day-start
5 :hour-start 2 :minute-start 35 :year-end 2018 :month-end 8 :day-end 5
:hour-end 3 :minute-end 6 :begin 28124 :end 28171 :post-blank 1)) :duration
"0:31" :begin 28112 :end 28180 :post-blank 0 :post-affiliated 28112 :parent
(drawer (:begin 28097 :end 28191 :drawer-name "LOGBOOK" :contents-begin
28112 :contents-end 28180 :post-blank 0 :post-affiliated 28097 :parent
nil))))))


Then contents-begin isn't being accessed for some reason. I don't know
elisp well enough to know why just by looking at that. The raw output I got
from my point being over a TODO I yanked from the messages buffer was:


(clock (:status closed :value (timestamp (:type inactive-range :raw-value
"[2018-08-05 Sun 02:35]--[2018-08-05 Sun 03:06]" :year-start 2018
:month-start 8 :day-start 5 :hour-start 2 :minute-start 35 :year-end 2018
:month-end 8 :day-end 5 :hour-end 3 :minute-end 6 :begin 28124 :end 28171
:post-blank 1)) :duration "0:31" :begin 28112 :end 28180 :post-blank 0
:post-affiliated 28112 :parent (drawer (:begin 28097 :end 28191
:drawer-name "LOGBOOK" :contents-begin 28112 :contents-end 28180
:post-blank 0 :post-affiliated 28097 :parent nil))))


To be able to work with it in org mode I just put a ='= in front of it like:

        #+BEGIN_SRC elisp
        (org-element-property :contents-begin '((clock (:status closed
:value (timestamp (:type inactive-range :raw-value "[2018-08-05 Sun
02:35]--[2018-08-05 Sun 03:06]" :year-start 2018 :month-start 8 :day-start
5 :hour-start 2 :minute-start 35 :year-end 2018 :month-end 8 :day-end 5
:hour-end 3 :minute-end 6 :begin 28124 :end 28171 :post-blank 1)) :duration
"0:31" :begin 28112 :end 28180 :post-blank 0 :post-affiliated 28112 :parent
(drawer (:begin 28097 :end 28191 :drawer-name "LOGBOOK" :contents-begin
28112 :contents-end 28180 :post-blank 0 :post-affiliated 28097 :parent
nil))))))
        #+END_SRC

If that's the correct way to do that translation, then maybe we are using
different org mode versions? I'm using 9.1.9.

On Sun, Aug 5, 2018 at 5:41 PM John Kitchin <jkitchin@andrew.cmu.edu> wrote:

> I think something like this is what you are looking for:
>
> #+BEGIN_SRC emacs-lisp
> (defun get-clock-lines ()
>   "Return org-element representations of clock lines in a logbook drawer."
>   (interactive)
>   (save-excursion
>     (goto-char (org-log-beginning))
>     (let ((logbook (org-element-at-point))
>           (clock-entries '())
>           (current-element))
>       (goto-char (org-element-property :contents-begin logbook))
>       (setq current-element (org-element-at-point))
>       (while (eq 'clock (car current-element))
>         (push current-element clock-entries)
>         (forward-line)
>         (setq current-element (org-element-at-point)))
>       (reverse clock-entries))))
>
> (get-clock-lines)
> #+END_SRC
>
>
> Cody Goodman <codygman.consulting@gmail.com> writes:
>
> > Given a TODO that looks like this:
> >
> > *** DONE put into spacemacs file
> >     CLOSED: [2018-08-04 Sat 21:18]
> >    :LOGBOOK:
> >     CLOCK: [2018-08-04 Sat 21:16]--[2018-08-04 Sat 12:18] =>  0:02
> >    :END:
> >
> > What function will get me the parts in CLOCK: [2018-08-04 Sat
> > 21:16]--[2018-08-04 Sat 12:18] =>  0:02, preferably in plist format like
> > the closed timestamp org-element-at-point gives back of:
> >
> > (timestamp (:type inactive :raw-value "[2018-08-04 Sat 21:18]"
> :year-start
> > 2018 :month-start 8 :day-start 4 :hour-start 21 :minute-start 18
> :year-end
> > 2018 :month-end 8 :day-end 4 :hour-end 21 :minute-end 18 :begin 46 :end
> 68
> > :post-blank 0)
> >
> > Note org-element-at-point doesn't give back logbook information:
> >
> > (headline (:raw-value "put into spacemacs file" :begin 1 :end 157
> > :pre-blank 0 :contents-begin 34 :contents-end 157 :level 3 :priority nil
> > :tags nil :todo-keyword #("DONE" 0 4 (fontified t face org-done))
> > :todo-type done :post-blank 0 :footnote-section-p nil :archivedp nil
> > :commentedp nil :post-affiliated 1 :closed (timestamp (:type inactive
> > :raw-value "[2018-08-04 Sat 21:18]" :year-start 2018 :month-start 8
> > :day-start 4 :hour-start 21 :minute-start 18 :year-end 2018 :month-end 8
> > :day-end 4 :hour-end 21 :minute-end 18 :begin 46 :end 68 :post-blank 0))
> > :title "put into spacemacs file"))
> >
> > Thanks,
> >
> > Cody
>
>
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>

[-- Attachment #2: Type: text/html, Size: 6012 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How do you get the LOGBOOK information from the current heading at point?
  2018-08-06  2:56   ` Cody Goodman
@ 2018-08-06  3:10     ` John Kitchin
  0 siblings, 0 replies; 4+ messages in thread
From: John Kitchin @ 2018-08-06  3:10 UTC (permalink / raw)
  To: Cody Goodman; +Cc: org-mode-email

[-- Attachment #1: Type: text/plain, Size: 6222 bytes --]

I doubt it is the org version, I have 9.1.13. The function should return a
list of clock elements.


On Sun, Aug 5, 2018 at 7:56 PM, Cody Goodman <codygman.consulting@gmail.com>
wrote:

> Thanks! I think that's going to be what I'm looking for, but I got an
> error:
>
> let: Wrong type argument: integer-or-marker-p, nil
>
> I traced it down to the =org-element-property :contents-begin= call which
> essentially ends up looking like this:
>
> (org-element-property :contents-begin '((clock (:status closed :value
> (timestamp (:type inactive-range :raw-value "[2018-08-05 Sun
> 02:35]--[2018-08-05 Sun 03:06]" :year-start 2018 :month-start 8 :day-start
> 5 :hour-start 2 :minute-start 35 :year-end 2018 :month-end 8 :day-end 5
> :hour-end 3 :minute-end 6 :begin 28124 :end 28171 :post-blank 1)) :duration
> "0:31" :begin 28112 :end 28180 :post-blank 0 :post-affiliated 28112 :parent
> (drawer (:begin 28097 :end 28191 :drawer-name "LOGBOOK" :contents-begin
> 28112 :contents-end 28180 :post-blank 0 :post-affiliated 28097 :parent
> nil))))))
>

 I would not expect that to work, you have a list of elements, and not an
element.


>
> Then contents-begin isn't being accessed for some reason. I don't know
> elisp well enough to know why just by looking at that. The raw output I got
> from my point being over a TODO I yanked from the messages buffer was:
>
>
> (clock (:status closed :value (timestamp (:type inactive-range :raw-value
> "[2018-08-05 Sun 02:35]--[2018-08-05 Sun 03:06]" :year-start 2018
> :month-start 8 :day-start 5 :hour-start 2 :minute-start 35 :year-end 2018
> :month-end 8 :day-end 5 :hour-end 3 :minute-end 6 :begin 28124 :end 28171
> :post-blank 1)) :duration "0:31" :begin 28112 :end 28180 :post-blank 0
> :post-affiliated 28112 :parent (drawer (:begin 28097 :end 28191
> :drawer-name "LOGBOOK" :contents-begin 28112 :contents-end 28180
> :post-blank 0 :post-affiliated 28097 :parent nil))))
>
>
> To be able to work with it in org mode I just put a ='= in front of it
> like:
>

I don't think this will work either.


>
>         #+BEGIN_SRC elisp
>         (org-element-property :contents-begin '((clock (:status closed
> :value (timestamp (:type inactive-range :raw-value "[2018-08-05 Sun
> 02:35]--[2018-08-05 Sun 03:06]" :year-start 2018 :month-start 8 :day-start
> 5 :hour-start 2 :minute-start 35 :year-end 2018 :month-end 8 :day-end 5
> :hour-end 3 :minute-end 6 :begin 28124 :end 28171 :post-blank 1)) :duration
> "0:31" :begin 28112 :end 28180 :post-blank 0 :post-affiliated 28112 :parent
> (drawer (:begin 28097 :end 28191 :drawer-name "LOGBOOK" :contents-begin
> 28112 :contents-end 28180 :post-blank 0 :post-affiliated 28097 :parent
> nil))))))
>         #+END_SRC
>
> If that's the correct way to do that translation, then maybe we are using
> different org mode versions? I'm using 9.1.9.
>

You can get to the timestamps in each line like this:

#+BEGIN_SRC emacs-lisp
(mapcar (lambda (clock) (org-element-property :value clock))
(get-clock-lines))
#+END_SRC

#+RESULTS:
| timestamp | (:type inactive-range :raw-value [2018-08-04 Sat
21:16]--[2018-08-04 Sat 12:18] :year-start 2018 :month-start 8 :day-start 4
:hour-start 21 :minute-start 16 :year-end 2018 :month-end 8 :day-end 4
:hour-end 12 :minute-end 18 :begin 1502 :end 1549 :post-blank 1) |
| timestamp | (:type inactive-range :raw-value [2018-08-04 Sat
21:16]--[2018-08-04 Sat 15:35] :year-start 2018 :month-start 8 :day-start 4
:hour-start 21 :minute-start 16 :year-end 2018 :month-end 8 :day-end 4
:hour-end 15 :minute-end 35 :begin 1569 :end 1616 :post-blank 1) |

and then you can get to properties of those.


>
>
> On Sun, Aug 5, 2018 at 5:41 PM John Kitchin <jkitchin@andrew.cmu.edu>
> wrote:
>
>> I think something like this is what you are looking for:
>>
>> #+BEGIN_SRC emacs-lisp
>> (defun get-clock-lines ()
>>   "Return org-element representations of clock lines in a logbook drawer."
>>   (interactive)
>>   (save-excursion
>>     (goto-char (org-log-beginning))
>>     (let ((logbook (org-element-at-point))
>>           (clock-entries '())
>>           (current-element))
>>       (goto-char (org-element-property :contents-begin logbook))
>>       (setq current-element (org-element-at-point))
>>       (while (eq 'clock (car current-element))
>>         (push current-element clock-entries)
>>         (forward-line)
>>         (setq current-element (org-element-at-point)))
>>       (reverse clock-entries))))
>>
>> (get-clock-lines)
>> #+END_SRC
>>
>>
>> Cody Goodman <codygman.consulting@gmail.com> writes:
>>
>> > Given a TODO that looks like this:
>> >
>> > *** DONE put into spacemacs file
>> >     CLOSED: [2018-08-04 Sat 21:18]
>> >    :LOGBOOK:
>> >     CLOCK: [2018-08-04 Sat 21:16]--[2018-08-04 Sat 12:18] =>  0:02
>> >    :END:
>> >
>> > What function will get me the parts in CLOCK: [2018-08-04 Sat
>> > 21:16]--[2018-08-04 Sat 12:18] =>  0:02, preferably in plist format like
>> > the closed timestamp org-element-at-point gives back of:
>> >
>> > (timestamp (:type inactive :raw-value "[2018-08-04 Sat 21:18]"
>> :year-start
>> > 2018 :month-start 8 :day-start 4 :hour-start 21 :minute-start 18
>> :year-end
>> > 2018 :month-end 8 :day-end 4 :hour-end 21 :minute-end 18 :begin 46 :end
>> 68
>> > :post-blank 0)
>> >
>> > Note org-element-at-point doesn't give back logbook information:
>> >
>> > (headline (:raw-value "put into spacemacs file" :begin 1 :end 157
>> > :pre-blank 0 :contents-begin 34 :contents-end 157 :level 3 :priority nil
>> > :tags nil :todo-keyword #("DONE" 0 4 (fontified t face org-done))
>> > :todo-type done :post-blank 0 :footnote-section-p nil :archivedp nil
>> > :commentedp nil :post-affiliated 1 :closed (timestamp (:type inactive
>> > :raw-value "[2018-08-04 Sat 21:18]" :year-start 2018 :month-start 8
>> > :day-start 4 :hour-start 21 :minute-start 18 :year-end 2018 :month-end 8
>> > :day-end 4 :hour-end 21 :minute-end 18 :begin 46 :end 68 :post-blank 0))
>> > :title "put into spacemacs file"))
>> >
>> > Thanks,
>> >
>> > Cody
>>
>>
>> --
>> Professor John Kitchin
>> Doherty Hall A207F
>> Department of Chemical Engineering
>> Carnegie Mellon University
>> Pittsburgh, PA 15213
>> 412-268-7803
>> @johnkitchin
>> http://kitchingroup.cheme.cmu.edu
>>
>

[-- Attachment #2: Type: text/html, Size: 8301 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-06  3:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-05 16:48 How do you get the LOGBOOK information from the current heading at point? Cody Goodman
2018-08-05 22:41 ` John Kitchin
2018-08-06  2:56   ` Cody Goodman
2018-08-06  3:10     ` John Kitchin

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).