Merge from emacs-24; up to 2012-12-06T01:39:03Z!monnier@iro.umontreal.ca
[bpt/emacs.git] / doc / misc / ses.texi
CommitLineData
4009494e
GM
1\input texinfo @c -*-texinfo-*-
2@c %**start of header
db78a8cb 3@setfilename ../../info/ses
1796ef98 4@settitle @acronym{SES}: Simple Emacs Spreadsheet
4009494e
GM
5@setchapternewpage off
6@syncodeindex fn cp
7@syncodeindex vr cp
8@syncodeindex ky cp
9@c %**end of header
10
11@copying
1796ef98 12This file documents @acronym{SES}: the Simple Emacs Spreadsheet.
4009494e 13
ab422c4d 14Copyright @copyright{} 2002--2013 Free Software Foundation, Inc.
4009494e
GM
15
16@quotation
17Permission is granted to copy, distribute and/or modify this document
6a2c4aec 18under the terms of the GNU Free Documentation License, Version 1.3 or
4009494e 19any later version published by the Free Software Foundation; with no
debf4439
GM
20Invariant Sections, with the Front-Cover texts being ``A GNU Manual,''
21and with the Back-Cover Texts as in (a) below. A copy of the license
22is included in the section entitled ``GNU Free Documentation License.''
4009494e 23
6f093307 24(a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
6bf430d1 25modify this GNU manual.''
4009494e
GM
26@end quotation
27@end copying
28
0c973505 29@dircategory Emacs misc features
4009494e 30@direntry
1796ef98 31* @acronym{SES}: (ses). Simple Emacs Spreadsheet.
4009494e
GM
32@end direntry
33
34@finalout
35
36@titlepage
1796ef98 37@title @acronym{SES}
4009494e
GM
38@subtitle Simple Emacs Spreadsheet
39@author Jonathan A. Yavner
40@author @email{jyavner@@member.fsf.org}
41
42@page
43@vskip 0pt plus 1filll
44@insertcopying
45@end titlepage
46
47@contents
48
49@c ===================================================================
50
51@ifnottex
563a450c 52@node Top
4009494e 53@comment node-name, next, previous, up
1796ef98 54@top @acronym{SES}: Simple Emacs Spreadsheet
4009494e
GM
55
56@display
1796ef98 57@acronym{SES} is a major mode for GNU Emacs to edit spreadsheet files, which
4009494e
GM
58contain a rectangular grid of cells. The cells' values are specified
59by formulas that can refer to the values of other cells.
60@end display
61@end ifnottex
62
63To report bugs, send email to @email{jyavner@@member.fsf.org}.
64
5dc584b5
KB
65@insertcopying
66
4009494e 67@menu
1796ef98 68* Sales Pitch:: Why use @acronym{SES}?
4009494e
GM
69* The Basics:: Basic spreadsheet commands
70* Advanced Features:: Want to know more?
71* For Gurus:: Want to know @emph{even more}?
72* Index:: Concept, Function and Variable Index
09ae5da1 73* Acknowledgments:: Acknowledgments
4009494e
GM
74* GNU Free Documentation License:: The license for this documentation.
75@end menu
76
77@c ===================================================================
78
563a450c 79@node Sales Pitch
4009494e
GM
80@comment node-name, next, previous, up
81@chapter Sales Pitch
82@cindex features
83
84@itemize @bullet
85@item Create and edit simple spreadsheets with a minimum of fuss.
86@item Full undo/redo/autosave.
87@item Immune to viruses in spreadsheet files.
88@item Cell formulas are straight Emacs Lisp.
89@item Printer functions for control of cell appearance.
90@item Intuitive keystroke commands: C-o = insert row, M-o = insert column, etc.
91@item ``Spillover'' of lengthy cell values into following blank cells.
92@item Header line shows column letters or a selected row.
93@item Completing-read for entering symbols as cell values.
94@item Cut, copy, and paste can transfer formulas and printer functions.
95@item Import and export of tab-separated values or tab-separated formulas.
96@item Plaintext, easily-hacked file format.
97@end itemize
98
99@c ===================================================================
100
563a450c 101@node The Basics
4009494e
GM
102@comment node-name, next, previous, up
103@chapter The Basics
104@cindex basic commands
105@findex ses-jump
106@findex ses-mark-row
107@findex ses-mark-column
108@findex ses-mark-whole-buffer
109@findex set-mark-command
110@findex keyboard-quit
111
a9afba20
JY
112To create a new spreadsheet, visit a nonexistent file whose name ends
113 with ".ses". For example, @kbd{C-x C-f test.ses RET}.
114
115
4009494e
GM
116A @dfn{cell identifier} is a symbol with a column letter and a row
117number. Cell B7 is the 2nd column of the 7th row. For very wide
118spreadsheets, there are two column letters: cell AB7 is the 28th
a9afba20 119column of the 7th row. Super wide spreadsheets get AAA1, etc.
4009494e
GM
120
121@table @kbd
122@item j
123Moves point to cell, specified by identifier (@code{ses-jump}).
124@end table
125
126Point is always at the left edge of a cell, or at the empty endline.
127When mark is inactive, the current cell is underlined. When mark is
1796ef98 128active, the range is the highlighted rectangle of cells (@acronym{SES} always
4009494e 129uses transient mark mode). Drag the mouse from A1 to A3 to create the
1796ef98 130range A1-A2. Many @acronym{SES} commands operate only on single cells, not
4009494e
GM
131ranges.
132
133@table @kbd
134@item C-SPC
135@itemx C-@@
136Set mark at point (@code{set-mark-command}).
137
138@item C-g
139Turn off the mark (@code{keyboard-quit}).
140
141@item M-h
142Highlight current row (@code{ses-mark-row}).
143
144@item S-M-h
145Highlight current column (@code{ses-mark-column}).
146
147@item C-x h
148Highlight all cells (@code{mark-whole-buffer}).
149@end table
150
151@menu
152* Formulas::
153* Resizing::
154* Printer functions::
155* Clearing cells::
156* Copy/cut/paste::
1796ef98 157* Customizing @acronym{SES}::
4009494e
GM
158@end menu
159
563a450c 160@node Formulas
4009494e
GM
161@section Cell formulas
162@cindex formulas
163@cindex formulas, entering
164@findex ses-read-cell
165@findex ses-read-symbol
166@findex ses-edit-cell
167@findex ses-recalculate-cell
168@findex ses-recalculate-all
169
170To enter a number into the current cell, just start typing:
171
172@table @kbd
173@item 0..9
174Self-insert a digit (@code{ses-read-cell}).
175
176@item -
177Self-insert a negative number (@code{ses-read-cell}).
178
179@item .
180Self-insert a fractional number (@code{ses-read-cell}).
181
182@item "
183Self-insert a quoted string. The ending double-quote
184is inserted for you (@code{ses-read-cell}).
185
186@item (
187Self-insert an expression. The right-parenthesis is inserted for you
188(@code{ses-read-cell}). To access another cell's value, just use its
189identifier in your expression. Whenever the other cell is changed,
190this cell's formula will be reevaluated. While typing in the
191expression, you can use @kbd{M-@key{TAB}} to complete symbol names.
192
193@item ' @r{(apostrophe)}
1796ef98 194Enter a symbol (ses-read-symbol). @acronym{SES} remembers all symbols that have
4009494e
GM
195been used as formulas, so you can type just the beginning of a symbol
196and use @kbd{@key{SPC}}, @kbd{@key{TAB}}, and @kbd{?} to complete it.
197@end table
198
199To enter something else (e.g., a vector), begin with a digit, then
200erase the digit and type whatever you want.
201
202@table @kbd
203@item RET
204Edit the existing formula in the current cell (@code{ses-edit-cell}).
205
206@item C-c C-c
207Force recalculation of the current cell or range (@code{ses-recalculate-cell}).
208
209@item C-c C-l
210Recalculate the entire spreadsheet (@code{ses-recalculate-all}).
211@end table
212
563a450c 213@node Resizing
4009494e
GM
214@section Resizing the spreadsheet
215@cindex resizing spreadsheets
216@findex ses-insert-row
217@findex ses-insert-column
218@findex ses-delete-row
219@findex ses-delete-column
220@findex ses-set-column-width
221@findex ses-forward-or-insert
222@findex ses-append-row-jump-first-column
223
224
225Basic commands:
226
227@table @kbd
228@item C-o
229(@code{ses-insert-row})
230
231@item M-o
232(@code{ses-insert-column})
233
234@item C-k
235(@code{ses-delete-row})
236
237@item M-k
238(@code{ses-delete-column})
239
240@item w
241(@code{ses-set-column-width})
242
243@item TAB
244Moves point to the next rightward cell, or inserts a new column if
245already at last cell on line, or inserts a new row if at endline
246(@code{ses-forward-or-insert}).
247
248@item C-j
249Linefeed inserts below the current row and moves to column A
250(@code{ses-append-row-jump-first-column}).
251@end table
252
253Resizing the spreadsheet (unless you're just changing a column width)
254relocates all the cell-references in formulas so they still refer to
255the same cells. If a formula mentioned B1 and you insert a new first
256row, the formula will now mention B2.
257
258If you delete a cell that a formula refers to, the cell-symbol is
259deleted from the formula, so @code{(+ A1 B1 C1)} after deleting the third
260column becomes @code{(+ A1 B1)}. In case this is not what you wanted:
261
262@table @kbd
263@item C-_
264@itemx C-x u
265Undo previous action (@code{(undo)}).
266@end table
267
268
563a450c 269@node Printer functions
4009494e
GM
270@section Printer functions
271@cindex printer functions
272@findex ses-read-cell-printer
273@findex ses-read-column-printer
274@findex ses-read-default-printer
275@findex ses-center
276@findex ses-center-span
277@findex ses-dashfill
278@findex ses-dashfill-span
279@findex ses-tildefill-span
280
281
282Printer functions convert binary cell values into the print forms that
283Emacs will display on the screen.
284
285A printer can be a format string, like @samp{"$%.2f"}. The result
286string is right-aligned within the print cell. To get left-alignment,
287use parentheses: @samp{("$%.2f")}. A printer can also be a
288one-argument function (a symbol or a lambda), whose result is a string
289(right-aligned) or list of one string (left-aligned). While typing in
290a lambda, you can use @kbd{M-@key{TAB}} to complete the names of symbols.
291
292Each cell has a printer. If @code{nil}, the column-printer for the cell's
293column is used. If that is also @code{nil}, the default-printer for the
294spreadsheet is used.
295
296@table @kbd
297@item p
298Enter a printer for current cell or range (@code{ses-read-cell-printer}).
299
300@item M-p
301Enter a printer for the current column (@code{ses-read-column-printer}).
302
303@item C-c C-p
304Enter the default printer for the spreadsheet
305(@code{ses-read-default-printer}).
306@end table
307
308The @code{ses-read-@r{XXX}-printer} commands have their own minibuffer
309history, which is preloaded with the set of all printers used in this
310spreadsheet, plus the standard printers.
311
312The standard printers are suitable only for cells, not columns or
313default, because they format the value using the column-printer (or
314default-printer if @code{nil}) and then center the result:
315
316@table @code
317@item ses-center
318Just centering.
319
320@item ses-center-span
321Centering with spill-over to following blank cells.
322
323@item ses-dashfill
324Centering using dashes (-) instead of spaces.
325
326@item ses-dashfill-span
327Centering with dashes and spill-over.
328
329@item ses-tildefill-span
330Centering with tildes (~) and spill-over.
331@end table
332
333
563a450c 334@node Clearing cells
4009494e
GM
335@section Clearing cells
336@cindex clearing commands
337@findex ses-clear-cell-backward
338@findex ses-clear-cell-forward
339
340These commands set both formula and printer to @code{nil}:
341
342@table @kbd
343@item DEL
344Clear cell and move left (@code{ses-clear-cell-backward}).
345
346@item C-d
347Clear cell and move right (@code{ses-clear-cell-forward}).
348@end table
349
350
563a450c 351@node Copy/cut/paste
4009494e
GM
352@section Copy, cut, and paste
353@cindex copy
354@cindex cut
355@cindex paste
356@findex kill-ring-save
357@findex mouse-set-region
358@findex mouse-set-secondary
359@findex ses-kill-override
360@findex yank
361@findex clipboard-yank
362@findex mouse-yank-at-click
363@findex mouse-yank-at-secondary
364@findex ses-yank-pop
365
366The copy functions work on rectangular regions of cells. You can paste the
1796ef98 367copies into non-@acronym{SES} buffers to export the print text.
4009494e
GM
368
369@table @kbd
370@item M-w
371@itemx [copy]
372@itemx [C-insert]
373Copy the highlighted cells to kill ring and primary clipboard
374(@code{kill-ring-save}).
375
376@item [drag-mouse-1]
377Mark a region and copy it to kill ring and primary clipboard
378(@code{mouse-set-region}).
379
380@item [M-drag-mouse-1]
381Mark a region and copy it to kill ring and secondary clipboard
382(@code{mouse-set-secondary}).
383
384@item C-w
385@itemx [cut]
386@itemx [S-delete]
387The cut functions do not actually delete rows or columns---they copy
388and then clear (@code{ses-kill-override}).
389
390@item C-y
391@itemx [S-insert]
392Paste from kill ring (@code{yank}). The paste functions behave
393differently depending on the format of the text being inserted:
394@itemize @bullet
395@item
1796ef98 396When pasting cells that were cut from a @acronym{SES} buffer, the print text is
4009494e
GM
397ignored and only the attached formula and printer are inserted; cell
398references in the formula are relocated unless you use @kbd{C-u}.
399@item
400The pasted text overwrites a rectangle of cells whose top left corner
401is the current cell. If part of the rectangle is beyond the edges of
402the spreadsheet, you must confirm the increase in spreadsheet size.
403@item
1796ef98 404Non-@acronym{SES} text is usually inserted as a replacement formula for the
4009494e
GM
405current cell. If the formula would be a symbol, it's treated as a
406string unless you use @kbd{C-u}. Pasted formulas with syntax errors
407are always treated as strings.
408@end itemize
409
410@item [paste]
411Paste from primary clipboard or kill ring (@code{clipboard-yank}).
412
413@item [mouse-2]
414Set point and paste from primary clipboard (@code{mouse-yank-at-click}).
415
416@item [M-mouse-2]
417Set point and paste from secondary clipboard (@code{mouse-yank-secondary}).
418
419@item M-y
420Immediately after a paste, you can replace the text with a preceding
421element from the kill ring (@code{ses-yank-pop}). Unlike the standard
1796ef98 422Emacs yank-pop, the @acronym{SES} version uses @code{undo} to delete the old
4009494e
GM
423yank. This doesn't make any difference?
424@end table
425
563a450c 426@node Customizing @acronym{SES}
1796ef98 427@section Customizing @acronym{SES}
4009494e
GM
428@cindex customizing
429@vindex enable-local-eval
430@vindex ses-mode-hook
431@vindex safe-functions
432@vindex enable-local-eval
433
434
435By default, a newly-created spreadsheet has 1 row and 1 column. The
436column width is 7 and the default printer is @samp{"%.7g"}. Each of these
437can be customized. Look in group ``ses''.
438
439After entering a cell value, point normally moves right to the next
440cell. You can customize @code{ses-after-entry-functions} to move left or
441up or down. For diagonal movement, select two functions from the
442list.
443
444@code{ses-mode-hook} is a normal mode hook (list of functions to
1796ef98 445execute when starting @acronym{SES} mode for a buffer).
4009494e
GM
446
447The variable @code{safe-functions} is a list of possibly-unsafe
e4920bc9 448functions to be treated as safe when analyzing formulas and printers.
4009494e
GM
449@xref{Virus protection}. Before customizing @code{safe-functions},
450think about how much you trust the person who's suggesting this
451change. The value @code{t} turns off all anti-virus protection. A
452list-of-functions value might enable a ``gee whiz'' spreadsheet, but it
453also creates trapdoors in your anti-virus armor. In order for virus
454protection to work, you must always press @kbd{n} when presented with
455a virus warning, unless you understand what the questionable code is
456trying to do. Do not listen to those who tell you to customize
457@code{enable-local-eval}---this variable is for people who don't wear
458safety belts!
459
460
461@c ===================================================================
462
563a450c 463@node Advanced Features
4009494e
GM
464@chapter Advanced Features
465@cindex advanced features
466@findex ses-read-header-row
467
468
469@table @kbd
470@item C-c M-C-h
1796ef98
VB
471(@code{ses-set-header-row}).
472@findex ses-set-header-row
473@kindex C-c M-C-h
474The header line at the top of the @acronym{SES}
4009494e
GM
475window normally shows the column letter for each column. You can set
476it to show a copy of some row, such as a row of column titles, so that
477row will always be visible. Default is to set the current row as the
478header; use C-u to prompt for header row. Set the header to row 0 to
479show column letters again.
480@item [header-line mouse-3]
481Pops up a menu to set the current row as the header, or revert to
482column letters.
1796ef98 483@item M-x ses-rename-cell
7831fb1b
PE
484@findex ses-rename-cell
485Rename a cell from a standard A1-like name to any
486string.
1796ef98
VB
487@item M-x ses-repair-cell-reference-all
488@findex ses-repair-cell-reference-all
489When you interrupt a cell formula update by clicking @kbd{C-g}, then
490the cell reference link may be broken, which will jeopardize automatic
491cell update when any other cell on which it depends is changed. To
492repair that use function @code{ses-repair-cell-reference-all}
4009494e
GM
493@end table
494
495@menu
496* The print area::
497* Ranges in formulas::
498* Sorting by column::
499* Standard formula functions::
500* More on cell printing::
501* Import and export::
502* Virus protection::
503* Spreadsheets with details and summary::
504@end menu
505
563a450c 506@node The print area
4009494e
GM
507@section The print area
508@cindex print area
509@findex widen
510@findex ses-renarrow-buffer
511@findex ses-reprint-all
512
1796ef98 513A @acronym{SES} file consists of a print area and a data area. Normally the
4009494e 514buffer is narrowed to show only the print area. The print area is
1796ef98 515read-only except for special @acronym{SES} commands; it contains cell values
4009494e
GM
516formatted by printer functions. The data area records the formula and
517printer functions, etc.
518
519@table @kbd
520@item C-x n w
521Show print and data areas (@code{widen}).
522
523@item C-c C-n
524Show only print area (@code{ses-renarrow-buffer}).
525
526@item S-C-l
527@itemx M-C-l
528Recreate print area by reevaluating printer functions for all cells
529(@code{ses-reprint-all}).
530@end table
531
563a450c 532@node Ranges in formulas
4009494e
GM
533@section Ranges in formulas
534@cindex ranges
535@findex ses-insert-range-click
536@findex ses-insert-range
537@findex ses-insert-ses-range-click
538@findex ses-insert-ses-range
539@vindex from
540@vindex to
541
542A formula like
543@lisp
544(+ A1 A2 A3)
545@end lisp
546is the sum of three specific cells. If you insert a new second row,
547the formula becomes
548@lisp
549(+ A1 A3 A4)
550@end lisp
551and the new row is not included in the sum.
552
553The macro @code{(ses-range @var{from} @var{to})} evaluates to a list of
554the values in a rectangle of cells. If your formula is
555@lisp
556(apply '+ (ses-range A1 A3))
557@end lisp
558and you insert a new second row, it becomes
559@lisp
560(apply '+ (ses-range A1 A4))
561@end lisp
562and the new row is included in the sum.
563
564While entering or editing a formula in the minibuffer, you can select
565a range in the spreadsheet (using mouse or keyboard), then paste a
566representation of that range into your formula. Suppose you select
567A1-C1:
568
569@table @kbd
570@item [S-mouse-3]
571Inserts "A1 B1 C1" @code{(ses-insert-range-click})
572
573@item C-c C-r
574Keyboard version (@code{ses-insert-range}).
575
576@item [C-S-mouse-3]
577Inserts "(ses-range A1 C1)" (@code{ses-insert-ses-range-click}).
578
579@item C-c C-s
580Keyboard version (@code{ses-insert-ses-range}).
581@end table
582
583If you delete the @var{from} or @var{to} cell for a range, the nearest
584still-existing cell is used instead. If you delete the entire range,
585the formula relocator will delete the ses-range from the formula.
586
587If you insert a new row just beyond the end of a one-column range, or
588a new column just beyond a one-row range, the new cell is included in
589the range. New cells inserted just before a range are not included.
590
1796ef98
VB
591Flags can be added to @code{ses-range} immediately after the @var{to}
592cell.
593@table @code
594@item !
595Empty cells in range can be removed by adding the @code{!} flag. An
596empty cell is a cell the value of which is one of symbols @code{nil}
597or @code{*skip*}. For instance @code{(ses-range A1 A4 !)} will do the
598same as @code{(list A1 A3)} when cells @code{A2} and @code{A4} are
599empty.
600@item _
601Empty cell values are replaced by the argument following flag
602@code{_}, or @code{0} when flag @code{_} is last in argument list. For
603instance @code{(ses-range A1 A4 _ "empty")} will do the same as
604@code{(list A1 "empty" A3 "empty")} when cells @code{A2} and @code{A4}
605are empty. Similarly, @code{(ses-range A1 A4 _ )} will do the same as
606@code{(list A1 0 A3 0)}.
607@item >v
7831fb1b 608When order matters, list cells by reading cells row-wise from top left
1796ef98
VB
609to bottom right. This flag is provided for completeness only as it is
610the default reading order.
611@item <v
7831fb1b 612List cells by reading cells row-wise from top right to bottom left.
1796ef98 613@item v>
7831fb1b 614List cells by reading cells column-wise from top left to bottom right.
1796ef98 615@item v<
7831fb1b 616List cells by reading cells column-wise from top right to bottom left.
1796ef98
VB
617@item v
618A short hand for @code{v>}.
619@item ^
620A short hand for @code{^>}.
621@item >
622A short hand for @code{>v}.
623@item <
624A short hand for @code{>^}.
625@item *
626Instead of listing cells, it makes a Calc vector or matrix of it
627(@pxref{Top,,,calc,GNU Emacs Calc Manual}). If the range contains only
628one row or one column a vector is made, otherwise a matrix is made.
629@item *2
630Same as @code{*} except that a matrix is always made even when there
631is only one row or column in the range.
632@item *1
633Same as @code{*} except that a vector is always made even when there
634is only one row or column in the range, that is to say the
635corresponding matrix is flattened.
636@end table
4009494e 637
563a450c 638@node Sorting by column
4009494e
GM
639@section Sorting by column
640@cindex sorting
641@findex ses-sort-column
642@findex ses-sort-column-click
643
644@table @kbd
645@item C-c M-C-s
646Sort the cells of a range using one of the columns
647(@code{ses-sort-column}). The rows (or partial rows if the range
648doesn't include all columns) are rearranged so the chosen column will
649be in order.
650
651@item [header-line mouse-2]
652The easiest way to sort is to click mouse-2 on the chosen column's header row
653(@code{ses-sort-column-click}).
654@end table
655
656The sort comparison uses @code{string<}, which works well for
657right-justified numbers and left-justified strings.
658
659With prefix arg, sort is in descending order.
660
661Rows are moved one at a time, with relocation of formulas. This works
662well if formulas refer to other cells in their row, not so well for
663formulas that refer to other rows in the range or to cells outside the
664range.
665
666
563a450c 667@node Standard formula functions
4009494e
GM
668@section Standard formula functions
669@cindex standard formula functions
670@cindex *skip*
671@cindex *error*
672@findex ses-delete-blanks
673@findex ses-average
674@findex ses+
675
676Oftentimes you want a calculation to exclude the blank cells. Here
677are some useful functions to call from your formulas:
678
679@table @code
680@item (ses-delete-blanks &rest @var{args})
681Returns a list from which all blank cells (value is either @code{nil} or
682'*skip*) have been deleted.
683
684@item (ses+ &rest @var{args})
685Sum of non-blank arguments.
686
687@item (ses-average @var{list})
688Average of non-blank elements in @var{list}. Here the list is passed
689as a single argument, since you'll probably use it with @code{ses-range}.
690@end table
691
563a450c 692@node More on cell printing
4009494e
GM
693@section More on cell printing
694@cindex cell printing, more
695@findex ses-truncate-cell
696@findex ses-recalculate-cell
697
698Special cell values:
699@itemize
700@item nil prints the same as "", but allows previous cell to spill over.
701@item '*skip* replaces nil when the previous cell actually does spill over;
702nothing is printed for it.
703@item '*error* indicates that the formula signaled an error instead of
704producing a value: the print cell is filled with hash marks (#).
705@end itemize
706
707If the result from the printer function is too wide for the cell and
708the following cell is @code{nil}, the result will spill over into the
709following cell. Very wide results can spill over several cells. If
710the result is too wide for the available space (up to the end of the
711row or the next non-@code{nil} cell), the result is truncated if the cell's
712value is a string, or replaced with hash marks otherwise.
713
1796ef98 714@acronym{SES} could get confused by printer results that contain newlines or
4009494e
GM
715tabs, so these are replaced with question marks.
716
717@table @kbd
a9afba20 718@item t
4009494e
GM
719Confine a cell to its own column (@code{ses-truncate-cell}). This
720allows you to move point to a rightward cell that would otherwise be
721covered by a spill-over. If you don't change the rightward cell, the
722confined cell will spill over again the next time it is reprinted.
723
a9afba20
JY
724@item c
725When applied to a single cell, this command displays in the echo area
726any formula error or printer error that occurred during
727recalculation/reprinting (@code{ses-recalculate-cell}). You can use
728this to undo the effect of @kbd{t}.
4009494e
GM
729@end table
730
a9afba20 731When a printer function signals an error, the fallback printer
4009494e 732@samp{"%s"} is substituted. This is useful when your column printer
a9afba20
JY
733is numeric-only and you use a string as a cell value. Note that the
734standard default printer is ``%.7g'' which is numeric-only, so cells
735that are empty of contain strings will use the fallback printer.
736@kbd{c} on such cells will display ``Format specifier doesn't match
737argument type''.
4009494e
GM
738
739
563a450c 740@node Import and export
4009494e
GM
741@section Import and export
742@cindex import and export
743@cindex export, and import
744@findex ses-export-tsv
745@findex ses-export-tsf
746
747@table @kbd
748@item x t
749Export a range of cells as tab-separated values (@code{ses-export-tsv}).
750@item x T
751Export a range of cells as tab-separated formulas (@code{ses-export-tsf}).
752@end table
753
f99f1641 754The exported text goes to the kill ring; you can paste it into
4009494e
GM
755another buffer. Columns are separated by tabs, rows by newlines.
756
757To import text, use any of the yank commands where the text to paste
758contains tabs and/or newlines. Imported formulas are not relocated.
759
563a450c 760@node Virus protection
4009494e
GM
761@section Virus protection
762@cindex virus protection
763
764Whenever a formula or printer is read from a file or is pasted into
765the spreadsheet, it receives a ``needs safety check'' marking. Later,
766when the formula or printer is evaluated for the first time, it is
767checked for safety using the @code{unsafep} predicate; if found to be
768``possibly unsafe'', the questionable formula or printer is displayed
769and you must press Y to approve it or N to use a substitute. The
770substitute always signals an error.
771
772Formulas or printers that you type in are checked immediately for
773safety. If found to be possibly unsafe and you press N to disapprove,
774the action is canceled and the old formula or printer will remain.
775
776Besides viruses (which try to copy themselves to other files),
777@code{unsafep} can also detect all other kinds of Trojan horses, such as
778spreadsheets that delete files, send email, flood Web sites, alter
779your Emacs settings, etc.
780
781Generally, spreadsheet formulas and printers are simple things that
782don't need to do any fancy computing, so all potentially-dangerous
783parts of the Emacs Lisp environment can be excluded without cramping
784your style as a formula-writer. See the documentation in @file{unsafep.el}
785for more info on how Lisp forms are classified as safe or unsafe.
786
563a450c 787@node Spreadsheets with details and summary
4009494e
GM
788@section Spreadsheets with details and summary
789@cindex details and summary
790@cindex summary, and details
791
792A common organization for spreadsheets is to have a bunch of ``detail''
793rows, each perhaps describing a transaction, and then a set of
794``summary'' rows that each show reduced data for some subset of the
1796ef98 795details. @acronym{SES} supports this organization via the @code{ses-select}
4009494e
GM
796function.
797
798@table @code
799@item (ses-select @var{fromrange} @var{test} @var{torange})
800Returns a subset of @var{torange}. For each member in @var{fromrange}
801that is equal to @var{test}, the corresponding member of @var{torange}
802is included in the result.
803@end table
804
805Example of use:
806@lisp
807(ses-average (ses-select (ses-range A1 A5) 'Smith (ses-range B1 B5)))
808@end lisp
809This computes the average of the B column values for those rows whose
810A column value is the symbol 'Smith.
811
812Arguably one could specify only @var{fromrange} plus
813@var{to-row-offset} and @var{to-column-offset}. The @var{torange} is
814stated explicitly to ensure that the formula will be recalculated if
815any cell in either range is changed.
816
817File @file{etc/ses-example.el} in the Emacs distribution is an example of a
818details-and-summary spreadsheet.
819
820
821@c ===================================================================
822
563a450c 823@node For Gurus
4009494e
GM
824@chapter For Gurus
825@cindex advanced features
826
827@menu
828* Deferred updates::
829* Nonrelocatable references::
830* The data area::
831* Buffer-local variables in spreadsheets::
1796ef98 832* Uses of defadvice in @acronym{SES}::
4009494e
GM
833@end menu
834
563a450c 835@node Deferred updates
4009494e
GM
836@section Deferred updates
837@cindex deferred updates
838@cindex updates, deferred
839@vindex run-with-idle-timer
840
841To save time by avoiding redundant computations, cells that need
842recalculation due to changes in other cells are added to a set. At
843the end of the command, each cell in the set is recalculated once.
844This can create a new set of cells that need recalculation. The
845process is repeated until either the set is empty or it stops changing
846(due to circular references among the cells). In extreme cases, you
847might see progress messages of the form ``Recalculating... (@var{nnn}
848cells left)''. If you interrupt the calculation using @kbd{C-g}, the
849spreadsheet will be left in an inconsistent state, so use @kbd{C-_} or
850@kbd{C-c C-l} to fix it.
851
852To save even more time by avoiding redundant writes, cells that have
853changes are added to a set instead of being written immediately to the
854data area. Each cell in the set is written once, at the end of the
855command. If you change vast quantities of cells, you might see a
856progress message of the form ``Writing... (@var{nnn} cells left)''.
857These deferred cell-writes cannot be interrupted by @kbd{C-g}, so
858you'll just have to wait.
859
1796ef98 860@acronym{SES} uses @code{run-with-idle-timer} to move the cell underline when
4009494e
GM
861Emacs will be scrolling the buffer after the end of a command, and
862also to narrow and underline after @kbd{C-x C-v}. This is visible as
863a momentary glitch after C-x C-v and certain scrolling commands. You
864can type ahead without worrying about the glitch.
865
866
563a450c 867@node Nonrelocatable references
4009494e
GM
868@section Nonrelocatable references
869@cindex nonrelocatable references
870@cindex references, nonrelocatable
871
872@kbd{C-y} relocates all cell-references in a pasted formula, while
873@kbd{C-u C-y} relocates none of the cell-references. What about mixed
874cases?
875
876You can use
877@lisp
878(symbol-value 'B3)
879@end lisp
880to make an @dfn{absolute reference}. The formula relocator skips over
881quoted things, so this will not be relocated when pasted or when
882rows/columns are inserted/deleted. However, B3 will not be recorded
883as a dependency of this cell, so this cell will not be updated
884automatically when B3 is changed.
885
886The variables @code{row} and @code{col} are dynamically bound while a
887cell formula is being evaluated. You can use
888@lisp
889(ses-cell-value row 0)
890@end lisp
891to get the value from the leftmost column in the current row. This
892kind of dependency is also not recorded.
893
894
563a450c 895@node The data area
4009494e
GM
896@section The data area
897@cindex data area
898@findex ses-reconstruct-all
899
900Begins with an 014 character, followed by sets of cell-definition
901macros for each row, followed by column-widths, column-printers,
902default-printer, and header-row. Then there's the global parameters
903(file-format ID, numrows, numcols) and the local variables (specifying
1796ef98 904@acronym{SES} mode for the buffer, etc.)
4009494e 905
1796ef98 906When a @acronym{SES} file is loaded, first the numrows and numcols values are
4009494e
GM
907loaded, then the entire data area is @code{eval}ed, and finally the local
908variables are processed.
909
910You can edit the data area, but don't insert or delete any newlines
1796ef98 911except in the local-variables part, since @acronym{SES} locates things by
4009494e
GM
912counting newlines. Use @kbd{C-x C-e} at the end of a line to install
913your edits into the spreadsheet data structures (this does not update
1df7defd 914the print area, use, e.g., @kbd{C-c C-l} for that).
4009494e
GM
915
916The data area is maintained as an image of spreadsheet data
917structures that area stored in buffer-local variables. If the data
918area gets messed up, you can try reconstructing the data area from the
919data structures:
920
921@table @kbd
922@item C-c M-C-l
923(@code{ses-reconstruct-all}).
924@end table
925
926
563a450c 927@node Buffer-local variables in spreadsheets
4009494e
GM
928@section Buffer-local variables in spreadsheets
929@cindex buffer-local variables
930@cindex variables, buffer-local
931
932You can add additional local variables to the list at the bottom of
933the data area, such as hidden constants you want to refer to in your
934formulas.
935
a9afba20 936You can override the variable @code{ses--symbolic-formulas} to be a list of
4009494e
GM
937symbols (as parenthesized strings) to show as completions for the '
938command. This initial completions list is used instead of the actual
939set of symbols-as-formulas in the spreadsheet.
940
a9afba20 941For an example of this, see file @file{etc/ses-example.ses}.
4009494e
GM
942
943If (for some reason) you want your formulas or printers to save data
944into variables, you must declare these variables as buffer-locals in
945order to avoid a virus warning.
946
947You can define functions by making them values for the fake local
948variable @code{eval}. Such functions can then be used in your
949formulas and printers, but usually each @code{eval} is presented to
f99f1641 950the user during file loading as a potential virus. This can get
4009494e
GM
951annoying.
952
953You can define functions in your @file{.emacs} file. Other people can
954still read the print area of your spreadsheet, but they won't be able
955to recalculate or reprint anything that depends on your functions. To
956avoid virus warnings, each function used in a formula needs
957@lisp
958(put 'your-function-name 'safe-function t)
959@end lisp
960
563a450c 961@node Uses of defadvice in @acronym{SES}
1796ef98 962@section Uses of defadvice in @acronym{SES}
4009494e
GM
963@cindex defadvice
964@cindex undo-more
965@cindex copy-region-as-kill
966@cindex yank
967
968@table @code
969@item undo-more
970Defines a new undo element format (@var{fun} . @var{args}), which
971means ``undo by applying @var{fun} to @var{args}''. For spreadsheet
972buffers, it allows undos in the data area even though that's outside
973the narrowing.
974
975@item copy-region-as-kill
976When copying from the print area of a spreadsheet, treat the region as
977a rectangle and attach each cell's formula and printer as 'ses
978properties.
979
980@item yank
981When yanking into the print area of a spreadsheet, first try to yank
982as cells (if the yank text has 'ses properties), then as tab-separated
983formulas, then (if all else fails) as a single formula for the current
984cell.
985@end table
986
987@c ===================================================================
563a450c 988@node Index
4009494e
GM
989@unnumbered Index
990
991@printindex cp
992
993@c ===================================================================
994
563a450c 995@node Acknowledgments
d9b03add 996@unnumbered Acknowledgments
4009494e
GM
997
998Coding by:
999@quotation
1000Jonathan Yavner @email{jyavner@@member.fsf.org}@*
67525fb9
JY
1001Stefan Monnier @email{monnier@@gnu.org}@*
1002Shigeru Fukaya @email{shigeru.fukaya@@gmail.com}
4009494e
GM
1003@end quotation
1004
1005@noindent
1006Texinfo manual by:
1007@quotation
1008Jonathan Yavner @email{jyavner@@member.fsf.org}@*
1009Brad Collins <brad@@chenla.org>
1010@end quotation
1011
1012@noindent
1013Ideas from:
1014@quotation
1015Christoph Conrad @email{christoph.conrad@@gmx.de}@*
1016CyberBob @email{cyberbob@@redneck.gacracker.org}@*
1017Syver Enstad @email{syver-en@@online.no}@*
1018Ami Fischman @email{fischman@@zion.bpnetworks.com}@*
1019Thomas Gehrlein @email{Thomas.Gehrlein@@t-online.de}@*
1020Chris F.A. Johnson @email{c.f.a.johnson@@rogers.com}@*
1021Yusong Li @email{lyusong@@hotmail.com}@*
1022Juri Linkov @email{juri@@jurta.org}@*
1023Harald Maier @email{maierh@@myself.com}@*
1024Alan Nash @email{anash@@san.rr.com}@*
1025