emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* New exporter macro question
@ 2013-02-11 12:48 Carsten Dominik
  2013-02-11 13:45 ` Carsten Dominik
  2013-02-11 21:37 ` Nicolas Goaziou
  0 siblings, 2 replies; 6+ messages in thread
From: Carsten Dominik @ 2013-02-11 12:48 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org List


Hi,

I am porting my websites to the new exporter, finally.  Much is very smooth.  I do have a problem with macros:


* Macro definition


   #+MACRO: thumbright #+ATTR_HTML: style="float:right;width:$1;margin:0px 20px 0px 20px;"  \n     [[./Content/$2/thumb.jpg]]



* Macro call

   {{{thumbright(300px,Wiskunde)}}}




* This used to expand to

   <img src="./Content/Wiskunde/thumb.jpg" style="float:right;width:300px;margin:0px 20px 0px 20px;" alt="./Content/Wiskunde/thumb.jpg" />


* But now it expands to nothing
  I am sure I am missing something basic.  Thanks!

- Carsten

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: New exporter macro question
  2013-02-11 12:48 New exporter macro question Carsten Dominik
@ 2013-02-11 13:45 ` Carsten Dominik
  2013-02-11 14:43   ` Nick Dokos
  2013-02-11 21:37 ` Nicolas Goaziou
  1 sibling, 1 reply; 6+ messages in thread
From: Carsten Dominik @ 2013-02-11 13:45 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org List


On 11 feb. 2013, at 13:48, Carsten Dominik <carsten.dominik@gmail.com> wrote:

> 
> Hi,
> 
> I am porting my websites to the new exporter, finally.  Much is very smooth.  I do have a problem with macros:
> 
> 
> * Macro definition
> 
> 
>   #+MACRO: thumbright #+ATTR_HTML: style="float:right;width:$1;margin:0px 20px 0px 20px;"  \n     [[./Content/$2/thumb.jpg]]
> 
> 
> 
> * Macro call
> 
>   {{{thumbright(300px,Wiskunde)}}}
> 
> 
> 
> 
> * This used to expand to
> 
>   <img src="./Content/Wiskunde/thumb.jpg" style="float:right;width:300px;margin:0px 20px 0px 20px;" alt="./Content/Wiskunde/thumb.jpg" />
> 
> 
> * But now it expands to nothing
>  I am sure I am missing something basic.  Thanks!

OK, I see, this seems to be because the "\n" is no longer interpreted as a newline character upon macro expansion, so the entire text ends up in the ATTR_HTML line and is treated as a comment.

Is there a way to get what I meant?

Thanks

- Carsten

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: New exporter macro question
  2013-02-11 13:45 ` Carsten Dominik
@ 2013-02-11 14:43   ` Nick Dokos
  2013-02-11 16:31     ` Nick Dokos
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Dokos @ 2013-02-11 14:43 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode@gnu.org List

Carsten Dominik <carsten.dominik@gmail.com> wrote:

> 
> On 11 feb. 2013, at 13:48, Carsten Dominik <carsten.dominik@gmail.com> wrote:
> 
> > 
> > Hi,
> > 
> > I am porting my websites to the new exporter, finally.  Much is very smooth.  I do have a problem with macros:
> > 
> > 
> > * Macro definition
> > 
> > 
> >   #+MACRO: thumbright #+ATTR_HTML: style="float:right;width:$1;margin:0px 20px 0px 20px;"  \n     [[./Content/$2/thumb.jpg]]
> > 
> > 
> > 
> > * Macro call
> > 
> >   {{{thumbright(300px,Wiskunde)}}}
> > 
> > 
> > 
> > 
> > * This used to expand to
> > 
> >   <img src="./Content/Wiskunde/thumb.jpg" style="float:right;width:300px;margin:0px 20px 0px 20px;" alt="./Content/Wiskunde/thumb.jpg" />
> > 
> > 
> > * But now it expands to nothing
> >  I am sure I am missing something basic.  Thanks!
> 
> OK, I see, this seems to be because the "\n" is no longer interpreted as a newline character upon macro expansion, so the entire text ends up in the ATTR_HTML line and is treated as a comment.
> 
> Is there a way to get what I meant?
> 

It seems to be coming from deep with emacs: if I create a buffer
with

x y z \ x y z

and evaluate (with point somewhere on that line)

  (buffer-substring-no-properties (point-at-bol) (point-at-eol))

I get "x y z \\ x y z", so the backslash is escaped willy-nilly.

This happens in org-element-keyword-parser. I don't know if the
macro expansion would replace \n with a newline absent the extra
backslash, but I'm sure that its presence does not help any.

Nick

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: New exporter macro question
  2013-02-11 14:43   ` Nick Dokos
@ 2013-02-11 16:31     ` Nick Dokos
  0 siblings, 0 replies; 6+ messages in thread
From: Nick Dokos @ 2013-02-11 16:31 UTC (permalink / raw)
  Cc: emacs-orgmode@gnu.org List, Carsten Dominik

Nick Dokos <nicholas.dokos@hp.com> wrote:

> Carsten Dominik <carsten.dominik@gmail.com> wrote:
> 

> > OK, I see, this seems to be because the "\n" is no longer
> > interpreted as a newline character upon macro expansion, so the
> > entire text ends up in the ATTR_HTML line and is treated as a
> > comment.

