Merge branch 'maint'

This commit is contained in:
Nicolas Goaziou 2015-09-19 13:28:41 +02:00
commit 333edc7dd8
2 changed files with 79 additions and 62 deletions

View File

@ -4772,72 +4772,85 @@ This may be either a string or a function of two arguments:
example \"%s\\\\times10^{%s}\". This may also be a property example \"%s\\\\times10^{%s}\". This may also be a property
list with column numbers and format strings or functions. list with column numbers and format strings or functions.
:fmt will still be applied after :efmt." :fmt will still be applied after :efmt."
(let ((backend (plist-get params :backend)) (let* ((backend (plist-get params :backend))
;; Disable user-defined export filters and hooks. (custom-backend
(org-export-filters-alist nil) ;; Build a custom back-end according to PARAMS. Before
(org-export-before-parsing-hook nil) ;; defining a translator, check if there is anything to do.
(org-export-before-processing-hook nil)) ;; When there isn't, let BACKEND handle the element.
(when (and backend (symbolp backend) (not (org-export-get-backend backend))) (org-export-create-backend
(user-error "Unknown :backend value")) :parent (or backend 'org)
(when (or (not backend) (plist-get params :raw)) (require 'ox-org)) :transcoders
;; Remove final newline. `((table . ,(org-table--to-generic-table params))
(substring (table-row . ,(org-table--to-generic-row params))
(org-export-string-as (table-cell . ,(org-table--to-generic-cell params))
;; Return TABLE as Org syntax. Tolerate non-string cells. ;; Macros are not going to be expanded. However, no
(with-output-to-string ;; regular back-end has a transcoder for them. We
;; provide one so they are not ignored, but displayed
;; as-is instead.
(macro . (lambda (m c i) (org-element-macro-interpreter m nil))))))
data info)
;; Store TABLE as Org syntax in DATA. Tolerate non-string cells.
;; Initialize communication channel in INFO.
(with-temp-buffer
(let ((org-inhibit-startup t)) (org-mode))
(let ((standard-output (current-buffer)))
(dolist (e table) (dolist (e table)
(cond ((eq e 'hline) (princ "|--\n")) (cond ((eq e 'hline) (princ "|--\n"))
((consp e) ((consp e)
(princ "| ") (dolist (c e) (princ c) (princ " |")) (princ "| ") (dolist (c e) (princ c) (princ " |"))
(princ "\n"))))) (princ "\n")))))
;; Build a custom back-end according to PARAMS. Before defining (setq data
;; a translator, check if there is anything to do. When there (org-element-map (org-element-parse-buffer) 'table
;; isn't, let BACKEND handle the element. #'identity nil t))
(org-export-create-backend (setq info (org-export-get-environment backend nil params)))
:parent (or backend 'org) (when (and backend (symbolp backend) (not (org-export-get-backend backend)))
:filters (user-error "Unknown :backend value"))
'((:filter-parse-tree (when (or (not backend) (plist-get info :raw)) (require 'ox-org))
;; Handle :skip parameter. ;; Handle :skip parameter.
(lambda (tree backend info) (let ((skip (plist-get info :skip)))
(let ((skip (plist-get info :skip))) (when skip
(when skip (unless (wholenump skip) (user-error "Wrong :skip value"))
(unless (wholenump skip) (user-error "Wrong :skip value")) (let ((n 0))
(let ((n 0)) (org-element-map data 'table-row
(org-element-map tree 'table-row (lambda (row)
(lambda (row) (if (>= n skip) t
(if (>= n skip) t (org-element-extract-element row)
(org-element-extract-element row) (incf n)
(incf n) nil))
nil)) nil t))))
info t)) ;; Handle :skipcols parameter.
tree))) (let ((skipcols (plist-get info :skipcols)))
;; Handle :skipcols parameter. (when skipcols
(lambda (tree backend info) (unless (consp skipcols) (user-error "Wrong :skipcols value"))
(let ((skipcols (plist-get info :skipcols))) (org-element-map data 'table
(when skipcols (lambda (table)
(unless (consp skipcols) (user-error "Wrong :skipcols value")) (let ((specialp (org-export-table-has-special-column-p table)))
(org-element-map tree 'table (dolist (row (org-element-contents table))
(lambda (table) (when (eq (org-element-property :type row) 'standard)
(let ((specialp (let ((c 1))
(org-export-table-has-special-column-p table))) (dolist (cell (nthcdr (if specialp 1 0)
(dolist (row (org-element-contents table)) (org-element-contents row)))
(when (eq (org-element-property :type row) 'standard) (when (memq c skipcols)
(let ((c 1)) (org-element-extract-element cell))
(dolist (cell (nthcdr (if specialp 1 0) (incf c))))))))))
(org-element-contents row))) ;; Since we are going to export using a low-level mechanism,
(when (memq c skipcols) ;; ignore special column and special rows manually.
(org-element-extract-element cell)) (let ((special? (org-export-table-has-special-column-p data))
(incf c))))))) ignore)
info) (org-element-map data (if special? '(table-cell table-row) 'table-row)
tree))))) (lambda (datum)
:transcoders (when (if (eq (org-element-type datum) 'table-row)
`((table . ,(org-table--to-generic-table params)) (org-export-table-row-is-special-p datum nil)
(table-row . ,(org-table--to-generic-row params)) (org-export-first-sibling-p datum nil))
(table-cell . ,(org-table--to-generic-cell params)) (push datum ignore))))
;; Section. Return contents to avoid garbage around table. (setq info (plist-put info :ignore-list ignore)))
(section . (lambda (s c i) c)))) ;; We use a low-level mechanism to export DATA so as to skip all
'body-only (org-combine-plists params '(:with-tables t))) ;; usual pre-processing and post-processing, i.e., hooks, filters,
0 -1))) ;; Babel code evaluation, include keywords and macro expansion,
;; and filters.
(let ((output (org-export-data-with-backend data custom-backend info)))
;; Remove final newline.
(if (org-string-nw-p output) (substring output 0 -1) ""))))
(defun org-table--generic-apply (value name &optional with-cons &rest args) (defun org-table--generic-apply (value name &optional with-cons &rest args)
(cond ((null value) nil) (cond ((null value) nil)

View File

@ -1453,7 +1453,11 @@ See also `test-org-table/copy-field'."
"a\nb" "a\nb"
(let ((org-export-filter-table-cell-functions (list (lambda (c b i) "filter")))) (let ((org-export-filter-table-cell-functions (list (lambda (c b i) "filter"))))
(orgtbl-to-generic (org-table-to-lisp "| a |\n|---|\n| b |") (orgtbl-to-generic (org-table-to-lisp "| a |\n|---|\n| b |")
'(:hline nil)))))) '(:hline nil)))))
;; Macros, even if unknown, are returned as-is.
(should
(equal "{{{macro}}}"
(orgtbl-to-generic (org-table-to-lisp "| {{{macro}}} |") nil))))
(ert-deftest test-org-table/to-latex () (ert-deftest test-org-table/to-latex ()
"Test `orgtbl-to-latex' specifications." "Test `orgtbl-to-latex' specifications."