emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Ondřej Grover" <ondrej.grover@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH]Extend export hook example for removing headlines with tag ignore_heading
Date: Mon, 13 Apr 2015 17:23:33 +0200	[thread overview]
Message-ID: <CAOyjJOJOM9=khtBCoXwy2DCs2SSQR4u0vYP8p325s1n78i4uPQ@mail.gmail.com> (raw)

[-- Attachment #1.1: Type: text/plain, Size: 1393 bytes --]

Hi Rasmus,

I wasn't aware of this functionality being added to ox-extra, thank you for
pointing it out.
I've revised my patch to accommodate your suggestions and attached the new
version. Now it excludes noexport tagged headlines from removal and
promotes child headlines.
Using properties for this is also possible because the match string can
match properties too. I just find tags simpler for this case.
I'm trying to point out that something like this is often needed and a
definitive solution should be listed somewhere, preferably in the manual.
Otherwise someone looking for a solution to this common problem will end up
finding only half-baked, possibly broken examples.

Kind regards,
Ondřej Grover

On Sun, Apr 12, 2015 at 3:32 PM, Rasmus <rasmus@gmx.us> wrote:

> Hi,
> Thanks for the patch. I have not read it as I'm on the mobile.
> What is the difference between your patch and org-export-ignore-headlines
> in
> ox-extra?
> If you want the functionality in ox.el you should write a solution that
> uses
> a property like UNNUMBERED. It's however a non-trivial problem as discussed
> on the org-hacks worg page. This is, IMO, the right way to tackle this
> issue, if it is an issue.
> Skimming the so answer you link to your suggestion is not robust for
> ignored
> headlines following a no export headline.
> Rasmus

[-- Attachment #1.2: Type: text/html, Size: 1946 bytes --]

[-- Attachment #2: 0001-org.texi-Extend-export-hook-example-with-ignore_head.patch --]
[-- Type: text/x-diff, Size: 3620 bytes --]

From 9c75f9796a0fe4d270b72b503b318ddb6e4e3954 Mon Sep 17 00:00:00 2001
From: Ondrej Grover <ondrej.grover@gmail.com>
Date: Sun, 12 Apr 2015 13:43:31 +0200
Subject: [PATCH] org.texi: Extend export hook example with ignore_heading tag

* doc/org.texi (Advanced configuration): Extend the pre-processing
export hook example to support similar (but simpler and more general)
functionality like that provided by the ignoreheading tag in the
Beamer export backend.  This is a commonly requested snippet and the
Internet is full of much worse and broken solutions, so the manual
should show the recommended solution.

 doc/org.texi | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index c400f77..cc75a79 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -13806,29 +13806,40 @@ with @code{M-x org-html-convert-region-to-html RET}.
 @vindex org-export-before-processing-hook
 @vindex org-export-before-parsing-hook
-Two hooks are run during the first steps of the export process.  The first
-one, @code{org-export-before-processing-hook} is called before expanding
-macros, Babel code and include keywords in the buffer.  The second one,
-@code{org-export-before-parsing-hook}, as its name suggests, happens just
-before parsing the buffer.  Their main use is for heavy duties, that is
-duties involving structural modifications of the document.  For example, one
-may want to remove every headline in the buffer during export.  The following
+Two hooks are run during the first steps of the export process.  The
+first one, @code{org-export-before-processing-hook} is called before
+expanding macros, Babel code and include keywords in the buffer.  The
+second one, @code{org-export-before-parsing-hook}, as its name suggests,
+happens just before parsing the buffer.  Their main use is for heavy
+duties, that is duties involving structural modifications of the
+document. For example, one may want to remove every headline with the
+@samp{ignore_heading} tag (excluding those with the @samp{noexport} tag)
+in the buffer and promote their children during export.  The following
 code can achieve this:
-(defun my-headline-removal (backend)
-  "Remove all headlines in the current buffer.
+(defun ignored-headlines-removal (backend)
+  "Remove all headlines with the ignore_headline tag in the current buffer
+and promote all child headlines underneath them.
 BACKEND is the export back-end being used, as a symbol."
-   (lambda () (delete-region (point) (progn (forward-line) (point))))))
+   (lambda () (progn (org-map-tree 'org-promote)
+		     (delete-region (point) (point-at-eol))))
+   "+ignore_heading-noexport"))
-(add-hook 'org-export-before-parsing-hook 'my-headline-removal)
+(add-hook 'org-export-before-parsing-hook 'ignored-headlines-removal)
 @end group
 @end lisp
-Note that functions used in these hooks require a mandatory argument,
-a symbol representing the back-end used.
+The second argument to the @code{org-map-entries} function is an
+agenda-style match query string (@pxref{Matching tags and properties}).
+Note the underscore in the tag, it is not recommended to use the
+@samp{ignoreheading} tag because the Beamer export backend treates it in
+a similar, yet more complicated way.  It may also be useful to exclude
+the @samp{ignore_heading} tag from inheritance (@pxref{Tag
+inheritance}).  Also note that functions used in these hooks require a
+mandatory argument, a symbol representing the back-end used.
 @subheading Filters

             reply	other threads:[~2015-04-13 15:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-13 15:23 Ondřej Grover [this message]
2015-04-13 16:09 ` [PATCH]Extend export hook example for removing headlines with tag ignore_heading Rasmus
2015-04-13 18:13   ` Ondřej Grover
2015-04-13 19:42     ` Nicolas Goaziou
2015-04-13 22:40       ` Suvayu Ali
2015-04-13 19:59     ` Rasmus
  -- strict thread matches above, loose matches on Subject: below --
2015-04-12 11:59 Ondřej Grover

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOyjJOJOM9=khtBCoXwy2DCs2SSQR4u0vYP8p325s1n78i4uPQ@mail.gmail.com' \
    --to=ondrej.grover@gmail.com \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


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