From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [PATCH]Extend export hook example for removing headlines with tag ignore_heading Date: Mon, 13 Apr 2015 21:42:58 +0200 Message-ID: <87vbgzx1a5.fsf@nicolasgoaziou.fr> References: <87twwkj9gt.fsf@gmx.us> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41017) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YhkEq-0003tQ-GS for emacs-orgmode@gnu.org; Mon, 13 Apr 2015 15:41:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YhkEp-0005BN-Ij for emacs-orgmode@gnu.org; Mon, 13 Apr 2015 15:41:44 -0400 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:36751) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YhkEp-0005B4-Ak for emacs-orgmode@gnu.org; Mon, 13 Apr 2015 15:41:43 -0400 In-Reply-To: (=?utf-8?Q?=22Ond=C5=99ej?= Grover"'s message of "Mon, 13 Apr 2015 20:13:38 +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: =?utf-8?Q?Ond=C5=99ej?= Grover Cc: emacs-orgmode@gnu.org Hello, Ond=C5=99ej Grover writes: Thanks for the patch. Some comments follow. >> "export" becomes part of the noexport heading. >> >> * h0 >> ** h1 :noexport: >> no export >> ** h2 :ignore_heading: >> export >> > I have no idea how to get around this. It stems from the basic problem in > Org mode that there are no entry closures AFAIK: To export the "export" it > would have to be under a heading that does not have the :noexport: > tag. This is why it shouldn't be included in "ox.el". It may be useful, but it is broken. It might be fixable with proper specifications and by working at the parse tree level, tho. > +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 ^^^^ missing space > +@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: >=20=20 > @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 buff= er > +and promote all child headlines underneath them. > BACKEND is the export back-end being used, as a symbol." First sentence in docstrings should fit in a single line. > (org-map-entries > - (lambda () (delete-region (point) (progn (forward-line) (point)))))) > + (lambda () (progn (org-map-tree (lambda () (when (> (outline-level) 1) > + (org-promote)))) > + (delete-region (point) (point-at-eol)))) Nitpick : `point-at-eol' -> `line-end-position' > + "+ignore_heading-noexport")) >=20=20 > -(add-hook 'org-export-before-parsing-hook 'my-headline-removal) > +(add-hook 'org-export-before-parsing-hook 'ignored-headlines-removal) > @end group > @end lisp >=20=20 > -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. This is really out of the example scope. Also, `org-map-entries' is already extensively documented in the manual. > It may also be useful to exclude +the @samp{ignore_heading} tag from > inheritance (@pxref{Tag +inheritance}). Also off-topic. Please keep in mind this is an example to illustrate `org-export-before-parsing-hook', not really a place to document some hack. Regards, --=20 Nicolas Goaziou