emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <nicholas.dokos@hp.com>
To: emacs-orgmode@gnu.org
Cc: nicholas.dokos@hp.com
Subject: Re: Include does not work when doing org-export-as-org
Date: Tue, 11 Oct 2011 12:51:24 -0400	[thread overview]
Message-ID: <6501.1318351884@alphaville.dokosmarshall.org> (raw)
In-Reply-To: Message from Henry Hirsch <henry.hirsch@adition.com> of "Tue, 11 Oct 2011 18:09:35 +0200." <20111011160935.GA26914@olymp.office.virtualminds.de>

Henry Hirsch <henry.hirsch@adition.com> 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---

  parent reply	other threads:[~2011-10-11 16:51 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-11 12:38 Include does not work when doing org-export-as-org Henry Hirsch
2011-10-11 13:41 ` Nick Dokos
2011-10-11 13:53   ` Henry Hirsch
2011-10-11 14:01     ` Henry Hirsch
2011-10-11 14:09 ` Nick Dokos
2011-10-11 14:18   ` Nick Dokos
2011-10-11 14:21   ` Nick Dokos
2011-10-11 14:27     ` Nick Dokos
2011-10-11 14:34       ` Henry Hirsch
     [not found]         ` <henry.hirsch@adition.com>
2011-10-11 14:57           ` Nick Dokos
2011-10-11 15:09             ` Henry Hirsch
2011-10-11 15:37               ` Nick Dokos
2011-10-11 16:09                 ` Henry Hirsch
2011-10-11 16:51           ` Nick Dokos [this message]
2011-10-12  7:44             ` Henry Hirsch
2011-10-12 10:15               ` Carsten Dominik
2011-10-21 16:49                 ` Bastien
2011-10-21 17:14                   ` Nick Dokos
2011-10-11 18:27         ` Carsten Dominik
2011-10-11 14:22   ` Henry Hirsch

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=6501.1318351884@alphaville.dokosmarshall.org \
    --to=nicholas.dokos@hp.com \
    --cc=emacs-orgmode@gnu.org \
    /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).