From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason Riedy Subject: [PATCH 3/3] Allow functions for some orgtbl parameters. Date: Sun, 02 Mar 2008 21:51:48 -0800 Message-ID: <87d4qc8idn.fsf_-_@sparse.yi.org> References: <87fxv8iqw1.fsf@sparse.yi.org> <87hcfo8j2l.fsf@sparse.yi.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JW3aZ-0002PL-H3 for emacs-orgmode@gnu.org; Mon, 03 Mar 2008 00:51:51 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JW3aY-0002OW-Pv for emacs-orgmode@gnu.org; Mon, 03 Mar 2008 00:51:51 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JW3aY-0002OT-Hd for emacs-orgmode@gnu.org; Mon, 03 Mar 2008 00:51:50 -0500 Received: from a.mail.sonic.net ([64.142.16.245]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JW3aX-0004vi-WC for emacs-orgmode@gnu.org; Mon, 03 Mar 2008 00:51:50 -0500 Received: from nan.sparse.yi.org ([76.191.193.207]) (authenticated bits=0) by a.mail.sonic.net (8.13.8.Beta0-Sonic/8.13.7) with ESMTP id m235plV2001988 for ; Sun, 2 Mar 2008 21:51:48 -0800 In-Reply-To: <87hcfo8j2l.fsf@sparse.yi.org> (jason@acm.org's message of "Sun, 02 Mar 2008 21:36:50 -0800") 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: emacs-orgmode@gnu.org Functions and dynamic binding permit some fun uses, including gathering up header names for use in SQL insert statements. Signed-off-by: Jason Riedy --- org.el | 38 ++++++++++++++++++++++++++++++-------- org.texi | 5 ++++- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/org.el b/org.el index f38f6ae..6f17f1e 100644 --- a/org.el +++ b/org.el @@ -11778,16 +11778,26 @@ First element has index 0, or I0 if given." (mapcar (lambda (f) (setq i (1+ i)) - (let* ((fmt (if (consp fmt) (plist-get fmt i) fmt)) - (efmt (if (consp efmt) (plist-get efmt i) efmt)) + (let* ((fmt (if (and (not (functionp fmt)) (consp fmt)) + (plist-get fmt i) fmt)) + (efmt (if (and (not (functionp efmt)) (consp efmt)) + (plist-get efmt i) efmt)) (f (if (and efmt (string-match orgtbl-exp-regexp f)) - (format efmt (match-string 1 f) - (match-string 2 f)) + (if (functionp efmt) (funcall efmt + (match-string 1 f) + (match-string 2 f)) + (format efmt (match-string 1 f) + (match-string 2 f))) f))) - (if fmt (format fmt f) f))) + (cond ((functionp fmt) (funcall fmt f)) + (fmt (format fmt f)) + (t f)))) line))) - (push (if lfmt (apply 'format lfmt line) - (concat lstart (mapconcat 'identity line sep) lend)) + (push (cond ((functionp lfmt) (funcall lfmt line)) + (lfmt (apply 'format lfmt line)) + (t (concat (if (functionp lstart) (funcall lstart) lstart) + (mapconcat 'identity line sep) + (if (functionp lend) (funcall lend) lend)))) rtn)))) (defun orgtbl-format-section (section-stopper) @@ -11821,11 +11831,18 @@ Valid parameters are :hline String to be inserted on horizontal separation lines. May be nil to ignore hlines. +:sep Separator between two fields + + Each in the following group may be either a string or a function + of no arguments returning a string: :lstart String to start a new table line. :llstart String to start the last table line, defaults to :lstart. :lend String to end a table line :llend String to end the last table line, defaults to :lend. -:sep Separator between two fields + + Each in the following group may be a string, a function of one + argument (the field or line) returning a string, or a plist + mapping columns to either of the above: :lfmt Format for entire line, with enough %s to capture all fields. If this is present, :lstart, :lend, and :sep are ignored. :llfmt Format for the entire last line, defaults to :lfmt. @@ -11840,6 +11857,7 @@ Valid parameters are All lines before the first hline are treated as header. If any of these is not present, the data line value is used. + This may be either a string or a function of two arguments: :efmt Use this format to print numbers with exponentials. The format should have %s twice for inserting mantissa and exponent, for example \"%s\\\\times10^{%s}\". This @@ -11906,11 +11924,13 @@ LaTeX are: original field value. For example, to wrap everything in dollars, use :fmt \"$%s$\". This may also be a property list with column numbers and formats. For example :fmt (2 \"$%s$\" 4 \"%s%%\") + The format may also be a function that formats its one argument. :efmt Format for transforming numbers with exponentials. The format should have %s twice for inserting mantissa and exponent, for example \"%s\\\\times10^{%s}\". LaTeX default is \"%s\\\\,(%s)\". This may also be a property list with column numbers and formats. + The format may also be a function that formats its two arguments. :llend If you find too much space below the last line of a table, pass a value of \"\" for :llend to suppress the final \\\\. @@ -11972,6 +11992,8 @@ TeXInfo are: everything in @kbd{}, you could use :fmt \"@kbd{%s}\". This may also be a property list with column numbers and formats. For example :fmt (2 \"@kbd{%s}\" 4 \"@code{%s}\"). + Each format also may be a function that formats its one + argument. :cf \"f1 f2..\" The column fractions for the table. By default these are computed automatically from the width of the columns diff --git a/org.texi b/org.texi index eae2db0..2ab0dda 100644 --- a/org.texi +++ b/org.texi @@ -8255,6 +8255,8 @@ A format to be used to wrap each field, should contain @code{%s} for the original field value. For example, to wrap each field value in dollars, you could use @code{:fmt "$%s$"}. This may also be a property list with column numbers and formats. for example @code{:fmt (2 "$%s$" 4 "%s\\%%")}. +A function of one argument can be used in place of the strings; the +function must return a formatted string. @item :efmt efmt Use this format to print numbers with exponentials. The format should @@ -8263,7 +8265,8 @@ have @code{%s} twice for inserting mantissa and exponent, for example may also be a property list with column numbers and formats, for example @code{:efmt (2 "$%s\\times10^@{%s@}$" 4 "$%s\\cdot10^@{%s@}$")}. After @code{efmt} has been applied to a value, @code{fmt} will also be -applied. +applied. Similar to @code{fmt}, functions of two arguments can be +supplied instead of strings. @end table @node Translator functions, Radio lists, A LaTeX example, Tables in arbitrary syntax -- 1.5.4.3