From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: [PATCH 3/5] Some improvements to org-table-export Date: Wed, 9 Apr 2008 17:59:20 +0200 Message-ID: <718481B6-C639-4980-A163-A0973EC63248@science.uva.nl> References: <20080316162417.23004.16993.stgit@nyarlathotep.internal> <20080316162920.23004.97374.stgit@nyarlathotep.internal> Mime-Version: 1.0 (Apple Message framework v919.2) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JjdAu-00087u-GO for emacs-orgmode@gnu.org; Wed, 09 Apr 2008 12:29:28 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JjdAt-00086t-Ay for emacs-orgmode@gnu.org; Wed, 09 Apr 2008 12:29:27 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JjdAt-00086i-29 for emacs-orgmode@gnu.org; Wed, 09 Apr 2008 12:29:27 -0400 Received: from fg-out-1718.google.com ([72.14.220.158]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JjdAs-0004YM-GI for emacs-orgmode@gnu.org; Wed, 09 Apr 2008 12:29:26 -0400 Received: by fg-out-1718.google.com with SMTP id d23so3721432fga.30 for ; Wed, 09 Apr 2008 09:29:26 -0700 (PDT) In-Reply-To: <20080316162920.23004.97374.stgit@nyarlathotep.internal> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: James TD Smith Cc: emacs-orgmode@gnu.org Also this is a fine addition, thank you very much. - Carsten On Mar 16, 2008, at 5:29 PM, James TD Smith wrote: > From: James TD Smith > > Specify the file to export to as parameter or property > Use the export mechanisms from orgtbl instead of the simple export. > Specify the table output format in property. > > --- > > org.el | 91 ++++++++++++++++++++++++++++++++++++++++++++ > +------------------- > 1 files changed, 64 insertions(+), 27 deletions(-) > > > diff --git a/org.el b/org.el > index 021bd59..dee8471 100644 > --- a/org.el > +++ b/org.el > @@ -965,6 +965,13 @@ table, obtained by prompting the user." > (list (symbol :tag "Major mode") > (string :tag "Format")))) > > +(defcustom org-table-export-default "orgtbl-to-generic :splice > t :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." > + :group 'org-table) > + > (defgroup org-table-settings nil > "Settings for tables in Org-mode." > :tag "Org Table Settings" > @@ -975,6 +982,7 @@ table, obtained by prompting the user." > :group 'org-table-settings > :type 'string) > > + > (defcustom org-table-number-regexp > "^\\([<>]?[-+^.0-9]*[0-9][-+^.0-9eEdDx()%:]*\\|\\(0[xX]\\)[0-9a-fA- > F]+\\|nan\\)$" > "Regular expression for recognizing numbers in table columns. > @@ -8568,41 +8576,70 @@ are found, lines will be split on whitespace > into fields." > (insert-file-contents file) > (org-table-convert-region beg (+ (point) (- (point-max) pm)) > arg))) > > -(defun org-table-export () > +(defun org-table-export (&optional target) > "Export table as a tab-separated file. > -Such a file can be imported into a spreadsheet program like Excel." > +Such a file can be imported into a spreadsheet program like > +Excel. If TARGET is set, the table is exported to that file. If > +the property TABLE_EXPORT_FILE is set on the entry the table is > +in, the table will be exported to that file. Otherwise the user > +is prompted for a file to write the table to. > + > +If the TABLE_EXPORT_FORMAT property is set, the contents of this > +property will control export format in the same way as radio > +tables in OrgTbl mode. > +" > (interactive) > (let* ((beg (org-table-begin)) > (end (org-table-end)) > - (table (buffer-substring beg end)) > - (file (read-file-name "Export table to: ")) > + (txt (buffer-substring-no-properties beg end)) > + (file (or target (org-entry-get beg "TABLE_EXPORT_FILE") > + (read-file-name "Export table to: "))) > + (format (or (org-entry-get beg "TABLE_EXPORT_FORMAT") > + org-table-export-default)) > buf) > (unless (or (not (file-exists-p file)) > (y-or-n-p (format "Overwrite file %s? " file))) > (error "Abort")) > - (with-current-buffer (find-file-noselect file) > - (setq buf (current-buffer)) > - (erase-buffer) > - (fundamental-mode) > - (insert table) > - (goto-char (point-min)) > - (while (re-search-forward "^[ \t]*|[ \t]*" nil t) > - (replace-match "" t t) > - (end-of-line 1)) > - (goto-char (point-min)) > - (while (re-search-forward "[ \t]*|[ \t]*$" nil t) > - (replace-match "" t t) > - (goto-char (min (1+ (point)) (point-max)))) > - (goto-char (point-min)) > - (while (re-search-forward "^-[-+]*$" nil t) > - (replace-match "") > - (if (looking-at "\n") > - (delete-char 1))) > - (goto-char (point-min)) > - (while (re-search-forward "[ \t]*|[ \t]*" nil t) > - (replace-match "\t" t t)) > - (save-buffer)) > - (kill-buffer buf))) > + (message format) > + > + (if (string-match "\\([^ \t\r\n]+\\)\\( +.*\\)?" format) > + (let* ((transform (intern (match-string 1 format))) > + (params (if (match-end 2) > + (read (concat "(" (match-string 2 format) ")")))) > + (skip (plist-get params :skip)) > + (skipcols (plist-get params :skipcols)) > + (lines (nthcdr (or skip 0) (org-split-string txt "[ \t]* > \n[ \t]*"))) > + (lines (org-table-clean-before-export lines)) > + (i0 (if org-table-clean-did-remove-column 2 1)) > + (table (mapcar > + (lambda (x) > + (if (string-match org-table-hline-regexp x) > + 'hline > + (org-remove-by-index > + (org-split-string (org-trim x) "\\s-*|\\s-*") > + skipcols i0))) > + lines)) > + (fun (if (= i0 2) 'cdr 'identity)) > + (org-table-last-alignment > + (org-remove-by-index (funcall fun org-table-last-alignment) > + skipcols i0)) > + (org-table-last-column-widths > + (org-remove-by-index (funcall fun org-table-last-column-widths) > + skipcols i0))) > + > + (unless (fboundp transform) > + (error "No such transformation function %s" transform)) > + (setq txt (funcall transform table params)) > + > + (with-current-buffer (find-file-noselect file) > + (setq buf (current-buffer)) > + (erase-buffer) > + (fundamental-mode) > + (insert txt "\n") > + (save-buffer)) > + (kill-buffer buf) > + (message "Export done.")) > + (error "TABLE_EXPORT_FORMAT invalid")))) > > (defvar org-table-aligned-begin-marker (make-marker) > "Marker at the beginning of the table last aligned. > > > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode