Function: org-export-output-file-name

org-export-output-file-name is a byte-compiled function defined in ox.el.gz.

Signature

(org-export-output-file-name EXTENSION &optional SUBTREEP PUB-DIR)

Documentation

Return output file's name according to buffer specifications.

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 of subtree at point.

When optional argument PUB-DIR is set, use it as the publishing directory.

Return file name as a string.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox.el.gz
(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,
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
of subtree at point.

When optional argument PUB-DIR is set, use it as the publishing
directory.

Return file name as a string."
  (let* ((visited-file (buffer-file-name (buffer-base-buffer)))
	 (base-name
	  (concat
	   (file-name-sans-extension
	    (or
	     ;; Check EXPORT_FILE_NAME subtree property.
	     (and subtreep (org-entry-get nil "EXPORT_FILE_NAME" 'selective))
	     ;; Check #+EXPORT_FILE_NAME keyword.
	     (org-with-point-at (point-min)
	       (catch :found
		 (let ((case-fold-search t))
		   (while (re-search-forward
			   "^[ \t]*#\\+EXPORT_FILE_NAME:[ \t]+\\S-" nil t)
		     (let ((element (org-element-at-point)))
		       (when (org-element-type-p element 'keyword)
			 (throw :found
				(org-element-property :value element))))))))
	     ;; Extract from buffer's associated file, if any.
	     (and visited-file
                  (file-name-nondirectory
                   ;; For a .gpg visited file, remove the .gpg extension:
                   (replace-regexp-in-string "\\.gpg\\'" "" visited-file)))
	     ;; Can't determine file name on our own: ask user.
	     (read-file-name
	      "Output file: " pub-dir nil nil nil
	      (lambda (n) (string= extension (file-name-extension n t))))))
	   extension))
	 (output-file
	  ;; 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)))
	   (t base-name))))
    ;; If writing to OUTPUT-FILE would overwrite original file, append
    ;; EXTENSION another time to final name.
    (if (and visited-file (file-equal-p visited-file output-file))
	(concat output-file extension)
      output-file)))