(latexenc-find-file-coding-system): Don't inherit the EOL part of the
[emacs.git] / man / ses.texi
blob9b0137d200247ac13f7d380b9a41f74d119b37e0
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename ../info/ses
4 @settitle SES: Simple Emacs Spreadsheet
5 @setchapternewpage off
6 @c %**end of header
8 @copying
9 This file documents SES: the Simple Emacs Spreadsheet.
11 Copyright @copyright{} 2002, 2005  Free Software Foundation, Inc.
13 @quotation
14 Permission is granted to copy, distribute and/or modify this document
15 under the terms of the GNU Free Documentation License, Version 1.1 or
16 any later version published by the Free Software Foundation; with no
17 Invariant Sections, with the Front-Cover texts being ``A GNU
18 Manual,'' and with the Back-Cover Texts as in (a) below.  A copy of the
19 license is included in the section entitled ``GNU Free Documentation
20 License'' in the Emacs manual.
22 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
23 this GNU Manual, like GNU software.  Copies published by the Free
24 Software Foundation raise funds for GNU development.''
26 This document is part of a collection distributed under the GNU Free
27 Documentation License.  If you want to distribute this document
28 separately from the collection, you can do so by adding a copy of the
29 license to the document, as described in section 6 of the license.
30 @end quotation
31 @end copying
33 @dircategory Emacs
34 @direntry
35 * SES: (ses).       Simple Emacs Spreadsheet
36 @end direntry
38 @finalout
40 @titlepage
41 @title SES
42 @subtitle Simple Emacs Spreadsheet
43 @author Jonathan A. Yavner
44 @author @email{jyavner@@member.fsf.org}
46 @page
47 @vskip 0pt plus 1filll
48 @insertcopying
49 @end titlepage
51 @contents
53 @c ===================================================================
55 @ifnottex
56 @node Top, Sales Pitch, (dir), (dir)
57 @comment  node-name,  next,  previous,  up
58 @top SES: Simple Emacs Spreadsheet
60 @display
61 SES is a major mode for GNU Emacs to edit spreadsheet files, which
62 contain a rectangular grid of cells.  The cells' values are specified
63 by formulas that can refer to the values of other cells.
64 @end display
65 @end ifnottex
67 To report bugs, send email to @email{jyavner@@member.fsf.org}.
69 @menu
70 * Sales Pitch::                 Why use SES?
71 * The Basics::                  Basic spreadsheet commands
72 * Advanced Features::           Want to know more?
73 * For Gurus::                   Want to know @emph{even more}?
74 * Index::                       Concept, Function and Variable Index
75 * Acknowledgements::            Acknowledgements
76 @end menu
78 @c ===================================================================
80 @node Sales Pitch, The Basics, Top, Top
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 The Basics, Advanced Features, Sales Pitch, Top
103 @comment  node-name,  next,  previous,  up
104 @chapter The Basics
105 @cindex basic commands
106 @findex ses-jump
107 @findex ses-mark-row
108 @findex ses-mark-column
109 @findex ses-mark-whole-buffer
110 @findex set-mark-command
111 @findex keyboard-quit
113 A @dfn{cell identifier} is a symbol with a column letter and a row
114 number.  Cell B7 is the 2nd column of the 7th row.  For very wide
115 spreadsheets, there are two column letters: cell AB7 is the 28th
116 column of the 7th row.
118 @table @kbd
119 @item j
120 Moves point to cell, specified by identifier (@code{ses-jump}).
121 @end table
123 Point is always at the left edge of a cell, or at the empty endline.
124 When mark is inactive, the current cell is underlined.  When mark is
125 active, the range is the highlighted rectangle of cells (SES always
126 uses transient mark mode).  Drag the mouse from A1 to A3 to create the
127 range A1-A2.  Many SES commands operate only on single cells, not
128 ranges.
130 @table @kbd
131 @item C-SPC
132 @itemx C-@@
133 Set mark at point (@code{set-mark-command}).
135 @item C-g
136 Turn off the mark (@code{keyboard-quit}).
138 @item M-h
139 Highlight current row (@code{ses-mark-row}).
141 @item S-M-h
142 Highlight current column (@code{ses-mark-column}).
144 @item C-x h
145 Highlight all cells (@code{mark-whole-buffer}).
146 @end table
148 @menu
149 * Formulas::
150 * Resizing::
151 * Printer functions::
152 * Clearing cells::
153 * Copy/cut/paste::
154 * Customizing SES::
155 @end menu
157 @node Formulas, Resizing, The Basics, The Basics
158 @section Cell formulas
159 @cindex formulas
160 @cindex formulas, entering
161 @findex ses-read-cell
162 @findex ses-read-symbol
163 @findex ses-edit-cell
164 @findex ses-recalculate-cell
165 @findex ses-recalculate-all
167 To enter a number into the current cell, just start typing:
169 @table @kbd
170 @item 0..9
171 Self-insert a digit (@code{ses-read-cell}).
173 @item -
174 Self-insert a negative number (@code{ses-read-cell}).
176 @item .
177 Self-insert a fractional number (@code{ses-read-cell}).
179 @item "
180 Self-insert a quoted string.  The ending double-quote
181 is inserted for you (@code{ses-read-cell}).
183 @item (
184 Self-insert an expression.  The right-parenthesis is inserted for you
185 (@code{ses-read-cell}).  To access another cell's value, just use its
186 identifier in your expression.  Whenever the other cell is changed,
187 this cell's formula will be reevaluated.  While typing in the
188 expression, you can use @kbd{M-TAB} to complete symbol names.
190 @item ' @r{(apostrophe)}
191 Enter a symbol (ses-read-symbol).  SES remembers all symbols that have
192 been used as formulas, so you can type just the beginning of a symbol
193 and use @kbd{SPC}, @kbd{TAB}, and @kbd{?} to complete it.
194 @end table
196 To enter something else (e.g., a vector), begin with a digit, then
197 erase the digit and type whatever you want.
199 @table @kbd
200 @item RET
201 Edit the existing formula in the current cell (@code{ses-edit-cell}).
203 @item C-c C-c
204 Force recalculation of the current cell or range (@code{ses-recalculate-cell}).
206 @item C-c C-l
207 Recalculate the entire spreadsheet (@code{ses-recalculate-all}).
208 @end table
210 @node Resizing, Printer functions, Formulas, The Basics
211 @section Resizing the spreadsheet
212 @cindex resizing spreadsheets
213 @findex ses-insert-row
214 @findex ses-insert-column
215 @findex ses-delete-row
216 @findex ses-delete-column
217 @findex ses-set-column-width
218 @findex ses-forward-or-insert
219 @findex ses-append-row-jump-first-column
222 Basic commands:
224 @table @kbd
225 @item C-o
226 (@code{ses-insert-row})
228 @item M-o
229 (@code{ses-insert-column})
231 @item C-k
232 (@code{ses-delete-row})
234 @item M-k
235 (@code{ses-delete-column})
237 @item w
238 (@code{ses-set-column-width})
240 @item TAB
241 Moves point to the next rightward cell, or inserts a new column if
242 already at last cell on line, or inserts a new row if at endline
243 (@code{ses-forward-or-insert}).
245 @item C-j
246 Linefeed inserts below the current row and moves to column A
247 (@code{ses-append-row-jump-first-column}).
248 @end table
250 Resizing the spreadsheet (unless you're just changing a column width)
251 relocates all the cell-references in formulas so they still refer to
252 the same cells.  If a formula mentioned B1 and you insert a new first
253 row, the formula will now mention B2.
255 If you delete a cell that a formula refers to, the cell-symbol is
256 deleted from the formula, so @code{(+ A1 B1 C1)} after deleting the third
257 column becomes @code{(+ A1 B1)}.  In case this is not what you wanted:
259 @table @kbd
260 @item C-_
261 @itemx C-x u
262 Undo previous action (@code{(undo)}).
263 @end table
266 @node Printer functions, Clearing cells, Resizing, The Basics
267 @section Printer functions
268 @cindex printer functions
269 @findex ses-read-cell-printer
270 @findex ses-read-column-printer
271 @findex ses-read-default-printer
272 @findex ses-center
273 @findex ses-center-span
274 @findex ses-dashfill
275 @findex ses-dashfill-span
276 @findex ses-tildefill-span
279 Printer functions convert binary cell values into the print forms that
280 Emacs will display on the screen.
282 A printer can be a format string, like @samp{"$%.2f"}.  The result
283 string is right-aligned within the print cell.  To get left-alignment,
284 use parentheses: @samp{("$%.2f")}.  A printer can also be a
285 one-argument function (a symbol or a lambda), whose result is a string
286 (right-aligned) or list of one string (left-aligned).  While typing in
287 a lambda, you can use @kbd{M-TAB} to complete the names of symbols.
289 Each cell has a printer.  If @code{nil}, the column-printer for the cell's
290 column is used.  If that is also @code{nil}, the default-printer for the
291 spreadsheet is used.
293 @table @kbd
294 @item p
295 Enter a printer for current cell or range (@code{ses-read-cell-printer}).
297 @item M-p
298 Enter a printer for the current column (@code{ses-read-column-printer}).
300 @item C-c C-p
301 Enter the default printer for the spreadsheet
302 (@code{ses-read-default-printer}).
303 @end table
305 The @code{ses-read-@r{XXX}-printer} commands have their own minibuffer
306 history, which is preloaded with the set of all printers used in this
307 spreadsheet, plus the standard printers.
309 The standard printers are suitable only for cells, not columns or
310 default, because they format the value using the column-printer (or
311 default-printer if @code{nil}) and then center the result:
313 @table @code
314 @item ses-center
315 Just centering.
317 @item ses-center-span
318 Centering with spill-over to following blank cells.
320 @item ses-dashfill
321 Centering using dashes (-) instead of spaces.
323 @item ses-dashfill-span
324 Centering with dashes and spill-over.
326 @item ses-tildefill-span
327 Centering with tildes (~) and spill-over.
328 @end table
331 @node Clearing cells, Copy/cut/paste, Printer functions, The Basics
332 @section Clearing cells
333 @cindex clearing commands
334 @findex ses-clear-cell-backward
335 @findex ses-clear-cell-forward
337 These commands set both formula and printer to @code{nil}:
339 @table @kbd
340 @item DEL
341 Clear cell and move left (@code{ses-clear-cell-backward}).
343 @item C-d
344 Clear cell and move right (@code{ses-clear-cell-forward}).
345 @end table
348 @node Copy/cut/paste, Customizing SES, Clearing cells, The Basics
349 @section Copy, cut, and paste
350 @cindex copy
351 @cindex cut
352 @cindex paste
353 @findex kill-ring-save
354 @findex mouse-set-region
355 @findex mouse-set-secondary
356 @findex ses-kill-override
357 @findex yank
358 @findex clipboard-yank
359 @findex mouse-yank-at-click
360 @findex mouse-yank-at-secondary
361 @findex ses-yank-pop
363 The copy functions work on rectangular regions of cells.  You can paste the
364 copies into non-SES buffers to export the print text.
366 @table @kbd
367 @item M-w
368 @itemx [copy]
369 @itemx [C-insert]
370 Copy the highlighted cells to kill ring and primary clipboard
371 (@code{kill-ring-save}).
373 @item [drag-mouse-1]
374 Mark a region and copy it to kill ring and primary clipboard
375 (@code{mouse-set-region}).
377 @item [M-drag-mouse-1]
378 Mark a region and copy it to kill ring and secondary clipboard
379 (@code{mouse-set-secondary}).
381 @item C-w
382 @itemx [cut]
383 @itemx [S-delete]
384 The cut functions do not actually delete rows or columns---they copy
385 and then clear (@code{ses-kill-override}).
387 @item C-y
388 @itemx [S-insert]
389 Paste from kill ring (@code{yank}).  The paste functions behave
390 differently depending on the format of the text being inserted:
391 @itemize @bullet
392 @item
393 When pasting cells that were cut from a SES buffer, the print text is
394 ignored and only the attached formula and printer are inserted; cell
395 references in the formula are relocated unless you use @kbd{C-u}.
396 @item
397 The pasted text overwrites a rectangle of cells whose top left corner
398 is the current cell.  If part of the rectangle is beyond the edges of
399 the spreadsheet, you must confirm the increase in spreadsheet size.
400 @item
401 Non-SES text is usually inserted as a replacement formula for the
402 current cell.  If the formula would be a symbol, it's treated as a
403 string unless you use @kbd{C-u}.  Pasted formulas with syntax errors
404 are always treated as strings.
405 @end itemize
407 @item [paste]
408 Paste from primary clipboard or kill ring (@code{clipboard-yank}).
410 @item [mouse-2]
411 Set point and paste from primary clipboard (@code{mouse-yank-at-click}).
413 @item [M-mouse-2]
414 Set point and paste from secondary clipboard (@code{mouse-yank-secondary}).
416 @item M-y
417 Immediately after a paste, you can replace the text with a preceding
418 element from the kill ring (@code{ses-yank-pop}).  Unlike the standard
419 Emacs yank-pop, the SES version uses @code{undo} to delete the old
420 yank.  This doesn't make any difference?
421 @end table
423 @node Customizing SES,  , Copy/cut/paste, The Basics
424 @section Customizing SES
425 @cindex customizing
426 @vindex enable-local-eval
427 @vindex ses-mode-hook
428 @vindex safe-functions
429 @vindex enable-local-eval
432 By default, a newly-created spreadsheet has 1 row and 1 column.  The
433 column width is 7 and the default printer is @samp{"%.7g"}.  Each of these
434 can be customized.  Look in group ``ses''.
436 After entering a cell value, point normally moves right to the next
437 cell.  You can customize @code{ses-after-entry-functions} to move left or
438 up or down.  For diagonal movement, select two functions from the
439 list.
441 @code{ses-mode-hook} is a normal mode hook (list of functions to
442 execute when starting SES mode for a buffer).
444 The variable @code{safe-functions} is a list of possibly-unsafe
445 functions to be treated as safe when analysing formulas and printers.
446 @xref{Virus protection}.  Before customizing @code{safe-functions},
447 think about how much you trust the person who's suggesting this
448 change.  The value @code{t} turns off all anti-virus protection.  A
449 list-of-functions value might enable a ``gee whiz'' spreadsheet, but it
450 also creates trapdoors in your anti-virus armor.  In order for virus
451 protection to work, you must always press @kbd{n} when presented with
452 a virus warning, unless you understand what the questionable code is
453 trying to do.  Do not listen to those who tell you to customize
454 @code{enable-local-eval}---this variable is for people who don't wear
455 safety belts!
458 @c ===================================================================
460 @node Advanced Features, For Gurus, The Basics, Top
461 @chapter Advanced Features
462 @cindex advanced features
463 @findex ses-read-header-row
466 @table @kbd
467 @item C-c M-C-h
468 (@code{ses-set-header-row}).  The header line at the top of the SES
469 window normally shows the column letter for each column.  You can set
470 it to show a copy of some row, such as a row of column titles, so that
471 row will always be visible.  Default is to set the current row as the
472 header; use C-u to prompt for header row.  Set the header to row 0 to
473 show column letters again.
474 @item [header-line mouse-3]
475 Pops up a menu to set the current row as the header, or revert to
476 column letters.
477 @end table
479 @menu
480 * The print area::
481 * Ranges in formulas::
482 * Sorting by column::
483 * Standard formula functions::
484 * More on cell printing::
485 * Import and export::
486 * Virus protection::
487 * Spreadsheets with details and summary::
488 @end menu
490 @node The print area, Ranges in formulas, Advanced Features, Advanced Features
491 @section The print area
492 @cindex print area
493 @findex widen
494 @findex ses-renarrow-buffer
495 @findex ses-reprint-all
497 A SES file consists of a print area and a data area.  Normally the
498 buffer is narrowed to show only the print area.  The print area is
499 read-only except for special SES commands; it contains cell values
500 formatted by printer functions.  The data area records the formula and
501 printer functions, etc.
503 @table @kbd
504 @item C-x n w
505 Show print and data areas (@code{widen}).
507 @item C-c C-n
508 Show only print area (@code{ses-renarrow-buffer}).
510 @item S-C-l
511 @itemx M-C-l
512 Recreate print area by reevaluating printer functions for all cells
513 (@code{ses-reprint-all}).
514 @end table
516 @node Ranges in formulas, Sorting by column, The print area, Advanced Features
517 @section Ranges in formulas
518 @cindex ranges
519 @findex ses-insert-range-click
520 @findex ses-insert-range
521 @findex ses-insert-ses-range-click
522 @findex ses-insert-ses-range
523 @vindex from
524 @vindex to
526 A formula like
527 @lisp
528 (+ A1 A2 A3)
529 @end lisp
530 is the sum of three specific cells.  If you insert a new second row,
531 the formula becomes
532 @lisp
533 (+ A1 A3 A4)
534 @end lisp
535 and the new row is not included in the sum.
537 The macro @code{(ses-range @var{from} @var{to})} evalutes to a list of
538 the values in a rectangle of cells.  If your formula is
539 @lisp
540 (apply '+ (ses-range A1 A3))
541 @end lisp
542 and you insert a new second row, it becomes
543 @lisp
544 (apply '+ (ses-range A1 A4))
545 @end lisp
546 and the new row is included in the sum.
548 While entering or editing a formula in the minibuffer, you can select
549 a range in the spreadsheet (using mouse or keyboard), then paste a
550 representation of that range into your formula.  Suppose you select
551 A1-C1:
553 @table @kbd
554 @item [S-mouse-3]
555 Inserts "A1 B1 C1" @code{(ses-insert-range-click})
557 @item C-c C-r
558 Keyboard version (@code{ses-insert-range}).
560 @item [C-S-mouse-3]
561 Inserts "(ses-range A1 C1)" (@code{ses-insert-ses-range-click}).
563 @item C-c C-s
564 Keyboard version (@code{ses-insert-ses-range}).
565 @end table
567 If you delete the @var{from} or @var{to} cell for a range, the nearest
568 still-existing cell is used instead.  If you delete the entire range,
569 the formula relocator will delete the ses-range from the formula.
571 If you insert a new row just beyond the end of a one-column range, or
572 a new column just beyond a one-row range, the new cell is included in
573 the range.  New cells inserted just before a range are not included.
576 @node Sorting by column, Standard formula functions, Ranges in formulas, Advanced Features
577 @section Sorting by column
578 @cindex sorting
579 @findex ses-sort-column
580 @findex ses-sort-column-click
582 @table @kbd
583 @item C-c M-C-s
584 Sort the cells of a range using one of the columns
585 (@code{ses-sort-column}).  The rows (or partial rows if the range
586 doesn't include all columns) are rearranged so the chosen column will
587 be in order.
589 @item [header-line mouse-2]
590 The easiest way to sort is to click mouse-2 on the chosen column's header row
591 (@code{ses-sort-column-click}).
592 @end table
594 The sort comparison uses @code{string<}, which works well for
595 right-justified numbers and left-justified strings.
597 With prefix arg, sort is in descending order.
599 Rows are moved one at a time, with relocation of formulas.  This works
600 well if formulas refer to other cells in their row, not so well for
601 formulas that refer to other rows in the range or to cells outside the
602 range.
605 @node Standard formula functions, More on cell printing, Sorting by column, Advanced Features
606 @section Standard formula functions
607 @cindex standard formula functions
608 @cindex *skip*
609 @cindex *error*
610 @findex ses-delete-blanks
611 @findex ses-average
612 @findex ses+
614 Oftentimes you want a calculation to exclude the blank cells.  Here
615 are some useful functions to call from your formulas:
617 @table @code
618 @item (ses-delete-blanks &rest @var{args})
619 Returns a list from which all blank cells (value is either @code{nil} or
620 '*skip*) have been deleted.
622 @item (ses+ &rest @var{args})
623 Sum of non-blank arguments.
625 @item (ses-average @var{list})
626 Average of non-blank elements in @var{list}.  Here the list is passed
627 as a single argument, since you'll probably use it with @code{ses-range}.
628 @end table
630 @node More on cell printing, Import and export, Standard formula functions, Advanced Features
631 @section More on cell printing
632 @cindex cell printing, more
633 @findex ses-truncate-cell
634 @findex ses-recalculate-cell
636 Special cell values:
637 @itemize
638 @item nil prints the same as "", but allows previous cell to spill over.
639 @item '*skip* replaces nil when the previous cell actually does spill over;
640 nothing is printed for it.
641 @item '*error* indicates that the formula signalled an error instead of
642 producing a value: the print cell is filled with hash marks (#).
643 @end itemize
645 If the result from the printer function is too wide for the cell and
646 the following cell is @code{nil}, the result will spill over into the
647 following cell.  Very wide results can spill over several cells.  If
648 the result is too wide for the available space (up to the end of the
649 row or the next non-@code{nil} cell), the result is truncated if the cell's
650 value is a string, or replaced with hash marks otherwise.
652 SES could get confused by printer results that contain newlines or
653 tabs, so these are replaced with question marks.
655 @table @kbd
656 @item C-c C-t
657 Confine a cell to its own column (@code{ses-truncate-cell}).  This
658 alows you to move point to a rightward cell that would otherwise be
659 covered by a spill-over.  If you don't change the rightward cell, the
660 confined cell will spill over again the next time it is reprinted.
662 @item C-c C-c
663 When applied to a single cell, this command displays in the echo area any
664 formula error or printer error that occurred during
665 recalculation/reprinting (@code{ses-recalculate-cell}).
666 @end table
668 When a printer function signals an error, the default printer
669 @samp{"%s"} is substituted.  This is useful when your column printer
670 is numeric-only and you use a string as a cell value.
673 @node Import and export, Virus protection, More on cell printing, Advanced Features
674 @section Import and export
675 @cindex import and export
676 @cindex export, and import
677 @findex ses-export-tsv
678 @findex ses-export-tsf
680 @table @kbd
681 @item x t
682 Export a range of cells as tab-separated values (@code{ses-export-tsv}).
683 @item x T
684 Export a range of cells as tab-separated formulas (@code{ses-export-tsf}).
685 @end table
687 The exported text goes to the kill ring --- you can paste it into
688 another buffer.  Columns are separated by tabs, rows by newlines.
690 To import text, use any of the yank commands where the text to paste
691 contains tabs and/or newlines.  Imported formulas are not relocated.
693 @node Virus protection, Spreadsheets with details and summary, Import and export, Advanced Features
694 @section Virus protection
695 @cindex virus protection
697 Whenever a formula or printer is read from a file or is pasted into
698 the spreadsheet, it receives a ``needs safety check'' marking.  Later,
699 when the formula or printer is evaluated for the first time, it is
700 checked for safety using the @code{unsafep} predicate; if found to be
701 ``possibly unsafe'', the questionable formula or printer is displayed
702 and you must press Y to approve it or N to use a substitute.  The
703 substitute always signals an error.
705 Formulas or printers that you type in are checked immediately for
706 safety.  If found to be possibly unsafe and you press N to disapprove,
707 the action is cancelled and the old formula or printer will remain.
709 Besides viruses (which try to copy themselves to other files),
710 @code{unsafep} can also detect all other kinds of Trojan horses, such as
711 spreadsheets that delete files, send email, flood Web sites, alter
712 your Emacs settings, etc.
714 Generally, spreadsheet formulas and printers are simple things that
715 don't need to do any fancy computing, so all potentially-dangerous
716 parts of the Emacs Lisp environment can be excluded without cramping
717 your style as a formula-writer.  See the documentation in @file{unsafep.el}
718 for more info on how Lisp forms are classified as safe or unsafe.
720 @node Spreadsheets with details and summary,  , Virus protection, Advanced Features
721 @section Spreadsheets with details and summary
722 @cindex details and summary
723 @cindex summary, and details
725 A common organization for spreadsheets is to have a bunch of ``detail''
726 rows, each perhaps describing a transaction, and then a set of
727 ``summary'' rows that each show reduced data for some subset of the
728 details.  SES supports this organization via the @code{ses-select}
729 function.
731 @table @code
732 @item (ses-select @var{fromrange} @var{test} @var{torange})
733 Returns a subset of @var{torange}.  For each member in @var{fromrange}
734 that is equal to @var{test}, the corresponding member of @var{torange}
735 is included in the result.
736 @end table
738 Example of use:
739 @lisp
740 (ses-average (ses-select (ses-range A1 A5) 'Smith (ses-range B1 B5)))
741 @end lisp
742 This computes the average of the B column values for those rows whose
743 A column value is the symbol 'Smith.
745 Arguably one could specify only @var{fromrange} plus
746 @var{to-row-offset} and @var{to-column-offset}.  The @var{torange} is
747 stated explicitly to ensure that the formula will be recalculated if
748 any cell in either range is changed.
750 File @file{etc/ses-example.el} in the Emacs distribution is an example of a
751 details-and-summary spreadsheet.
754 @c ===================================================================
756 @node For Gurus, Index, Advanced Features, Top
757 @chapter For Gurus
758 @cindex advanced features
760 @menu
761 * Deferred updates::
762 * Nonrelocatable references::
763 * The data area::
764 * Buffer-local variables in spreadsheets::
765 * Uses of defadvice in SES::
766 @end menu
768 @node Deferred updates, Nonrelocatable references, For Gurus, For Gurus
769 @section Deferred updates
770 @cindex deferred updates
771 @cindex updates, deferred
772 @vindex run-with-idle-timer
774 To save time by avoiding redundant computations, cells that need
775 recalculation due to changes in other cells are added to a set.  At
776 the end of the command, each cell in the set is recalculated once.
777 This can create a new set of cells that need recalculation.  The
778 process is repeated until either the set is empty or it stops changing
779 (due to circular references among the cells).  In extreme cases, you
780 might see progress messages of the form ``Recalculating... (@var{nnn}
781 cells left)''.  If you interrupt the calculation using @kbd{C-g}, the
782 spreadsheet will be left in an inconsistent state, so use @kbd{C-_} or
783 @kbd{C-c C-l} to fix it.
785 To save even more time by avoiding redundant writes, cells that have
786 changes are added to a set instead of being written immediately to the
787 data area.  Each cell in the set is written once, at the end of the
788 command.  If you change vast quantities of cells, you might see a
789 progress message of the form ``Writing... (@var{nnn} cells left)''.
790 These deferred cell-writes cannot be interrupted by @kbd{C-g}, so
791 you'll just have to wait.
793 SES uses @code{run-with-idle-timer} to move the cell underline when
794 Emacs will be scrolling the buffer after the end of a command, and
795 also to narrow and underline after @kbd{C-x C-v}.  This is visible as
796 a momentary glitch after C-x C-v and certain scrolling commands.  You
797 can type ahead without worrying about the glitch.
800 @node Nonrelocatable references, The data area, Deferred updates, For Gurus
801 @section Nonrelocatable references
802 @cindex nonrelocatable references
803 @cindex references, nonrelocatable
805 @kbd{C-y} relocates all cell-references in a pasted formula, while
806 @kbd{C-u C-y} relocates none of the cell-references.  What about mixed
807 cases?
809 You can use
810 @lisp
811 (symbol-value 'B3)
812 @end lisp
813 to make an @dfn{absolute reference}.  The formula relocator skips over
814 quoted things, so this will not be relocated when pasted or when
815 rows/columns are inserted/deleted.  However, B3 will not be recorded
816 as a dependency of this cell, so this cell will not be updated
817 automatically when B3 is changed.
819 The variables @code{row} and @code{col} are dynamically bound while a
820 cell formula is being evaluated.  You can use
821 @lisp
822 (ses-cell-value row 0)
823 @end lisp
824 to get the value from the leftmost column in the current row.  This
825 kind of dependency is also not recorded.
828 @node The data area, Buffer-local variables in spreadsheets, Nonrelocatable references, For Gurus
829 @section The data area
830 @cindex data area
831 @findex ses-reconstruct-all
833 Begins with an 014 character, followed by sets of cell-definition
834 macros for each row, followed by column-widths, column-printers,
835 default-printer, and header-row.  Then there's the global parameters
836 (file-format ID, numrows, numcols) and the local variables (specifying
837 SES mode for the buffer, etc.)
839 When a SES file is loaded, first the numrows and numcols values are
840 loaded, then the entire data area is @code{eval}ed, and finally the local
841 variables are processed.
843 You can edit the data area, but don't insert or delete any newlines
844 except in the local-variables part, since SES locates things by
845 counting newlines.  Use @kbd{C-x C-e} at the end of a line to install
846 your edits into the spreadsheet data structures (this does not update
847 the print area, use e.g. @kbd{C-c C-l} for that).
849 The data area is maintained as an image of spreadsheet data
850 structures that area stored in buffer-local variables.  If the data
851 area gets messed up, you can try reconstructing the data area from the
852 data structures:
854 @table @kbd
855 @item C-c M-C-l
856 (@code{ses-reconstruct-all}).
857 @end table
860 @node Buffer-local variables in spreadsheets, Uses of defadvice in SES, The data area, For Gurus
861 @section Buffer-local variables in spreadsheets
862 @cindex buffer-local variables
863 @cindex variables, buffer-local
865 You can add additional local variables to the list at the bottom of
866 the data area, such as hidden constants you want to refer to in your
867 formulas.
869 You can override the variable @code{symbolic-formulas} to be a list of
870 symbols (as parenthesized strings) to show as completions for the '
871 command.  This initial completions list is used instead of the actual
872 set of symbols-as-formulas in the spreadsheet.
874 For examples of these, see file @file{etc/ses-example.ses}.
876 If (for some reason) you want your formulas or printers to save data
877 into variables, you must declare these variables as buffer-locals in
878 order to avoid a virus warning.
880 You can define functions by making them values for the fake local
881 variable @code{eval}.  Such functions can then be used in your
882 formulas and printers, but usually each @code{eval} is presented to
883 the user during file loading as a potential virus --- this can get
884 annoying.
886 You can define functions in your @file{.emacs} file.  Other people can
887 still read the print area of your spreadsheet, but they won't be able
888 to recalculate or reprint anything that depends on your functions.  To
889 avoid virus warnings, each function used in a formula needs
890 @lisp
891 (put 'your-function-name 'safe-function t)
892 @end lisp
894 @node Uses of defadvice in SES,  , Buffer-local variables in spreadsheets, For Gurus
895 @section Uses of defadvice in SES
896 @cindex defadvice
897 @cindex undo-more
898 @cindex copy-region-as-kill
899 @cindex yank
901 @table @code
902 @item undo-more
903 Defines a new undo element format (@var{fun} . @var{args}), which
904 means ``undo by applying @var{fun} to @var{args}''.  For spreadsheet
905 buffers, it allows undos in the data area even though that's outside
906 the narrowing.
908 @item copy-region-as-kill
909 When copying from the print area of a spreadsheet, treat the region as
910 a rectangle and attach each cell's formula and printer as 'ses
911 properties.
913 @item yank
914 When yanking into the print area of a spreadsheet, first try to yank
915 as cells (if the yank text has 'ses properties), then as tab-separated
916 formulas, then (if all else fails) as a single formula for the current
917 cell.
918 @end table
920 @c ===================================================================
921 @node Index, Acknowledgements, For Gurus, Top
922 @unnumbered Concept Index
924 @printindex cp
926 @heading Function Index
928 @printindex fn
930 @heading Variable Index
932 @printindex vr
935 @c ===================================================================
937 @node Acknowledgements, , Index, Top
938 @chapter Acknowledgements
940 Coding by:
941 @quotation
942 Jonathan Yavner @email{jyavner@@member.fsf.org}@*
943 Stefan Monnier @email{monnier@@gnu.org}
944 @end quotation
946 @noindent
947 Texinfo manual by:
948 @quotation
949 Jonathan Yavner @email{jyavner@@member.fsf.org}@*
950 Brad Collins <brad@@chenla.org>
951 @end quotation
953 @noindent
954 Ideas from:
955 @quotation
956 Christoph Conrad @email{christoph.conrad@@gmx.de}@*
957 CyberBob @email{cyberbob@@redneck.gacracker.org}@*
958 Syver Enstad @email{syver-en@@online.no}@*
959 Ami Fischman @email{fischman@@zion.bpnetworks.com}@*
960 Thomas Gehrlein @email{Thomas.Gehrlein@@t-online.de}@*
961 Chris F.A. Johnson @email{c.f.a.johnson@@rogers.com}@*
962 Yusong Li @email{lyusong@@hotmail.com}@*
963 Juri Linkov @email{juri@@jurta.org}@*
964 Harald Maier @email{maierh@@myself.com}@*
965 Alan Nash @email{anash@@san.rr.com}@*
966 François Pinard @email{pinard@@iro.umontreal.ca}@*
967 Pedro Pinto @email{ppinto@@cs.cmu.edu}@*
968 Stefan Reichör @email{xsteve@@riic.at}@*
969 Oliver Scholz @email{epameinondas@@gmx.de}@*
970 Richard M. Stallman @email{rms@@gnu.org}@*
971 Luc Teirlinck @email{teirllm@@dms.auburn.edu}@*
972 J. Otto Tennant @email{jotto@@pobox.com}@*
973 Jean-Philippe Theberge @email{jphil@@acs.pagesjaunes.fr}
974 @end quotation
976 @c ===================================================================
978 @bye
980 @ignore
981    arch-tag: 10a4ee1c-7ef4-4c06-8b7a-f975e39f0dec
982 @end ignore