summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2013-04-04 15:09:22 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2013-04-04 15:09:22 +0200
commit3d65b46c0cefb37808507ba1cc61c6c35e3230f2 (patch)
tree78d540e3963a7013d4f6e738e1073dfcf803f929
parentcf5e96c8e1be5d0f9df2d98415f3ee16df9408f0 (diff)
downloadorg-mode-3d65b46c0cefb37808507ba1cc61c6c35e3230f2.tar.gz
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.
-rw-r--r--lisp/org.el1
-rw-r--r--lisp/ox-org.el101
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: