]> code.delx.au - gnu-emacs/commitdiff
Don't fake empty cells value by "" when printing with a lambda.
authorVincent Belaïche <vincentb1@users.sourceforge.net>
Wed, 30 Dec 2015 11:37:54 +0000 (12:37 +0100)
committerVincent Belaïche <vincentb1@users.sourceforge.net>
Wed, 30 Dec 2015 16:42:03 +0000 (17:42 +0100)
When using a lambda expression printer function the user should be
free to format differently a really empty cell, ie. containing nil,
from a cell containing an empty string "".

* ses.el (ses-call-printer): Replace `(or value "")' by just `value'
in the case of a lambda expression printer function.

* ses.texi (Printer functions): Add example and description about
lambda expression printer function handling all the possible values,
including unexpected ones.

doc/misc/ses.texi
lisp/ses.el

index 2f92e3ea836975d7f9c94dd5ad3bed74631c4ca1..4cb4188f6907031faf4509d845ba8d782803a637 100644 (file)
@@ -443,6 +443,36 @@ printer function. Then, if you call again
 @code{"%.3f"} all the cells using printer @samp{foo} will be reprinted
 accordingly.
 
+When you define a printer function with a lambda expression taking one
+argument, please take care that the returned value is a string, or a
+list containing a string, even when the input argument has an
+unexpected value. Here is an example:
+
+@example
+(lambda (val)
+   (cond
+      ((null val) "")
+      ((and (numberp val) (>= val 0)) (format "%.1f" val))
+      (t (ses-center-span (format "%S" val) ?#))))
+@end example
+
+This example will:
+@itemize
+@item
+When the cell is empty (ie.@: when @code{val} is @code{nil}), print an
+empty string @code{""}
+@item
+When the cell value is a non negative number, format the the value in
+fixed-point notation with one decimal after point
+@item
+Otherwise, handle the value as erroneous by printing it as an
+s-expression (using @code{prin1}), centered and surrounded by @code{#}
+filling.
+@end itemize
+
+
+
+
 @node Clearing cells
 @section Clearing cells
 @cindex clearing commands
index 7347eb8f5fdcc7d9bcf461c7fae36eb190c4c3e7..8cbc2e80cdec8fa605302715d3b40f319f98ded8 100644 (file)
@@ -1289,7 +1289,7 @@ printer signaled one (and \"%s\" is used as the default printer), else nil."
                           (and locprn
                                (ses--locprn-compiled locprn))))
                    printer)
-               (or value "")))
+               value))
        (if (stringp value)
            value
          (or (stringp (car-safe value))