emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Lee Jia Hong <jia_hong@live.com.my>
To: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: 2 Surprises and 2 Questions Regarding Org Tangle
Date: Tue, 9 Feb 2021 12:29:35 +0000	[thread overview]
Message-ID: <KL1PR0401MB446689858E994799C7E21D87AA8E9@KL1PR0401MB4466.apcprd04.prod.outlook.com> (raw)

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

(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: experiment-file.org --]
[-- Type: application/octet-stream, Size: 7166 bytes --]

* Instructions
1. Tangle this file, and you should get 8 tangled Org files.
2. Tangle each of the tangled Org files to see the effects of different reference placing styles and block naming style.

* To Recap
** Four Noweb Reference Placing Styles
*** P1
#+begin_src emacs-lisp
(setq org-capture-templates '(<<ORG_CAPTURE>>))
#+end_src
*** P2
#+begin_src emacs-lisp
(setq org-capture-templates
      '(<<ORG_CAPTURE>>))
#+end_src
*** P3
#+begin_src emacs-lisp
(setq org-capture-templates
      '(
        <<ORG_CAPTURE>>))
#+end_src
*** P4
#+begin_src emacs-lisp
(setq org-capture-templates
      '(
        <<ORG_CAPTURE>>
        ))
#+end_src
* Two Source Block Naming Styles
** 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
** NOWEBREF
#+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
* Test Files
** P1-NAME
#+begin_src org :tangle P1-NAME.org
,#+begin_src emacs-lisp :noweb yes :tangle yes
(setq org-capture-templates '(<<ORG_CAPTURE>>))
,#+end_src

,#+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
#+end_src
** P2-NAME
#+begin_src org :tangle P2-NAME.org
,#+begin_src emacs-lisp :noweb yes :tangle yes
(setq org-capture-templates
      '(<<ORG_CAPTURE>>))
,#+end_src

,#+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
#+end_src
** P3-NAME
#+begin_src org :tangle P3-NAME.org
,#+begin_src emacs-lisp :noweb yes :tangle yes
(setq org-capture-templates
      '(
        <<ORG_CAPTURE>>))
,#+end_src

,#+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
#+end_src
** P4-NAME
#+begin_src org :tangle P4-NAME.org
,#+begin_src emacs-lisp :noweb yes :tangle yes
(setq org-capture-templates
      '(
        <<ORG_CAPTURE>>
        ))
,#+end_src

,#+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
#+end_src
** P1-NOWEBREF
#+begin_src org :tangle P1-NOWEBREF.org
,#+begin_src emacs-lisp :noweb yes :tangle yes
(setq org-capture-templates '(<<ORG_CAPTURE>>))
,#+end_src

,#+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
#+end_src
** P2-NOWEBREF
#+begin_src org :tangle P2-NOWEBREF.org
,#+begin_src emacs-lisp :noweb yes :tangle yes
(setq org-capture-templates
      '(<<ORG_CAPTURE>>))
,#+end_src

,#+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
#+end_src
** P3-NOWEBREF
#+begin_src org :tangle P3-NOWEBREF.org
,#+begin_src emacs-lisp :noweb yes :tangle yes
(setq org-capture-templates
      '(
        <<ORG_CAPTURE>>))
,#+end_src

,#+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
#+end_src
** P4-NOWEBREF
#+begin_src org :tangle P4-NOWEBREF.org
,#+begin_src emacs-lisp :noweb yes :tangle yes
(setq org-capture-templates
      '(
        <<ORG_CAPTURE>>
        ))
,#+end_src

,#+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
#+end_src
* My Results
** P1-NAME
#+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")))
#+end_example
** P2-NAME
#+begin_example
(setq org-capture-templates
      '(("t" "TODO inbox"
      '( entry
      '( (file "~/gtd/capture.org")
      '( "* TODO %?
      '(    SCHEDULED: %t")))
#+end_example
** P3-NAME
#+begin_example
(setq org-capture-templates
      '(
        ("t" "TODO inbox"
         entry
         (file "~/gtd/capture.org")
         "* TODO %?
            SCHEDULED: %t")))
#+end_example
** P4-NAME
#+begin_example
(setq org-capture-templates
      '(
        ("t" "TODO inbox"
         entry
         (file "~/gtd/capture.org")
         "* TODO %?
            SCHEDULED: %t")
        ))
#+end_example
** P1-NOWEBREF
#+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
** P2-NOWEBREF
#+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
** P3-NOWEBREF                         :good:
#+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
** P4-NOWEBREF                         :good:
#+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

             reply	other threads:[~2021-02-11 16:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09 12:29 Lee Jia Hong [this message]
2021-02-11 17:44 ` 2 Surprises and 2 Questions Regarding Org Tangle Diego Zamboni
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=KL1PR0401MB446689858E994799C7E21D87AA8E9@KL1PR0401MB4466.apcprd04.prod.outlook.com \
    --to=jia_hong@live.com.my \
    --cc=emacs-orgmode@gnu.org \
    /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).