> 
> It seems to be coming from deep with emacs: if I create a buffer
> with
> 
> x y z \ x y z
> 
> and evaluate (with point somewhere on that line)
> 
>   (buffer-substring-no-properties (point-at-bol) (point-at-eol))
> 
> I get "x y z \\ x y z", so the backslash is escaped willy-nilly.
> 
> This happens in org-element-keyword-parser. I don't know if the
> macro expansion would replace \n with a newline absent the extra
> backslash, but I'm sure that its presence does not help any.
> 

Even if I delete the extra backslash from the value of the macro
in org-macro-initialize-templates, the regexp fails to properly
match:

,----
|     ;; Install buffer-local macros.
|     (org-with-wide-buffer
|      (goto-char (point-min))
|      (while (re-search-forward "^[ \t]*#\\+MACRO:" nil t)
|        (let ((element (org-element-at-point)))
| 	 (when (eq (org-element-type element) 'keyword)
| 	   (let ((value (org-element-property :value element)))
| 	     (when (string-match "^\\(.*?\\)\\(?:\\s-+\\(.*\\)\\)?\\s-*$" value)
| 	       (funcall set-template
| 			(cons (match-string 1 value)
| 			      (or (match-string 2 value) "")))))))))
`----

OTOH, if I modify the cell argument inside set-template[fn:1] to get rid of
the extra backslash, the macro expansion happened as expected.

Nick

Footnotes:

[fn:1] This is obviously a gross hack, only meant as a debugging aid.
       In fact, I didn't even code it up: I just stepped through the
       thing with edebug and slammed the modified value into the cell
       argument.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: New exporter macro question
  2013-02-11 12:48 New exporter macro question Carsten Dominik
  2013-02-11 13:45 ` Carsten Dominik
@ 2013-02-11 21:37 ` Nicolas Goaziou
  2013-02-12  6:23   ` Carsten Dominik
  1 sibling, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2013-02-11 21:37 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode@gnu.org List

Hello,

Carsten Dominik <carsten.dominik@gmail.com> writes:

> I am porting my websites to the new exporter, finally.  Much is very smooth.  I do have a problem with macros:
>
>
> * Macro definition
>
>
>    #+MACRO: thumbright #+ATTR_HTML: style="float:right;width:$1;margin:0px 20px 0px 20px;"  \n     [[./Content/$2/thumb.jpg]]
>
>
>
> * Macro call
>
>    {{{thumbright(300px,Wiskunde)}}}
>
>
>
>
> * This used to expand to
>
>    <img src="./Content/Wiskunde/thumb.jpg" style="float:right;width:300px;margin:0px 20px 0px 20px;" alt="./Content/Wiskunde/thumb.jpg" />
>
>
> * But now it expands to nothing
>   I am sure I am missing something basic.  Thanks!

Macros have been downgraded a bit, as there was some overlapping with
Babel functionalities. In particular, they are meant to replace objects,
not elements, which means they cannot contain newline characters
anymore.

You can use a Babel block to generate the Org code you want. You can
also try the following macro, which will generate the HTML code you
want:

#+MACRO: thumbright @@html:<img src="./Content/$2/thumb.jpg" style="float:right;width:$1;margin:0px 20px 0px 20px;" alt="./Content/$2/thumb.jpg" />@@


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: New exporter macro question
  2013-02-11 21:37 ` Nicolas Goaziou
@ 2013-02-12  6:23   ` Carsten Dominik
  0 siblings, 0 replies; 6+ messages in thread
From: Carsten Dominik @ 2013-02-12  6:23 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode@gnu.org List

Hello Nicolas,

thanks for your reply.  I now remember this point of downgrading the macros and replacing complex macro calls with babel code.  Thanks also for the easy work-around.

- Carsten

On 11.2.2013, at 22:37, Nicolas Goaziou <n.goaziou@gmail.com> wrote:

> Hello,
> 
> Carsten Dominik <carsten.dominik@gmail.com> writes:
> 
>> I am porting my websites to the new exporter, finally.  Much is very smooth.  I do have a problem with macros:
>> 
>> 
>> * Macro definition
>> 
>> 
>>   #+MACRO: thumbright #+ATTR_HTML: style="float:right;width:$1;margin:0px 20px 0px 20px;"  \n     [[./Content/$2/thumb.jpg]]
>> 
>> 
>> 
>> * Macro call
>> 
>>   {{{thumbright(300px,Wiskunde)}}}
>> 
>> 
>> 
>> 
>> * This used to expand to
>> 
>>   <img src="./Content/Wiskunde/thumb.jpg" style="float:right;width:300px;margin:0px 20px 0px 20px;" alt="./Content/Wiskunde/thumb.jpg" />
>> 
>> 
>> * But now it expands to nothing
>>  I am sure I am missing something basic.  Thanks!
> 
> Macros have been downgraded a bit, as there was some overlapping with
> Babel functionalities. In particular, they are meant to replace objects,
> not elements, which means they cannot contain newline characters
> anymore.
> 
> You can use a Babel block to generate the Org code you want. You can
> also try the following macro, which will generate the HTML code you
> want:
> 
> #+MACRO: thumbright @@html:<img src="./Content/$2/thumb.jpg" style="float:right;width:$1;margin:0px 20px 0px 20px;" alt="./Content/$2/thumb.jpg" />@@
> 
> 
> Regards,
> 
> -- 
> Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-02-12  6:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-11 12:48 New exporter macro question Carsten Dominik
2013-02-11 13:45 ` Carsten Dominik
2013-02-11 14:43   ` Nick Dokos
2013-02-11 16:31     ` Nick Dokos
2013-02-11 21:37 ` Nicolas Goaziou
2013-02-12  6:23   ` Carsten Dominik

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