From: "Eric Schulte" <schulte.eric@gmail.com>
To: "Sébastien Vauban" <wxhgmqzgwmuf@spammotel.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Literate Programming with Org mode
Date: Sat, 01 Aug 2009 19:46:30 -0600 [thread overview]
Message-ID: <m263d7vvgp.fsf@gmail.com> (raw)
In-Reply-To: m2iqhadsdg.fsf@gmail.com
[-- Attachment #1: Type: text/plain, Size: 5096 bytes --]
"Eric Schulte" <schulte.eric@gmail.com> writes:
> Hi Sébastien,
>
> Thanks for the description. This is very interesting and I think
> warrants a re-working of the tangle functionality in org-babel.
>
> Given your description below I think I may try to add the Nuweb
> link/reference syntax "<<source-block-name>>" to org-babel. As
> source-code blocks are already named in the current org-babel setup this
> wouldn't be a very significant change. Once this is added it shouldn't
> be difficult to expand these links/references on export.
>
> Under this new setup the example file you described would be analogous
> to the this org-mode file.
>
> Does this sound like it would accomplish most of what you are after?
>
> I will reply to this message if/when I get this implemented.
>
Alright,
I've changed the tangling functionality of org-babel so that it now
follows some of the noweb conventions.
With the newest version of org-babel [1], try opening the attached
org-mode file [2] which is an org-mode translation of Sébastien's noweb
file from his previous email. Calling `org-babel-tangle' from within
this file will create the Payment.sql, Lessons.sql, and Enterprise.sql
source-code files. The document can also be exported into html and
latex using org-mode's standard export functionality.
Cheers -- Eric
>
> Cheers -- Eric
>
> Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:
>
>> Hi Eric and all,
>>
>> Here some promised description of how I'm using Literate Programming with
>> LaTeX (up to now -- soon directly from Org mode?).
>>
>> I write an "enhanced LaTeX" file ([1], having the `.nw' -- for Nuweb --
>> extension). It is enhanced as I can put blocks of code in there (SQL blocks,
>> for example), and give them a name for further referencing.
>>
>> Then, at some point in the file, I say how I want the code files to look like,
>> by assembling the blocks in a certain order, with some glue.
>>
>> For example:
>>
>> <<Enterprise.sql>>=
>> <<sql-init>>
>> SELECT abcID, etpID, etpAssurATPolNum
>> FROM enterprise JOIN record
>> ON (etpAbcID_fk = abcID)
>> WHERE etpAbcID_fk
>> <<sql-cond>>
>> @ %def
>>
>> The above file is made up of two defined blocks (`sql-init' and `sql-cond')
>> plus some glue in between.
>>
>> The good thing is I can reuse the same blocks in other context, completely
>> avoiding copy/paste of code:
>>
>> <<Lessons.sql>>=
>> <<sql-init>>
>> SELECT abcID, lesAlternNbrSem, lesNbrSem,
>> CONVERT(varchar(10), lesDateDeb, @dateFmtStyleOut) AS lesDateDeb,
>> CONVERT(varchar(10), lesDateFin, @dateFmtStyleOut) AS lesDateFin
>> FROM lessons JOIN record
>> ON (lesAbcID_fk = abcID)
>> WHERE lesAbcID_fk
>> <<sql-cond>>
>> @ %def
>>
>> OK. So, my `org-lit-prog.nw' file is ready, and committed under Subversion
>> (this is the only one I'm committing as it contains both the documentation of
>> the code, and the source code itself).
>>
>> Then, I just type (in a terminal):
>>
>> noweb org-lit-prog.nw
>>
>> to extract both:
>>
>> o the LaTeX file [2] to be compiled into a PDF [3],
>> o the different source code files (Enterprise.sql [4], Lessons.sql [5],
>> [6] and [7])
>>
>> Just that easy to keep code and doc in sync, and get a very nice-to-read
>> documentation of the code.
>>
>> Sometimes, I play an extra trick is made in the noweb file: I put blocks of
>> static code (for which I don't especially need any noweb feature) after the
>> end of the LaTeX document. That way, it gets outputted by noweb as a source
>> file during the Tangle process, and included in my LaTeX document via the
>> listings package.
>>
>> Why that trick? I could directly put the code in the body of the document!
>> Yes, but I want the code to be highlighted via listings. Otherwise, it's just
>> black and white display of the code...
>>
>> For easy access, I've put all the above files on a my Web space:
>>
>> [1] http://www.mygooglest.com/sva/org-lit-prog.nw
>> [2] http://www.mygooglest.com/sva/org-lit-prog.tex
>> [3] http://www.mygooglest.com/sva/org-lit-prog.pdf
>> [4] http://www.mygooglest.com/sva/Enterprise.sql
>> [5] http://www.mygooglest.com/sva/Lessons.sql
>> [6] http://www.mygooglest.com/sva/Payment.sql
>> [7] http://www.mygooglest.com/sva/prsNumNat.awk
>>
>> From what I understand, what we both wanna reach is writing all of the `.nw'
>> file as an Org file directly, and let Org-babel extracts the source code files
>> and the documentation out of it.
>>
>> What should be good in the future, when it will be ready for prime time, is
>> that this becomes complete part of the export process: no tangle operation
>> needed.
>>
>> Is the above description worth for you? Do you understand how I work when
>> documenting code? Pay attention: I'm *the* expert in literate programming.
>> Just an amateur being seduced by some of its features.
>>
>> Best regards,
>> Seb
Footnotes:
[1] http://github.com/eschulte/org-babel/tree/master
[2]
[-- Attachment #2: org-babel-lit-prog.org --]
[-- Type: application/octet-stream, Size: 2553 bytes --]
#+TITLE: Showing the benefits of Literate Programming
#+AUTHOR: Sebastien Vauban
#+OPTIONS: toc:nil num:nil ^:nil
* Context
I wanna show (or, at least, try to show) some advantages of literate
programming, such as no copy/pasting of code, and being able to
explain the code independently of its final structure as ``source
code''.
This file is a translation of Sebastien's noweb file into an org-mode
document.
* Files with SQL commands
** Common Code
All files have some code in common.
*** Header
#+srcname: sql-init
#+begin_src sql
-- Hey, Emacs! This is a -*- coding: utf-8 -*- file!
-- no longer display the count message
SET NOCOUNT ON
DECLARE @dateFmtStyleIn int; SET @dateFmtStyleIn = 120 -- ODBC canonical
DECLARE @dateFmtStyleOut int; SET @dateFmtStyleOut = 103 -- French dd/mm/yyyy
DECLARE @firstDayOfThisMonth smalldatetime
SET @firstDayOfThisMonth = CONVERT(smalldatetime,
CAST(YEAR(GETDATE()) AS char(4)) + '-'
+ CAST(MONTH(GETDATE()) AS char(2)) + '-'
+ '01' + ' 00:00:00',
@dateFmtStyleIn)
#+end_src
*** Condition to be satisfied
Condition to select rows will stay the same for all requests.
#+srcname: sql-cond
#+begin_src sql
IN (SELECT actAbcID_fk
FROM status
WHERE (staID = 338 AND staEtat = 3))
AND abcSignDate < @firstDayOfThisMonth
ORDER BY abcID
#+end_src
** Specific code
*** File Enterprise
Specific part to enterprise is:
#+srcname: enterprise
#+begin_src sql :tangle Enterprise
-- <<sql-init>>
SELECT abcID, etpID, etpAssurATPolNum
FROM enterprise JOIN record
ON (etpAbcID_fk = abcID)
WHERE etpAbcID_fk
-- <<sql-cond>>
#+end_src
*** File Lessons
Specific part to lessons is:
#+srcname: lessons
#+begin_src sql :tangle Lessons
-- <<sql-init>>
SELECT abcID, lesAlternNbrSem, lesNbrSem,
CONVERT(varchar(10), lesDateDeb, @dateFmtStyleOut) AS lesDateDeb,
CONVERT(varchar(10), lesDateFin, @dateFmtStyleOut) AS lesDateFin
FROM lessons JOIN record
ON (lesAbcID_fk = abcID)
WHERE lesAbcID_fk
-- <<sql-cond>>
#+end_src
*** File Payment
Specific part to payment is:
#+srcname: payment
#+begin_src sql :tangle Payment
-- <<sql-init>>
SELECT abcID, payFDNbrKm, payAllocType, payCompens, payFDMontantJ,
payAllocChomBrute, payAllocChomBruteJM, payAutresAllocsSocBrutes
FROM payments JOIN record
ON (payAbcID_fk = abcID)
WHERE payAbcID_fk
-- <<sql-cond>>
#+end_src
[-- Attachment #3: Type: text/plain, Size: 204 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
next prev parent reply other threads:[~2009-08-02 1:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-28 16:14 Literate Programming with Org mode Sébastien Vauban
2009-07-28 16:46 ` Marcelo de Moraes Serpa
2009-07-28 20:41 ` Sébastien Vauban
2009-07-28 21:53 ` sam kleinman
2009-07-29 22:16 ` Eric H. Neilsen, Jr.
2009-07-31 17:01 ` Eric Schulte
2009-07-31 20:30 ` sam kleinman
2009-07-30 0:42 ` Eric Schulte
2009-08-02 1:46 ` Eric Schulte [this message]
2009-08-03 8:42 ` Sébastien Vauban
2009-08-03 15:38 ` Eric Schulte
2009-08-11 9:42 ` Sébastien Vauban
2009-08-11 18:55 ` Eric Schulte
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=m263d7vvgp.fsf@gmail.com \
--to=schulte.eric@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=wxhgmqzgwmuf@spammotel.com \
/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).