3.3.4 Local printer functions

You can define printer function local to a sheet with the command ses-define-local-printer. For instance, define a printer ‘foo’ to "%.2f", and then use symbol ‘foo’ as a printer function. Then, if you call again ses-define-local-printer on ‘foo’ to redefine it as "%.3f", all the cells using printer ‘foo’ will be reprinted accordingly.

Sometimes there are local printers that you want to define or re-define automatically every time you open a sheet. For instance imagine that you want to define/re-define automatically a local printer euro to display a number like an amount of euros, that is to say number 3.1 would be displayed as 3.10. To do so in any non read-only SES buffer, you can add some code like this to your .emacs init file:

(defun my-ses-mode-hook ()
  (unless buffer-read-only
    (ses-define-local-printer
     'euro
     (lambda (x)
       (cond
	((null x) "")
	((numberp x) (format "%.2f€" x))
	(t (ses-center-span x ?# 'ses-prin1)))))))
(add-hook 'ses-mode-hook 'my-ses-mode-hook)

If you replace command ses-define-local-printer by function ses-define-if-new-local-printer the definition will occur only if a local printer with the same name in not already defined.