summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2014-07-28 17:24:40 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2014-07-29 15:45:18 +0200
commit3c22bb19e025e350ebcc25c6fc23e2dd59e49693 (patch)
tree4f84f9e3f7f79c3ac525ff698a3da3a486e29dc2
parent0540dccaddfc7e6464fe984402f06b082d59314c (diff)
downloadorg-mode-3c22bb19e025e350ebcc25c6fc23e2dd59e49693.tar.gz
ox-odt: Use options instead of hard-coded variables
* lisp/ox-odt.el (org-odt-styles-dir, org-odt-create-custom-styles-for-srcblocks, org-odt-table-styles, org-odt-get-table-cell-styles): Fix docstring. (org-odt-format-headline-function, org-odt-format-inlinetask-function): Change default value. (org-odt-template, org-odt-drawer, org-odt-format-headline--wrap, org-odt-inlinetask, org-odt--enumerate, org-odt--image-size, org-odt--enumerable-image-p, org-odt--enumerable-latex-image-p, org-odt--enumerable-formula-p, org-odt-link, org-odt-table-style-spec, org-odt-timestamp): Use option instead of hard-coded variables. (org-odt-format-headline): Remove function. (org-odt-do-format-code): Change signature. Use options instead of hard-coded variables. (org-odt-fixed-width, org-odt-latex-environment, org-odt-link--inline-image, org-odt-format-code): Apply signature change. (org-odt-format-headline-default-function, org-odt-format-inlinetask-default-function): New functions. (org-odt-link--inline-image): Fix indentation.
-rw-r--r--lisp/ox-odt.el211
1 files changed, 109 insertions, 102 deletions
diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index b6f237c..adbb596 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -203,8 +203,7 @@ heuristically based on the values of `org-odt-lib-dir' and
This directory contains the following XML files -
\"OrgOdtStyles.xml\" and \"OrgOdtContentTemplate.xml\". These
XML files are used as the default values of
- `org-odt-styles-file' and
- `org-odt-content-template-file'.
+ `org-odt-styles-file' and `org-odt-content-template-file'.
The default value of this variable varies depending on the
version of org in use and is initialized from
@@ -676,7 +675,8 @@ The default value simply returns the value of CONTENTS."
;;;; Headline
-(defcustom org-odt-format-headline-function 'ignore
+(defcustom org-odt-format-headline-function
+ 'org-odt-format-headline-default-function
"Function to format headline text.
This function will be called with 5 arguments:
@@ -688,14 +688,15 @@ TAGS the tags string, separated with colons \(string or nil\).
The function result will be used as headline text."
:group 'org-export-odt
- :version "24.4"
- :package-version '(Org . "8.0")
+ :version "24.5"
+ :package-version '(Org . "8.3")
:type 'function)
;;;; Inlinetasks
-(defcustom org-odt-format-inlinetask-function 'ignore
+(defcustom org-odt-format-inlinetask-function
+ 'org-odt-format-inlinetask-default-function
"Function called to format an inlinetask in ODT code.
The function must accept six parameters:
@@ -708,8 +709,8 @@ The function must accept six parameters:
The function should return the string to be exported."
:group 'org-export-odt
- :version "24.4"
- :package-version '(Org . "8.0")
+ :version "24.5"
+ :package-version '(Org . "8.3")
:type 'function)
@@ -797,8 +798,8 @@ Use the latter option if you do not want the custom styles to be
based on your current display settings. It is necessary that the
styles.xml already contains needed styles for colorizing to work.
-This variable is effective only if
-`org-odt-fontify-srcblocks' is turned on."
+This variable is effective only if `org-odt-fontify-srcblocks' is
+turned on."
:group 'org-export-odt
:version "24.1"
:type 'boolean)
@@ -835,8 +836,7 @@ TABLE-STYLE-NAME is the style associated with the table through
TABLE-TEMPLATE-NAME is a set of - upto 9 - automatic
TABLE-CELL-STYLE-NAMEs and PARAGRAPH-STYLE-NAMEs (as defined
-below) that is included in
-`org-odt-content-template-file'.
+below) that is included in `org-odt-content-template-file'.
TABLE-CELL-STYLE-NAME := TABLE-TEMPLATE-NAME + TABLE-CELL-TYPE +
\"TableCell\"
@@ -1375,7 +1375,7 @@ original parsed data. INFO is a plist holding export options."
;; Non-availability of styles.xml is not a critical
;; error. For now, throw an error.
(styles-file (or styles-file
- org-odt-styles-file
+ (plist-get info :odt-styles-file)
(expand-file-name "OrgOdtStyles.xml"
org-odt-styles-dir)
(error "org-odt: Missing styles file?"))))
@@ -1400,7 +1400,7 @@ original parsed data. INFO is a plist holding export options."
(org-odt--zip-extract styles-file "styles.xml" org-odt-zip-dir)))))
(t
(error (format "Invalid specification of styles.xml file: %S"
- org-odt-styles-file))))
+ (plist-get info :odt-styles-file)))))
;; create a manifest entry for styles.xml
(org-odt-create-manifest-file-entry "text/xml" "styles.xml")
@@ -1461,7 +1461,7 @@ original parsed data. INFO is a plist holding export options."
'("%Y-%M-%d %a" . "%Y-%M-%d %a %H:%M"))))
(with-temp-buffer
(insert-file-contents
- (or org-odt-content-template-file
+ (or (plist-get info :odt-content-template-file)
(expand-file-name "OrgOdtContentTemplate.xml"
org-odt-styles-dir)))
;; Write automatic styles.
@@ -1475,7 +1475,7 @@ original parsed data. INFO is a plist holding export options."
(when (setq props (or (plist-get props :rel-width) "96"))
(insert (format org-odt-table-style-format style-name props))))
;; - Dump date-styles.
- (when org-odt-use-date-fields
+ (when (plist-get info :odt-use-date-fields)
(insert (org-odt--build-date-styles (car custom-time-fmts)
"OrgDate1")
(org-odt--build-date-styles (cdr custom-time-fmts)
@@ -1494,7 +1494,8 @@ original parsed data. INFO is a plist holding export options."
(lambda (x)
(format
"<text:sequence-decl text:display-outline-level=\"%d\" text:name=\"%s\"/>"
- org-odt-display-outline-level (nth 1 x)))
+ (plist-get info :odt-display-outline-level)
+ (nth 1 x)))
org-odt-category-map-alist "\n")))
;; Position the cursor to document body.
(goto-char (point-min))
@@ -1550,7 +1551,7 @@ original parsed data. INFO is a plist holding export options."
(concat
(format "\n<text:p text:style-name=\"%s\">%s</text:p>"
"OrgSubtitle"
- (if (and org-odt-use-date-fields timestamp)
+ (if (and (plist-get info :odt-use-date-fields) timestamp)
(org-odt--format-timestamp (car date))
(org-export-data (plist-get info :date) info)))
;; Separator
@@ -1635,7 +1636,7 @@ channel."
CONTENTS holds the contents of the block. INFO is a plist
holding contextual information."
(let* ((name (org-element-property :drawer-name drawer))
- (output (funcall org-odt-format-drawer-function
+ (output (funcall (plist-get info :odt-format-drawer-function)
name contents)))
output))
@@ -1680,7 +1681,7 @@ CONTENTS is nil. INFO is a plist holding contextual information."
(defun org-odt-fixed-width (fixed-width contents info)
"Transcode a FIXED-WIDTH element from Org to ODT.
CONTENTS is nil. INFO is a plist holding contextual information."
- (org-odt-do-format-code (org-element-property :value fixed-width)))
+ (org-odt-do-format-code (org-element-property :value fixed-width) info))
;;;; Footnote Definition
@@ -1756,33 +1757,6 @@ CONTENTS is nil. INFO is a plist holding contextual information."
;;;; Headline
-(defun* org-odt-format-headline
- (todo todo-type priority text tags
- &key level section-number headline-label &allow-other-keys)
- (concat
- ;; Todo.
- (when todo
- (let ((style (if (member todo org-done-keywords) "OrgDone" "OrgTodo")))
- (format "<text:span text:style-name=\"%s\">%s</text:span> "
- style todo)))
- (when priority
- (let* ((style (format "OrgPriority-%s" priority))
- (priority (format "[#%c]" priority)))
- (format "<text:span text:style-name=\"%s\">%s</text:span> "
- style priority)))
- ;; Title.
- text
- ;; Tags.
- (when tags
- (concat
- "<text:tab/>"
- (format "<text:span text:style-name=\"%s\">[%s]</text:span>"
- "OrgTags" (mapconcat
- (lambda (tag)
- (format
- "<text:span text:style-name=\"%s\">%s</text:span>"
- "OrgTag" tag)) tags " : "))))))
-
(defun org-odt-format-headline--wrap (headline backend info
&optional format-function
&rest extra-keys)
@@ -1807,17 +1781,16 @@ INFO is a plist holding contextual information."
(org-export-get-tags headline info)))
(headline-label (concat "sec-" (mapconcat 'number-to-string
headline-number "-")))
- (format-function (cond
- ((functionp format-function) format-function)
- ((not (eq org-odt-format-headline-function 'ignore))
- (function*
- (lambda (todo todo-type priority text tags
- &allow-other-keys)
- (funcall org-odt-format-headline-function
- todo todo-type priority text tags))))
- (t 'org-odt-format-headline))))
+ (format-function
+ (if (functionp format-function) format-function
+ (function*
+ (lambda (todo todo-type priority text tags
+ &key level section-number headline-label
+ &allow-other-keys)
+ (funcall (plist-get info :odt-format-headline-function)
+ todo todo-type priority text tags))))))
(apply format-function
- todo todo-type priority text tags
+ todo todo-type priority text tags
:headline-label headline-label :level level
:section-number section-number extra-keys)))
@@ -1893,6 +1866,33 @@ holding contextual information."
(concat extra-targets anchored-title))
contents))))))
+(defun org-odt-format-headline-default-function
+ (todo todo-type priority text tags)
+ "Default format function for a headline.
+See `org-odt-format-headline-function' for details."
+ (concat
+ ;; Todo.
+ (when todo
+ (let ((style (if (eq todo-type 'done) "OrgDone" "OrgTodo")))
+ (format "<text:span text:style-name=\"%s\">%s</text:span> " style todo)))
+ (when priority
+ (let* ((style (format "OrgPriority-%s" priority))
+ (priority (format "[#%c]" priority)))
+ (format "<text:span text:style-name=\"%s\">%s</text:span> "
+ style priority)))
+ ;; Title.
+ text
+ ;; Tags.
+ (when tags
+ (concat
+ "<text:tab/>"
+ (format "<text:span text:style-name=\"%s\">[%s]</text:span>"
+ "OrgTags" (mapconcat
+ (lambda (tag)
+ (format
+ "<text:span text:style-name=\"%s\">%s</text:span>"
+ "OrgTag" tag)) tags " : "))))))
+
;;;; Horizontal Rule
@@ -1934,29 +1934,33 @@ contextual information."
"Transcode an INLINETASK element from Org to ODT.
CONTENTS holds the contents of the block. INFO is a plist
holding contextual information."
- (cond
- ;; If `org-odt-format-inlinetask-function' is not 'ignore, call it
- ;; with appropriate arguments.
- ((not (eq org-odt-format-inlinetask-function 'ignore))
- (let ((format-function
- (function*
- (lambda (todo todo-type priority text tags
- &key contents &allow-other-keys)
- (funcall org-odt-format-inlinetask-function
- todo todo-type priority text tags contents)))))
- (org-odt-format-headline--wrap
- inlinetask nil info format-function :contents contents)))
- ;; Otherwise, use a default template.
- (t
- (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
- "Text_20_body"
- (org-odt--textbox
- (concat
- (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
- "OrgInlineTaskHeading"
- (org-odt-format-headline--wrap inlinetask nil info))
- contents)
- nil nil "OrgInlineTaskFrame" " style:rel-width=\"100%\"")))))
+ (let* ((todo
+ (and (plist-get info :with-todo-keywords)
+ (let ((todo (org-element-property :todo-keyword inlinetask)))
+ (and todo (org-export-data todo info)))))
+ (todo-type (and todo (org-element-property :todo-type inlinetask)))
+ (priority (and (plist-get info :with-priority)
+ (org-element-property :priority inlinetask)))
+ (text (org-export-data (org-element-property :title inlinetask) info))
+ (tags (and (plist-get info :with-tags)
+ (org-export-get-tags inlinetask info))))
+ (funcall (plist-get info :odt-format-inlinetask-function)
+ todo todo-type priority text tags contents)))
+
+(defun org-odt-format-inlinetask-default-function
+ (todo todo-type priority name tags contents)
+ "Default format function for a inlinetasks.
+See `org-odt-format-inlinetask-function' for details."
+ (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
+ "Text_20_body"
+ (org-odt--textbox
+ (concat
+ (format "\n<text:p text:style-name=\"%s\">%s</text:p>"
+ "OrgInlineTaskHeading"
+ (org-odt-format-headline-default-function
+ todo todo-type priority name tags))
+ contents)
+ nil nil "OrgInlineTaskFrame" " style:rel-width=\"100%\"")))
;;;; Italic
@@ -2037,7 +2041,7 @@ CONTENTS is nil. INFO is a plist holding contextual information."
CONTENTS is nil. INFO is a plist holding contextual information."
(let* ((latex-frag (org-remove-indentation
(org-element-property :value latex-environment))))
- (org-odt-do-format-code latex-frag)))
+ (org-odt-do-format-code latex-frag info)))
;;;; Latex Fragment
@@ -2092,7 +2096,9 @@ CONTENTS is nil. INFO is a plist holding contextual information."
counter))
info 'first-match)))))
(scope (funcall --numbered-parent-headline-at-<=-n
- element (or n org-odt-display-outline-level) info))
+ element
+ (or n (plist-get info :odt-display-outline-level))
+ info))
(ordinal (funcall --enumerate element scope info predicate))
(tag
(concat
@@ -2212,8 +2218,8 @@ SHORT-CAPTION are strings."
(org-odt-create-manifest-file-entry media-type target-file)
target-file))
-(defun org-odt--image-size (file &optional user-width
- user-height scale dpi embed-as)
+(defun org-odt--image-size
+ (file info &optional user-width user-height scale dpi embed-as)
(let* ((--pixels-to-cms
(function (lambda (pixels dpi)
(let ((cms-per-inch 2.54)
@@ -2225,7 +2231,7 @@ SHORT-CAPTION are strings."
(and size-in-pixels
(cons (funcall --pixels-to-cms (car size-in-pixels) dpi)
(funcall --pixels-to-cms (cdr size-in-pixels) dpi))))))
- (dpi (or dpi org-odt-pixels-per-inch))
+ (dpi (or dpi (plist-get info :odt-pixels-per-inch)))
(anchor-type (or embed-as "paragraph"))
(user-width (and (not scale) user-width))
(user-height (and (not scale) user-height))
@@ -2314,7 +2320,7 @@ used as a communication channel."
;; Handle `:width', `:height' and `:scale' properties. Read
;; them as numbers since we need them for computations.
(size (org-odt--image-size
- src-expanded
+ src-expanded info
(let ((width (plist-get attr-plist :width)))
(and width (read width)))
(let ((length (plist-get attr-plist :length)))
@@ -2343,7 +2349,7 @@ used as a communication channel."
;; description. This quite useful for debugging.
(desc (and replaces (org-element-property :value replaces))))
(org-odt--render-image/formula entity href width height
- captions user-frame-params title desc)))
+ captions user-frame-params title desc)))
;;;; Links :: Math formula
@@ -2545,7 +2551,7 @@ used as a communication channel."
;; Link should point to an image file.
(lambda (l)
(assert (eq (org-element-type l) 'link))
- (org-export-inline-image-p l org-odt-inline-image-rules))))
+ (org-export-inline-image-p l (plist-get info :odt-inline-image-rules)))))
(defun org-odt--enumerable-latex-image-p (element info)
(org-odt--standalone-link-p
@@ -2560,7 +2566,7 @@ used as a communication channel."
;; Link should point to an image file.
(lambda (l)
(assert (eq (org-element-type l) 'link))
- (org-export-inline-image-p l org-odt-inline-image-rules))))
+ (org-export-inline-image-p l (plist-get info :odt-inline-image-rules)))))
(defun org-odt--enumerable-formula-p (element info)
(org-odt--standalone-link-p
@@ -2572,7 +2578,7 @@ used as a communication channel."
;; Link should point to a MathML or ODF file.
(lambda (l)
(assert (eq (org-element-type l) 'link))
- (org-export-inline-image-p l org-odt-inline-formula-rules))))
+ (org-export-inline-image-p l (plist-get info :odt-inline-formula-rules)))))
(defun org-odt--standalone-link-p (element info &optional
paragraph-predicate
@@ -2712,7 +2718,7 @@ INFO is a plist holding contextual information. See
;; Ensure DESC really exists, or set it to nil.
(desc (and (not (string= desc "")) desc))
(imagep (org-export-inline-image-p
- link org-odt-inline-image-rules))
+ link (plist-get info :odt-inline-image-rules)))
(path (cond
((member type '("http" "https" "ftp" "mailto"))
(concat type ":" raw-path))
@@ -2725,11 +2731,11 @@ INFO is a plist holding contextual information. See
(cond
;; Image file.
((and (not desc) (org-export-inline-image-p
- link org-odt-inline-image-rules))
+ link (plist-get info :odt-inline-image-rules)))
(org-odt-link--inline-image link info))
;; Formula file.
((and (not desc) (org-export-inline-image-p
- link org-odt-inline-formula-rules))
+ link (plist-get info :odt-inline-formula-rules)))
(org-odt-link--inline-formula link info))
;; Radio target: Transcode target's contents and use them as
;; link's description.
@@ -2817,7 +2823,8 @@ INFO is a plist holding contextual information. See
(let ((desc-element (car link-contents)))
(and (eq (org-element-type desc-element) 'link)
(org-export-inline-image-p
- desc-element org-odt-inline-image-rules))))
+ desc-element
+ (plist-get info :odt-inline-image-rules)))))
;; Format link as a clickable image.
(format "\n<draw:a xlink:type=\"simple\" xlink:href=\"%s\">\n%s\n</draw:a>"
path desc)
@@ -3133,13 +3140,13 @@ and prefix with \"OrgSrc\". For example,
(org-no-warnings (htmlfontify-string line))))
(defun org-odt-do-format-code
- (code &optional lang refs retain-labels num-start)
+ (code info &optional lang refs retain-labels num-start)
(let* ((lang (or (assoc-default lang org-src-lang-modes) lang))
(lang-mode (and lang (intern (format "%s-mode" lang))))
(code-lines (org-split-string code "\n"))
(code-length (length code-lines))
(use-htmlfontify-p (and (functionp lang-mode)
- org-odt-fontify-srcblocks
+ (plist-get info :odt-fontify-srcblocks)
(require 'htmlfontify nil t)
(fboundp 'htmlfontify-string)))
(code (if (not use-htmlfontify-p) code
@@ -3194,7 +3201,7 @@ and prefix with \"OrgSrc\". For example,
(num-start (case (org-element-property :number-lines element)
(continued (org-export-get-loc element info))
(new 0))))
- (org-odt-do-format-code code lang refs retain-labels num-start)))
+ (org-odt-do-format-code code info lang refs retain-labels num-start)))
(defun org-odt-src-block (src-block contents info)
"Transcode a SRC-BLOCK element from Org to ODT.
@@ -3261,13 +3268,13 @@ contextual information."
(let* ((table (org-export-get-parent-table element))
(table-attributes (org-export-read-attribute :attr_odt table))
(table-style (plist-get table-attributes :style)))
- (assoc table-style org-odt-table-styles)))
+ (assoc table-style (plist-get info :odt-table-styles))))
(defun org-odt-get-table-cell-styles (table-cell info)
"Retrieve styles applicable to a table cell.
R and C are (zero-based) row and column numbers of the table
cell. STYLE-SPEC is an entry in `org-odt-table-styles'
-applicable to the current table. It is `nil' if the table is not
+applicable to the current table. It is nil if the table is not
associated with any style attributes.
Return a cons of (TABLE-CELL-STYLE-NAME . PARAGRAPH-STYLE-NAME).
@@ -3656,8 +3663,8 @@ information."
CONTENTS is nil. INFO is a plist used as a communication
channel."
(let* ((raw-value (org-element-property :raw-value timestamp))
- (type (org-element-property :type timestamp)))
- (if (not org-odt-use-date-fields)
+ (type (org-element-property :type timestamp)))
+ (if (not (plist-get info :odt-use-date-fields))
(let ((value (org-odt-plain-text
(org-timestamp-translate timestamp) info)))
(case (org-element-property :type timestamp)
@@ -3693,7 +3700,7 @@ channel."
(format "<text:span text:style-name=\"%s\">%s</text:span>"
"OrgDiaryTimestamp"
(org-odt-plain-text (org-timestamp-translate timestamp)
- info)))))))
+ info)))))))
;;;; Underline