;;; ox.el --- Generic Export Engine for Org Mode
-;; Copyright (C) 2012-2013 Free Software Foundation, Inc.
+;; Copyright (C) 2012-2014 Free Software Foundation, Inc.
;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
;; Keywords: outlines, hypermedia, calendar, wp
"Alist between export properties and ways to set them.
The CAR of the alist is the property name, and the CDR is a list
-like (KEYWORD OPTION DEFAULT BEHAVIOUR) where:
+like (KEYWORD OPTION DEFAULT BEHAVIOR) where:
KEYWORD is a string representing a buffer keyword, or nil. Each
property defined this way can also be set, during subtree
property).
OPTION is a string that could be found in an #+OPTIONS: line.
DEFAULT is the default value for the property.
-BEHAVIOUR determines how Org should handle multiple keywords for
+BEHAVIOR determines how Org should handle multiple keywords for
the same property. It is a symbol among:
nil Keep old value and discard the new one.
t Replace old value with the new one.
:group 'org-export-general
:type '(choice
(const :tag "No creator sentence" nil)
- (const :tag "Sentence as a comment" 'comment)
+ (const :tag "Sentence as a comment" comment)
(const :tag "Insert the sentence" t)))
(defcustom org-export-with-date t
:type 'coding-system)
(defcustom org-export-copy-to-kill-ring 'if-interactive
- "Should we push exported content to the kill ring?"
+ "Non-nil means pushing export output to the kill ring.
+This variable is ignored during asynchronous export."
:group 'org-export-general
:version "24.3"
:type '(choice
(defcustom org-export-show-temporary-export-buffer t
"Non-nil means show buffer after exporting to temp buffer.
-When Org exports to a file, the buffer visiting that file is ever
+When Org exports to a file, the buffer visiting that file is never
shown, but remains buried. However, when exporting to
a temporary buffer, that buffer is popped up in a second window.
When this variable is nil, the buffer remains buried also in
;; - category :: tree
;; - type :: list of elements and objects
;;
+;; + `:input-buffer' :: Name of input buffer.
+;; - category :: option
+;; - type :: string
+;;
;; + `:input-file' :: Full path to input file, if any.
;; - category :: option
;; - type :: string or nil
;; - category :: option
;; - type :: string
;;
+;; + `:output-file' :: Full path to output file, if any.
+;; - category :: option
+;; - type :: string or nil
+;;
;; + `:parse-tree' :: Whole parse tree, available at any time during
;; transcoding.
;; - category :: option
;; Make sure point is at a heading.
(if (org-at-heading-p) (org-up-heading-safe) (org-back-to-heading t))
;; Take care of EXPORT_TITLE. If it isn't defined, use headline's
- ;; title as its fallback value.
+ ;; title (with no todo keyword, priority cookie or tag) as its
+ ;; fallback value.
(when (setq prop (or (org-entry-get (point) "EXPORT_TITLE")
- (progn (looking-at org-todo-line-regexp)
- (org-match-string-no-properties 3))))
+ (progn (looking-at org-complex-heading-regexp)
+ (org-match-string-no-properties 4))))
(setq plist
(plist-put
plist :title
((member keyword org-element-document-properties)
(org-element-parse-secondary-string
value (org-element-restriction 'keyword)))
- ;; If BEHAVIOUR is `split' expected value is
+ ;; If BEHAVIOR is `split' expected value is
;; a list of strings, not a string.
((eq (nth 4 option) 'split) (org-split-string value))
(t value)))))))))
(plist-put
plist property
;; Handle value depending on specified
- ;; BEHAVIOUR.
+ ;; BEHAVIOR.
(case behaviour
(space
(if (not (plist-get plist property))
(when (stringp value)
(setq plist
(plist-put plist property
- (org-element-parse-secondary-string
- value (org-element-restriction 'keyword))))))))))
+ (or (org-element-parse-secondary-string
+ value (org-element-restriction 'keyword))
+ ;; When TITLE keyword sets an empty
+ ;; string, make sure it doesn't
+ ;; appear as nil in the plist.
+ (and (eq property :title) ""))))))))))
(defun org-export--get-buffer-attributes ()
"Return properties related to buffer attributes, as a plist."
;; Store full path of input file name, or nil. For internal use.
(let ((visited-file (buffer-file-name (buffer-base-buffer))))
(list :input-file visited-file
- :title (if (not visited-file) (buffer-name (buffer-base-buffer))
- (file-name-sans-extension
- (file-name-nondirectory visited-file))))))
+ :input-buffer (buffer-name (buffer-base-buffer)))))
(defun org-export--get-global-options (&optional backend)
"Return global export options as a plist.
(all (append (and backend (org-export-get-all-options backend))
org-export-options-alist)))
(dolist (cell all plist)
- (let ((prop (car cell))
- (default-value (nth 3 cell)))
- (unless (or (not default-value) (plist-member plist prop))
+ (let ((prop (car cell)))
+ (unless (plist-member plist prop)
(setq plist
(plist-put
plist
prop
- ;; Eval default value provided. If keyword is
+ ;; Evaluate default value provided. If keyword is
;; a member of `org-element-document-properties',
;; parse it as a secondary string before storing it.
(let ((value (eval (nth 3 cell))))
- (if (not (stringp value)) value
- (let ((keyword (nth 1 cell)))
- (if (member keyword org-element-document-properties)
- (org-element-parse-secondary-string
- value (org-element-restriction 'keyword))
- value)))))))))))
+ (if (and (stringp value)
+ (member (nth 1 cell)
+ org-element-document-properties))
+ (org-element-parse-secondary-string
+ value (org-element-restriction 'keyword))
+ value)))))))))
(defun org-export--list-bound-variables ()
"Return variables bound from BIND keywords in current buffer.
;; Return value in appropriate order of appearance.
(nreverse (funcall collect-bind nil nil)))))
+;; defsubst org-export-get-parent must be defined before first use,
+;; was originally defined in the topology section
+
+(defsubst org-export-get-parent (blob)
+ "Return BLOB parent or nil.
+BLOB is the element or object considered."
+ (org-element-property :parent blob))
;;;; Tree Properties
;;
DATA is a parse tree, an element or an object or a secondary
string. INFO is a plist holding export options.
-Return transcoded string."
- (let ((memo (gethash data (plist-get info :exported-data) 'no-memo)))
- (if (not (eq memo 'no-memo)) memo
+Return a string."
+ (or (gethash data (plist-get info :exported-data))
(let* ((type (org-element-type data))
(results
(cond
;; Secondary string.
((not type)
(mapconcat (lambda (obj) (org-export-data obj info)) data ""))
- ;; Element/Object without contents or, as a special case,
- ;; headline with archive tag and archived trees restricted
- ;; to title only.
+ ;; Element/Object without contents or, as a special
+ ;; case, headline with archive tag and archived trees
+ ;; restricted to title only.
((or (not (org-element-contents data))
(and (eq type 'headline)
(eq (plist-get info :with-archived-trees) 'headline)
(lambda (element) (org-export-data element info))
(org-element-contents
(if (or greaterp objectp) data
- ;; Elements directly containing objects
- ;; must have their indentation normalized
- ;; first.
+ ;; Elements directly containing
+ ;; objects must have their indentation
+ ;; normalized first.
(org-element-normalize-contents
data
- ;; When normalizing contents of the first
- ;; paragraph in an item or a footnote
- ;; definition, ignore first line's
- ;; indentation: there is none and it
- ;; might be misleading.
+ ;; When normalizing contents of the
+ ;; first paragraph in an item or
+ ;; a footnote definition, ignore
+ ;; first line's indentation: there is
+ ;; none and it might be misleading.
(when (eq type 'paragraph)
(let ((parent (org-export-get-parent data)))
(and
(puthash
data
(cond
- ((not results) nil)
+ ((not results) "")
((memq type '(org-data plain-text nil)) results)
- ;; Append the same white space between elements or objects as in
- ;; the original buffer, and call appropriate filters.
+ ;; Append the same white space between elements or objects
+ ;; as in the original buffer, and call appropriate filters.
(t
(let ((results
(org-export-filter-apply-functions
(if (memq type org-element-all-elements)
(concat (org-element-normalize-string results)
(make-string post-blank ?\n))
- (concat results (make-string post-blank ? ))))
+ (concat results (make-string post-blank ?\s))))
info)))
results)))
- (plist-get info :exported-data))))))
+ (plist-get info :exported-data)))))
(defun org-export-data-with-backend (data backend info)
"Convert DATA into BACKEND format.
(org-export-install-filters
(org-combine-plists
info (org-export-get-environment backend subtreep ext-plist))))
+ ;; Special case: provide original file name or buffer name as
+ ;; default value for :title property.
+ (unless (plist-get info :title)
+ (plist-put
+ info :title
+ (let ((file (plist-get info :input-file)))
+ (if file (file-name-sans-extension (file-name-nondirectory file))
+ (plist-get info :input-buffer)))))
;; Expand export-specific set of macros: {{{author}}},
;; {{{date}}}, {{{email}}} and {{{title}}}. It must be done
;; once regular macros have been expanded, since document
;; Populate OPTIONS and KEYWORDS.
(dolist (entry (cond ((eq backend 'default) org-export-options-alist)
((org-export-backend-p backend)
- (org-export-get-all-options backend))
- (t (org-export-get-all-options
+ (org-export-backend-options backend))
+ (t (org-export-backend-options
(org-export-get-backend backend)))))
(let ((keyword (nth 1 entry))
(option (nth 2 entry)))
(defconst org-export-smart-quotes-regexps
(list
;; Possible opening quote at beginning of string.
- "\\`\\([\"']\\)\\(\\w\\|\\s.\\|\\s_\\)"
+ "\\`\\([\"']\\)\\(\\w\\|\\s.\\|\\s_\\|\\s(\\)"
;; Possible closing quote at beginning of string.
"\\`\\([\"']\\)\\(\\s-\\|\\s)\\|\\s.\\)"
;; Possible apostrophe at beginning of string.
;;;; Topology
;;
;; Here are various functions to retrieve information about the
-;; neighbourhood of a given element or object. Neighbours of interest
+;; neighborhood of a given element or object. Neighbors of interest
;; are direct parent (`org-export-get-parent'), parent headline
;; (`org-export-get-parent-headline'), first element containing an
;; object, (`org-export-get-parent-element'), parent table
;; `org-export-get-genealogy' returns the full genealogy of a given
;; element or object, from closest parent to full parse tree.
-(defsubst org-export-get-parent (blob)
- "Return BLOB parent or nil.
-BLOB is the element or object considered."
- (org-element-property :parent blob))
-
+;; defsubst org-export-get-parent must be defined before first use
(defun org-export-get-genealogy (blob)
"Return full genealogy relative to a given element or object.
;; Register running process in stack.
(org-export-add-to-stack (get-buffer ,proc-buffer) nil ,process)
;; Set-up sentinel in order to catch results.
- (let ((handler ,fun))
+ (let ((handler ',fun))
(set-process-sentinel
,process
`(lambda (p status)
a string.
A non-nil optional argument ASYNC means the process should happen
-asynchronously. The resulting buffer file then be accessible
+asynchronously. The resulting buffer will then be accessible
through the `org-export-stack' interface.
Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
or FILE."
(declare (indent 2))
(if (not (file-writable-p file)) (error "Output file not writable")
- (let ((encoding (or org-export-coding-system buffer-file-coding-system)))
+ (let ((ext-plist (org-combine-plists `(:output-file ,file) ext-plist))
+ (encoding (or org-export-coding-system buffer-file-coding-system)))
(if async
(org-export-async-start
`(lambda (file)