org-e-latex: Small refactoring

* EXPERIMENTAL/org-e-latex.el (org-e-latex-table--format-string):
  Small refactoring.
This commit is contained in:
Nicolas Goaziou 2012-02-08 22:36:18 +01:00
parent f4a568f06a
commit c804bef74b
1 changed files with 24 additions and 31 deletions

View File

@ -1714,11 +1714,12 @@ TABLE-INFO is the plist containing format info about the table,
as returned by `org-export-table-format-info'. INFO is a plist as returned by `org-export-table-format-info'. INFO is a plist
used as a communication channel. used as a communication channel.
The format string one placeholder for the body of the table." The format string leaves one placeholder for the body of the
table."
(let* ((label (org-element-get-property :name table)) (let* ((label (org-element-get-property :name table))
(caption (org-e-latex--caption/label-string (caption (org-e-latex--caption/label-string
(org-element-get-property :caption table) label info)) (org-element-get-property :caption table) label info))
(attr (mapconcat #'identity (attr (mapconcat 'identity
(org-element-get-property :attr_latex table) (org-element-get-property :attr_latex table)
" ")) " "))
;; Determine alignment string. ;; Determine alignment string.
@ -1727,8 +1728,8 @@ The format string one placeholder for the body of the table."
(table-env (cond (table-env (cond
((not attr) org-e-latex-default-table-environment) ((not attr) org-e-latex-default-table-environment)
((string-match "\\<longtable\\>" attr) "longtable") ((string-match "\\<longtable\\>" attr) "longtable")
((string-match "\\(tabular.\\)" attr) ((string-match "\\<tabular.?\\>" attr)
(org-match-string-no-properties 1 attr)) (org-match-string-no-properties 0 attr))
(t org-e-latex-default-table-environment))) (t org-e-latex-default-table-environment)))
;; If table is a float, determine environment: table or table*. ;; If table is a float, determine environment: table or table*.
(float-env (cond (float-env (cond
@ -1739,29 +1740,23 @@ The format string one placeholder for the body of the table."
"table*") "table*")
((or (not (string= caption "")) label) "table"))) ((or (not (string= caption "")) label) "table")))
;; Extract others display options. ;; Extract others display options.
(width (and attr (width (and attr (string-match "\\<width=\\(\\S-+\\)" attr)
(string-match "\\<width=\\(\\S-+\\)" attr)
(org-match-string-no-properties 1 attr))) (org-match-string-no-properties 1 attr)))
(placement (if (and attr (placement
(string-match "\\<placement=\\(\\S-+\\)" attr)) (if (and attr (string-match "\\<placement=\\(\\S-+\\)" attr))
(org-match-string-no-properties 1 attr) (org-match-string-no-properties 1 attr)
(concat "[" (format "[%s]" org-e-latex-default-figure-position))))
org-e-latex-default-figure-position
"]"))))
;; Prepare the final format string for the table. ;; Prepare the final format string for the table.
(cond (cond
;; Longtable. ;; Longtable.
((string= "longtable" table-env) ((string= "longtable" table-env)
(format "\\begin{longtable}{%s}\n%s\n%%s\n%s\\end{longtable}" (format
alignment "\\begin{longtable}{%s}\n%s\n%%s\n%s\\end{longtable}"
(if (or (not org-e-latex-table-caption-above) alignment
(string= "" caption)) (if (or (not org-e-latex-table-caption-above) (string= "" caption)) ""
"" (concat (org-trim caption) "\\\\"))
(concat (org-trim caption) "\\\\")) (if (or org-e-latex-table-caption-above (string= "" caption)) ""
(if (or org-e-latex-table-caption-above (concat (org-trim caption) "\\\\\n"))))
(string= "" caption))
""
(concat (org-trim caption) "\\\\\n"))))
;; Others. ;; Others.
(t (concat (when float-env (t (concat (when float-env
(concat (concat
@ -1770,9 +1765,7 @@ The format string one placeholder for the body of the table."
(when org-e-latex-tables-centered "\\begin{center}\n") (when org-e-latex-tables-centered "\\begin{center}\n")
(format "\\begin{%s}%s{%s}\n%%s\n\\end{%s}" (format "\\begin{%s}%s{%s}\n%%s\n\\end{%s}"
table-env table-env
(if width (format "{%s}" width) "") (if width (format "{%s}" width) "") alignment table-env)
alignment
table-env)
(when org-e-latex-tables-centered "\n\\end{center}") (when org-e-latex-tables-centered "\n\\end{center}")
(when float-env (when float-env
(concat (if org-e-latex-table-caption-above "" caption) (concat (if org-e-latex-table-caption-above "" caption)
@ -1828,8 +1821,8 @@ CONTENTS is nil. INFO is a plist holding contextual information."
((eq (org-element-get-property :type table) 'table.el) ((eq (org-element-get-property :type table) 'table.el)
(require 'table) (require 'table)
;; Ensure "*org-export-table*" buffer is empty. ;; Ensure "*org-export-table*" buffer is empty.
(and (get-buffer "*org-export-table*") (with-current-buffer (get-buffer-create "*org-export-table*")
(kill-buffer (get-buffer "*org-export-table*"))) (erase-buffer))
(let ((output (with-temp-buffer (let ((output (with-temp-buffer
(insert raw-table) (insert raw-table)
(goto-char 1) (goto-char 1)
@ -1848,10 +1841,10 @@ CONTENTS is nil. INFO is a plist holding contextual information."
(while (and (< (length output) pos) (while (and (< (length output) pos)
(setq pos (string-match "^\\\\hline\n?" output pos))) (setq pos (string-match "^\\\\hline\n?" output pos)))
(incf n) (incf n)
(unless (= n 2) (setq output (replace-match "" nil nil output)))))) (unless (= n 2)
(if org-e-latex-tables-centered (setq output (replace-match "" nil nil output))))))
(format "\\begin{center}\n%s\n\\end{center}" output) (if (not org-e-latex-tables-centered) output
output))) (format "\\begin{center}\n%s\n\\end{center}" output))))
;; Case 3: Standard table. ;; Case 3: Standard table.
(t (t
(let* ((table-info (org-export-table-format-info raw-table)) (let* ((table-info (org-export-table-format-info raw-table))