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 qI85EQUxul7LSQAA0tVLHw (envelope-from ) for ; Tue, 12 May 2020 05:15:49 +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 yHlVHRMxul57QgAAbx9fmQ (envelope-from ) for ; Tue, 12 May 2020 05:16:03 +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 96B6B940068 for ; Tue, 12 May 2020 05:16:00 +0000 (UTC) Received: from localhost ([::1]:60520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYNGq-0003XU-Av for larch@yhetil.org; Tue, 12 May 2020 01:16:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYNGT-0003XN-Ui for emacs-orgmode@gnu.org; Tue, 12 May 2020 01:15:37 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:36063) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYNGR-0000I1-Q5 for emacs-orgmode@gnu.org; Tue, 12 May 2020 01:15:37 -0400 Received: by mail-pj1-x1034.google.com with SMTP id q24so8810678pjd.1 for ; Mon, 11 May 2020 22:15:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:in-reply-to:references:date:message-id:mime-version; bh=ElI1lz5QW0KuV1O3y7B+tmbddpgZWLM3N8x6ZZ+OnMw=; b=BcDsUolqs/QXiImvRrI8mBucwqeTEObleUN3ziUVktqZH0t+GsYW6lYV2dOiON0Gr+ vwPV8cNGH5W+txLFgK064klUKklwV0BzDwSSFtKtFadwH5QolwtOC74zuDw5kSbSo9eS LRhVAY07KmB0GDugd8LewB1OISLNHnWWv2k+6K+0SFKheWs7JrY3aD13Q0Eil6bPqbpZ jinVF8tPFQayJ/1KCD1f2s5JLAaroAb8fYZPu317cxZuvlWtZz++fA6OT+eGEoG/yMUU PdVwTYUj4uEn0oDqz0rcucmQBiWPh/TJudZUCCDN/a3dmS/dlqdktOXnzr/OrS53bZhd j/Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=ElI1lz5QW0KuV1O3y7B+tmbddpgZWLM3N8x6ZZ+OnMw=; b=Px56TmSEnaxAkzlPPOIpke66CLpbX9VCeUB6aDFJ5ZdrFP8YUvm6zg+rcFIn33uVJQ Vmssf4AswHWvK0+JUOPjoyTZA7HLbqo3UDhvH64e3RrQ9a7KLCJTZl91kcSUIR5UPKMC YhbcTR+2Rw9+Xx6SkmOTH1lAwUvllQElNcUtvNBh91TSmsnPyeds2839LN56yXkPFlZr SSPwLciyQgOrWzw25wnzccfj+CZesjPkCP6iE++xGePMZ5vJ1AKVzq6bZZRFG+VRNYua ZifKQguv8hY/WNRLx0lJrodhwsbqzSwLmSwg2CDeyfsy+NBYGscJn82Iym+6PX9p1Nog KEIA== X-Gm-Message-State: AGi0PuZoFi2BE17Ckk0lZPwcsVL/W9M6/NUI+gdhUgxNkk9bcHZs97SL CxY9tYX/UE+8ajaTGrq2FAc= X-Google-Smtp-Source: APiQypIufRgvVZ3hbzNQmF3AbOaVkAFOZp1o19bR0vxA4rdyEzXqTgoKRfyJCKRPkDrQZr2crp1+GQ== X-Received: by 2002:a17:90a:e38c:: with SMTP id b12mr27870333pjz.102.1589260533908; Mon, 11 May 2020 22:15:33 -0700 (PDT) Received: from localhost ([203.146.170.148]) by smtp.gmail.com with ESMTPSA id d4sm8878523pgk.2.2020.05.11.22.15.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2020 22:15:33 -0700 (PDT) From: Ihor Radchenko To: John Kitchin , org-mode-email Subject: Re: get the body of a heading up to the next subheading In-Reply-To: References: Date: Tue, 12 May 2020 13:11:14 +0800 Message-ID: <87ftc5agb1.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=yantar92@gmail.com; helo=mail-pj1-x1034.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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=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: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 X-Spam-Score: -1.21 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=BcDsUolq; dmarc=pass (policy=none) header.from=gmail.com; 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.21 / 13.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; GENERIC_REPUTATION(0.00)[-0.53978254978682]; DWL_DNSWL_FAIL(0.00)[gmail.com:server fail,209.51.188.17:server fail]; R_SPF_ALLOW(-0.20)[+ip4:209.51.188.0/24:c]; FREEMAIL_FROM(0.00)[gmail.com]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.07), 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]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; MAILLIST(-0.20)[mailman]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MIME_TRACE(0.00)[0:+]; 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)[yantar92@gmail.com,emacs-orgmode-bounces@gnu.org]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; RCVD_COUNT_FIVE(0.00)[6]; FROM_HAS_DN(0.00)[]; URIBL_BLOCKED(0.00)[sutd.edu.sg:email,cmu.edu:email]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[emacs-orgmode@gnu.org]; HAS_LIST_UNSUB(-0.01)[]; DNSWL_BLOCKED(0.00)[209.51.188.17:from]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.51.188.17:from]; MID_RHS_NOT_FQDN(0.50)[]; FORGED_SENDER_MAILLIST(0.00)[] X-TUID: AR86EzDxy237 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 -- 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