From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cody Goodman Subject: Re: How do you get the LOGBOOK information from the current heading at point? Date: Sun, 5 Aug 2018 21:56:46 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000004cac390572bb6e10" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmVhd-0005ct-9A for emacs-orgmode@gnu.org; Sun, 05 Aug 2018 22:57:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmVhb-0001h2-Jb for emacs-orgmode@gnu.org; Sun, 05 Aug 2018 22:57:01 -0400 Received: from mail-qt0-x234.google.com ([2607:f8b0:400d:c0d::234]:43744) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmVhb-0001gY-C4 for emacs-orgmode@gnu.org; Sun, 05 Aug 2018 22:56:59 -0400 Received: by mail-qt0-x234.google.com with SMTP id f18-v6so12254252qtp.10 for ; Sun, 05 Aug 2018 19:56:59 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: jkitchin@andrew.cmu.edu Cc: emacs-orgmode@gnu.org --0000000000004cac390572bb6e10 Content-Type: text/plain; charset="UTF-8" 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 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 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 > --0000000000004cac390572bb6e10 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks! I think that's going to be what I'm lookin= g for, but I got an error:

let: Wrong type argument: integer-or-mark= er-p, nil

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

(org-elem= ent-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 :minu= te-end 6 :begin 28124 :end 28171 :post-blank 1)) :duration "0:31"= :begin 28112 :end 28180 :post-blank 0 :post-affiliated 28112 :parent (draw= er (:begin 28097 :end 28191 :drawer-name "LOGBOOK" :contents-begi= n 28112 :contents-end 28180 :post-blank 0 :post-affiliated 28097 :parent ni= l))))))


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


(clock (:status closed :value (timestamp (:t= ype 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 :m= inute-start 35 :year-end 2018 :month-end 8 :day-end 5 :hour-end 3 :minute-e= nd 6 :begin 28124 :end 28171 :post-blank 1)) :duration "0:31" :be= gin 28112 :end 28180 :post-blank 0 :post-affiliated 28112 :parent (drawer (= :begin 28097 :end 28191 :drawer-name "LOGBOOK" :contents-begin 28= 112 :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 =3D'= =3D in front of it like:

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = #+BEGIN_SRC elisp
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (org-elemen= t-property :contents-begin '((clock (:status closed :value (timestamp (= :type inactive-range :raw-value "[2018-08-05 Sun 02:35]--[2018-08-05 S= un 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)= )))))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 #+END_SRC

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

On Sun, Aug 5, 2018 at 5:41 PM John Kitchin <jkitchin@andrew.cmu.edu> wrot= e:
I think somet= hing like this is what you are looking for:

#+BEGIN_SRC emacs-lisp
(defun get-clock-lines ()
=C2=A0 "Return org-element representations of clock lines in a logbook= drawer."
=C2=A0 (interactive)
=C2=A0 (save-excursion
=C2=A0 =C2=A0 (goto-char (org-log-beginning))
=C2=A0 =C2=A0 (let ((logbook (org-element-at-point))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (clock-entries '())
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (current-element))
=C2=A0 =C2=A0 =C2=A0 (goto-char (org-element-property :contents-begin logbo= ok))
=C2=A0 =C2=A0 =C2=A0 (setq current-element (org-element-at-point))
=C2=A0 =C2=A0 =C2=A0 (while (eq 'clock (car current-element))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (push current-element clock-entries)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (forward-line)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq current-element (org-element-at-point)))<= br> =C2=A0 =C2=A0 =C2=A0 (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
>=C2=A0 =C2=A0 =C2=A0CLOSED: [2018-08-04 Sat 21:18]
>=C2=A0 =C2=A0 :LOGBOOK:
>=C2=A0 =C2=A0 =C2=A0CLOCK: [2018-08-04 Sat 21:16]--[2018-08-04 Sat 12:1= 8] =3D>=C2=A0 0:02
>=C2=A0 =C2=A0 :END:
>
> What function will get me the parts in CLOCK: [2018-08-04 Sat
> 21:16]--[2018-08-04 Sat 12:18] =3D>=C2=A0 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]&quo= t; :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 :en= d 68
> :post-blank 0)
>
> Note org-element-at-point doesn't give back logbook information: >
> (headline (:raw-value "put into spacemacs file" :begin 1 :en= d 157
> :pre-blank 0 :contents-begin 34 :contents-end 157 :level 3 :priority n= il
> :tags nil :todo-keyword #("DONE" 0 4 (fontified t face org-d= one))
> :todo-type done :post-blank 0 :footnote-section-p nil :archivedp nil > :commentedp nil :post-affiliated 1 :closed (timestamp (:type inactive<= br> > :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
--0000000000004cac390572bb6e10--