From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 2K5HLTgBvF4PWAAA0tVLHw (envelope-from ) for ; Wed, 13 May 2020 14:16:24 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id wMolHUcBvF4BXQAAbx9fmQ (envelope-from ) for ; Wed, 13 May 2020 14:16:39 +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 93551940C01 for ; Wed, 13 May 2020 14:16:36 +0000 (UTC) Received: from localhost ([::1]:41044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYsBZ-0004o0-Fn for larch@yhetil.org; Wed, 13 May 2020 10:16:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYsAv-0004bY-Q0 for emacs-orgmode@gnu.org; Wed, 13 May 2020 10:15:57 -0400 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]:37179) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYsAu-0006Er-Hu for emacs-orgmode@gnu.org; Wed, 13 May 2020 10:15:57 -0400 Received: by mail-qk1-x729.google.com with SMTP id s186so15602883qkd.4 for ; Wed, 13 May 2020 07:15:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:references:user-agent:from:to:cc:subject:in-reply-to :message-id:date:mime-version; bh=/AkWE7YiOfpnBhmwvcLYT1j9jdR2A2C+ufEHHYSaOew=; b=EAPbYm1AvDdrnkvZOsZzhpHPHZQ9ZzrNdvKQXhmElM/6qrFPB9csqe3V8361Vpk+Gn LzDnjx/uFO+cHrCucrHBQn4PdtHJ6UYpvSX4J0rX/lIYihYWYGu4F4xaHcz7FaNowyin NJZPcgukfts84cHGR4Eu9F9ItTu4MhO7Jmw8i7oJF2etBfauxEuruWjFBllGxklJxM+X Ud/lRcdbjp5NGHhFKcA2cvw2JkKg+euGyCsBIHMRYUTvU0226+cbOQJgrm/X9qe6UW7G cGb8XUEmveitDPs3QpFJBStyhWZ9f1P3N3t9gnUc5K84/AoH3q4SwNwYTUHnQY5JrrLN cvJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:references:user-agent:from:to:cc:subject :in-reply-to:message-id:date:mime-version; bh=/AkWE7YiOfpnBhmwvcLYT1j9jdR2A2C+ufEHHYSaOew=; b=toSHP5PONaIMf5lyzU+RcZMtCJjZQ5eypnHuTvIU+gTPssGb1KktHqGfYIprXLstRr LxizRdf8EvCQQTMYYyxBbEJDFGX0alERtTlrhDO7zBcJEMsQR77FLIa3YpqJWhekMhyT dl7sIqytU+Squ/37ZmDi4OnI7A9ju+2iSmj9dZ4irlPhiQQ3wmRnsWhI1NWBHavH0FQk 8vf8ONsHtGsRnOOKwdiePgmOUtxZZ7KTG/ivnbAjHeZ1r4sCzwZDkFHZ5MgDrkJBx5uO bGj9crfHJg56RcqAiMkHxFBK21zXZLgGUXJLX6NpEABg0r+7SoLvXAf+OM7S83tK5k3U Mnpw== X-Gm-Message-State: AGi0PuYHn3bVhuCmYKQV0IwrdJUIUVEXC3Gfr4+A1PZ3eAewMJAyR4LU EVCCnEHeDH04Dk8bHHdooK/z57Su X-Google-Smtp-Source: APiQypK9qiK85XrKc9PFB88wyoHgNRdYBSY3Y6Rfg/ot/dcvCs6Kz14BXhr3t0/0/QmeZZDBMkw7ZA== X-Received: by 2002:a37:4c93:: with SMTP id z141mr26058534qka.143.1589379354570; Wed, 13 May 2020 07:15:54 -0700 (PDT) Received: from Johns-MacBook-Air.local ([2601:547:901:1830:25f0:43a9:ca19:6a81]) by smtp.gmail.com with ESMTPSA id s56sm7927081qtk.45.2020.05.13.07.15.53 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 May 2020 07:15:53 -0700 (PDT) References: <87ftc5agb1.fsf@localhost> User-agent: mu4e 1.3.6; emacs 26.3 From: John Kitchin To: Ihor Radchenko Subject: Re: get the body of a heading up to the next subheading In-reply-to: <87ftc5agb1.fsf@localhost> Message-ID: Date: Wed, 13 May 2020 10:15:52 -0400 MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::729; envelope-from=johnrkitchin@gmail.com; helo=mail-qk1-x729.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: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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: 0.09 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=gmail.com header.s=20161025 header.b=EAPbYm1A; dmarc=fail reason="SPF 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 [0.09 / 13.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; GENERIC_REPUTATION(0.00)[-0.53985945634619]; DWL_DNSWL_FAIL(0.00)[209.51.188.17:server fail]; R_SPF_ALLOW(-0.20)[+ip4:209.51.188.0/24:c]; R_DKIM_REJECT(1.00)[gmail.com:s=20161025]; 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)[]; DKIM_TRACE(0.00)[gmail.com:-]; RCPT_COUNT_TWO(0.00)[2]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; 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:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:22989, ipnet:209.51.188.0/24, country:US]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_FROM(0.00)[larch=yhetil.org]; ARC_NA(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jkitchin@andrew.cmu.edu,emacs-orgmode-bounces@gnu.org]; FROM_HAS_DN(0.00)[]; URIBL_BLOCKED(0.00)[cmu.edu:email]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MIME_GOOD(-0.10)[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),none] X-TUID: RJNQwH6npHY4 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