[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Orgmode] [PATCH 3/3] Allow functions for some orgtbl parameters.
From: |
Jason Riedy |
Subject: |
[Orgmode] [PATCH 3/3] Allow functions for some orgtbl parameters. |
Date: |
Sun, 02 Mar 2008 21:51:48 -0800 |
User-agent: |
Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.60 (gnu/linux) |
Functions and dynamic binding permit some fun uses, including
gathering up header names for use in SQL insert statements.
Signed-off-by: Jason Riedy <address@hidden>
---
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 "address@hidden@}$" 4 "address@hidden@}$")}. 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