emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Mark Edgington <edgimar@gmail.com>
To: Bastien <bzg@gnu.org>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>,
	Eric Schulte <schulte.eric@gmail.com>,
	Nicolas Goaziou <mail@nicolasgoaziou.fr>,
	Nicolas Girard <girard.nicolas@gmail.com>
Subject: Re: proposal to have ignoreheading tags/properties
Date: Sat, 2 Aug 2014 01:16:15 -0400	[thread overview]
Message-ID: <CAMsBe8pQEUR01_19euQYqcDbLOu+T8pMFMFV3U+gfJEjqb5iHw@mail.gmail.com> (raw)
In-Reply-To: <87wqawb5ig.fsf@bzg.ath.cx>

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

Hi Bastien,

I've attached a patch for ox-extra which doesn't yet include the
option for choosing specific tag names (the 'ignore' tag is currently
hard-coded).  Feel free to modify / commit it.

Regards,

Mark


On Tue, Jul 29, 2014 at 10:31 AM, Bastien <bzg@gnu.org> wrote:
> Hi Nicolas,
>
> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
>> Filters are _not_ meant to be in core since they are hardly a generic
>> solution for a class of problem. They are entry points for user-level
>> hacking. Generic patches should operate at the parse tree level, not
>> using regexps.
>>
>> Eric's filter, like any other filter, has flaws that cannot be fixed.
>> Useful filters ought to be published in Worg, not included in core.
>
> Fair enough.
>
> Still, can someone add Eric's solution to contrib/lisp/ox-extra.el?
>
> Thanks,
>
> --
>  Bastien

