Use options instead of hard-coded variables

* lisp/ox-beamer.el (org-beamer--format-frame,
  org-beamer--format-block, org-beamer-template): Use options instead
  of hard-coded variables.

* lisp/ox-man.el (org-man-inline-src-block, org-man-src-block,
  org-man-table, org-man-table-cell): Use options instead of
  hard-coded variables.

* lisp/ox-md.el (org-md-headline): Use options instead of hard-coded
  variables.

* lisp/ox-texinfo.el (org-texinfo-format-headline-function,
  org-texinfo-format-inlinetask-function): Change default value.
(org-texinfo--text-markup, org-texinfo--format-menu): Change signature
(org-texinfo--build-menu, org-texinfo-bold, org-texinfo-code,
org-texinfo-comment, org-texinfo-italic, org-texinfo-verbatim): Apply
signature change.

(org-texinfo-template, org-texinfo-clock, org-texinfo-drawer,
org-texinfo-link, org-texinfo-plain-list, org-texinfo-planning,
org-texinfo-table, org-texinfo-table-cell, org-texinfo-timestamp): Use
options instead of variable names.

(org-texinfo-format-headline-default-function,
org-texinfo-format-inlinetask-default-function): New functions.
(org-texinfo-headline, org-texinfo-inlinetask): Use new functions.
This commit is contained in:
Nicolas Goaziou 2014-07-28 15:44:56 +02:00
parent fd448cb1e2
commit 0540dccadd
4 changed files with 131 additions and 177 deletions

View File

