Re: [Orgmode] suggesting a new function org-export-string

2010-10-22 Thread Eric Schulte
Applied, Thanks -- Eric

Carsten Dominik  writes:

> Looks good to me.
>
> - Carsten
>
> On Oct 17, 2010, at 11:22 PM, Eric Schulte wrote:
>
>> The attached patch adds a new functions org-export-as-string.
>>
>> ,
>> | org-export-string is a Lisp function in `org-exp.el'.
>> |
>> | (org-export-string STRING FMT &optional DIR)
>> |
>> | Export STRING to FMT using existing export facilities.
>> | During export STRING is saved to a temporary file whose location
>> | could vary.  Optional argument DIR can be used to force the
>> | directory in which the temporary file is created during export
>> | which can be useful for resolving relative paths.  Dir defaults
>> | to the value of `temporary-file-directory'.
>> `
>>
>> This function should be useful in user code, and can already reduce
>> the
>> amount of code in ob-org.el and org-mime.el.
>>
>> From e51017e4d7051aad31384a470f0a695dca0d6716 Mon Sep 17 00:00:00 2001
>> From: Eric Schulte 
>> Date: Sun, 17 Oct 2010 15:17:13 -0600
>> Subject: [PATCH] org-export-string -- exports a string of org-mode
>> markup text
>>
>> * lisp/org-exp.el (org-export-string): new function org-export-string
>>  can be used to convert a string of test in org-mode markup to a
>>  specified format
>>
>> * contrib/lisp/org-mime.el (org-mime-htmlize): now using new
>>  org-export-string function for exportation
>>
>> * lisp/ob-org.el (org-babel-execute:org): now using new
>>  org-export-string function for exportation
>> ---
>> contrib/lisp/org-mime.el |   20 +---
>> lisp/ob-org.el   |   27 ---
>> lisp/org-exp.el  |   22 ++
>> 3 files changed, 27 insertions(+), 42 deletions(-)
>>
>> diff --git a/contrib/lisp/org-mime.el b/contrib/lisp/org-mime.el
>> index 109ec69..0537b9d 100644
>> --- a/contrib/lisp/org-mime.el
>> +++ b/contrib/lisp/org-mime.el
>> @@ -175,7 +175,7 @@ export that region, otherwise export the entire
>> body."
>>(point-max)))
>>  (raw-body (buffer-substring html-start html-end))
>>  (tmp-file (make-temp-name (expand-file-name "mail"
>> temporary-file-directory)))
>> - (body (org-mime-org-export "org" raw-body tmp-file))
>> + (body (org-export-string raw-body "org" (file-name-
>> directory tmp-file)))
>>  ;; because we probably don't want to skip part of our mail
>>  (org-export-skip-text-before-1st-heading nil)
>>  ;; because we probably don't want to export a huge style file
>> @@ -198,24 +198,6 @@ export that region, otherwise export the entire
>> body."
>>   (insert (org-mime-multipart body html)
>>   (mapconcat 'identity html-images "\n")
>>
>> -(defun org-mime-org-export (fmt body tmp-file)
>> -  "Org-Export BODY to format FMT with the file name set to
>> -TMP-FILE during export."
>> -  (save-excursion
>> -(with-temp-buffer
>> -  (insert org-mime-default-header)
>> -  (insert body)
>> -  (write-file tmp-file)
>> -  (org-load-modules-maybe)
>> -  (unless org-local-vars
>> -(setq org-local-vars (org-get-local-variables)))
>> -  (substring
>> -   (eval ;; convert to fmt -- mimicing `org-run-like-in-org-mode'
>> -(list 'let org-local-vars
>> -  (list (intern (concat "org-export-as-" fmt))
>> -nil nil nil ''string t)))
>> -   (if (string= fmt "org") (length org-mime-default-header)
>> 0)
>> -
>> (defun org-mime-apply-html-hook (html)
>>   (if org-mime-html-hook
>>   (with-temp-buffer
>> diff --git a/lisp/ob-org.el b/lisp/ob-org.el
>> index 8b45de8..dcc2ee1 100644
>> --- a/lisp/ob-org.el
>> +++ b/lisp/ob-org.el
>> @@ -30,8 +30,7 @@
>> ;;; Code:
>> (require 'ob)
>>
>> -(declare-function org-load-modules-maybe "org" (&optional force))
>> -(declare-function org-get-local-variables "org" ())
>> +(declare-function org-export-string "org-exp" (string fmt &optional
>> dir))
>>
>> (defvar org-babel-default-header-args:org
>>   '((:results . "raw silent") (:exports . "results"))
>> @@ -50,29 +49,11 @@ This function is called by `org-babel-execute-
>> src-block'."
>>   (let ((result-params (split-string (or (cdr (assoc :results
>> params)) "")))
>>  (body (replace-regexp-in-string "^," "" body)))
>> (cond
>> - ((member "latex" result-params) (org-babel-org-export body
>> "latex"))
>> - ((member "html" result-params)  (org-babel-org-export body
>> "html"))
>> - ((member "ascii" result-params) (org-babel-org-export body
>> "ascii"))
>> + ((member "latex" result-params) (org-export-string body
>> "latex"))
>> + ((member "html" result-params)  (org-export-string body "html"))
>> + ((member "ascii" result-params) (org-export-string body
>> "ascii"))
>>  (t body
>>
>> -(defvar org-local-vars)
>> -(defun org-babel-org-export (body fmt)
>> -  "Export BODY to FMT using Org-mode's export facilities. "
>> -  (when (get-buffer " org-mode-tmp")
>> -(error "Nested call to org-export

Re: [Orgmode] suggesting a new function org-export-string

2010-10-22 Thread Carsten Dominik

Looks good to me.

- Carsten

On Oct 17, 2010, at 11:22 PM, Eric Schulte wrote:


The attached patch adds a new functions org-export-as-string.

,
| org-export-string is a Lisp function in `org-exp.el'.
|
| (org-export-string STRING FMT &optional DIR)
|
| Export STRING to FMT using existing export facilities.
| During export STRING is saved to a temporary file whose location
| could vary.  Optional argument DIR can be used to force the
| directory in which the temporary file is created during export
| which can be useful for resolving relative paths.  Dir defaults
| to the value of `temporary-file-directory'.
`

This function should be useful in user code, and can already reduce  
the

amount of code in ob-org.el and org-mime.el.

From e51017e4d7051aad31384a470f0a695dca0d6716 Mon Sep 17 00:00:00 2001
From: Eric Schulte 
Date: Sun, 17 Oct 2010 15:17:13 -0600
Subject: [PATCH] org-export-string -- exports a string of org-mode  
markup text


* lisp/org-exp.el (org-export-string): new function org-export-string
 can be used to convert a string of test in org-mode markup to a
 specified format

* contrib/lisp/org-mime.el (org-mime-htmlize): now using new
 org-export-string function for exportation

* lisp/ob-org.el (org-babel-execute:org): now using new
 org-export-string function for exportation
---
contrib/lisp/org-mime.el |   20 +---
lisp/ob-org.el   |   27 ---
lisp/org-exp.el  |   22 ++
3 files changed, 27 insertions(+), 42 deletions(-)

diff --git a/contrib/lisp/org-mime.el b/contrib/lisp/org-mime.el
index 109ec69..0537b9d 100644
--- a/contrib/lisp/org-mime.el
+++ b/contrib/lisp/org-mime.el
@@ -175,7 +175,7 @@ export that region, otherwise export the entire  
body."

   (point-max)))
 (raw-body (buffer-substring html-start html-end))
 (tmp-file (make-temp-name (expand-file-name "mail"  
temporary-file-directory)))

- (body (org-mime-org-export "org" raw-body tmp-file))
+ (body (org-export-string raw-body "org" (file-name- 
directory tmp-file)))

 ;; because we probably don't want to skip part of our mail
 (org-export-skip-text-before-1st-heading nil)
 ;; because we probably don't want to export a huge style file
@@ -198,24 +198,6 @@ export that region, otherwise export the entire  
body."

  (insert (org-mime-multipart body html)
  (mapconcat 'identity html-images "\n")

-(defun org-mime-org-export (fmt body tmp-file)
-  "Org-Export BODY to format FMT with the file name set to
-TMP-FILE during export."
-  (save-excursion
-(with-temp-buffer
-  (insert org-mime-default-header)
-  (insert body)
-  (write-file tmp-file)
-  (org-load-modules-maybe)
-  (unless org-local-vars
-(setq org-local-vars (org-get-local-variables)))
-  (substring
-   (eval ;; convert to fmt -- mimicing `org-run-like-in-org-mode'
-(list 'let org-local-vars
-  (list (intern (concat "org-export-as-" fmt))
-nil nil nil ''string t)))
-   (if (string= fmt "org") (length org-mime-default-header)  
0)

-
(defun org-mime-apply-html-hook (html)
  (if org-mime-html-hook
  (with-temp-buffer
diff --git a/lisp/ob-org.el b/lisp/ob-org.el
index 8b45de8..dcc2ee1 100644
--- a/lisp/ob-org.el
+++ b/lisp/ob-org.el
@@ -30,8 +30,7 @@
;;; Code:
(require 'ob)

-(declare-function org-load-modules-maybe "org" (&optional force))
-(declare-function org-get-local-variables "org" ())
+(declare-function org-export-string "org-exp" (string fmt &optional  
dir))


(defvar org-babel-default-header-args:org
  '((:results . "raw silent") (:exports . "results"))
@@ -50,29 +49,11 @@ This function is called by `org-babel-execute- 
src-block'."
  (let ((result-params (split-string (or (cdr (assoc :results  
params)) "")))

(body (replace-regexp-in-string "^," "" body)))
(cond
- ((member "latex" result-params) (org-babel-org-export body  
"latex"))
- ((member "html" result-params)  (org-babel-org-export body  
"html"))
- ((member "ascii" result-params) (org-babel-org-export body  
"ascii"))
+ ((member "latex" result-params) (org-export-string body  
"latex"))

+ ((member "html" result-params)  (org-export-string body "html"))
+ ((member "ascii" result-params) (org-export-string body  
"ascii"))

 (t body

-(defvar org-local-vars)
-(defun org-babel-org-export (body fmt)
-  "Export BODY to FMT using Org-mode's export facilities. "
-  (when (get-buffer " org-mode-tmp")
-(error "Nested call to org-export: from org code block  
exporting results"))

-  (let ((tmp-file (org-babel-temp-file "org-")))
-(with-temp-buffer
-  (insert org-babel-org-default-header)
-  (insert body)
-  (write-file tmp-file)
-  (org-load-modules-maybe)
-  (unless org-local-vars
-   (setq org-local-vars (org-get-local-variables)))
-  (eval ;; convert to fmt -- mimi