From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Include does not work when doing org-export-as-org Date: Tue, 11 Oct 2011 12:51:24 -0400 Message-ID: <6501.1318351884@alphaville.dokosmarshall.org> References: <20111011123829.GB17611@olymp.office.virtualminds.de> <6195.1318342189@alphaville.dokosmarshall.org> <6528.1318342888@alphaville.dokosmarshall.org> <6750.1318343276@alphaville.dokosmarshall.org> <20111011143414.GA25699@olymp.office.virtualminds.de> <7523.1318345078@alphaville.dokosmarshall.org> <20111011150901.GB25699@olymp.office.virtualminds.de> <4492.1318347474@alphaville.dokosmarshall.org> <20111011160935.GA26914@olymp.office.virtualminds.de> Reply-To: nicholas.dokos@hp.com Return-path: Received: from eggs.gnu.org ([140.186.70.92]:48077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDfY8-0003Ty-6X for emacs-orgmode@gnu.org; Tue, 11 Oct 2011 12:51:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RDfY6-0007T4-Jz for emacs-orgmode@gnu.org; Tue, 11 Oct 2011 12:51:28 -0400 Received: from g6t0185.atlanta.hp.com ([15.193.32.62]:1377) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDfY6-0007Sr-GO for emacs-orgmode@gnu.org; Tue, 11 Oct 2011 12:51:26 -0400 Received: from g5t0029.atlanta.hp.com (g5t0029.atlanta.hp.com [16.228.8.141]) by g6t0185.atlanta.hp.com (Postfix) with ESMTP id 635DA24380 for ; Tue, 11 Oct 2011 16:51:25 +0000 (UTC) In-Reply-To: Message from Henry Hirsch of "Tue, 11 Oct 2011 18:09:35 +0200." <20111011160935.GA26914@olymp.office.virtualminds.de> 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: emacs-orgmode@gnu.org Cc: nicholas.dokos@hp.com Henry Hirsch wrote: > On Tue, Oct 11, 2011 at 11:37:54AM -0400, Nick Dokos wrote: > > What is *your* use case? That is not at all clear, so far at least. > > > > Nick > > I want to apply the don't repeat yourself (dry) principle to my org files. > For the documentation of software quality I have huge org documents > with a lot of tables which tend to repeat themselves since I > have to document the same parameters in different environments. > > To prevent having to go through a lot of lines and files every time I > add a parameter to be documented or change anything else on the table > for that matter. > > I would like to export it to an org file and have it put the included > files in that file. And while I realy don't get why org-export-as-org > does not do this. I am sure implementing this does not need to break > established api. It could very well be added as a seperate function. > > If this needs any more clarification I will contribute every > information I can. Also I understand that there is not much motivation > to implement this since nobody besides me seems to mind the > absence of the functionality. > The following should do basically what you want, but there are several assumptions built into it: it assumes that 1) you are visiting the buffer of the top file (a.org in your example). 2) there is a file associated with the buffer (i.e. (buffer-file-name) returns a path, not nil). 3) the file is named something like "/path/to/my/file.org" and the output file is named "/path/to/my/file.I.org" 4) the output file is sacrificial: it is *clobbered* by the function. 5) if there is narrowing in effect, only the narrowed portion is processed. There may be other limitations as well. Nick --8<---------------cut here---------------start------------->8--- (defun org-to-org-handle-includes () "Copy the contents of the current buffer to OUTFILE, recursively processing #+INCLUDEs." (let* ((s (buffer-string)) (fname (buffer-file-name)) (ofname (format "%s.I.org" (file-name-sans-extension fname)))) (setq result (with-temp-buffer (insert s) (org-export-handle-include-files-recurse) (buffer-string))) (find-file ofname) (delete-region (point-min) (point-max)) (insert result) (save-buffer))) --8<---------------cut here---------------end--------------->8---