emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [RFC] Changing internal representation of back-ends to defstruct


From: Nicolas Goaziou
Subject: Re: [O] [RFC] Changing internal representation of back-ends to defstructs
Date: Thu, 04 Jul 2013 15:42:31 +0200

Completing myself,

> I applied the patches. Now, onto orgtbl-to-*.

Here is an example illustrating the new features provided by quick and
anonymous export back-ends:

#+begin_src emacs-lisp
(defun my-orgtbl-to-csv ()
  "Insert a comma separated version of Org table at point.
The table will be inserted at the end of the buffer.  This
function makes no assumption about the major mode in the current
back-end."
  (interactive)
  (unless (org-at-table-p) (user-error "Not at an Org table"))
  (require 'ox-org)
  (let ((table
         (org-export-string-as
          ;; Export the following table...
          (buffer-substring-no-properties (org-table-begin) (org-table-end))
          ;; ... with the following back-end.
          (org-export-create-backend
           :parent 'org
           :transcoders
           '((table . (lambda (table contents info) contents))
             (table-row . (lambda (row contents info)
                            ;; Ignore table separators.
                            (and (eq (org-element-property :type row) 'standard)
                                 (concat contents "\n"))))
             (table-cell . (lambda (cell contents info)
                             (let ((field (org-quote-csv-field contents)))
                               (if (org-export-get-next-element cell info)
                                   (concat field ",")
                                 field))))))
          ;; Focus on the table only.
          'body-only)))
    ;; Insert TABLE at an appropriate location.  For the sake of
    ;; example, it will be point-max.
    (goto-char (point-max))
    (insert table)))
#+end_src

-- 
Nicolas Goaziou



reply via email to

[Prev in Thread] Current Thread [Next in Thread]