[-- Attachment #2: 0001-ox-extra.el-add-ignore-headlines-filter.patch --]
[-- Type: text/x-patch, Size: 4541 bytes --]

From 7b60eefcb21c2a62b1ab7f248f6a0b993d89cc4d Mon Sep 17 00:00:00 2001
From: Mark Edgington <edgimar@gmail.com>
Date: Sat, 2 Aug 2014 00:32:29 -0400
Subject: [PATCH] * ox-extra.el: add ignore-headlines filter

---
 contrib/lisp/ox-extra.el | 82 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 81 insertions(+), 1 deletion(-)

diff --git a/contrib/lisp/ox-extra.el b/contrib/lisp/ox-extra.el
index f4f0b76..01368cb 100644
--- a/contrib/lisp/ox-extra.el
+++ b/contrib/lisp/ox-extra.el
@@ -23,6 +23,12 @@
 ;; are not part of org's core.  Call `ox-extras-activate' passing a
 ;; list of symbols naming extras, which will be installed globally in
 ;; your org session.
+;;
+;; For example, you could include the following in your .emacs file:
+;;
+;;    (require 'ox-extra)
+;;    (ox-extras-activate '(latex-header-blocks ignore-headlines))
+;;
 
 ;; Currently available extras:
 
@@ -35,6 +41,12 @@
 ;;   ...
 ;; #+end_latex
 
+;; - `ignore-headlines' -- allow a headline (but not its children) to
+;; be ignored.  Any headline tagged with the 'ignore' tag will be
+;; ignored (i.e. will not be included in the export), but any child
+;; headlines will not be ignored (unless explicitly tagged to be
+;; ignored), and will instead have their levels promoted by one.
+
 ;; TODO:
 ;; - add a function to org-mode-hook that looks for a ox-extras local
 ;;   variable and activates the specified extras buffer-locally
@@ -75,8 +87,76 @@
 	    ;; earlier in the file
 	    (reverse positions)))))
 
+
+;; During export headlines which have the "ignore" tag are removed
+;; from the parse tree.  Their contents are retained (leading to a
+;; possibly invalid parse tree, which nevertheless appears to function
+;; correctly with most export backends) all children headlines are
+;; retained and are promoted to the level of the ignored parent
+;; headline.
+;;
+;; This makes it possible to add structure to the original Org-mode
+;; document which does not effect the exported version, such as in the
+;; following examples.
+;;
+;; Wrapping an abstract in a headline
+;;
+;;     * Abstract                        :ignore:
+;;     #+LaTeX: \begin{abstract}
+;;     #+HTML: <div id="abstract">
+;;
+;;     ...
+;;
+;;     #+HTML: </div>
+;;     #+LaTeX: \end{abstract}
+;;
+;; Placing References under a headline (using ox-bibtex in contrib)
+;;
+;;     * References                     :ignore:
+;;     #+BIBLIOGRAPHY: dissertation plain
+;;
+;; Inserting an appendix for LaTeX using the appendix package.
+;;
+;;     * Appendix                       :ignore:
+;;     #+LaTeX: \begin{appendices}
+;;     ** Reproduction
+;;     ...
+;;     ** Definitions
+;;     #+LaTeX: \end{appendices}
+;;
+(defun org-export-ignore-headlines (data backend info)
+  "Remove headlines tagged \"ignore\" retaining contents and promoting children.
+Each headline tagged \"ignore\" will be removed retaining its
+contents and promoting any children headlines to the level of the
+parent."
+  (org-element-map data 'headline
+    (lambda (object)
+      (when (member "ignore" (org-element-property :tags object))
+        (let ((level-top (org-element-property :level object))
+              level-diff)
+          (mapc (lambda (el)
+                  ;; recursively promote all nested headlines
+                  (org-element-map el 'headline
+                    (lambda (el)
+                      (when (equal 'headline (org-element-type el))
+                        (unless level-diff
+                          (setq level-diff (- (org-element-property :level el)
+                                              level-top)))
+                        (org-element-put-property el
+                          :level (- (org-element-property :level el)
+                                    level-diff)))))
+                  ;; insert back into parse tree
+                  (org-element-insert-before el object))
+                (org-element-contents object)))
+        (org-element-extract-element object)))
+    info nil)
+  data)
+
+;(add-hook 'org-export-filter-parse-tree-functions 'org-export-ignore-headlines)
+
 (defconst ox-extras
-  '((latex-header-blocks org-latex-header-blocks-filter org-export-before-parsing-hook))
+  '((latex-header-blocks org-latex-header-blocks-filter org-export-before-parsing-hook)
+    (ignore-headlines org-export-ignore-headlines org-export-filter-parse-tree-functions))
   "A list of org export extras that can be enabled.
 
 Should be a list of items of the form (NAME FN HOOK).  NAME is a
-- 
1.9.2


  reply	other threads:[~2014-08-02  5:17 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-12 16:49 proposal to have ignoreheading tags/properties Mark Edgington
2014-06-12 17:32 ` Thorsten Jolitz
2014-06-12 17:41   ` Ken Mankoff
2014-06-12 18:11     ` Thorsten Jolitz
2014-06-12 18:16       ` Ken Mankoff
2014-06-13 14:32       ` Rasmus
2014-06-13 15:02         ` Thorsten Jolitz
2014-06-12 18:09   ` Mark Edgington
2014-06-12 18:12 ` Eric Schulte
2014-06-12 18:54   ` Aaron Ecay
2014-06-12 19:21     ` Nicolas Girard
2014-06-12 19:26       ` Ken Mankoff
2014-06-12 19:52         ` Nicolas Girard
2014-06-13  1:20         ` Samuel Wales
2014-06-12 19:34       ` Nicolas Girard
2014-06-12 20:13       ` Eric Schulte
2014-06-12 22:42         ` Nicolas Girard
2014-06-12 23:36           ` Eric Schulte
2014-06-13  0:35         ` Ken Mankoff
2014-06-13  0:46           ` Eric Schulte
2014-06-13  2:35             ` Ken Mankoff
2014-06-13 11:11               ` Eric Schulte
2014-06-13  3:28             ` Mark Edgington
2014-06-13 14:23         ` Rasmus
2014-06-14 12:43         ` Nicolas Goaziou
2014-06-14 16:48           ` Mark Edgington
2014-06-14 18:12             ` Aaron Ecay
2014-06-14 18:12             ` Nicolas Goaziou
2014-06-14 18:07           ` Aaron Ecay
2014-06-14 18:22             ` Nicolas Goaziou
2014-06-14 22:39               ` Aaron Ecay
2014-06-16  1:14           ` Eric Schulte
2014-06-16  8:08             ` Nicolas Goaziou
2014-06-16 12:19               ` Mark Edgington
2014-06-16 13:29               ` Eric Schulte
2014-06-22  2:03                 ` Aaron Ecay
2014-06-22 23:52                   ` Eric Schulte
2014-07-27 17:21                     ` Bastien
2014-07-28 18:15                       ` Mark Edgington
2014-07-28 18:27                       ` Rasmus
2014-07-28 19:21                         ` Mark Edgington
2014-07-28 19:43                       ` Nicolas Goaziou
2014-07-28 22:01                         ` Rasmus
2014-07-29 14:31                         ` Bastien
2014-08-02  5:16                           ` Mark Edgington [this message]
2014-08-06  4:09                             ` Aaron Ecay
2014-06-13  2:38 ` Eric Abrahamsen
2014-06-13  4:07   ` Mark Edgington
2014-06-13  4:44     ` Eric Abrahamsen

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  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=CAMsBe8pQEUR01_19euQYqcDbLOu+T8pMFMFV3U+gfJEjqb5iHw@mail.gmail.com \
    --to=edgimar@gmail.com \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=girard.nicolas@gmail.com \
    --cc=mail@nicolasgoaziou.fr \
    --cc=schulte.eric@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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

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