@ -406,7 +406,8 @@ used as a communication channel."
;; Collect options from default value and headline's
;; properties. Also add a label for links.
(append
(org-split-string org-beamer-frame-default-options ",")
(org-split-string
(plist-get info :beamer-frame-default-options) ",")
(and beamer-opt
(org-split-string
;; Remove square brackets if user provided
@ -468,7 +469,7 @@ used as a communication channel."
(env-format
(cond ((member environment '("column" "columns")) nil)
((assoc environment
(append org-beamer-environments-extra
(append (plist-get info :beamer-environments-extra)
org-beamer-environments-default)))
(t (user-error "Wrong block type at a headline named \"%s\""
raw-title))))
@ -875,8 +876,8 @@ holding export options."
(concat
(format "\\begin{frame}%s{%s}\n"
(org-beamer--normalize-argument
org-beamer-outline-frame-options 'option)
org-beamer-outline-frame-title)
(plist-get info :beamer-outline-frame-options) 'option)
(plist-get info :beamer-outline-frame-title))
(when (wholenump depth)
(format "\\setcounter{tocdepth}{%d}\n" depth))
"\\tableofcontents\n"

View File

@ -522,7 +522,7 @@ CONTENTS holds the contents of the item. INFO is a plist holding
contextual information."
(let* ((code (org-element-property :value inline-src-block)))
(cond
(org-man-source-highlight
((plist-get info :man-source-highlight)
(let* ((tmpdir (if (featurep 'xemacs)
temp-directory
temporary-file-directory ))
@ -531,8 +531,9 @@ contextual information."
(out-file (make-temp-name
(expand-file-name "reshilite" tmpdir)))
(org-lang (org-element-property :language inline-src-block))
(lst-lang (cadr (assq (intern org-lang)
org-man-source-highlight-langs)))
(lst-lang
(cadr (assq (intern org-lang)
(plist-get info :man-source-highlight-langs))))
(cmd (concat (expand-file-name "source-highlight")
" -s " lst-lang
@ -785,31 +786,22 @@ contextual information."
(continued (org-export-get-loc src-block info))
(new 0)))
(retain-labels (org-element-property :retain-labels src-block)))
(cond
;; Case 1. No source fontification.
((not org-man-source-highlight)
(format ".RS\n.nf\n\\fC%s\\fP\n.fi\n.RE\n\n"
(org-export-format-code-default src-block info)))
(org-man-source-highlight
(let* ((tmpdir (if (featurep 'xemacs)
temp-directory
temporary-file-directory ))
(in-file (make-temp-name
(expand-file-name "srchilite" tmpdir)))
(out-file (make-temp-name
(expand-file-name "reshilite" tmpdir)))
(if (not (plist-get info :man-source-highlight))
(format ".RS\n.nf\n\\fC%s\\fP\n.fi\n.RE\n\n"
(org-export-format-code-default src-block info))
(let* ((tmpdir (if (featurep 'xemacs) temp-directory
temporary-file-directory))
(in-file (make-temp-name (expand-file-name "srchilite" tmpdir)))
(out-file (make-temp-name (expand-file-name "reshilite" tmpdir)))
(org-lang (org-element-property :language src-block))
(lst-lang (cadr (assq (intern org-lang)
org-man-source-highlight-langs)))
(lst-lang
(cadr (assq (intern org-lang)
(plist-get info :man-source-highlight-langs))))
(cmd (concat "source-highlight"
" -s " lst-lang
" -f groff_man "
" -i " in-file
" -o " out-file)))
(if lst-lang
(let ((code-block ""))
(with-temp-file in-file (insert code))
@ -818,7 +810,7 @@ contextual information."
(delete-file in-file)
(delete-file out-file)
code-block)
(format ".RS\n.nf\n\\fC\\m[black]%s\\m[]\\fP\n.fi\n.RE" code)))))))
(format ".RS\n.nf\n\\fC\\m[black]%s\\m[]\\fP\n.fi\n.RE" code))))))
;;; Statistics Cookie
@ -871,7 +863,7 @@ CONTENTS is the contents of the table. INFO is a plist holding
contextual information."
(cond
;; Case 1: verbatim table.
((or org-man-tables-verbatim
((or (plist-get info :man-tables-verbatim)
(let ((attr (read (format "(%s)"
(mapconcat
#'identity
@ -946,7 +938,8 @@ This function assumes TABLE has `org' as its `:type' attribute."
(let ((placement (plist-get attr :placement)))
(cond ((string= placement 'center) "center")
((string= placement 'left) nil)
(t (if org-man-tables-centered "center" ""))))
((plist-get info :man-tables-centered) "center")
(t "")))
(or (plist-get attr :boxtype) "box"))))
(title-line (plist-get attr :title-line))
@ -1021,16 +1014,17 @@ This function assumes TABLE has `org' as its `:type' attribute."
"Transcode a TABLE-CELL element from Org to Man
CONTENTS is the cell contents. INFO is a plist used as
a communication channel."
(concat (if (and contents
org-man-table-scientific-notation
(string-match orgtbl-exp-regexp contents))
;; Use appropriate format string for scientific
;; notation.
(format org-man-table-scientific-notation
(match-string 1 contents)
(match-string 2 contents))
contents )
(when (org-export-get-next-element table-cell info) "\t")))
(concat
(let ((scientific-format (plist-get info :man-table-scientific-notation)))
(if (and contents
scientific-format
(string-match orgtbl-exp-regexp contents))
;; Use appropriate format string for scientific notation.
(format scientific-format
(match-string 1 contents)
(match-string 2 contents))
contents))
(when (org-export-get-next-element table-cell info) "\t")))
;;; Table Row

View File

@ -193,13 +193,14 @@ a communication channel."
(org-export-get-headline-number
headline info) "-"))))))
;; Headline text without tags.
(heading (concat todo priority title)))
(heading (concat todo priority title))
(style (plist-get info :md-headline-style)))
(cond
;; Cannot create a headline. Fall-back to a list.
((or (org-export-low-level-p headline info)
(not (memq org-md-headline-style '(atx setext)))
(and (eq org-md-headline-style 'atx) (> level 6))
(and (eq org-md-headline-style 'setext) (> level 2)))
(not (memq style '(atx setext)))
(and (eq style 'atx) (> level 6))
(and (eq style 'setext) (> level 2)))
(let ((bullet
(if (not (org-export-numbered-headline-p headline info)) "-"
(concat (number-to-string
@ -211,7 +212,7 @@ a communication channel."
(and contents
(replace-regexp-in-string "^" " " contents)))))
;; Use "Setext" style.
((eq org-md-headline-style 'setext)
((eq style 'setext)
(concat heading tags anchor "\n"
(make-string (length heading) (if (= level 1) ?= ?-))
"\n\n"

View File

@ -215,7 +215,8 @@ a format string in which the section title will be added."
;;; Headline
(defcustom org-texinfo-format-headline-function 'ignore
(defcustom org-texinfo-format-headline-function
'org-texinfo-format-headline-default-function
"Function to format headline text.
This function will be called with 5 arguments:
@ -225,23 +226,11 @@ PRIORITY the priority of the headline (integer or nil)
TEXT the main headline text (string).
TAGS the tags as a list of strings (list of strings or nil).
The function result will be used in the section format string.
As an example, one could set the variable to the following, in
order to reproduce the default set-up:
\(defun org-texinfo-format-headline (todo todo-type priority text tags)
\"Default format function for a headline.\"
\(concat (when todo
\(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
\(when priority
\(format \"\\\\framebox{\\\\#%c} \" priority))
text
\(when tags
\(format \"\\\\hfill{}\\\\textsc{%s}\"
\(mapconcat 'identity tags \":\"))))"
The function result will be used in the section format string."
:group 'org-export-texinfo
:type 'function)
:type 'function
:version "24.5"
:package-version '(Org . "8.3"))
;;; Node listing (menu)
@ -349,7 +338,8 @@ The default function simply returns the value of CONTENTS."
;;; Inlinetasks
(defcustom org-texinfo-format-inlinetask-function 'ignore
(defcustom org-texinfo-format-inlinetask-function
'org-texinfo-format-inlinetask-default-function
"Function called to format an inlinetask in Texinfo code.
The function must accept six parameters:
@ -360,26 +350,7 @@ The function must accept six parameters:
TAGS the inlinetask tags, as a list of strings.
CONTENTS the contents of the inlinetask, as a string.
The function should return the string to be exported.
For example, the variable could be set to the following function
in order to mimic default behavior:
\(defun org-texinfo-format-inlinetask \(todo type priority name tags contents\)
\"Format an inline task element for Texinfo export.\"
\(let ((full-title
\(concat
\(when todo
\(format \"@strong{%s} \" todo))
\(when priority (format \"#%c \" priority))
title
\(when tags
\(format \":%s:\"
\(mapconcat 'identity tags \":\")))))
\(format (concat \"@center %s\n\n\"
\"%s\"
\"\n\"))
full-title contents))"
The function should return the string to be exported."
:group 'org-export-texinfo
:type 'function)
@ -458,9 +429,10 @@ nil."
options
","))
(defun org-texinfo--text-markup (text markup)
(defun org-texinfo--text-markup (text markup info)
"Format TEXT depending on MARKUP text markup.
See `org-texinfo-text-markup-alist' for details."
INFO is a plist used as a communication channel. See
`org-texinfo-text-markup-alist' for details."
(let ((fmt (cdr (assq markup org-texinfo-text-markup-alist))))
(cond
;; No format string: Return raw text.
@ -563,7 +535,7 @@ recurse into all children as well."
(t
(setq text-menu (org-texinfo--generate-menu-items menu info))))
(when text-menu
(setq output (org-texinfo--format-menu text-menu))
(setq output (org-texinfo--format-menu text-menu info))
(mapconcat 'identity output "\n"))))
(defun org-texinfo--generate-detailed (menu level info)
@ -648,8 +620,9 @@ entries."
(org-element-property :title headline) info)))
(list -1 title 'nil)))
(defun org-texinfo--format-menu (text-menu)
(defun org-texinfo--format-menu (text-menu info)
"Format the TEXT-MENU items to be properly printed in the menu.
INFO is a plist containing contextual information.
Each entry in the menu should be provided as (length title
description).
@ -663,29 +636,22 @@ Other menu items are output as:
With the spacing between :: and description based on the length
of the longest menu entry."
(let (output)
(setq output
(mapcar (lambda (name)
(let* ((title (nth 1 name))
(desc (nth 2 name))
(length (nth 0 name))
(column (max
;;6 is "* " ":: " for inserted text
length
(-
org-texinfo-node-description-column
6)))
(spacing (- column length)
))
(if (> length -1)
(concat "* " title ":: "
(make-string spacing ?\s)
(if desc
(concat desc)))
(concat "\n" title "\n"))))
text-menu))
output))
(mapcar
(lambda (name)
(let* ((title (nth 1 name))
(desc (nth 2 name))
(length (nth 0 name))
(column (max
length
;; 6 is "* " ":: " for inserted text
(- (plist-get info :texinfo-node-description-column) 6)))
(spacing (- column length)))
(if (> length -1)
(concat "* " title ":: "
(make-string spacing ?\s)
(and desc (concat desc)))
(concat "\n" title "\n"))))
text-menu))
;;; Template
@ -704,7 +670,7 @@ holding export options."
(subtitle (plist-get info :subtitle))
(subauthor (plist-get info :subauthor))
(class (plist-get info :texinfo-class))
(header (nth 1 (assoc class org-texinfo-classes)))
(header (nth 1 (assoc class (plist-get info :texinfo-classes))))
(copying
(org-element-map (plist-get info :parse-tree) 'headline
(lambda (hl) (and (org-element-property :COPYING hl) hl)) info t))
@ -837,7 +803,7 @@ holding export options."
"Transcode BOLD from Org to Texinfo.
CONTENTS is the text with bold markup. INFO is a plist holding
contextual information."
(org-texinfo--text-markup contents 'bold))
(org-texinfo--text-markup contents 'bold info))
;;; Center Block
@ -856,7 +822,7 @@ information."
(concat
"@noindent"
(format "@strong{%s} " org-clock-string)
(format org-texinfo-inactive-timestamp-format
(format (plist-get info :texinfo-inactive-timestamp-format)
(concat (org-translate-time
(org-element-property :raw-value
(org-element-property :value clock)))
@ -870,7 +836,7 @@ information."
"Transcode a CODE object from Org to Texinfo.
CONTENTS is nil. INFO is a plist used as a communication
channel."
(org-texinfo--text-markup (org-element-property :value code) 'code))
(org-texinfo--text-markup (org-element-property :value code) 'code info))
;;; Comment
@ -878,7 +844,8 @@ channel."
"Transcode a COMMENT object from Org to Texinfo.
CONTENTS is the text in the comment. INFO is a plist holding
contextual information."
(org-texinfo--text-markup (org-element-property :value comment) 'comment))
(org-texinfo--text-markup
(org-element-property :value comment) 'comment info))
;;; Comment Block
@ -895,7 +862,7 @@ contextual information."
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-texinfo-format-drawer-function
(output (funcall (plist-get info :texinfo-format-drawer-function)
name contents)))
output))
@ -964,7 +931,7 @@ holding contextual information."
(let* ((class (plist-get info :texinfo-class))
(level (org-export-get-relative-level headline info))
(numberedp (org-export-numbered-headline-p headline info))
(class-sectioning (assoc class org-texinfo-classes))
(class-sectioning (assoc class (plist-get info :texinfo-classes)))
;; Find the index type, if any
(index (org-element-property :INDEX headline))
;; Check if it is an appendix
@ -1020,7 +987,7 @@ holding contextual information."
"unnumbered"
"appendix"
(cdr sec)) "\n%s"))
;; Otherwise number as needed.
;; Otherwise number as needed.
(t
(concat menu node
(funcall
@ -1037,30 +1004,12 @@ holding contextual information."
;; Create the headline text along with a no-tag version. The
;; latter is required to remove tags from table of contents.
(full-text (org-texinfo--sanitize-content
(if (not (eq org-texinfo-format-headline-function 'ignore))
;; User-defined formatting function.
(funcall org-texinfo-format-headline-function
todo todo-type priority text tags)
;; Default formatting.
(concat
(when todo
(format "@strong{%s} " todo))
(when priority (format "@emph{#%s} " priority))
text
(when tags
(format " :%s:"
(mapconcat 'identity tags ":")))))))
(funcall (plist-get info :texinfo-format-headline-function)
todo todo-type priority text tags)))
(full-text-no-tag
(org-texinfo--sanitize-content
(if (not (eq org-texinfo-format-headline-function 'ignore))
;; User-defined formatting function.
(funcall org-texinfo-format-headline-function
todo todo-type priority text nil)
;; Default formatting.
(concat
(when todo (format "@strong{%s} " todo))
(when priority (format "@emph{#%c} " priority))
text))))
(funcall (plist-get info :texinfo-format-headline-function)
todo todo-type priority text nil)))
(pre-blanks
(make-string (org-element-property :pre-blank headline) 10)))
(cond
@ -1127,6 +1076,15 @@ holding contextual information."
(format (replace-regexp-in-string "%]" "%%]" section-fmt) full-text
(concat pre-blanks contents))))))))
(defun org-texinfo-format-headline-default-function
(todo todo-type priority text tags)
"Default format function for a headline.
See `org-texinfo-format-headline-function' for details."
(concat (when todo (format "@strong{%s} " todo))
(when priority (format "@emph{#%s} " priority))
text
(when tags (format " :%s:" (mapconcat 'identity tags ":")))))
;;; Inline Src Block
(defun org-texinfo-inline-src-block (inline-src-block contents info)
@ -1152,23 +1110,19 @@ holding contextual information."
(org-export-get-tags inlinetask info)))
(priority (and (plist-get info :with-priority)
(org-element-property :priority inlinetask))))
;; If `org-texinfo-format-inlinetask-function' is provided, call it
;; with appropriate arguments.
(if (not (eq org-texinfo-format-inlinetask-function 'ignore))
(funcall org-texinfo-format-inlinetask-function
todo todo-type priority title tags contents)
;; Otherwise, use a default template.
(let ((full-title
(concat
(when todo (format "@strong{%s} " todo))
(when priority (format "#%c " priority))
title
(when tags (format ":%s:"
(mapconcat 'identity tags ":"))))))
(format (concat "@center %s\n\n"
"%s"
"\n")
full-title contents)))))
(funcall (plist-get info :texinfo-format-inlinetask-function)
todo todo-type priority title tags contents)))
(defun org-texinfo-format-inlinetask-default-function
(todo todo-type priority title tags contents)
"Default format function for a inlinetasks.
See `org-texinfo-format-inlinetask-function' for details."
(let ((full-title
(concat (when todo (format "@strong{%s} " todo))
(when priority (format "#%c " priority))
title
(when tags (format ":%s:" (mapconcat #'identity tags ":"))))))
(format "@center %s\n\n%s\n" full-title contents)))
;;; Italic
@ -1176,7 +1130,7 @@ holding contextual information."
"Transcode ITALIC from Org to Texinfo.
CONTENTS is the text with italic markup. INFO is a plist holding
contextual information."
(org-texinfo--text-markup contents 'italic))
(org-texinfo--text-markup contents 'italic info))
;;; Item
@ -1284,7 +1238,8 @@ INFO is a plist holding contextual information. See
;; External link without a description part.
(path (format "@uref{%s}" path))
;; No path, only description. Try to do something useful.
(t (format org-texinfo-link-with-unknown-path-format desc)))))
(t
(format (plist-get info :texinfo-link-with-unknown-path-format) desc)))))
;;; Menu
@ -1334,7 +1289,7 @@ CONTENTS is the contents of the list. INFO is a plist holding
contextual information."
(let* ((attr (org-export-read-attribute :attr_texinfo plain-list))
(indic (or (plist-get attr :indic)
org-texinfo-def-table-markup))
(plist-get info :texinfo-def-table-markup)))
(type (org-element-property :type plain-list))
(table-type (plist-get attr :table-type))
;; Ensure valid texinfo table type.
@ -1398,21 +1353,21 @@ information."
(when closed
(concat
(format "@strong{%s} " org-closed-string)
(format org-texinfo-inactive-timestamp-format
(format (plist-get info :texinfo-inactive-timestamp-format)
(org-translate-time
(org-element-property :raw-value closed))))))
(let ((deadline (org-element-property :deadline planning)))
(when deadline
(concat
(format "@strong{%s} " org-deadline-string)
(format org-texinfo-active-timestamp-format
(format (plist-get info :texinfo-active-timestamp-format)
(org-translate-time
(org-element-property :raw-value deadline))))))
(let ((scheduled (org-element-property :scheduled planning)))
(when scheduled
(concat
(format "@strong{%s} " org-scheduled-string)
(format org-texinfo-active-timestamp-format
(format (plist-get info :texinfo-active-timestamp-format)
(org-translate-time
(org-element-property :raw-value scheduled))))))))
" ")
@ -1528,7 +1483,7 @@ CONTENTS is the contents of the table. INFO is a plist holding
contextual information."
(cond
;; Case 1: verbatim table.
((or org-texinfo-tables-verbatim
((or (plist-get info :texinfo-tables-verbatim)
(let ((attr (mapconcat 'identity
(org-element-property :attr_latex table)
" ")))
@ -1606,16 +1561,18 @@ Rather than return an invalid table, nothing is returned."
"Transcode a TABLE-CELL element from Org to Texinfo.
CONTENTS is the cell contents. INFO is a plist used as
a communication channel."
(concat (if (and contents
org-texinfo-table-scientific-notation
(string-match orgtbl-exp-regexp contents))
;; Use appropriate format string for scientific
;; notation.
(format org-texinfo-table-scientific-notation
(match-string 1 contents)
(match-string 2 contents))
contents)
(when (org-export-get-next-element table-cell info) "\n@tab ")))
(concat
(let ((scientific-notation
(plist-get info :texinfo-table-scientific-notation)))
(if (and contents
scientific-notation
(string-match orgtbl-exp-regexp contents))
;; Use appropriate format string for scientific notation.
(format scientific-notation
(match-string 1 contents)
(match-string 2 contents))
contents))
(when (org-export-get-next-element table-cell info) "\n@tab ")))
;;; Table Row
@ -1659,10 +1616,10 @@ information."
(org-timestamp-translate timestamp) info)))
(case (org-element-property :type timestamp)
((active active-range)
(format org-texinfo-active-timestamp-format value))
(format (plist-get info :texinfo-active-timestamp-format) value))
((inactive inactive-range)
(format org-texinfo-inactive-timestamp-format value))
(t (format org-texinfo-diary-timestamp-format value)))))
(format (plist-get info :texinfo-inactive-timestamp-format) value))
(t (format (plist-get info :texinfo-diary-timestamp-format) value)))))
;;; Verbatim
@ -1670,7 +1627,8 @@ information."
"Transcode a VERBATIM object from Org to Texinfo.
CONTENTS is nil. INFO is a plist used as a communication
channel."
(org-texinfo--text-markup (org-element-property :value verbatim) 'verbatim))
(org-texinfo--text-markup
(org-element-property :value verbatim) 'verbatim info))
;;; Verse Block