summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-01-18 18:30:11 +0100
committerNicolas Goaziou <n.goaziou@gmail.com>2012-01-21 22:58:23 +0100
commitfc93b6f34071703d5a154a51540f3f4e3f15b8a2 (patch)
tree93a427f328962efdc642e696be6993eb5a0d5250
parent58b509c0914c7fd859cbe53055be8085b7cd4469 (diff)
downloadorg-mode-fc93b6f34071703d5a154a51540f3f4e3f15b8a2.tar.gz
org-export: Ask user for a file name when exporting from temporary buffer
* contrib/lisp/org-export.el (org-export-output-file-name): Ask user for a file name when exporting from temporary buffer.
-rw-r--r--contrib/lisp/org-export.el49
1 files changed, 32 insertions, 17 deletions
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el
index 6be4ac0..42fe808 100644
--- a/contrib/lisp/org-export.el
+++ b/contrib/lisp/org-export.el
@@ -1935,7 +1935,8 @@ Return output file's name."
(defun org-export-output-file-name (extension &optional subtreep pub-dir)
"Return output file's name according to buffer specifications.
-EXTENSION is a string representing the output file extension.
+EXTENSION is a string representing the output file extension,
+with the leading dot.
With a non-nil optional argument SUBTREEP, try to determine
output file's name by looking for \"EXPORT_FILE_NAME\" property
@@ -1947,22 +1948,36 @@ directory.
Return file name as a string, or nil if it couldn't be
determined."
(let ((base-name
- (concat
- (file-name-as-directory (or pub-dir "."))
- ;; Output file name either comes from EXPORT_FILE_NAME
- ;; sub-tree property, assuming point is at beginning of said
- ;; sub-tree, or to the name of buffer's associated file.
- (file-name-sans-extension
- (or (and subtreep
- (org-entry-get
- (save-excursion
- (ignore-errors
- (org-back-to-heading (not visible-only)) (point)))
- "EXPORT_FILE_NAME" t))
- (file-name-nondirectory
- (or (buffer-file-name (buffer-base-buffer)))))))))
- ;; BASE-NAME will be nil when original buffer was temporary one.
- (when base-name (concat base-name extension))))
+ ;; File name may come from EXPORT_FILE_NAME subtree property,
+ ;; assuming point is at beginning of said sub-tree.
+ (file-name-sans-extension
+ (or (and subtreep
+ (org-entry-get
+ (save-excursion
+ (ignore-errors
+ (org-back-to-heading (not visible-only)) (point)))
+ "EXPORT_FILE_NAME" t))
+ ;; File name may be extracted from buffer's associated
+ ;; file, if any.
+ (buffer-file-name (buffer-base-buffer))
+ ;; Can't determine file name on our own: Ask user.
+ (let ((read-file-name-function
+ (and org-completion-use-ido 'ido-read-file-name)))
+ (read-file-name
+ "Output file: " pub-dir nil nil nil
+ (lambda (name)
+ (string= (file-name-extension name t) extension))))))))
+ ;; Build file name. Enforce EXTENSION over whatever user may have
+ ;; come up with. PUB-DIR, if defined, always has precedence over
+ ;; any provided path.
+ (cond
+ (pub-dir
+ (concat (file-name-as-directory pub-dir)
+ (file-name-nondirectory base-name)
+ extension))
+ ((string= (file-name-nondirectory base-name) base-name)
+ (concat (file-name-as-directory ".") base-name extension))
+ (t (concat base-name extension)))))
(defmacro org-export-with-current-buffer-copy (&rest body)
"Apply BODY in a copy of the current buffer.