diff --git a/doc/org.texi b/doc/org.texi index 3e5e7d552..ab32569e4 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -1554,7 +1554,8 @@ exchange with, for example, spreadsheet or database programs. The format used to export the file can be configured in the variable @code{org-table-export-default-format}. You may also use properties @code{TABLE_EXPORT_FILE} and @code{TABLE_EXPORT_FORMAT} to specify the file -name and the format for table export in a subtree. +name and the format for table export in a subtree. For the possible export +transformations, see @ref{Translator functions}. @end table If you don't like the automatic table editor because it gets in your diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 71e26bbd2..3ecad1fce 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2008-05-10 Carsten Dominik + + * org-table.el (org-table-export-default-format): Remove :splice + from default format, we get the same effect by not specifying + :tstart and :tend. + (org-table-export): Improve setup, distinguish better between + interactive and non-interactive use, allow specifying the format + on the fly, better protection against wrong file names. + (orgtbl-to-generic): Fix documentation. Do not require :tstart + and :tend when :splice is omitted. + 2008-05-09 Bernt Hansen * org-clock.el (org-clock-select-task): Make sure the selection diff --git a/lisp/org-table.el b/lisp/org-table.el index a3a52c10d..86e5f09ba 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -249,12 +249,11 @@ Automatically means, when TAB or RET or C-c C-c are pressed in the line." :tag "Org Table Import Export" :group 'org-table) -(defcustom org-table-export-default-format - "orgtbl-to-generic :splice t :sep \"\t\"" +(defcustom org-table-export-default-format "orgtbl-to-generic :sep \"\t\"" "Default export parameters for org-table-export. These can be - overridden on for a specific table by setting the - TABLE_EXPORT_FORMAT parameter. See orgtbl-export for the - different export transforms and available parameters." +overridden on for a specific table by setting the TABLE_EXPORT_FORMAT +property. See the manual section on orgtbl radio tables for the different +export transformations and available parameters." :group 'org-table-import-export :type 'string) @@ -428,7 +427,7 @@ are found, lines will be split on whitespace into fields." (defvar org-table-last-alignment) (defvar org-table-last-column-widths) (defun org-table-export (&optional file format) - "Export table as a tab-separated file. + "Export table to a file, with configurable format. Such a file can be imported into a spreadsheet program like Excel. FILE can be the output file name. If not given, it will be taken from a TABLE_EXPORT_FILE property in the current entry or higher up in the @@ -439,19 +438,31 @@ be found in the variable `org-table-export-default-format', but the function first checks if there is an export format specified in a TABLE_EXPORT_FORMAT property, locally or anywhere up in the hierarchy." (interactive) + (require 'org-exp) (org-table-align) ;; make sure we have everything we need (let* ((beg (org-table-begin)) (end (org-table-end)) (txt (buffer-substring-no-properties beg end)) - (file (or file (org-entry-get beg "TABLE_EXPORT_FILE" t) - (read-file-name "Export table to: "))) - (format (or (org-entry-get beg "TABLE_EXPORT_FORMAT" t) - org-table-export-default-format)) - buf) - (unless (or (not (file-exists-p file)) - (y-or-n-p (format "Overwrite file %s? " file))) - (error "Abort")) - (message format) + (file (or file (org-entry-get beg "TABLE_EXPORT_FILE" t))) + (format (or format (org-entry-get beg "TABLE_EXPORT_FORMAT" t))) + buf deffmt-readable) + (unless file + (setq file (read-file-name "Export table to: ")) + (unless (or (not (file-exists-p file)) + (y-or-n-p (format "Overwrite file %s? " file))) + (error "Abort"))) + (if (file-directory-p file) + (error "This is a directory path, not a file")) + (if (equal (file-truename file) + (file-truename (buffer-file-name))) + (error "Please specify a file name that is different from current")) + (unless format + (setq deffmt-readable org-table-export-default-format) + (while (string-match "\t" deffmt-readable) + (setq deffmt-readable (replace-match "\\t" t t deffmt-readable))) + (while (string-match "\n" deffmt-readable) + (setq deffmt-readable (replace-match "\\n" t t deffmt-readable))) + (setq format (read-string "Format: " deffmt-readable))) (if (string-match "\\([^ \t\r\n]+\\)\\( +.*\\)?" format) (let* ((transform (intern (match-string 1 format))) @@ -3701,8 +3712,7 @@ TABLE is a list, each entry either the symbol `hline' for a horizontal separator line, or a list of fields for that line. PARAMS is a property list of parameters that can influence the conversion. For the generic converter, some parameters are obligatory: You need to -specify either :lfmt, or all of (:lstart :lend :sep). If you do not use -:splice, you must have :tstart and :tend. +specify either :lfmt, or all of (:lstart :lend :sep). Valid parameters are @@ -3771,10 +3781,9 @@ directly by `orgtbl-send-table'. See manual." ;; Put header (unless splicep - (if (not (plist-member params :tstart)) - (push "ERROR: no :tstart" *orgtbl-rtn*) - (let ((tstart (orgtbl-eval-str (plist-get params :tstart)))) - (if tstart (push tstart *orgtbl-rtn*))))) + (when (plist-member params :tstart) + (let ((tstart (orgtbl-eval-str (plist-get params :tstart)))) + (if tstart (push tstart *orgtbl-rtn*))))) ;; Do we have a heading section? If so, format it and handle the ;; trailing hline. @@ -3801,8 +3810,7 @@ directly by `orgtbl-send-table'. See manual." (orgtbl-format-section nil) (unless splicep - (if (not (plist-member params :tend)) - (push "ERROR: no :tend" *orgtbl-rtn*) + (when (plist-member params :tend) (let ((tend (orgtbl-eval-str (plist-get params :tend)))) (if tend (push tend *orgtbl-rtn*))))) diff --git a/lisp/org.el b/lisp/org.el index a85cb1dc8..cf98ed232 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -9580,7 +9580,8 @@ but in some other way.") (defconst org-default-properties '("ARCHIVE" "CATEGORY" "SUMMARY" "DESCRIPTION" - "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY") + "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY" + "TABLE_EXPORT_FORMAT" "TABLE_EXPORT_FILE") "Some properties that are used by Org-mode for various purposes. Being in this list makes sure that they are offered for completion.")