From mboxrd@z Thu Jan 1 00:00:00 1970 From: Zhaohui Li Subject: Feature wish: macro functionality for literate programming Date: Sun, 6 Nov 2016 10:58:32 +0800 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=94eb2c18aaec2e953805409915e0 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43012) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c3DfH-0006Qk-Kj for emacs-orgmode@gnu.org; Sat, 05 Nov 2016 22:58:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c3DfG-0005NN-G3 for emacs-orgmode@gnu.org; Sat, 05 Nov 2016 22:58:35 -0400 Received: from mail-it0-x229.google.com ([2607:f8b0:4001:c0b::229]:36337) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c3DfG-0005Ml-Ah for emacs-orgmode@gnu.org; Sat, 05 Nov 2016 22:58:34 -0400 Received: by mail-it0-x229.google.com with SMTP id m138so41219501itm.1 for ; Sat, 05 Nov 2016 19:58:33 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --94eb2c18aaec2e953805409915e0 Content-Type: text/plain; charset=UTF-8 I use org-babel with [:noweb] argument for literate programming. But soon I find the macro functionality is absent in this system. For example, I have #+name: example #+BEGIN_SRC ruby :tangle yes :noweb yes dir = "~" Find.find(dir) do |path| if <> puts path end end #+END_SRC #+name: path is a file #+BEGIN_SRC ruby :tangle no :noweb yes FileTest.file?(path) #+END_SRC But with macro functionality, the program can be more flexible: #+name: example #+BEGIN_SRC ruby :tangle yes :noweb yes dir = "~" Find.find(dir) do |path| if <> puts path end end #+END_SRC #+name: is_a_file? #+BEGIN_SRC ruby :tangle no :noweb yes :noweb-macro file-path FileTest.file?(file-path) #+END_SRC In [is_a_file?] block, I use argument [:noweb-macro] to indicate this block is a macro with one argument. When expanding block [example], <> will be expanded to [FileTest.file?(path)]. As a result, The src-block [is_a_file?] achieves better abstraction. I have tried native macro replacement of org({{{is_a_file?(path)}}}), but it doesn't work well in src-block. So, is this feature valuable? --94eb2c18aaec2e953805409915e0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I use org-babel with [:noweb] argument for literate progra= mming.
But soon I find the macro functionality is absent in this system.=
For example, I have
#+name: example
#+BEGIN_SRC ruby :tangle yes = :noweb yes
dir =3D "~"
Find.find(dir) do |path|
=C2=A0 i= f <<path is a file>>
=C2=A0=C2=A0=C2=A0 puts path
=C2=A0 = end
end
#+END_SRC=C2=A0=C2=A0

#+name: path is a file
#+BEG= IN_SRC ruby :tangle no :noweb yes
FileTest.file?(path)
#+END_SRC
<= br>But with macro functionality, the program can be more flexible:
#+nam= e: example
#+BEGIN_SRC ruby :tangle yes :noweb yes
dir =3D "~&qu= ot;
Find.find(dir) do |path|
=C2=A0 if <<is_a_file?(path)>&g= t;
=C2=A0=C2=A0=C2=A0 puts path
=C2=A0 end
end
#+END_SRC=C2=A0= =C2=A0

#+name: is_a_file?
#+BEGIN_SRC ruby :tangle no :noweb yes= :noweb-macro file-path
FileTest.file?(file-path)
#+END_SRC

In= [is_a_file?] block, I use argument [:noweb-macro] to indicate this block i= s a macro with
one argument.
When expanding block [example], <<= ;is_a_file?(path)>> will be expanded to [FileTest.file?(path)].
As= a result, The src-block [is_a_file?] achieves better abstraction.

I= have tried native macro replacement of org({{{is_a_file?(path)}}}), but it= doesn't work well in src-block.

So, is this feature valuable? <= br>

--94eb2c18aaec2e953805409915e0--