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