all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* 2 Surprises and 2 Questions Regarding Org Tangle
@ 2021-02-09 12:29 Lee Jia Hong
  2021-02-11 17:44 ` Diego Zamboni
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Lee Jia Hong @ 2021-02-09 12:29 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

[-- 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

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

end of thread, other threads:[~2021-02-13  4:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-09 12:29 2 Surprises and 2 Questions Regarding Org Tangle Lee Jia Hong
2021-02-11 17:44 ` 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

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.