From: Kaushal Modi <kaushal.modi@gmail.com>
To: "Clément Pit--Claudel" <clement.pit@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Restrict include to some backend
Date: Wed, 14 Sep 2016 12:33:25 +0000 [thread overview]
Message-ID: <CAFyQvY1aw9b6LJO7XJ4=H5pW576101OOms1Fvn=vm_-nJuHUyg@mail.gmail.com> (raw)
In-Reply-To: <b4262280-45cd-8738-0f67-eadcf0a19230@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2536 bytes --]
On Wed, Sep 14, 2016 at 8:21 AM Clément Pit--Claudel <clement.pit@gmail.com>
wrote:
>
> Back when I wrote this I was starting out with Org-mode, I was in a hurry,
> and I didn't know about org-export-before-processing-hook :) So instead I
> had a larger ELisp script that opened the file, ran this filter, then
> called org-latex-export-to-latex :)
>
:)
> Looks good. Maybe using the same syntax for both would be good though;
> something like "BEGIN_ONLY tex" and "BEGIN_ONLY :not tex" maybe?
>
Thanks. I was exactly my earlier syntax idea but I scrapped it!
> We could probably get rid of the "tex" part after the END_ONLY, and change
> "tex" to "latex" for consistency with BEGIN_EXPORT :)
I thought of removing that too. But then thought of keeping it in case we
want to support nesting of these blocks.. I haven't yet needed to have
anything like this, but below is a rough idea.
#+BEGIN_EXCEPT tex
something
#+BEGIN_EXCEPT html
else
#+END_EXCEPT html
#+END_EXCEPT tex
I haven't tested this, but based on the code, nesting anyways doesn't work
as of now I believe.
Below is a modification of your code.
(defun cpit/filter-begin-only (type)
"Remove BEGIN_ONLY %s blocks whose %s doesn't equal TYPE.
For those that match, only remove the delimiters.
On the flip side, for BEGIN_EXCEPT %s blocks, remove those if %s equals
TYPE. "
(goto-char (point-min))
(while (re-search-forward " *#\\+BEGIN_\\(ONLY\\|EXCEPT\\)
+\\([a-z]+\\)\n" nil t)
(let ((only-or-export (match-string-no-properties 1))
(block-type (match-string-no-properties 2))
(begin-from (match-beginning 0))
(begin-to (match-end 0)))
(re-search-forward (format " *#\\+END_%s +%s\n" only-or-export
block-type))
(let ((end-from (match-beginning 0))
(end-to (match-end 0)))
(if (or (and (string= "ONLY" only-or-export)
(string= type block-type))
(and (string= "EXCEPT" only-or-export)
(not (string= type block-type))))
(progn ; Keep the block,
; delete just the comment markers
(delete-region end-from end-to)
(delete-region begin-from begin-to))
;; Delete the block
(message "Removing %s block" block-type)
(delete-region begin-from end-to))))))
(add-hook 'org-export-before-process #'cpit/filter-begin-only)
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 3851 bytes --]
next prev parent reply other threads:[~2016-09-14 12:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-06 5:13 Restrict include to some backend Fabrice Popineau
2016-09-06 13:59 ` Clément Pit--Claudel
2016-09-06 14:59 ` Clément Pit--Claudel
2016-09-06 15:58 ` Nicolas Goaziou
2016-09-06 18:15 ` Clément Pit--Claudel
2016-09-06 20:32 ` Nicolas Goaziou
2016-09-13 3:10 ` Kaushal Modi
2016-09-13 3:14 ` Clément Pit--Claudel
2016-09-14 11:55 ` Kaushal Modi
2016-09-14 12:21 ` Clément Pit--Claudel
2016-09-14 12:33 ` Kaushal Modi [this message]
2016-09-06 20:10 ` Fabrice Popineau
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='CAFyQvY1aw9b6LJO7XJ4=H5pW576101OOms1Fvn=vm_-nJuHUyg@mail.gmail.com' \
--to=kaushal.modi@gmail.com \
--cc=clement.pit@gmail.com \
--cc=emacs-orgmode@gnu.org \
/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).