emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Literate Programming in Org-Mode
@ 2007-06-22 16:45 Emre Sahin
  2007-06-22 17:34 ` Xiao-Yong Jin
  0 siblings, 1 reply; 2+ messages in thread
From: Emre Sahin @ 2007-06-22 16:45 UTC (permalink / raw)
  To: Org-mode ML


Hi all, 

Do any of you use org-mode for literate programming? I think that
would be a very natural use of org-mode. 

Support in other compilers may be minimal, but one can write a
Literate Haskell program in org-mode without any changes I
think. E.g. (a meaningless program from Haskell wikibook) 

* Preamble
** Module Definition

> module YourModule where

** Imports
*** import only the functions toLower and toUpper from Data.Char

> import Data.Char (toLower, toUpper) 

*** import everything exported from Data.List 

> import Data.List 

*** import everything exported from MyModule

> import MyModule

* Functions
** put a c in front of the text

> someFunction :: String -> String
> someFunction text = 'c' : text 

** build a string of c's using someFunction

> stringOfCs :: String -> String
> stringOfCs = (someFunction "") : stringOfCs

** etc

* Input and output

> main = do
>   putStrLn "Please enter your name: "
>   name <- getLine
>   putStrLn ("Hello, " ++ (someFunction name) ++ ", how are you?")


In Literate Haskell, program lines start with a >. If it's not used,
than the line is considered as a comment line, hence making org-mode
useful in folding, maintainin TODOs etc. (This message is already a
Literate Haskell program.) Currently, one can use Literate Haskell
major mode during compilation and writing codes and org-mode during
general overview for the program. Writing first the documentation and
pseudocode of the program in org-mode and then filling the "gaps" with
code may result in better programs. (You can see
http://www.haskell.org/onlinereport/literate.html for literate
comments in Haskell.)

This can give an idea how org-mode can be employed for writing
programs. Developing some functionality to consider lines starting
with > (or any other character) as a code line and syntax highlighting
and feeding these to a compiler may ease things. Currently one can
switch back and forth to the language major mode and org-mode (or use
multiple major mode packs, but I didn't try them) but a support for
code lines (for any programming language) may result in one of the
best Literate Programming tools out there, I think. (Ability to use
LaTeX in org-mode already makes it very useful for LP.)

I don't know if anybody considered this, but using org-mode as a
"super mode" for programming major modes seems a good idea. 

Best regards,

Emre

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

* Re: Literate Programming in Org-Mode
  2007-06-22 16:45 Literate Programming in Org-Mode Emre Sahin
@ 2007-06-22 17:34 ` Xiao-Yong Jin
  0 siblings, 0 replies; 2+ messages in thread
From: Xiao-Yong Jin @ 2007-06-22 17:34 UTC (permalink / raw)
  To: emacs-orgmode


Emre Sahin <iesahin@bilkent.edu.tr> writes:

> [... Haskell literals ...]
>
> In Literate Haskell, program lines start with a >. If it's not used,
> than the line is considered as a comment line, hence making org-mode
> useful in folding, maintainin TODOs etc. (This message is already a
> Literate Haskell program.) Currently, one can use Literate Haskell
> major mode during compilation and writing codes and org-mode during
> general overview for the program. Writing first the documentation and
> pseudocode of the program in org-mode and then filling the "gaps" with
> code may result in better programs. (You can see
> http://www.haskell.org/onlinereport/literate.html for literate
> comments in Haskell.)
>
> This can give an idea how org-mode can be employed for writing
> programs. Developing some functionality to consider lines starting
> with > (or any other character) as a code line and syntax highlighting
> and feeding these to a compiler may ease things. Currently one can
> switch back and forth to the language major mode and org-mode (or use
> multiple major mode packs, but I didn't try them) but a support for
> code lines (for any programming language) may result in one of the
> best Literate Programming tools out there, I think. (Ability to use
> LaTeX in org-mode already makes it very useful for LP.)
>
> I don't know if anybody considered this, but using org-mode as a
> "super mode" for programming major modes seems a good idea. 

This certainly is very interesting.  Probably org-mode can
just ask other mode to deal with some specific marked-up
text.  In this Haskell case, line starting with '>' or lines
sandwiched with

\begin{code}
main = print "We love org-mode!"
\end{code}

may play well with haskell-mode.  Or as the case in C/C++,
it may be feasible to make org-mode deal with comment lines,
which is like /* org-mode region */, or better

/*
* This code doing nothing
*/

int main (void)
{

/*
** Show we love org-mode
*/

  printf ("We love org-mode!\n");

/*
** Some thing useful
   One can put some useful code here.
*/

/*
** Tell shell we are happy
   She likes 0.
*/

  return 0;
}

Probably it's too wild?

Cheers,
Xiao-Yong

>
> Best regards,
>
> Emre
>

Sorry Emre, I incidentally replied to your email.

-- 
    c/*    __o/*
    <\     * (__
    */\      <

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

end of thread, other threads:[~2007-06-22 17:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-22 16:45 Literate Programming in Org-Mode Emre Sahin
2007-06-22 17:34 ` Xiao-Yong Jin

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).