From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: Including source code *from* a file in #+BEGIN_SRC blocks Date: Sun, 11 Dec 2011 12:25:24 -0700 Message-ID: <8762hm6hcr.fsf@gmx.com> References: <87aa6z82ws.fsf@gmx.com> <22202.1323631330@alphaville.dokosmarshall.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:54060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RZp1g-0003W3-EW for emacs-orgmode@gnu.org; Sun, 11 Dec 2011 14:25:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RZp1f-0001MY-12 for emacs-orgmode@gnu.org; Sun, 11 Dec 2011 14:25:32 -0500 Received: from mailout-us.gmx.com ([74.208.5.67]:42467) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1RZp1e-0001MU-Ru for emacs-orgmode@gnu.org; Sun, 11 Dec 2011 14:25:30 -0500 In-Reply-To: <22202.1323631330@alphaville.dokosmarshall.org> (Nick Dokos's message of "Sun, 11 Dec 2011 14:22:10 -0500") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: nicholas.dokos@hp.com Cc: Sankalp , emacs-orgmode Nick Dokos writes: > Eric Schulte wrote: > >> Sankalp writes: >> >> > Hi, >> > I've been using org mode's #+BEGIN_SRC ... #+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/