diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2012-02-08 22:36:18 +0100 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2012-02-08 23:26:02 +0100 |
commit | c804bef74bc7885b73d8008af826c61ac9176b8c (patch) | |
tree | 5f42d0440b458e1b76008bfc080253a580f81e61 | |
parent | f4a568f06a956eb6b4496c712f572af296fa5d89 (diff) | |
download | org-mode-c804bef74bc7885b73d8008af826c61ac9176b8c.tar.gz |
org-e-latex: Small refactoring
* EXPERIMENTAL/org-e-latex.el (org-e-latex-table--format-string):
Small refactoring.
-rw-r--r-- | EXPERIMENTAL/org-e-latex.el | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/EXPERIMENTAL/org-e-latex.el b/EXPERIMENTAL/org-e-latex.el index d328248..8e92ee0 100644 --- a/EXPERIMENTAL/org-e-latex.el +++ b/EXPERIMENTAL/org-e-latex.el @@ -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 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)) (caption (org-e-latex--caption/label-string (org-element-get-property :caption table) label info)) - (attr (mapconcat #'identity + (attr (mapconcat 'identity (org-element-get-property :attr_latex table) " ")) ;; Determine alignment string. @@ -1727,8 +1728,8 @@ The format string one placeholder for the body of the table." (table-env (cond ((not attr) org-e-latex-default-table-environment) ((string-match "\\<longtable\\>" attr) "longtable") - ((string-match "\\(tabular.\\)" attr) - (org-match-string-no-properties 1 attr)) + ((string-match "\\<tabular.?\\>" attr) + (org-match-string-no-properties 0 attr)) (t org-e-latex-default-table-environment))) ;; If table is a float, determine environment: table or table*. (float-env (cond @@ -1739,29 +1740,23 @@ The format string one placeholder for the body of the table." "table*") ((or (not (string= caption "")) label) "table"))) ;; Extract others display options. - (width (and attr - (string-match "\\<width=\\(\\S-+\\)" attr) + (width (and attr (string-match "\\<width=\\(\\S-+\\)" attr) (org-match-string-no-properties 1 attr))) - (placement (if (and attr - (string-match "\\<placement=\\(\\S-+\\)" attr)) - (org-match-string-no-properties 1 attr) - (concat "[" - org-e-latex-default-figure-position - "]")))) + (placement + (if (and attr (string-match "\\<placement=\\(\\S-+\\)" attr)) + (org-match-string-no-properties 1 attr) + (format "[%s]" org-e-latex-default-figure-position)))) ;; Prepare the final format string for the table. (cond ;; Longtable. ((string= "longtable" table-env) - (format "\\begin{longtable}{%s}\n%s\n%%s\n%s\\end{longtable}" - alignment - (if (or (not org-e-latex-table-caption-above) - (string= "" caption)) - "" - (concat (org-trim caption) "\\\\")) - (if (or org-e-latex-table-caption-above - (string= "" caption)) - "" - (concat (org-trim caption) "\\\\\n")))) + (format + "\\begin{longtable}{%s}\n%s\n%%s\n%s\\end{longtable}" + alignment + (if (or (not org-e-latex-table-caption-above) (string= "" caption)) "" + (concat (org-trim caption) "\\\\")) + (if (or org-e-latex-table-caption-above (string= "" caption)) "" + (concat (org-trim caption) "\\\\\n")))) ;; Others. (t (concat (when float-env (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") (format "\\begin{%s}%s{%s}\n%%s\n\\end{%s}" table-env - (if width (format "{%s}" width) "") - alignment - table-env) + (if width (format "{%s}" width) "") alignment table-env) (when org-e-latex-tables-centered "\n\\end{center}") (when float-env (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) (require 'table) ;; Ensure "*org-export-table*" buffer is empty. - (and (get-buffer "*org-export-table*") - (kill-buffer (get-buffer "*org-export-table*"))) + (with-current-buffer (get-buffer-create "*org-export-table*") + (erase-buffer)) (let ((output (with-temp-buffer (insert raw-table) (goto-char 1) @@ -1848,10 +1841,10 @@ CONTENTS is nil. INFO is a plist holding contextual information." (while (and (< (length output) pos) (setq pos (string-match "^\\\\hline\n?" output pos))) (incf n) - (unless (= n 2) (setq output (replace-match "" nil nil output)))))) - (if org-e-latex-tables-centered - (format "\\begin{center}\n%s\n\\end{center}" output) - output))) + (unless (= n 2) + (setq output (replace-match "" nil nil output)))))) + (if (not org-e-latex-tables-centered) output + (format "\\begin{center}\n%s\n\\end{center}" output)))) ;; Case 3: Standard table. (t (let* ((table-info (org-export-table-format-info raw-table)) |