From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: [PATCH]Extend export hook example for removing headlines with tag ignore_heading Date: Mon, 13 Apr 2015 18:09:54 +0200 Message-ID: <87twwkj9gt.fsf@gmx.us> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YhgwA-0002sw-Vv for emacs-orgmode@gnu.org; Mon, 13 Apr 2015 12:10:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yhgw1-00015U-Qk for emacs-orgmode@gnu.org; Mon, 13 Apr 2015 12:10:14 -0400 Received: from plane.gmane.org ([80.91.229.3]:33349) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yhgw1-00010K-H2 for emacs-orgmode@gnu.org; Mon, 13 Apr 2015 12:10:05 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Yhgvx-000410-T4 for emacs-orgmode@gnu.org; Mon, 13 Apr 2015 18:10:02 +0200 Received: from ip-pool-137.iue.it ([192.167.90.137]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 13 Apr 2015 18:10:01 +0200 Received: from rasmus by ip-pool-137.iue.it with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 13 Apr 2015 18:10:01 +0200 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: emacs-orgmode@gnu.org Hi Ondřej, Ondřej Grover writes: > 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. Thanks. Your snippet doesn't work on these two examples. Can't promote from level 1: * h1 :noexport: no export * h2 :ignore_heading: export "export" becomes part of the noexport heading. * h0 ** h1 :noexport: no export ** h2 :ignore_heading: export > 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. If this is often needed feature, ox.el and potentially backends should be patched to support it. I think it would be great if ox did support it. Of course, Nicolas would have the final say in such a matter. But I'm not sure so difficult hacks should be promoted in the manual. Improving the example is fine, though. > From 9c75f9796a0fe4d270b72b503b318ddb6e4e3954 Mon Sep 17 00:00:00 2001 > From: Ondrej Grover > Date: Sun, 12 Apr 2015 13:43:31 +0200 > Subject: [PATCH] org.texi: Extend export hook example with ignore_heading tag > support > * 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. > TINYCHANGE > --- > 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 Why do you delete these indexes? > -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 , (I think) > +expanding macros, Babel code and include keywords in the buffer. The > +second one, @code{org-export-before-parsing-hook}, as its name suggests, ^^^^^^^^^^^^^^^^^^^^^^^ I'd just kill that one. > +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: > > @lisp > @group > -(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." > (org-map-entries > - (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 Maybe: The second argument to @code{org-map-entries} 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. ^^^^^^^^^ This function is fine as well: (λ (&optional ignored) (· ⋯)). It's great with better documentation for how to use org-map-entries! But the example is not very robust. I think another, less complicated example would be better. Also, perhaps it would make sense to also show how to use org-element-map to solve the same problem. Of course that's a separate patch. Thanks, Rasmus -- I hear there's rumors on the, uh, Internets. . .