Sure thing :) Here it is:

(defun ~/filter-begin-only (type)
  "Remove BEGIN_ONLY %s blocks whose %s doesn't equal TYPE.
For those that match, only remove the delimiters."
  (goto-char (point-min))
  (while (re-search-forward " *#\\+BEGIN_ONLY \\([a-z]+\\)\n" nil t)
    (let ((begin-block-type (match-string-no-properties 1))
          (begin-from (match-beginning 0))
          (begin-to (match-end 0)))
      (re-search-forward " *#\\+END_ONLY \\([a-z]+\\)\n")
      (let ((end-block-type (match-string-no-properties 1))
            (end-from (match-beginning 0))
            (end-to (match-end 0)))
        (cl-assert (string= begin-block-type end-block-type))
        (cond
         ((string= type begin-block-type)
          (delete-region end-from end-to)
          (delete-region begin-from begin-to))
         (t
          (message "Removing %s block" begin-block-type)
          (delete-region begin-from end-to)))))))

I call this before calling `org-latex-export-to-latex'.  The syntax it accepts 
is a bit weird:

#+BEGIN_ONLY tex
…
#+END_ONLY tex

Please share improvements :)

Cheers,
Clément.

On 2016-09-12 23:10, Kaushal Modi wrote:
> I am looking forward to the BEGIN_ONLY/END_ONLY kind of solution too.
> 
> @Clément Would you please share your draft solution?
> 
> Thanks.
> 
> On Tue, Sep 6, 2016 at 5:39 PM Nicolas Goaziou <m...@nicolasgoaziou.fr 
> <mailto:m...@nicolasgoaziou.fr>> wrote:
> 
>     Hello,
> 
>     Clément Pit--Claudel <clement....@gmail.com 
> <mailto:clement....@gmail.com>> writes:
> 
>     > Do you think so? Wouldn't BEGIN_ONLY … END_ONLY work? It would be 
> similar to BEGIN_EXPORT, right?
>     > Or it could even be an option to begin_export?
> 
> -- 
> 
> Kaushal Modi
> 

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to