emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Fwd: Re: How to identify all headings that won't be exported?


From: Jonathan Leech-Pepin
Subject: [O] Fwd: Re: How to identify all headings that won't be exported?
Date: Thu, 26 Jun 2014 20:59:11 -0400

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

---------- Forwarded message ----------
From: "Jonathan Leech-Pepin" <address@hidden>
Date: Jun 26, 2014 4:05 PM
Subject: Re: [O] How to identify all headings that won't be exported?
To: "Thomas S. Dye" <address@hidden>
Cc:

Hello Thomas


On 26 June 2014 15:09, Thomas S. Dye <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]