[Top][All Lists]

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

Re: [O] Include does not work when doing org-export-as-org

From: Nick Dokos
Subject: Re: [O] Include does not work when doing org-export-as-org
Date: Tue, 11 Oct 2011 12:51:24 -0400

Henry Hirsch <address@hidden> 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.


--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
            (insert s)
    (find-file ofname)
    (delete-region (point-min) (point-max))
    (insert result)
--8<---------------cut here---------------end--------------->8---

reply via email to

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