From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonathan Leech-Pepin Subject: Fwd: Re: How to identify all headings that won't be exported? Date: Thu, 26 Jun 2014 20:59:11 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c15df4412b4504fcc6d183 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0KVV-0001uc-Qk for emacs-orgmode@gnu.org; Thu, 26 Jun 2014 20:59:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X0KVU-00049H-Ae for emacs-orgmode@gnu.org; Thu, 26 Jun 2014 20:59:13 -0400 Received: from mail-qa0-x234.google.com ([2607:f8b0:400d:c00::234]:59809) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0KVU-00049B-53 for emacs-orgmode@gnu.org; Thu, 26 Jun 2014 20:59:12 -0400 Received: by mail-qa0-f52.google.com with SMTP id w8so3534741qac.11 for ; Thu, 26 Jun 2014 17:59:11 -0700 (PDT) In-Reply-To: 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org Mode Mailing List --001a11c15df4412b4504fcc6d183 Content-Type: text/plain; charset=UTF-8 Forwarding to list. Somehow reply-all did not actually reply to all ---------- Forwarded message ---------- From: "Jonathan Leech-Pepin" Date: Jun 26, 2014 4:05 PM Subject: Re: [O] How to identify all headings that won't be exported? To: "Thomas S. Dye" Cc: Hello Thomas On 26 June 2014 15:09, Thomas S. Dye wrote: > Aloha all, > > Inspired by John Kitchin's org-ref, I'm working on a little function that > returns all the pieces of an Org mode file that are candidates for cross > referencing. The helm package lets me choose from among the candidates > and then another little function inserts the chosen link. > > This all works for me, and I'm finding it really useful. The only > slight problem is that I haven't been able to figure out how to > eliminate all the headings that won't be exported. You'll see in the > code below that my simple-minded approach gets all the headings tagged > :noexport:, but it doesn't understand that the tag is inherited by > descendants. Is there a practical way to identify descendants for my use > case? > > (defun tsd-get-names-labels-and-headings () > (interactive) > (save-excursion > (goto-char (point-min)) > (let ((matches)) > (while > (re-search-forward "\\#\\+\\(name\\|label\\):\\s-\\(.*\\)" > (point-max) t) > (add-to-list 'matches (match-string-no-properties 2) t)) > (dolist (heading (org-map-entries 'org-heading-components)) > (when (and (nth 4 heading) (not (search "noexport"(nth 5 > heading)))) > (add-to-list 'matches (nth 4 heading)))) > (dolist (properties (org-map-entries 'org-entry-properties)) > (when (cdr (assoc "CUSTOM_ID" properties)) > (add-to-list 'matches > (format "#%s" (cdr (assoc "CUSTOM_ID" > properties)))))) > (sort matches 'string<)))) > For the matching portion itself the following should work: (org-map-entries (lambda () (org-element-property :raw-value (org-element-at-point))) (format "-%s" (mapconcat 'identity org-export-exclude-tags "-"))) Rather than try and search for the tag afterwards, create a string that will match all non-exporting tags and have them excluded from the match itself (by default this will be "-noexport" but if you add "test" it will become "-noexport-test"). It also gives you the exact raw value of the element. Using just 'org-element-at-point would give you the entire element, allowing you to display the :raw-value in your output but also have the associated :begin to jump to, removing the need to search for the headline again later on. > All the best, > Tom > > -- > Thomas S. Dye > http://www.tsdye.com > > --001a11c15df4412b4504fcc6d183 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

Forwarding to list. Somehow reply-all did not actually reply= to all

---------- Forwarded message ----------
From:= "Jonathan Leech-Pepin" <jonathan.leechpepin@gmail.com>
Date: Jun 26, 2014 4:0= 5 PM
Subject: Re: [O] How to identify all headings that won't be exported?To: "Thomas S. Dye" <tsd@ts= dye.com>
Cc:

Hello = Thomas


On 26 Ju= ne 2014 15:09, Thomas S. Dye <tsd@tsdye.com> wrote:
Aloha all,

Inspired by John Kitchin's org-ref, I'm working on a little functio= n that
returns all the pieces of an Org mode file that are candidates for cross referencing. The helm package lets me choose from among the candidates
and then another little function inserts the chosen link.

This all works for me, and I'm finding it really useful. =C2=A0The only=
slight problem is that I haven't been able to figure out how to
eliminate all the headings that won't be exported. =C2=A0You'll see= in the
code below that my simple-minded approach gets all the headings tagged
:noexport:, but it doesn't understand that the tag is inherited by
descendants. Is there a practical way to identify descendants for my use case?

=C2=A0 (defun tsd-get-names-labels-and-headings ()
=C2=A0 =C2=A0 (interactive)
=C2=A0 =C2=A0 (save-excursion
=C2=A0 =C2=A0 =C2=A0 (goto-char (point-min))
=C2=A0 =C2=A0 =C2=A0 (let ((matches))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (while
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (re-search-forward "\\#\\+\\= (name\\|label\\):\\s-\\(.*\\)" (point-max) t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (add-to-list 'matches (match-string-= no-properties 2) t))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (dolist (heading (org-map-entries 'org-head= ing-components))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (when (and (nth 4 heading) (not (search = "noexport"(nth 5 heading))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (add-to-list 'matches (nth 4 = heading))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (dolist (properties (org-map-entries 'org-e= ntry-properties))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (when (cdr (assoc "CUSTOM_ID" = properties))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (add-to-list 'matches
=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(format "#%s" (cdr (assoc "CUSTOM_ID" = properties))))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (sort matches 'string<))))

For the matching portion itself the following should work:=

(org-map-entries (lambda () (org-element-property :raw-value (org-e= lement-at-point))) (format "-%s" (mapconcat 'identity org-exp= ort-exclude-tags "-")))

Rather than try and search for the tag afterwards, create a strin= g that will match all non-exporting tags and have them excluded from the ma= tch itself (by default this will be "-noexport" but if you add &q= uot;test" it will become "-noexport-test").=C2=A0 It also gi= ves you the exact raw value of the element.=C2=A0 Using just 'org-eleme= nt-at-point would give you the entire element, allowing you to display the = :raw-value in your output but also have the associated :begin to jump to, r= emoving the need to search for the headline again later on.


=C2=A0
All the best,
Tom

--
Thomas S. Dye
http://www.tsdye.com=


--001a11c15df4412b4504fcc6d183--