emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <eric.schulte@gmx.com>
To: nicholas.dokos@hp.com
Cc: Sankalp <sankalpkhare@gmail.com>, emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Including source code *from* a file in #+BEGIN_SRC blocks
Date: Sun, 11 Dec 2011 12:25:24 -0700	[thread overview]
Message-ID: <8762hm6hcr.fsf@gmx.com> (raw)
In-Reply-To: <22202.1323631330@alphaville.dokosmarshall.org> (Nick Dokos's message of "Sun, 11 Dec 2011 14:22:10 -0500")

Nick Dokos <nicholas.dokos@hp.com> writes:

> Eric Schulte <eric.schulte@gmx.com> wrote:
>
>> Sankalp <sankalpkhare@gmail.com> 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	other threads:[~2011-12-11 19:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-11  5:56 Including source code *from* a file in #+BEGIN_SRC blocks Sankalp
2011-12-11  6:53 ` Puneeth Chaganti
2011-12-11 16:00 ` Eric Schulte
2011-12-11 17:08   ` Sankalp
2011-12-11 19:22   ` Nick Dokos
2011-12-11 19:25     ` Eric Schulte [this message]

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=8762hm6hcr.fsf@gmx.com \
    --to=eric.schulte@gmx.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=nicholas.dokos@hp.com \
    --cc=sankalpkhare@gmail.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).