From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id SOvBFDEJvF41ZQAA0tVLHw (envelope-from ) for ; Wed, 13 May 2020 14:50:25 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 2JiTBUAJvF5cdgAA1q6Kng (envelope-from ) for ; Wed, 13 May 2020 14:50:40 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 843019411C5 for ; Wed, 13 May 2020 14:50:35 +0000 (UTC) Received: from localhost ([::1]:36442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYsiS-000866-3B for larch@yhetil.org; Wed, 13 May 2020 10:50:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYshp-00084I-Ku for emacs-orgmode@gnu.org; Wed, 13 May 2020 10:49:57 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:42920) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYshm-0007KC-ES for emacs-orgmode@gnu.org; Wed, 13 May 2020 10:49:57 -0400 Received: by mail-wr1-x432.google.com with SMTP id s8so21259263wrt.9 for ; Wed, 13 May 2020 07:49:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=andrew-cmu-edu.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7yhQ+0Xv4uDQSXeGN/3nJ7aC1+UQmH4opKEIa76lYNY=; b=G3VnrIEL9qpMgkGZzMz4vuhAmMNMUlUaU48hI8GHEhHIvLdGryTfJH2wJLUzjguBGV QmyVFruLHbgat2WP5iZM3BFGQ9SHVTIZD7O+aTPstbURD7b/4WiHsPlu0vFyL5KqtSHL ipAN6HnvhPBve7kdfwzlr+vNAT5QL2pXvFkcG4gWoMfnayc5SHRFhmh/165A/8DcMRlG zRQRaZfbDJZjn772WrnCz1s6z0Rap94YUewYMi6mbYEjA8lXnuIX6qyvmT385zZKo3lv csM5I/eYa7zi4uT+/fVDGpJ2BkXBx+UOtRdU7Kx1y0ce50lpFX00rLhOtSWBlXuCvNB3 vpug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7yhQ+0Xv4uDQSXeGN/3nJ7aC1+UQmH4opKEIa76lYNY=; b=YoEFyy7ZvSlG5r/+cFLXrSiHD9ycwMEOdWy18Skw0CztRmHydpQV3xRJXXVtGJmVmP Vv2a1TK9DnrUJJkHMlV6QrLgkQfX3+g44PR9IP7CoFmYc3E7Z3Y1lcuVZa9mcIte6CDf P/UynB4lT+Fsy1NMTDJlYtZyrmTOrfOFbI4mRBJNzHR2SAZDOMTYG4ugJw2bNQWWwEF0 GEe1IJA+YmldPFpJRoOfgFJknr9HryeDk2gBBBp7mvjPeC4T76BYI8CBFRj0ZFqLOasU 6mm4qEJ2DrUETnAazqsFyqPlvlAM1Kai0tNu0/VwvSWGr/HjedV7saFu40iLQea4VxHh v5BA== X-Gm-Message-State: AGi0PuZOTFZ8jE81+s70KJizB716M/W+xYokn/m34Y3UGguAlkP9cMZB ZG3f794AIRVkAfpOqo644xJku4eMZMi+FEF1pOQ= X-Google-Smtp-Source: APiQypKakOoQf+1q/MMGpOjOUGSp8Nkb59Z1WB6WUqNlCSn8Vs2hZGYBWD82AEsDv60I0bJXP8rMMZ45nryEXaS+cpA= X-Received: by 2002:a5d:62c7:: with SMTP id o7mr30968996wrv.212.1589381392401; Wed, 13 May 2020 07:49:52 -0700 (PDT) MIME-Version: 1.0 References: <87ftc5agb1.fsf@localhost> <87o8qraoj8.fsf@localhost> In-Reply-To: <87o8qraoj8.fsf@localhost> From: John Kitchin Date: Wed, 13 May 2020 10:49:41 -0400 Message-ID: Subject: Re: get the body of a heading up to the next subheading To: Ihor Radchenko Content-Type: multipart/alternative; boundary="0000000000004e8a3305a588b11e" Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=johnrkitchin@gmail.com; helo=mail-wr1-x432.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: org-mode-email Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 X-Spam-Score: -1.11 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=andrew-cmu-edu.20150623.gappssmtp.com header.s=20150623 header.b=G3VnrIEL; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=andrew.cmu.edu (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Scan-Result: default: False [-1.11 / 13.00]; GENERIC_REPUTATION(0.00)[-0.53991316423359]; DWL_DNSWL_FAIL(0.00)[209.51.188.17:server fail]; R_SPF_ALLOW(-0.20)[+ip4:209.51.188.0/24:c]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.05), country: US(-0.00), ip: 209.51.188.17(-0.54)]; TO_DN_ALL(0.00)[]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; RCPT_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[andrew-cmu-edu.20150623.gappssmtp.com:+]; MAILLIST(-0.20)[mailman]; FREEMAIL_TO(0.00)[gmail.com]; RCVD_IN_DNSWL_FAIL(0.00)[209.51.188.17:server fail]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:22989, ipnet:209.51.188.0/24, country:US]; TAGGED_FROM(0.00)[larch=yhetil.org]; FROM_NEQ_ENVFROM(0.00)[jkitchin@andrew.cmu.edu,emacs-orgmode-bounces@gnu.org]; ARC_NA(0.00)[]; RCVD_COUNT_FIVE(0.00)[5]; R_DKIM_ALLOW(-0.20)[andrew-cmu-edu.20150623.gappssmtp.com:s=20150623]; FROM_HAS_DN(0.00)[]; URIBL_BLOCKED(0.00)[cmu.edu:email,andrew-cmu-edu.20150623.gappssmtp.com:dkim,sutd.edu.sg:email]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[emacs-orgmode@gnu.org]; HAS_LIST_UNSUB(-0.01)[]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.51.188.17:from]; FORGED_SENDER_MAILLIST(0.00)[]; DMARC_POLICY_SOFTFAIL(0.10)[andrew.cmu.edu : SPF not aligned (relaxed), DKIM not aligned (relaxed),none] X-TUID: gsKBHHehbgnN --0000000000004e8a3305a588b11e Content-Type: text/plain; charset="UTF-8" good point, thanks! Here is a new version that might fail some other way! (defun canvas-org-get-heading-body () "Return the body of the current heading up to the next heading." (interactive) (save-excursion (unless (org-at-heading-p) (org-previous-visible-heading 1)) (org-end-of-meta-data) (buffer-substring (point) (progn (org-next-visible-heading 1) (point))))) John ----------------------------------- 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 On Wed, May 13, 2020 at 10:42 AM Ihor Radchenko wrote: > > Thanks! Here is what I am currently using: > > Note that your code may fail if there is an inline task in the body. > > Best, > Ihor > > John Kitchin writes: > > > Thanks! Here is what I am currently using: > > > > (defun canvas-org-get-heading-body () > > "Return the body of the current heading up to the next heading." > > (interactive) > > (save-excursion > > (unless (org-at-heading-p) > > (org-previous-visible-heading 1)) > > (org-end-of-meta-data) > > (buffer-substring (point) > > (progn (re-search-forward org-heading-regexp nil 'mv) > > (line-beginning-position))))) > > > > So far it gets what I want. I am pretty sure I have reinvented this, > > maybe even from code I wrote before... I couldn't find my answer on SO > > or my blog though. > > > > Ihor Radchenko writes: > > > >> You may use something similar to org-quick-peek--get-entry-text from > >> org-quick-peek package (https://github.com/alphapapa/org-quick-peek): > >> > >> (cl-defun org-quick-peek--get-entry-text (marker &key keep-drawers > keep-planning) > >> "Return Org entry text from node at MARKER. > >> If KEEP-DRAWERS is non-nil, drawers will be kept, otherwise > >> removed." > >> ;; Modeled after `org-agenda-get-some-entry-text' > >> (let (text) > >> (with-current-buffer (marker-buffer marker) > >> ;; Get raw entry text > >> (org-with-wide-buffer > >> (goto-char marker) > >> ;; Skip heading > >> (end-of-line 1) > >> ;; Get entry text > >> (setq text (buffer-substring > >> (point) > >> (or (save-excursion (outline-next-heading) (point)) > >> (point-max)))))) > >> (with-temp-buffer > >> (org-mode) > >> (insert text) > >> (unless keep-drawers > >> (goto-char (point-min)) > >> (while (re-search-forward org-drawer-regexp nil t) > >> ;; Remove drawers > >> (delete-region (match-beginning 0) > >> (progn (re-search-forward > >> "^[ \t]*:END:.*\n?" nil 'move) > >> (point))))) > >> (unless keep-planning > >> (goto-char (point-min)) > >> (while (re-search-forward org-planning-line-re nil t) > >> ;; Remove planning line > >> (kill-whole-line))) > >> (setq text (buffer-substring (point-min) (point-max)))) > >> (-reduce-r #'funcall (reverse (cons text (cons #'identity > org-quick-peek-filter-functions)))))) > >> > >> Best, > >> Ihor > >> > >> John Kitchin writes: > >> > >>> Hi everyone, > >>> > >>> I am trying to get the body of a heading up to the next subheading. For > >>> example with this org file, > >>> > >>> * quiz one > >>> > >>> This is the description. > >>> Use emacs for this. > >>> > >>> ** question 1 > >>> what is 40 + 2 > >>> > >>> If the point is in the first heading, I want to run a function that > would > >>> return the string "This is the description.\nUse emacs for this." > >>> > >>> I thought there was a simple way to do that, but so far it has eluded > my > >>> google fu. Any hints? > >>> > >>> John > >>> > >>> ----------------------------------- > >>> 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 > > -- > Ihor Radchenko, > PhD, > Center for Advancing Materials Performance from the Nanoscale (CAMP-nano) > State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong > University, Xi'an, China > Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg > --0000000000004e8a3305a588b11e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
good point, thanks!

Here is a new versi= on that might fail some other way!

(defun canvas-o= rg-get-heading-body ()
=C2=A0 "Return the body of the current headi= ng up to the next heading."
=C2=A0 (interactive)
=C2=A0 (save-ex= cursion
=C2=A0 =C2=A0 (unless (org-at-heading-p)
=C2=A0 =C2=A0 =C2=A0= (org-previous-visible-heading 1))
=C2=A0 =C2=A0 (org-end-of-meta-data) =
=C2=A0 =C2=A0 (buffer-substring (point)
=C2=A0 =C2=A0 =C2=A0(prog= n (org-next-visible-heading 1) (point)))))

=


John

-----------------------------------
Professor John Kitchin= =C2=A0
Doherty Hall A207F
Department of Chemical Engineering
Carne= gie Mellon University
Pittsburgh, PA 15213
412-268-7803


On Wed, May 13, 2020 at 10:42 AM Ihor Radchenko <= ;yantar92@gmail.com> wrote:
> Thanks! Here = is what I am currently using:

Note that your code may fail if there is an inline task in the body.

Best,
Ihor

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> Thanks! Here is what I am currently using:
>
> (defun canvas-org-get-heading-body ()
>=C2=A0 =C2=A0"Return the body of the current heading up to the nex= t heading."
>=C2=A0 =C2=A0(interactive)
>=C2=A0 =C2=A0(save-excursion
>=C2=A0 =C2=A0 =C2=A0(unless (org-at-heading-p)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(org-previous-visible-heading 1))
>=C2=A0 =C2=A0 =C2=A0(org-end-of-meta-data)
>=C2=A0 =C2=A0 =C2=A0(buffer-substring (point)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(progn (re-search-forward org-heading-regexp nil 'mv)
>=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 (line-beginning-position)))))
>
> So far it gets what I want. I am pretty sure I have reinvented this, > maybe even from code I wrote before... I couldn't find my answer o= n SO
> or my blog though.
>
> Ihor Radchenko <yantar92@gmail.com> writes:
>
>> You may use something similar to org-quick-peek--get-entry-text fr= om
>> org-quick-peek package (https://github.com/alpha= papa/org-quick-peek):
>>
>> (cl-defun org-quick-peek--get-entry-text (marker &key keep-dra= wers keep-planning)
>>=C2=A0 =C2=A0"Return Org entry text from node at MARKER.
>> If KEEP-DRAWERS is non-nil, drawers will be kept, otherwise
>> removed."
>>=C2=A0 =C2=A0;; Modeled after `org-agenda-get-some-entry-text'<= br> >>=C2=A0 =C2=A0(let (text)
>>=C2=A0 =C2=A0 =C2=A0(with-current-buffer (marker-buffer marker)
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0;; Get raw entry text
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0(org-with-wide-buffer
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (goto-char marker)
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; Skip heading
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (end-of-line 1)
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; Get entry text
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq text (buffer-substring
>>=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 (or (save-excursion (outline-next-heading) (point))
>>=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-max))))))
>>=C2=A0 =C2=A0 =C2=A0(with-temp-buffer
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0(org-mode)
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0(insert text)
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0(unless keep-drawers
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(goto-char (point-min))
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(while (re-search-forward org-dra= wer-regexp nil t)
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; Remove drawers
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(delete-region (match-begi= nning 0)
>>=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 (progn (re-search-forward
>>=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 =C2=A0 "^[ \t]*:END:.*\n= ?" nil 'move)
>>=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 =C2=A0(point)))))
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0(unless keep-planning
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(goto-char (point-min))
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(while (re-search-forward org-pla= nning-line-re nil t)
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; Remove planning line >>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(kill-whole-line)))
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0(setq text (buffer-substring (point-min)= (point-max))))
>>=C2=A0 =C2=A0 =C2=A0(-reduce-r #'funcall (reverse (cons text (c= ons #'identity org-quick-peek-filter-functions))))))
>>
>> Best,
>> Ihor
>>
>> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>>
>>> Hi everyone,
>>>
>>> I am trying to get the body of a heading up to the next subhea= ding. For
>>> example with this org file,
>>>
>>> * quiz one
>>>
>>> This is the description.
>>> Use emacs for this.
>>>
>>> ** question 1
>>> what is 40 + 2
>>>
>>> If the point is in the first heading, I want to run a function= that would
>>> return the string "This is the description.\nUse emacs fo= r this."
>>>
>>> I thought there was a simple way to do that, but so far it has= eluded my
>>> google fu. Any hints?
>>>
>>> John
>>>
>>> -----------------------------------
>>> 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

--
Ihor Radchenko,
PhD,
Center for Advancing Materials Performance from the Nanoscale (CAMP-nano) State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaoto= ng University, Xi'an, China
Email: yantar92@gma= il.com, ihor_radchenko@alumni.sutd.edu.sg
--0000000000004e8a3305a588b11e--