From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Tweaking the export Date: Fri, 17 Feb 2012 21:06:59 +0100 Message-ID: <87ty2p8brw.fsf@gmail.com> References: <87pqec4xua.fsf@gmail.com> <87obtvk6j0.fsf@gmail.com> <87obtrel2z.fsf@gmail.com> <4F20F779.2060803@gmail.com> <877h0ds39y.fsf@gmail.com> <8162fxjm02.fsf@gmail.com> <4F235BC2.2080903@gmail.com> <87wr8akhc5.fsf@gmail.com> <4F2CCE67.2020304@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:39481) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RyU6u-0004Gc-Cu for emacs-orgmode@gnu.org; Fri, 17 Feb 2012 15:08:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RyU6t-0008E1-19 for emacs-orgmode@gnu.org; Fri, 17 Feb 2012 15:08:52 -0500 Received: from mail-wi0-f169.google.com ([209.85.212.169]:48070) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RyU6s-0008CK-NA for emacs-orgmode@gnu.org; Fri, 17 Feb 2012 15:08:50 -0500 Received: by wibhj13 with SMTP id hj13so2386398wib.0 for ; Fri, 17 Feb 2012 12:08:50 -0800 (PST) In-Reply-To: <4F2CCE67.2020304@gmail.com> (Christian Wittern's message of "Sat, 04 Feb 2012 15:21:27 +0900") 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: Christian Wittern Cc: emacs-orgmode@gnu.org Hello, Christian Wittern 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 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