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