emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Tweaking the export


From: Nicolas Goaziou
Subject: Re: [O] Tweaking the export
Date: Fri, 17 Feb 2012 21:06:59 +0100

Hello,

Christian Wittern <address@hidden> writes:

>>    3. If all went well, you now have an impressive Org to Org converter.
>>       You can even test it with:
>>
>>       #+begin_src emacs-lisp
>>       (switch-to-buffer (org-export-to-buffer 'translator "*Translation*"))
>>       #+end_src
>>
>>       Obviously, there is not much to see.

> It worked wonderful until here.

>> Now, we're going to redefine `org-translator-paragraph' to properly
>> ignore one language or the other, depending on `:translator-side' value.
>>
>> #+begin_src emacs-lisp
>> (defun org-translator-paragraph (paragraph contents info)
>>    "Convert PARAGRAPH to Org, ignoring one language.
>> Language kept is determined by `:translator-side' value."
>>    (let ((leftp (eq (plist-get info :translator-side) 'left)))
>>      (replace-regexp-in-string
>>       (if leftp "\t+.*$" "^.*\t+") "" contents)))
>> #+end_src
>
> With a little tweaking, I got rid of errors when running this code.
> However, no changes in the output where observable.  Finally, I looked
> at the output from step 3 above and realized that the parser
> normalizes my <tab> characters away.  Only a bunch of spaces in the
> output!  Ouch!!
> So I guess I would need an option on the parser to switch tab expansion off.
>
> I also intended to implement my transformer in a way that I first
> define the general org-e-org transformer and then derive a specialized
> transcormer by somehow inheriting the general transformer and then
> implement my specialized paragraph transformation.   It seems that
> this is at the moment not possible, but I think it would be good to
> think about this, that will make defining new exporters or even
> org-file tweakers a breeze.

In fact the problem is subtle.  For example, you don't want include
keywords to be expanded and babel block to be executed when exporting
from Org to Org.  I've added a noexpand keyword for that.  Hence, you
will need to call your converter with:

#+begin_src emacs-lisp
(switch-to-buffer (org-export-to-buffer 'translator "*Translation*" nil nil nil 
nil 'noexpand))
#+end_src

The TAB problem is different.  I expand tab early because the machine
creating the parse-tree and the machine exporting it may not be the
same.  Tab widths may differ, and it could lead to subtle bugs.  I may
add a :tab-width property in the initial environment.  I'm not sure
about it yet.

Anyway, your tabs have been replaced with spaces, for now. `tab-width'
of them.  Your paragraph translator may then become something like:

#+begin_src emacs-lisp
(defun org-translator-paragraph (paragraph contents info)
   "Convert PARAGRAPH to Org, ignoring one language.
Language kept is determined by `:translator-side' value."
   (let ((leftp (eq (plist-get info :translator-side) 'left)))
     (replace-regexp-in-string
      (format (if leftp " \\{%d,\\}.*$" "^.* \\{%d,\\}") tab-width) "" 
contents)))
#+end_src

Is it better?


Regards,

-- 
Nicolas Goaziou



reply via email to

[Prev in Thread] Current Thread [Next in Thread]