* Feature wish: macro functionality for literate programming
@ 2016-11-06 2:58 Zhaohui Li
0 siblings, 0 replies; only message in thread
From: Zhaohui Li @ 2016-11-06 2:58 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1142 bytes --]
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 <<path is a file>>
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 <<is_a_file?(path)>>
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], <<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?
[-- Attachment #2: Type: text/html, Size: 1381 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-11-06 2:58 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-06 2:58 Feature wish: macro functionality for literate programming Zhaohui Li
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.