emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Including source code *from* a file in #+BEGIN_SRC blocks


From: Eric Schulte
Subject: Re: [O] Including source code *from* a file in #+BEGIN_SRC blocks
Date: Sun, 11 Dec 2011 12:25:24 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Nick Dokos <address@hidden> writes:

> Eric Schulte <address@hidden> wrote:
>
>> Sankalp <address@hidden> writes:
>> 
>> > Hi,
>> > I've been using org mode's #+BEGIN_SRC ... <code> #+END_SRC feature to
>> > display source code.
>> >
>> > I was wondering if there's a way to include code from an external file.
>> > Like the *\lstinputlisting* feature in the LaTeX *listings* package.
>> >
>> 
>> You could write a code block which when executed wraps the file's
>> contents in a code block which is then inserted into the Org-mode
>> buffer.  For example if your external file is named foo.c and holds C
>> code the following
>> 
>> #+begin_src sh :exports results :results raw output
>>   echo "#+BEGIN_SRC C"
>>   cat foo.c
>>   echo "#+END_SRC"
>> #+end_src
>> 
>> will insert its contents into the buffer during every export.
>> 
>
> That might be necessary in more complex situations, but in the OP's case
> (at least, to the extent that I understand it), Puneeth's suggestion of
>
> #+begin_src c :exports code
> #+include: foo.c
> #+end_src
>

Oh, I didn't notice the code block surrounding the include call in
Puneeth's suggestion.  I didn't realize include working inside of
blocks, very cool.  I agree that is preferable to my code block
execution base solution.

Best,

>
> seems to work fine.
>
> Nick
>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]