From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Parsons Subject: Re: Function to return content of item Date: Mon, 8 May 2017 18:19:58 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=94eb2c06f5c6dd0e87054f067279 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d7mKH-0003ww-CT for emacs-orgmode@gnu.org; Mon, 08 May 2017 13:20:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d7mKF-0006td-Ts for emacs-orgmode@gnu.org; Mon, 08 May 2017 13:20:01 -0400 Received: from mail-io0-x22a.google.com ([2607:f8b0:4001:c06::22a]:35648) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d7mKF-0006tZ-Mf for emacs-orgmode@gnu.org; Mon, 08 May 2017 13:19:59 -0400 Received: by mail-io0-x22a.google.com with SMTP id f102so53996669ioi.2 for ; Mon, 08 May 2017 10:19: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: John Kitchin Cc: emacs-orgmode@gnu.org --94eb2c06f5c6dd0e87054f067279 Content-Type: text/plain; charset=UTF-8 That is very kind of you - many thanks indeed for your assistance. On Mon, May 8, 2017 at 4:05 PM, John Kitchin wrote: > I think this is basically what you are looking for. > > (defun org-heading-content () > (interactive) > (let (bp ep) > (setq bp (save-excursion > (or (and (outline-previous-heading) > (progn (org-end-of-meta-data) > (point))) > (point-min))) > ep (save-excursion > (or (and (outline-next-heading) (point)) > (point-max)))) > (buffer-substring-no-properties bp ep))) > > Richard Parsons writes: > > > John, many thanks for your reply. > > > > Regarding subheadings, I would only want the content of the current > > sub-item, so if it is a subheading I only want the text from after the > > subheading (and after its property drawer) up to the next heading (or the > > end of the file). > > > > Also, when I run your code on a paragraph, I just get the contents from > > that paragraph (rather than all paragraphs in that item). Maybe "item" is > > the wrong work, is "node" better? > > > > Maybe I need to write some code using the org motion commands in order to > > manually identify the region that I'm looking for. > > > > Many thanks > > Richard > > > > > > On Mon, May 8, 2017 at 1:45 AM, John Kitchin > > wrote: > > > >> I don't know of a function. Something like this may be what you want. > >> not all elements have :contents-begin though > >> > >> (let ((el (org-element-context))) > >> (buffer-substring-no-properties > >> (org-element-property :contents-begin el) > >> (org-element-property :contents-end el))) > >> > >> > >> It also a little tricky to figure out what to do about subheadings. Do > >> they count as content or not? > >> > >> Richard Parsons writes: > >> > >> > Hi there > >> > > >> > Is there a function that will give me the content of the current > item? I > >> > mean simply the text of the whole item without its heading or > properties > >> > drawer. > >> > > >> > It seems to me likely that such a function would exist, but I haven't > >> been > >> > able to find it in the documentation. > >> > > >> > Many thanks > >> > Richard > >> > >> > >> -- > >> 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 > >> > > > -- > 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 > -- Richard Parsons Email: richard.lee.parsons@googlemail.com --94eb2c06f5c6dd0e87054f067279 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
That is very kind of you - many thanks indeed for your ass= istance.


On Mon, May 8, 2017 at 4:05 PM, John Kitchin <jkitchin@andrew.c= mu.edu> wrote:
I think this= is basically what you are looking for.

(defun org-heading-content ()
=C2=A0 (interactive)
=C2=A0 (let (bp ep)
=C2=A0 =C2=A0 (setq bp (save-excursion
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(or (and (outline-pr= evious-heading)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (progn (org-end-of-meta-data)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(point)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(point= -min)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ep (save-excursion
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(or (and (outline-ne= xt-heading) (point))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(point= -max))))
=C2=A0 =C2=A0 (buffer-substring-no-properties bp ep)))

Richard Parsons writes:

> John, many thanks for your reply.
>
> Regarding subheadings, I would only want the content of the current > sub-item, so if it is a subheading I only want the text from after the=
> subheading (and after its property drawer) up to the next heading (or = the
> end of the file).
>
> Also, when I run your code on a paragraph, I just get the contents fro= m
> that paragraph (rather than all paragraphs in that item). Maybe "= item" is
> the wrong work, is "node" better?
>
> Maybe I need to write some code using the org motion commands in order= to
> manually identify the region that I'm looking for.
>
> Many thanks
> Richard
>
>
> On Mon, May 8, 2017 at 1:45 AM, John Kitchin <jkitchin@andrew.cmu.edu>
> wrote:
>
>> I don't know of a function. Something like this may be what yo= u want.
>> not all elements have :contents-begin though
>>
>> (let ((el (org-element-context)))
>>=C2=A0 (buffer-substring-no-properties
>>=C2=A0 (org-element-property :contents-begin el)
>>=C2=A0 (org-element-property :contents-end el)))
>>
>>
>> It also a little tricky to figure out what to do about subheadings= . Do
>> they count as content or not?
>>
>> Richard Parsons writes:
>>
>> > Hi there
>> >
>> > Is there a function that will give me the content of the curr= ent item? I
>> > mean simply the text of the whole item without its heading or= properties
>> > drawer.
>> >
>> > It seems to me likely that such a function would exist, but I= haven't
>> been
>> > able to find it in the documentation.
>> >
>> > Many thanks
>> > Richard
>>
>>
>> --
>> 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
>>


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



--
Richard Parsons
= =C2=A0
Email:=C2=A0 richard.lee.parsons@googlemail.com
--94eb2c06f5c6dd0e87054f067279--