From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Bastien <bzg@altern.org>
Cc: emacs-orgmode@gnu.org
Subject: Re: Export a Subtree to an other .org file
Date: Thu, 04 Apr 2013 15:10:36 +0200 [thread overview]
Message-ID: <87obduxwz7.fsf@gmail.com> (raw)
In-Reply-To: <87wqsi5vt9.fsf@bzg.ath.cx> (Bastien's message of "Thu, 04 Apr 2013 14:23:14 +0200")
[-- Attachment #1: Type: text/plain, Size: 413 bytes --]
Hello,
Bastien <bzg@altern.org> writes:
> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>
>> Anyway, it's possible to (require 'ox-org) and (org-export-to-file 'org
>> "my-file.org").
>
> I can see how useful it would be to have an interactive function and
> keybindings for it. I can implement it if you want, but feel free to
> beat me on this one.
What about the following?
Regards,
--
Nicolas Goaziou
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-org-Add-interactive-functions-to-back-end.patch --]
[-- Type: text/x-patch, Size: 5801 bytes --]
From 3d65b46c0cefb37808507ba1cc61c6c35e3230f2 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Thu, 4 Apr 2013 15:09:22 +0200
Subject: [PATCH] ox-org: Add interactive functions to back-end
* lisp/ox-org.el (org): Add a menu entry for the back-end.
(org-org-export-as-org, org-org-export-to-org): New functions.
* lisp/org.el (org-export-backends): Accept `org' as a loadable
back-end.
---
lisp/org.el | 1 +
lisp/ox-org.el | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 98 insertions(+), 4 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index 06ba60a..1c15afd 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -495,6 +495,7 @@ depends on, if any."
(const :tag " man Export buffer to MAN format" man)
(const :tag " md Export buffer to Markdown format" md)
(const :tag " odt Export buffer to ODT format" odt)
+ (const :tag " org Export buffer to Org format" org)
(const :tag " texinfo Export buffer to Texinfo format" texinfo)
(const :tag "C confluence Export buffer to Confluence Wiki format" confluence)
(const :tag "C deck Export buffer to deck.js presentations" deck)
diff --git a/lisp/ox-org.el b/lisp/ox-org.el
index fdd009a..18925c5 100644
--- a/lisp/ox-org.el
+++ b/lisp/ox-org.el
@@ -20,9 +20,13 @@
;;; Commentary:
-;; This library implements an Org back-end for Org exporter. Since
-;; its usage is mainly internal, it doesn't provide any interactive
-;; function.
+;; This library implements an Org back-end for Org exporter.
+;;
+;; It introduces two interactive functions, `org-org-export-as-org'
+;; and `org-org-export-to-org', which export, respectively, to
+;; a temporary buffer and to a file.
+;;
+;; A publishing function is also provided: `org-org-publish-to-org'.
;;; Code:
(require 'ox)
@@ -102,7 +106,15 @@ setting of `org-html-htmlize-output-type' is 'css."
(timestamp . org-org-identity)
(underline . org-org-identity)
(verbatim . org-org-identity)
- (verse-block . org-org-identity)))
+ (verse-block . org-org-identity))
+ :menu-entry
+ '(?O "Export to Org"
+ ((?O "As Org buffer" org-org-export-as-org)
+ (?o "As Org file" org-org-export-to-org)
+ (?v "As Org file and open"
+ (lambda (a s v b)
+ (if a (org-org-export-to-org t s v b)
+ (org-open-file (org-org-export-to-org nil s v b))))))))
(defun org-org-identity (blob contents info)
"Transcode BLOB element or object back into Org syntax."
@@ -132,6 +144,86 @@ Ignore keywords targeted at other export back-ends."
(org-element-keyword-interpreter keyword nil)))
;;;###autoload
+(defun org-org-export-as-org (&optional async subtreep visible-only ext-plist)
+ "Export current buffer to an Org buffer.
+
+If narrowing is active in the current buffer, only export its
+narrowed part.
+
+If a region is active, export that region.
+
+A non-nil optional argument ASYNC means the process should happen
+asynchronously. The resulting buffer should be accessible
+through the `org-export-stack' interface.
+
+When optional argument SUBTREEP is non-nil, export the sub-tree
+at point, extracting information from the headline properties
+first.
+
+When optional argument VISIBLE-ONLY is non-nil, don't export
+contents of hidden elements.
+
+EXT-PLIST, when provided, is a property list with external
+parameters overriding Org default settings, but still inferior to
+file-local settings.
+
+Export is done in a buffer named \"*Org ORG Export*\", which will
+be displayed when `org-export-show-temporary-export-buffer' is
+non-nil."
+ (interactive)
+ (if async
+ (org-export-async-start
+ (lambda (output)
+ (with-current-buffer (get-buffer-create "*Org ORG Export*")
+ (erase-buffer)
+ (insert output)
+ (goto-char (point-min))
+ (org-mode)
+ (org-export-add-to-stack (current-buffer) 'org)))
+ `(org-export-as 'org ,subtreep ,visible-only nil ',ext-plist))
+ (let ((outbuf
+ (org-export-to-buffer
+ 'org "*Org ORG Export*" subtreep visible-only nil ext-plist)))
+ (with-current-buffer outbuf (org-mode))
+ (when org-export-show-temporary-export-buffer
+ (switch-to-buffer-other-window outbuf)))))
+
+;;;###autoload
+(defun org-org-export-to-org (&optional async subtreep visible-only ext-plist)
+ "Export current buffer to an org file.
+
+If narrowing is active in the current buffer, only export its
+narrowed part.
+
+If a region is active, export that region.
+
+A non-nil optional argument ASYNC means the process should happen
+asynchronously. The resulting file should be accessible through
+the `org-export-stack' interface.
+
+When optional argument SUBTREEP is non-nil, export the sub-tree
+at point, extracting information from the headline properties
+first.
+
+When optional argument VISIBLE-ONLY is non-nil, don't export
+contents of hidden elements.
+
+EXT-PLIST, when provided, is a property list with external
+parameters overriding Org default settings, but still inferior to
+file-local settings.
+
+Return output file name."
+ (interactive)
+ (let ((outfile (org-export-output-file-name ".org" subtreep)))
+ (if async
+ (org-export-async-start
+ (lambda (f) (org-export-add-to-stack f 'org))
+ `(expand-file-name
+ (org-export-to-file
+ 'org ,outfile ,subtreep ,visible-only nil ',ext-plist)))
+ (org-export-to-file 'org outfile subtreep visible-only nil ext-plist))))
+
+;;;###autoload
(defun org-org-publish-to-org (plist filename pub-dir)
"Publish an org file to org.
@@ -167,6 +259,7 @@ Return output file name."
(unless visitingp (kill-buffer work-buffer)))
(set-buffer-modified-p nil)))
+
(provide 'ox-org)
;; Local variables:
--
1.8.2
next prev parent reply other threads:[~2013-04-04 13:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-03 17:35 Export a Subtree to an other .org file Steve Prud'Homme
2013-04-03 18:36 ` Bastien
2013-04-03 19:31 ` Steve Prud'Homme
2013-04-03 20:35 ` John Hendy
2013-04-03 21:36 ` Hsiu-Khuern Tang
2013-04-03 22:50 ` John Hendy
2013-04-04 12:19 ` Nicolas Goaziou
2013-04-04 12:23 ` Bastien
2013-04-04 13:10 ` Nicolas Goaziou [this message]
2013-04-04 13:13 ` Bastien
2013-04-04 18:40 ` Hsiu-Khuern Tang
2013-04-05 23:58 ` Hsiu-Khuern Tang
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87obduxwz7.fsf@gmail.com \
--to=n.goaziou@gmail.com \
--cc=bzg@altern.org \
--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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.