From: Diego Zamboni <diego@zzamboni.org>
To: Lee Jia Hong <jia_hong@live.com.my>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: Re: 2 Surprises and 2 Questions Regarding Org Tangle
Date: Thu, 11 Feb 2021 18:44:19 +0100 [thread overview]
Message-ID: <CAGY83Ef23PZoY5ve05+8p4UwuV8BoCT1o7gjd574ddvourSxQQ@mail.gmail.com> (raw)
In-Reply-To: <KL1PR0401MB446689858E994799C7E21D87AA8E9@KL1PR0401MB4466.apcprd04.prod.outlook.com>
[-- Attachment #1: Type: text/plain, Size: 7087 bytes --]
Jia,
#2 is known (maybe documented? Not sure) behavior: using :noweb-ref
accumulates multiple blocks with the same name, whereas #+NAME uses only
the first one. I think #+NAME's are supposed to be unique within a document.
I don't know about #1, the output from your P1 example seems surprising to
me as well.
--Diego
On Thu, Feb 11, 2021 at 5:13 PM Lee Jia Hong <jia_hong@live.com.my> wrote:
> (First time posting to a mailing list, please correct me if I did
> something wrong.)
>
> TLDR:
> Surprise 1: Different Noweb reference placing styles produces different
> tangled results.
> Question 1: Is it a bug?
>
> Surprise 2: Source block naming with #+NAME: and :noweb-ref produce
> different tangled results.
> Question 2: Is it a bug?
>
> ------------------------------------------------------------------------------------
>
> Hi,
>
> I stumble upon this article (https://www.hhyu.org/posts/literate_config/),
> and there are two things that standout:
> 1. the way author places the Noweb reference, i.e.:
> (setq org-capture-templates
> '(
> <<ORG_CAPTURE>>
> )
> )
> 2. the way he uses :noweb-ref to tangle multiple code blocks to the same
> Noweb reference.
>
>
>
> * Surprise 1: Different Noweb Reference Placing Styles Produces Different
> Tangled Results
>
> ------------------------------------------------------------------------------------------------
> The way he places the Noweb reference intrigues me, so I try writing it in
> different (placing) styles:
> P1:
> (setq org-capture-templates '(<<ORG_CAPTURE>>))
>
> P2:
> (setq org-capture-templates
> '(<<ORG_CAPTURE>>))
>
> P3:
> (setq org-capture-templates
> '(
> <<ORG_CAPTURE>>))
>
> P4:
> (setq org-capture-templates
> '(
> <<ORG_CAPTURE>>
> ))
>
> Tangled results using P3 and P4 styles match my expectations. But the
> results of P1 and P2 styles surprise me.
>
> Expected result for P1:
> #+begin_example
> (setq org-capture-templates '(("t" "TODO inbox"
> entry
> (file "~/gtd/capture.org")
> "* TODO %?
> SCHEDULED: %t")
> ("n" "notes inbox"
> entry
> (file "~/gtd/inbox.org")
> "* %T\n%i%?")))
> #+end_example
>
> Actual result:
> #+begin_example
> (setq org-capture-templates '(("t" "TODO inbox"
> (setq org-capture-templates '( entry
> (setq org-capture-templates '( (file "~/gtd/capture.org")
> (setq org-capture-templates '( "* TODO %?
> (setq org-capture-templates '( SCHEDULED: %t")
> (setq org-capture-templates '(("n" "notes inbox"
> (setq org-capture-templates '( entry
> (setq org-capture-templates '( (file "~/gtd/inbox.org")
> (setq org-capture-templates '( "* %T\n%i%?")))
> #+end_example
>
> Expected result for P2:
> #+begin_example
> (setq org-capture-templates
> '(("t" "TODO inbox"
> entry
> (file "~/gtd/capture.org")
> "* TODO %?
> SCHEDULED: %t")
> ("n" "notes inbox"
> entry
> (file "~/gtd/inbox.org")
> "* %T\n%i%?")))
> #+end_example
>
> Actual result:
> #+begin_example
> (setq org-capture-templates
> '(("t" "TODO inbox"
> '( entry
> '( (file "~/gtd/capture.org")
> '( "* TODO %?
> '( SCHEDULED: %t")
> '(("n" "notes inbox"
> '( entry
> '( (file "~/gtd/inbox.org")
> '( "* %T\n%i%?")))
> #+end_example
>
> Question 1: Is this a bug? If not, how can I make sure that style P1 and
> P2 produce the expected results?
>
>
>
> * Surprise 2: Source Block Naming with #+NAME: and :noweb-ref Produce
> Different Tangled Results
>
> -----------------------------------------------------------------------------------------------------------
> I have been naming my source blocks with #+NAME, and it's my first time
> realising that it's possible to tangle multiple source blocks to a single
> Noweb reference. To try it out, I write the reference holder like this:
> #+begin_src emacs-lisp
> (setq org-capture-templates
> '(
> <<ORG_CAPTURE>>))
> #+end_src
> (Note: Use placing style P3 because styles P1 and P2 doesn't work as
> expected, see Surprise 1 above)
>
> Then follow by source blocks named with #+NAME:
> #+NAME: ORG_CAPTURE
> #+begin_src emacs-lisp
> ("t" "TODO inbox"
> entry
> (file "~/gtd/capture.org")
> "* TODO %?
> SCHEDULED: %t")
> #+end_src
>
> #+NAME: ORG_CAPTURE
> #+begin_src emacs-lisp
> ("n" "notes inbox"
> entry
> (file "~/gtd/inbox.org")
> "* %T\n%i%?")
> #+end_src
>
> Expected result:
> #+begin_example
> (setq org-capture-templates
> '(
> ("t" "TODO inbox"
> entry
> (file "~/gtd/capture.org")
> "* TODO %?
> SCHEDULED: %t")
> ("n" "notes inbox"
> entry
> (file "~/gtd/inbox.org")
> "* %T\n%i%?")))
> #+end_example
>
> Actual result:
> #+begin_example
> (setq org-capture-templates
> '(
> ("t" "TODO inbox"
> entry
> (file "~/gtd/capture.org")
> "* TODO %?
> SCHEDULED: %t")))
> #+end_example
> (Not working as expected, because it only tangle the first source block
> with the given name.)
>
> However, with :noweb-ref <<REFERENCE>>, it's working as expected:
> #+begin_src emacs-lisp :noweb-ref ORG_CAPTURE
> ("t" "TODO inbox"
> entry
> (file "~/gtd/capture.org")
> "* TODO %?
> SCHEDULED: %t")
> #+end_src
>
> #+begin_src emacs-lisp :noweb-ref ORG_CAPTURE
> ("n" "notes inbox"
> entry
> (file "~/gtd/inbox.org")
> "* %T\n%i%?")
> #+end_src
>
> Result:
> #+begin_example
> (setq org-capture-templates
> '(
> ("t" "TODO inbox"
> entry
> (file "~/gtd/capture.org")
> "* TODO %?
> SCHEDULED: %t")
> ("n" "notes inbox"
> entry
> (file "~/gtd/inbox.org")
> "* %T\n%i%?")))
> #+end_example
>
> Question 2: Is this a bug? If not, how can I produce the expected result
> using #+NAME naming?
> (I prefer #+NAME over :noweb-ref because that line is more obvious and
> easily to be read since it can be fontified to stand out in different
> colour for a given Emacs theme.)
>
>
>
> * What I Have Done
> --------------------
> Read the Org-mode info Section 15.10 "Noweb Reference Syntax".
>
>
>
> * My Environments
> --------------------
> OS: Ubuntu 18.04.3 LTS x86_64
> Emacs version: GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+
> Version 3.22.30, cairo version 1.15.10) of 2020-10-14
> Org-mode version: Org mode version 9.3 (release_9.3 @
> /usr/local/share/emacs/28.0.50/lisp/org/)
>
> You can reproduce my "experiment" with the attached Org file. Tangle the
> attached file and you will get eight files (eight because there are eight
> different combinations of placing style * naming style). Then tangle each
> of the eight file to see the result for yourself.
>
>
>
> ----
> Regards,
> Jia Hong
>
[-- Attachment #2: Type: text/html, Size: 10610 bytes --]
next prev parent reply other threads:[~2021-02-11 17:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-09 12:29 2 Surprises and 2 Questions Regarding Org Tangle Lee Jia Hong
2021-02-11 17:44 ` Diego Zamboni [this message]
2021-02-13 2:41 ` Kevin M. Stout
2021-02-13 4:13 ` Kevin M. Stout
2021-02-11 17:46 ` Greg Minshall
2021-02-11 17:52 ` Greg Minshall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAGY83Ef23PZoY5ve05+8p4UwuV8BoCT1o7gjd574ddvourSxQQ@mail.gmail.com \
--to=diego@zzamboni.org \
--cc=emacs-orgmode@gnu.org \
--cc=jia_hong@live.com.my \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).