From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Export a Subtree to an other .org file Date: Thu, 04 Apr 2013 15:10:36 +0200 Message-ID: <87obduxwz7.fsf@gmail.com> References: <048901ce3091$97eb1440$c7c13cc0$@gmail.com> <87ppybh35m.fsf@bzg.ath.cx> <04ef01ce30a1$cae9a220$60bce660$@gmail.com> <20130403213639.GA31923@localhost> <874nfmzdwl.fsf@gmail.com> <87wqsi5vt9.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:54315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNjwG-00063g-JI for emacs-orgmode@gnu.org; Thu, 04 Apr 2013 09:10:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UNjwB-0005n7-37 for emacs-orgmode@gnu.org; Thu, 04 Apr 2013 09:10:48 -0400 Received: from mail-wg0-f45.google.com ([74.125.82.45]:64589) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNjwA-0005mj-OQ for emacs-orgmode@gnu.org; Thu, 04 Apr 2013 09:10:42 -0400 Received: by mail-wg0-f45.google.com with SMTP id x12so2639494wgg.0 for ; Thu, 04 Apr 2013 06:10:41 -0700 (PDT) In-Reply-To: <87wqsi5vt9.fsf@bzg.ath.cx> (Bastien's message of "Thu, 04 Apr 2013 14:23:14 +0200") 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: Bastien Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hello, Bastien writes: > Nicolas Goaziou 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ox-org-Add-interactive-functions-to-back-end.patch >From 3d65b46c0cefb37808507ba1cc61c6c35e3230f2 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou 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 --=-=-=--