Org-mode mailing list
 help / color / mirror / Atom feed
* looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
@ 2020-11-21 10:56 Bruno BEAUFILS
  2020-11-21 13:18 ` Tim Cross
  2020-11-23 10:19 ` Eric S Fraga
  0 siblings, 2 replies; 6+ messages in thread
From: Bruno BEAUFILS @ 2020-11-21 10:56 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Bruno BEAUFILS

[-- Attachment #1: Type: text/plain, Size: 1584 bytes --]

I have a *lot* of org files with a macro =if-backend= which enables me
to decide what to export depending on the backend :

#+begin_src org
  #+macro: if-backend (eval (if (org-export-derived-backend-p org-export-current-backend '$1) "$2"))
#+end_src

For instance, I use it to include =\hfill= in LaTeX family export
engines but not in others (html for instance) :

#+begin_src org
  #+macro: hfill {{{if-backend(latex, \\hfill{} )}}}
#+end_src

I generally use emacs 26.3 as distributed by Debian bullseyes (which
offer org-mode version 9.1.9).

On another box I need to work with a more recent org-mode, precisely
9.4.

In that environment, due to an incompatible change introduced by
[[https://orgmode.org/Changes_old.html#outline-container-org003add6][release 9.2]] the same macro has to be written in a different way :

#+begin_src org
  #+macro: if-backend (eval (if (org-export-derived-backend-p org-export-current-backend (intern $1)) $2))
#+end_src

And thus I need to change also the macro using it, for instance the
=hfill= macro has to be written that way :

#+begin_src org
  #+macro: hfill {{{if-backend(latex, \hfill{} )}}}
#+end_src

For now I need to work on the same files in these two different environment.

Do anyone have an idea on how to be able whether to define the
=if-backend= in a way that it can work in both org versions or if
there is a way to define these macro in different ways depending on
org version?

I would like to let the definitions in org files and not in emacs init
files.

-- 
Bruno BEAUFILS

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
  2020-11-21 10:56 looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test Bruno BEAUFILS
@ 2020-11-21 13:18 ` Tim Cross
  2020-11-22 20:49   ` Bruno BEAUFILS
  2020-11-23 10:19 ` Eric S Fraga
  1 sibling, 1 reply; 6+ messages in thread
From: Tim Cross @ 2020-11-21 13:18 UTC (permalink / raw)
  To: emacs-orgmode


Bruno BEAUFILS <bruno@boulgour.com> writes:

> I have a *lot* of org files with a macro =if-backend= which enables me
> to decide what to export depending on the backend :
>
> #+begin_src org
>   #+macro: if-backend (eval (if (org-export-derived-backend-p org-export-current-backend '$1) "$2"))
> #+end_src
>
> For instance, I use it to include =\hfill= in LaTeX family export
> engines but not in others (html for instance) :
>
> #+begin_src org
>   #+macro: hfill {{{if-backend(latex, \\hfill{} )}}}
> #+end_src
>
> I generally use emacs 26.3 as distributed by Debian bullseyes (which
> offer org-mode version 9.1.9).
>
> On another box I need to work with a more recent org-mode, precisely
> 9.4.
>
> In that environment, due to an incompatible change introduced by
> [[https://orgmode.org/Changes_old.html#outline-container-org003add6][release 9.2]] the same macro has to be written in a different way :
>
> #+begin_src org
>   #+macro: if-backend (eval (if (org-export-derived-backend-p org-export-current-backend (intern $1)) $2))
> #+end_src
>
> And thus I need to change also the macro using it, for instance the
> =hfill= macro has to be written that way :
>
> #+begin_src org
>   #+macro: hfill {{{if-backend(latex, \hfill{} )}}}
> #+end_src
>
> For now I need to work on the same files in these two different environment.
>
> Do anyone have an idea on how to be able whether to define the
> =if-backend= in a way that it can work in both org versions or if
> there is a way to define these macro in different ways depending on
> org version?
>
> I would like to let the definitions in org files and not in emacs init
> files.

Hmm, I just use backend specific blocks for this purpose. e.g.

#+begin_export latex
  \hfil{}
#+end_export

Pretty sure 9.1 supports the same (there was a change, which used
#+EXPORT_LATEX instead of #+begin_export, but I think the old version
still works in 9.4, can't remember which version the change was
introduced). So if 9.1 only supports EXPORT_LATEX, you should still be
able to use it under 9.4

IMO the org #+MACRO is really just a text substitution mechanism (like
C), not a 'real' macro (like elisp has) and as is the case with C, you
really need to keep them pretty simple. Once you start using them to
evaluate code, it isn't hard to find yourself in a mine field.

--
Tim Cross


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

* Re: looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
  2020-11-21 13:18 ` Tim Cross
@ 2020-11-22 20:49   ` Bruno BEAUFILS
  0 siblings, 0 replies; 6+ messages in thread
From: Bruno BEAUFILS @ 2020-11-22 20:49 UTC (permalink / raw)
  To: Tim Cross; +Cc: Bruno BEAUFILS, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 743 bytes --]

On Sun, Nov 22, 2020 at 12:18:07AM +1100, Tim Cross wrote:
> Hmm, I just use backend specific blocks for this purpose. e.g.
> 
> #+begin_export latex
>   \hfil{}
> #+end_export

Yes but it is what I try to avoid in order to let the file as simple
and readable as possible.

> IMO the org #+MACRO is really just a text substitution mechanism (like
> C), not a 'real' macro (like elisp has) and as is the case with C, you
> really need to keep them pretty simple. Once you start using them to
> evaluate code, it isn't hard to find yourself in a mine field.

I agree but as the possibility was offered I used it ;-)

The only trouble is that this eval feature changed in a hard way
between 9.1 and 9.2.

-- 
Bruno BEAUFILS

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
  2020-11-21 10:56 looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test Bruno BEAUFILS
  2020-11-21 13:18 ` Tim Cross
@ 2020-11-23 10:19 ` Eric S Fraga
  2020-11-23 13:02   ` Bruno BEAUFILS
  1 sibling, 1 reply; 6+ messages in thread
From: Eric S Fraga @ 2020-11-23 10:19 UTC (permalink / raw)
  To: Bruno BEAUFILS; +Cc: emacs-orgmode

Maybe define your macro like this:

#+macro: hfill @@latex:\hfill@@

HTH,
eric

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.4-118-g2a4578.dirty


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

* Re: looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
  2020-11-23 10:19 ` Eric S Fraga
@ 2020-11-23 13:02   ` Bruno BEAUFILS
  2020-11-23 13:12     ` Eric S Fraga
  0 siblings, 1 reply; 6+ messages in thread
From: Bruno BEAUFILS @ 2020-11-23 13:02 UTC (permalink / raw)
  To: Bruno BEAUFILS, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 259 bytes --]

On Mon, Nov 23, 2020 at 10:19:16AM +0000, Eric S Fraga wrote:
> Maybe define your macro like this:
> 
> #+macro: hfill @@latex:\hfill@@

Very good idea indeed.

I blame myself not having it in the first place.

Thank's a lot!

-- 
Bruno BEAUFILS

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
  2020-11-23 13:02   ` Bruno BEAUFILS
@ 2020-11-23 13:12     ` Eric S Fraga
  0 siblings, 0 replies; 6+ messages in thread
From: Eric S Fraga @ 2020-11-23 13:12 UTC (permalink / raw)
  To: Bruno BEAUFILS; +Cc: emacs-orgmode

On Monday, 23 Nov 2020 at 14:02, Bruno BEAUFILS wrote:
> I blame myself not having it in the first place.

Don't be too hard on yourself! :-)

Org, just like Emacs, has so many different ways of accomplishing
anything that sometimes the easiest is overlooked!

Glad I could help.

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.4-118-g2a4578.dirty


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

end of thread, other threads:[~2020-11-23 13:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-21 10:56 looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test Bruno BEAUFILS
2020-11-21 13:18 ` Tim Cross
2020-11-22 20:49   ` Bruno BEAUFILS
2020-11-23 10:19 ` Eric S Fraga
2020-11-23 13:02   ` Bruno BEAUFILS
2020-11-23 13:12     ` Eric S Fraga

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git