all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Noweb blocks duplicate during Org export if part of #+include
@ 2018-12-06 14:34 Kaushal Modi
  2018-12-08  9:42 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Kaushal Modi @ 2018-12-06 14:34 UTC (permalink / raw)
  To: emacs-org list

Hello,

Here is a MWE:

1. With point on the "** Foo" section, running C-c C-e C-s h o, will
result in noweb-duplicate-bug.html with the <<some_snippet>> block
expanded only once, as expected.

2. But with point on the "* Foo Included" section, running the same
C-c C-e C-s h o, will result in foo_included.html with the
<<some_snippet>> block expanded twice! It seems like the Noweb
expansion happens first as usual, and then again when parsing
#+include (which shouldn't happen?).

=====
#+title: Noweb Duplicating Bug
#+author: Kaushal Modi

* Reused Sections
** Foo
:PROPERTIES:
:CUSTOM_ID: foo
:END:
*** Some Snippet
#+begin_src emacs-lisp :noweb-ref some_snippet
(message "Hello")
#+end_src
*** Some Snippet used again
#+begin_src emacs-lisp :noweb yes
(defun foo ()
  <<some_snippet>>
  )
#+end_src
* Foo Included
:PROPERTIES:
:EXPORT_FILE_NAME: foo_included
:END:
#+include: "./noweb-duplicate-bug.org::#foo" :only-contents t
=====


Org version, built from next branch: Org mode version 9.1.14
(release_9.1.14-1147-g6f8347 @
/home/kmodi/usr_local/apps/6/emacs/old-emacsclient/share/emacs/site-lisp/org/)

--
Kaushal Modi

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

* Re: Noweb blocks duplicate during Org export if part of #+include
  2018-12-06 14:34 Noweb blocks duplicate during Org export if part of #+include Kaushal Modi
@ 2018-12-08  9:42 ` Nicolas Goaziou
  2018-12-12 18:50   ` Kaushal Modi
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2018-12-08  9:42 UTC (permalink / raw)
  To: Kaushal Modi; +Cc: emacs-org list

Hello,

Kaushal Modi <kaushal.modi@gmail.com> writes:

> Here is a MWE:
>
> 1. With point on the "** Foo" section, running C-c C-e C-s h o, will
> result in noweb-duplicate-bug.html with the <<some_snippet>> block
> expanded only once, as expected.
>
> 2. But with point on the "* Foo Included" section, running the same
> C-c C-e C-s h o, will result in foo_included.html with the
> <<some_snippet>> block expanded twice! It seems like the Noweb
> expansion happens first as usual, and then again when parsing
> #+include (which shouldn't happen?).

That's not exactly what is happening.

INCLUDE keywords are always expanded before Babel kicks in. Moreover,
when exporting a subtree, only INCLUDE keywords from the subtree are
expanded. So, in your first example, nothing fancy happens.

Now, onto the second case. When evaluating Babel code, the whole initial
buffer is taken as reference. It allows, for example, to define source
blocks in a dedicated section, and export another one that calls them.
When the INCLUDE keyword is expanded, there are two ":noweb-ref
some_snippet". Even if they are outside the exported subtree, they are
still concatenated and used as a replacement for "<<some_snippet>".

In a nutshell, that can be surprising, but this is to be expected.

Regards,

-- 
Nicolas Goaziou

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

* Re: Noweb blocks duplicate during Org export if part of #+include
  2018-12-08  9:42 ` Nicolas Goaziou
@ 2018-12-12 18:50   ` Kaushal Modi
  0 siblings, 0 replies; 3+ messages in thread
From: Kaushal Modi @ 2018-12-12 18:50 UTC (permalink / raw)
  To: emacs-org list

On Sat, Dec 8, 2018 at 4:42 AM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:

> Now, onto the second case. When evaluating Babel code, the whole initial
> buffer is taken as reference. It allows, for example, to define source
> blocks in a dedicated section, and export another one that calls them.
> When the INCLUDE keyword is expanded, there are two ":noweb-ref
> some_snippet". Even if they are outside the exported subtree, they are
> still concatenated and used as a replacement for "<<some_snippet>".
>
> In a nutshell, that can be surprising, but this is to be expected.


Thank you for the detailed answer.

As I don't know how to "fix" this, I will just remember to not use
Noweb in subtrees that I plan to  #+include.

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

end of thread, other threads:[~2018-12-12 18:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-06 14:34 Noweb blocks duplicate during Org export if part of #+include Kaushal Modi
2018-12-08  9:42 ` Nicolas Goaziou
2018-12-12 18:50   ` Kaushal Modi

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.