From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kyle Meyer Subject: Re: Getting text at position? Date: Sun, 09 Jun 2019 23:35:30 -0400 Message-ID: <87wohuglj1.fsf@kyleam.com> References: <80214e4f-d9e5-1daa-8c91-116c19bfff59@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:43725) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1haB5v-0007kY-70 for emacs-orgmode@gnu.org; Sun, 09 Jun 2019 23:35:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1haB5t-0006uY-6T for emacs-orgmode@gnu.org; Sun, 09 Jun 2019 23:35:39 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:56473) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1haB5r-0006rx-AJ for emacs-orgmode@gnu.org; Sun, 09 Jun 2019 23:35:35 -0400 In-Reply-To: <80214e4f-d9e5-1daa-8c91-116c19bfff59@gmail.com> 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: Mike Gauland , emacs-orgmode@gnu.org Mike Gauland writes: > I'd like to be able to be able to get the text associated with a given > heading (based on the current point, for example). > > Can anyone point me to an example for doing this in the approved manner > (assuming there is one), or to functions to help with this? Don't trust me to give you an approved manner, but a couple of options: * If you just care about headlines and assuming you want all associated content, including the headline text itself, perhaps calling org-copy-subtree non-interactively will suffice. If that doesn't behave how you want, looking at org-copy-subtree's source could still give you an idea of how to do what you want in elisp. * You could use the org-element API to get the information and likely could easily tweak something like below to suit your needs. (and (ignore-errors (org-back-to-heading t)) (let ((el (org-element-at-point))) (buffer-substring (org-element-property :begin el) (org-element-property :end el)))) -- Kyle