From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 4ByFFGIHvF4GSAAA0tVLHw (envelope-from ) for ; Wed, 13 May 2020 14:42:42 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id +LlcBXEHvF4OAgAAB5/wlQ (envelope-from ) for ; Wed, 13 May 2020 14:42:57 +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 4D2E794066D for ; Wed, 13 May 2020 14:42:54 +0000 (UTC) Received: from localhost ([::1]:55568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYsb1-0003J4-3D for larch@yhetil.org; Wed, 13 May 2020 10:42:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57492) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYsac-0003Il-7S for emacs-orgmode@gnu.org; Wed, 13 May 2020 10:42:30 -0400 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]:52175) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYsaa-0004oX-J1 for emacs-orgmode@gnu.org; Wed, 13 May 2020 10:42:29 -0400 Received: by mail-pj1-x1044.google.com with SMTP id mq3so11200744pjb.1 for ; Wed, 13 May 2020 07:42:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=Yqy9weV7/bRTThKrWEGHUF6OoBsL3vQ2pch/WlgYFUA=; b=t9MT6juhgw+gq5EcUflFo0oUl2SUZefj2R/mPZmRhDd71+05qm2NgHjDdcbNu1loam jZPVgOPULPuDlgX/z8Ra96TD8GdhCR5GfUVmZl03esndo/O6PtuWcypnghKgH+zUlwaU AT9LGoGtTba+vVzqHjAR3z5OcpBhmkRYFmBjBTQmvv4PUf+gPHWycrYNs8o+NnG0ZzC0 3Lh7hx8Y5kjOJAaOBujtcg6cWyFlBq5Wpupn61cOqlyKkfp9xQT6s2rIn8fq77IazAJO JKNTXJPmd5XH1p5Dgdq1DWG6Ld2AiIJo53CYiGVFIgTVLeVZUwaE4dnUapRVGF+WpjIC IsYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=Yqy9weV7/bRTThKrWEGHUF6OoBsL3vQ2pch/WlgYFUA=; b=t6y5w+CEAOcLsOBKWi6O8qXOZ5DIbQSQ+RhHNQzlWZUogw9uVq/TuSDyHbtcx7Y6b0 00/ceAUDFeHI2/m1FXcNnJ2wdOVLtthX9vlJzD3EpjayvMm+ykrkVbqCIfvJsYaS99Bs Yzyq8Tqq5UeE7ujN0Tsa7CrcUCy4i8oMdfVvR04meaLj4cAHGPaaSnSp7l5Rt6CJ3E99 6aqFwCGLMTehg+aysf6f4xgT4XVe80TPRMjgdWQxqcCznXC56iIidZrNtqw/PpykDcZJ 2rU7rU4JMk0sjOVyd7GaXkMBvBLoJVuOQIWJM/L+8tEYUhyjXmPlXolMrx4Bcl8wZRVh bOyw== X-Gm-Message-State: AGi0PuZsUlx0c4lW0wzqgcPCKbudr2vXpoa0O2Em+9s6mvZErSiYEQ15 XG0O5Mql40h4xKiz3KU54WY= X-Google-Smtp-Source: APiQypK+0v1o1YxnaFMqS7AusCD/NjejHhp/JsCNYepCLXEbRtiIYVgORoP+cvbCcsOxAGcOYBN8sQ== X-Received: by 2002:a17:902:c193:: with SMTP id d19mr25615295pld.60.1589380946866; Wed, 13 May 2020 07:42:26 -0700 (PDT) Received: from localhost ([210.3.160.230]) by smtp.gmail.com with ESMTPSA id ce21sm15677118pjb.51.2020.05.13.07.42.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 07:42:26 -0700 (PDT) From: Ihor Radchenko To: John Kitchin Subject: Re: get the body of a heading up to the next subheading In-Reply-To: References: <87ftc5agb1.fsf@localhost> Date: Wed, 13 May 2020 22:38:03 +0800 Message-ID: <87o8qraoj8.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::1044; envelope-from=yantar92@gmail.com; helo=mail-pj1-x1044.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: , Cc: org-mode-email 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=t9MT6juh; 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.53992269757249]; 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.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]; 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)[]; 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]; 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)[cmu.edu:email,sutd.edu.sg:email]; 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]; MID_RHS_NOT_FQDN(0.50)[]; FORGED_SENDER_MAILLIST(0.00)[] X-TUID: L9ruJTGwWWgJ > 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