emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to identify all headings that won't be exported?
@ 2014-06-26 19:09 Thomas S. Dye
  2014-06-27  0:40 ` Thomas S. Dye
       [not found] ` <CAEWDx5f+MgsCFFw9h9hoPT_HcKstt4WG6s+FZKRzEEH3G1So_A@mail.gmail.com>
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas S. Dye @ 2014-06-26 19:09 UTC (permalink / raw)
  To: Org-mode

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<))))

All the best,
Tom

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to identify all headings that won't be exported?
  2014-06-26 19:09 How to identify all headings that won't be exported? Thomas S. Dye
@ 2014-06-27  0:40 ` Thomas S. Dye
       [not found] ` <CAEWDx5f+MgsCFFw9h9hoPT_HcKstt4WG6s+FZKRzEEH3G1So_A@mail.gmail.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas S. Dye @ 2014-06-27  0:40 UTC (permalink / raw)
  To: Org-mode

Aloha all,

Answering myself ...

tsd@tsdye.com (Thomas S. Dye) writes:

> 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<))))

Yes, use the MATCH argument to org-map-entries.

Many thanks to Jonathan Leech-Pepin for pointing this out to me off
list.

All the best,
Tom

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Fwd: Re: How to identify all headings that won't be exported?
       [not found] ` <CAEWDx5f+MgsCFFw9h9hoPT_HcKstt4WG6s+FZKRzEEH3G1So_A@mail.gmail.com>
@ 2014-06-27  0:59   ` Jonathan Leech-Pepin
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Leech-Pepin @ 2014-06-27  0:59 UTC (permalink / raw)
  To: Org Mode Mailing List

[-- Attachment #1: Type: text/plain, Size: 2755 bytes --]

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:05 PM
Subject: Re: [O] How to identify all headings that won't be exported?
To: "Thomas S. Dye" <tsd@tsdye.com>
Cc:

Hello Thomas


On 26 June 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 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
>
>

[-- Attachment #2: Type: text/html, Size: 3941 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-06-27  0:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-26 19:09 How to identify all headings that won't be exported? Thomas S. Dye
2014-06-27  0:40 ` Thomas S. Dye
     [not found] ` <CAEWDx5f+MgsCFFw9h9hoPT_HcKstt4WG6s+FZKRzEEH3G1So_A@mail.gmail.com>
2014-06-27  0:59   ` Fwd: " Jonathan Leech-Pepin

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).