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