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