From: Zhaohui Li <lizhaohui1991@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Feature wish: macro functionality for literate programming
Date: Sun, 6 Nov 2016 10:58:32 +0800 [thread overview]
Message-ID: <CAATu+k9VOB8qZ9xBj1tGhTvyJeY8QADG93saRUJQ0M40iWGNvg@mail.gmail.com> (raw)
[-- 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 --]
reply other threads:[~2016-11-06 2:58 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=CAATu+k9VOB8qZ9xBj1tGhTvyJeY8QADG93saRUJQ0M40iWGNvg@mail.gmail.com \
--to=lizhaohui1991@gmail.com \
--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).