root/trunk/lisp/textmodes/table.el

Revision 4220, 229.7 kB (checked in by miyoshi, 9 months ago)

Sync up with Emacs22.2.

Line 
1 ;;; table.el --- create and edit WYSIWYG text based embedded tables
2
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006, 2007, 2008  Free Software Foundation, Inc.
5
6 ;; Keywords: wp, convenience
7 ;; Author: Takaaki Ota <Takaaki.Ota@am.sony.com>
8 ;; Created: Sat Jul 08 2000 13:28:45 (PST)
9 ;; Revised: Wed Jan 03 2007 13:23:46 (PST)
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 3, or (at your option)
16 ;; any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
27
28 ;;; Commentary:
29
30 ;; -------------
31 ;; Introduction:
32 ;; -------------
33 ;;
34 ;; This package provides text based table creation and editing
35 ;; feature.  With this package Emacs is capable of editing tables that
36 ;; are embedded inside a text document, the feature similar to the
37 ;; ones seen in modern WYSIWYG word processors.  A table is a
38 ;; rectangular text area consisting from a surrounding frame and
39 ;; content inside the frame.  The content is usually subdivided into
40 ;; multiple rectangular cells, see the actual tables used below in
41 ;; this document.  Once a table is recognized, editing operation
42 ;; inside a table cell is confined into that specific cell's
43 ;; rectangular area.  This means that typing and deleting characters
44 ;; inside a cell do not affect any outside text but introduces
45 ;; appropriate formatting only to the cell contents.  If necessary for
46 ;; accommodating added text in the cell, the cell automatically grows
47 ;; vertically and/or horizontally.  The package uses no major mode nor
48 ;; minor mode for its implementation because the subject text is
49 ;; localized within a buffer.  Therefore the special behaviors inside
50 ;; a table cells are implemented by using keymap text property
51 ;; instead of buffer wide mode-map.
52 ;;
53 ;;
54 ;; -----------
55 ;; Background:
56 ;; -----------
57 ;;
58 ;; Paul Georgief is one of my best friends.  He became an Emacs
59 ;; convert after I recommended him trying it several years ago.  Now
60 ;; we both are devoted disciples of Emacsism and elisp cult.  One day
61 ;; in his Emacs exploration he asked me "Tak, what is a command to
62 ;; edit tables in Emacs?".  This question started my journey of this
63 ;; table package development.  May the code be with me!  In the
64 ;; software world Emacs is probably one of the longest lifetime record
65 ;; holders.  Amazingly there have been no direct support for WYSIWYG
66 ;; table editing tasks in Emacs.  Many people must have experienced
67 ;; manipulating existing overwrite-mode and picture-mode for this task
68 ;; and only dreamed of having such a lisp package which supports this
69 ;; specific task directly.  Certainly, I have been one of them.  The
70 ;; most difficult part of dealing with table editing in Emacs probably
71 ;; is how to realize localized rectangular editing effect.  Emacs has
72 ;; no rectangular narrowing mechanism.  Existing rect package provides
73 ;; basically kill, delete and yank operations of a rectangle, which
74 ;; internally is a mere list of strings.  A simple approach for
75 ;; realizing the localized virtual rectangular operation is combining
76 ;; rect package capability with a temporary buffer.  Insertion and
77 ;; deletion of a character to a table cell can be trapped by a
78 ;; function that copies the cell rectangle to a temporary buffer then
79 ;; apply the insertion/deletion to the temporary contents.  Then it
80 ;; formats the contents by filling the paragraphs in order to fit it
81 ;; into the original rectangular area and finally copy it back to the
82 ;; original buffer.  This simplistic approach has to bear with
83 ;; significant performance hit.  As cell grows larger the copying
84 ;; rectangle back and forth between the original buffer and the
85 ;; temporary buffer becomes expensive and unbearably slow.  It was
86 ;; completely impractical and an obvious failure.  An idea has been
87 ;; borrowed from the original Emacs design to overcome this
88 ;; shortcoming.  When the terminal screen update was slow and
89 ;; expensive Emacs employed a clever algorithm to reduce actual screen
90 ;; update by removing redundant redrawing operations.  Also the actual
91 ;; redrawing was done only when there was enough idling time.  This
92 ;; technique significantly improved the previously mentioned
93 ;; undesirable situation.  Now the original buffer's rectangle is
94 ;; copied into a cache buffer only once.  Any cell editing operation
95 ;; is done only to the cache contents.  When there is enough idling
96 ;; time the original buffer's rectangle is updated with the current
97 ;; cache contents.  This delayed operation is implemented by using
98 ;; Emacs's timer function.  To reduce the visual awkwardness
99 ;; introduced by the delayed effect the cursor location is updated in
100 ;; real-time as a user types while the cell contents remains the same
101 ;; until the next idling time.  A key to the success of this approach
102 ;; is how to maintain cache coherency.  As a user moves point in and
103 ;; out of a cell the table buffer contents and the cache buffer
104 ;; contents must be synchronized without a mistake.  By observing user
105 ;; action carefully this is possible however not easy.  Once this
106 ;; mechanism is firmly implemented the rest of table features grew in
107 ;; relatively painless progression.  Those users who are familiar with
108 ;; Emacs internals appreciate this table package more.  Because it
109 ;; demonstrates how extensible Emacs is by showing something that
110 ;; appears like a magic.  It lets you re-discover the potential of
111 ;; Emacs.
112 ;;
113 ;;
114 ;; -------------
115 ;; Entry Points:
116 ;; -------------
117 ;;
118 ;; If this is the first time for you to try this package, go ahead and
119 ;; load the package by M-x `load-file' RET.  Specify the package file
120 ;; name "table.el".  Then switch to a new test buffer and issue the
121 ;; command M-x `table-insert' RET.  It'll ask you number of columns,
122 ;; number of rows, cell width and cell height.  Give some small
123 ;; numbers for each of them.  Play with the resulted table for a
124 ;; while.  If you have menu system find the item "Table" under "Tools"
125 ;; and "Table" in the menu bar when the point is in a table cell.
126 ;; Some of them are pretty intuitive and you can easily guess what
127 ;; they do.  M-x `describe-function' and get the documentation of
128 ;; `table-insert'.  The document includes a short tutorial.  When you
129 ;; are tired of guessing how it works come back to this document
130 ;; again.
131 ;;
132 ;; To use the package regularly place this file in the site library
133 ;; directory and add the next expression in your .emacs file.  Make
134 ;; sure that directory is included in the `load-path'.
135 ;;
136 ;;   (require 'table)
137 ;;
138 ;; Have the next expression also, if you want always be ready to edit
139 ;; tables inside text files.  This mechanism is analogous to
140 ;; fontification in a sense that tables are recognized at editing time
141 ;; without having table information saved along with the text itself.
142 ;;
143 ;;   (add-hook 'text-mode-hook 'table-recognize)
144 ;;
145 ;; Following is a table of entry points and brief description of each
146 ;; of them.  The tables below are of course generated and edited by
147 ;; using this package.  Not all the commands are bound to keys.  Many
148 ;; of them must be invoked by "M-x" (`execute-extended-command')
149 ;; command.  Refer to the section "Keymap" below for the commands
150 ;; available from keys.
151 ;;
152 ;; +------------------------------------------------------------------+
153 ;; |                    User Visible Entry Points                     |
154 ;; +-------------------------------+----------------------------------+
155 ;; |           Function            |           Description            |
156 ;; +-------------------------------+----------------------------------+
157 ;; |`table-insert'                 |Insert a table consisting of grid |
158 ;; |                               |of cells by specifying the number |
159 ;; |                               |of COLUMNS, number of ROWS, cell  |
160 ;; |                               |WIDTH and cell HEIGHT.            |
161 ;; +-------------------------------+----------------------------------+
162 ;; |`table-insert-row'             |Insert row(s) of cells before the |
163 ;; |                               |current row that matches the      |
164 ;; |                               |current row structure.            |
165 ;; +-------------------------------+----------------------------------+
166 ;; |`table-insert-column'          |Insert column(s) of cells before  |
167 ;; |                               |the current column that matches   |
168 ;; |                               |the current column structure.     |
169 ;; +-------------------------------+----------------------------------+
170 ;; |`table-delete-row'             |Delete row(s) of cells.  The row  |
171 ;; |                               |must consist from cells of the    |
172 ;; |                               |same height.                      |
173 ;; +-------------------------------+----------------------------------+
174 ;; |`table-delete-column'          |Delete column(s) of cells.  The   |
175 ;; |                               |column must consist from cells of |
176 ;; |                               |the same width.                   |
177 ;; +-------------------------------+----------------------------------+
178 ;; |`table-recognize'              |Recognize all tables in the       |
179 ;; |`table-unrecognize'            |current buffer and                |
180 ;; |                               |activate/inactivate them.         |
181 ;; +-------------------------------+----------------------------------+
182 ;; |`table-recognize-region'       |Recognize all the cells in a      |
183 ;; |`table-unrecognize-region'     |region and activate/inactivate    |
184 ;; |                               |them.                             |
185 ;; +-------------------------------+----------------------------------+
186 ;; |`table-recognize-table'        |Recognize all the cells in a      |
187 ;; |`table-unrecognize-table'      |single table and                  |
188 ;; |                               |activate/inactivate them.         |
189 ;; +-------------------------------+----------------------------------+
190 ;; |`table-recognize-cell'         |Recognize a cell.  Find a cell    |
191 ;; |`table-unrecognize-cell'       |which contains the current point  |
192 ;; |                               |and activate/inactivate that cell.|
193 ;; +-------------------------------+----------------------------------+
194 ;; |`table-forward-cell'           |Move point to the next Nth cell in|
195 ;; |                               |a table.                          |
196 ;; +-------------------------------+----------------------------------+
197 ;; |`table-backward-cell'          |Move point to the previous Nth    |
198 ;; |                               |cell in a table.                  |
199 ;; +-------------------------------+----------------------------------+
200 ;; |`table-span-cell'              |Span the current cell toward the  |
201 ;; |                               |specified direction and merge it  |
202 ;; |                               |with the adjacent cell.  The      |
203 ;; |                               |direction is right, left, above or|
204 ;; |                               |below.                            |
205 ;; +-------------------------------+----------------------------------+
206 ;; |`table-split-cell-vertically'  |Split the current cell vertically |
207 ;; |                               |and create a cell above and a cell|
208 ;; |                               |below the point location.         |
209 ;; +-------------------------------+----------------------------------+
210 ;; |`table-split-cell-horizontally'|Split the current cell            |
211 ;; |                               |horizontally and create a cell on |
212 ;; |                               |the left and a cell on the right  |
213 ;; |                               |of the point location.            |
214 ;; +-------------------------------+----------------------------------+
215 ;; |`table-split-cell'             |Split the current cell vertically |
216 ;; |                               |or horizontally.  This is a       |
217 ;; |                               |wrapper command to the other two  |
218 ;; |                               |orientation specific commands.    |
219 ;; +-------------------------------+----------------------------------+
220 ;; |`table-heighten-cell'          |Heighten the current cell.        |
221 ;; +-------------------------------+----------------------------------+
222 ;; |`table-shorten-cell'           |Shorten the current cell.         |
223 ;; +-------------------------------+----------------------------------+
224 ;; |`table-widen-cell'             |Widen the current cell.           |
225 ;; +-------------------------------+----------------------------------+
226 ;; |`table-narrow-cell'            |Narrow the current cell.          |
227 ;; +-------------------------------+----------------------------------+
228 ;; |`table-fixed-width-mode'       |Toggle fixed width mode.  In the  |
229 ;; |                               |fixed width mode, typing inside a |
230 ;; |                               |cell never changes the cell width,|
231 ;; |                               |while in the normal mode the cell |
232 ;; |                               |width expands automatically in    |
233 ;; |                               |order to prevent a word being     |
234 ;; |                               |folded into multiple lines.  Fixed|
235 ;; |                               |width mode reverses video or      |
236 ;; |                               |underline the cell contents for   |
237 ;; |                               |its indication.                   |
238 ;; +-------------------------------+----------------------------------+
239 ;; |`table-query-dimension'        |Compute and report the current    |
240 ;; |                               |cell dimension, current table     |
241 ;; |                               |dimension and the number of       |
242 ;; |                               |columns and rows in the table.    |
243 ;; +-------------------------------+----------------------------------+
244 ;; |`table-generate-source'        |Generate the source of the current|
245 ;; |                               |table in the specified language   |
246 ;; |                               |and insert it into a specified    |
247 ;; |                               |buffer.                           |
248 ;; +-------------------------------+----------------------------------+
249 ;; |`table-insert-sequence'        |Travel cells forward while        |
250 ;; |                               |inserting a specified sequence    |
251 ;; |                               |string into each cell.            |
252 ;; +-------------------------------+----------------------------------+
253 ;; |`table-capture'                |Convert plain text into a table by|
254 ;; |                               |capturing the text in the region. |
255 ;; +-------------------------------+----------------------------------+
256 ;; |`table-release'                |Convert a table into plain text by|
257 ;; |                               |removing the frame from a table.  |
258 ;; +-------------------------------+----------------------------------+
259 ;; |`table-justify'                |Justify the contents of cell(s).  |
260 ;; +-------------------------------+----------------------------------+
261 ;;
262 ;;
263 ;; *Note*
264 ;;
265 ;; You may find that some of commonly expected table commands are
266 ;; missing such as copying a row/column and yanking it.  Those
267 ;; functions can be obtained through existing Emacs text editing
268 ;; commands.  Rows are easily manipulated with region commands and
269 ;; columns can be copied and pasted through rectangle commands.  After
270 ;; all a table is still a part of text in the buffer.  Only the
271 ;; special behaviors exist inside each cell through text properties.
272 ;;
273 ;; `table-generate-html' which appeared in earlier releases is
274 ;; deprecated in favor of `table-generate-source'.  Now HTML is
275 ;; treated as one of the languages used for describing the table's
276 ;; logical structure.
277 ;;
278 ;;
279 ;; -------
280 ;; Keymap:
281 ;; -------
282 ;;
283 ;; Although this package does not use a mode it does use its own
284 ;; keymap inside a table cell by way of keymap text property.  Some of
285 ;; the standard basic editing commands bound to certain keys are
286 ;; replaced with the table specific version of corresponding commands.
287 ;; This replacement combination is listed in the constant alist
288 ;; `table-command-remap-alist' declared below.  This alist is
289 ;; not meant to be user configurable but mentioned here for your
290 ;; better understanding of using this package.  In addition, table
291 ;; cells have some table specific bindings for cell navigation and
292 ;; cell reformation.  You can find these additional bindings in the
293 ;; constant `table-cell-bindings'.  Those key bound functions are
294 ;; considered as internal functions instead of normal commands,
295 ;; therefore they have special prefix, *table-- instead of table-, for
296 ;; symbols.  The purpose of this is to make it easier for a user to
297 ;; use command name completion.  There is a "normal hooks" variable
298 ;; `table-cell-map-hook' prepared for users to override the default
299 ;; table cell bindings.  Following is the table of predefined default
300 ;; key bound commands inside a table cell.  Remember these bindings
301 ;; exist only inside a table cell.  When your terminal is a tty, the
302 ;; control modifier may not be available or applicable for those
303 ;; special characters.  In this case use "C-cC-c", which is
304 ;; customizable via `table-command-prefix', as the prefix key
305 ;; sequence.  This should preceding the following special character
306 ;; without the control modifier.  For example, use "C-cC-c|" instead
307 ;; of "C-|".
308 ;;
309 ;; +------------------------------------------------------------------+
310 ;; |                Default Bindings in a Table Cell                  |
311 ;; +-------+----------------------------------------------------------+
312 ;; |  Key  |                      Function                            |
313 ;; +-------+----------------------------------------------------------+
314 ;; |  TAB  |Move point forward to the beginning of the next cell.     |
315 ;; +-------+----------------------------------------------------------+
316 ;; | "C->" |Widen the current cell.                                   |
317 ;; +-------+----------------------------------------------------------+
318 ;; | "C-<" |Narrow the current cell.                                  |
319 ;; +-------+----------------------------------------------------------+
320 ;; | "C-}" |Heighten the current cell.                                |
321 ;; +-------+----------------------------------------------------------+
322 ;; | "C-{" |Shorten the current cell.                                 |
323 ;; +-------+----------------------------------------------------------+
324 ;; | "C--" |Split current cell vertically. (one above and one below)  |
325 ;; +-------+----------------------------------------------------------+
326 ;; | "C-|" |Split current cell horizontally. (one left and one right) |
327 ;; +-------+----------------------------------------------------------+
328 ;; | "C-*" |Span current cell into adjacent one.                      |
329 ;; +-------+----------------------------------------------------------+
330 ;; | "C-+" |Insert row(s)/column(s).                                  |
331 ;; +-------+----------------------------------------------------------+
332 ;; | "C-!" |Toggle between normal mode and fixed width mode.          |
333 ;; +-------+----------------------------------------------------------+
334 ;; | "C-#" |Report cell and table dimension.                          |
335 ;; +-------+----------------------------------------------------------+
336 ;; | "C-^" |Generate the source in a language from the current table. |
337 ;; +-------+----------------------------------------------------------+
338 ;; | "C-:" |Justify the contents of cell(s).                          |
339 ;; +-------+----------------------------------------------------------+
340 ;;
341 ;; *Note*
342 ;;
343 ;; When using `table-cell-map-hook' do not use `local-set-key'.
344 ;;
345 ;;   (add-hook 'table-cell-map-hook
346 ;;     (function (lambda ()
347 ;;       (local-set-key [<key sequence>] '<function>))))
348 ;;
349 ;; Above code is well known ~/.emacs idiom for customizing a mode
350 ;; specific keymap however it does not work for this package.  This is
351 ;; because there is no table mode in effect.  This package does not
352 ;; use a local map therefor you must modify `table-cell-map'
353 ;; explicitly.  The correct way of achieving above task is:
354 ;;
355 ;;   (add-hook 'table-cell-map-hook
356 ;;     (function (lambda ()
357 ;;       (define-key table-cell-map [<key sequence>] '<function>))))
358 ;;
359 ;; -----
360 ;; Menu:
361 ;; -----
362 ;;
363 ;; If a menu system is available a group of table specific menu items,
364 ;; "Table" under "Tools" section of the menu bar, is globally added
365 ;; after this package is loaded.  The commands in this group are
366 ;; limited to the ones that are related to creation and initialization
367 ;; of tables, such as to insert a table, to insert rows and columns,
368 ;; or recognize and unrecognize tables.  Once tables are created and
369 ;; point is placed inside of a table cell a table specific menu item
370 ;; "Table" appears directly on the menu bar.  The commands in this
371 ;; menu give full control on table manipulation that include cell
372 ;; navigation, insertion, splitting, spanning, shrinking, expansion
373 ;; and unrecognizing.  In addition to above two types of menu there is
374 ;; a pop-up menu available within a table cell.  The content of pop-up
375 ;; menu is identical to the full table menu.  [mouse-3] is the default
376 ;; button, defined in `table-cell-bindings', to bring up the pop-up
377 ;; menu.  It can be reconfigured via `table-cell-map-hook'.  The
378 ;; benefit of a pop-up menu is that it combines selection of the
379 ;; location (which cell, where in the cell) and selection of the
380 ;; desired operation into a single clicking action.
381 ;;
382 ;;
383 ;; -------------------------------
384 ;; Definition of tables and cells:
385 ;; -------------------------------
386 ;;
387 ;; There is no artificial-intelligence magic in this package.  The
388 ;; definition of a table and the cells inside the table is reasonably
389 ;; limited in order to achieve acceptable performance in the
390 ;; interactive operation under Emacs lisp implementation.  A valid
391 ;; table is a rectangular text area completely filled with valid
392 ;; cells.  A valid cell is a rectangle text area, which four borders
393 ;; consist of valid border characters.  Cells can not be nested one to
394 ;; another or overlapped to each other except sharing the border
395 ;; lines.  A valid character of a cell's vertical border is either
396 ;; table-cell-vertical-char `|' or table-cell-intersection-char `+'.
397 ;; A valid character of a cell's horizontal border is either
398 ;; table-cell-horizontal-char `-' or table-cell-intersection-char `+'.
399 ;; A valid character of the four corners of a cell must be
400 ;; table-cell-intersection-char `+'.  A cell must contain at least one
401 ;; character space inside.  There is no restriction about the contents
402 ;; of a table cell, however it is advised if possible to avoid using
403 ;; any of the border characters inside a table cell.  Normally a few
404 ;; boarder characters inside a table cell are harmless.  But it is
405 ;; possible that they accidentally align up to emulate a bogus cell
406 ;; corner on which software relies on for cell recognition.  When this
407 ;; happens the software may be fooled by it and fail to determine
408 ;; correct cell dimension.
409 ;;
410 ;; Following are the examples of valid tables.
411 ;;
412 ;; +--+----+---+     +-+     +--+-----+
413 ;; |  |    |   |     | |     |  |     |
414 ;; +--+----+---+     +-+     |  +--+--+
415 ;; |  |    |   |             |  |  |  |
416 ;; +--+----+---+             +--+--+  |
417 ;;                           |     |  |
418 ;;                           +-----+--+
419 ;;
420 ;; The next five tables are the examples of invalid tables.  (From
421 ;; left to right, 1. nested cells 2. overlapped cells and a
422 ;; non-rectangle cell 3. non-rectangle table 4. zero width/height
423 ;; cells 5. zero sized cell)
424 ;;
425 ;; +-----+    +-----+       +--+    +-++--+    ++
426 ;; |     |    |     |       |  |    | ||  |    ++
427 ;; | +-+ |    |     |       |  |    | ||  |
428 ;; | | | |    +--+  |    +--+--+    +-++--+
429 ;; | +-+ |    |  |  |    |  |  |    +-++--+
430 ;; |     |    |  |  |    |  |  |    | ||  |
431 ;; +-----+    +--+--+    +--+--+    +-++--+
432 ;;
433 ;; Although the program may recognizes some of these invalid tables,
434 ;; results from the subsequent editing operations inside those cells
435 ;; are not predictable and will most likely start destroying the table
436 ;; structures.
437 ;;
438 ;; It is strongly recommended to have at least one blank line above
439 ;; and below a table.  For a table to coexist peacefully with
440 ;; surrounding environment table needs to be separated from unrelated
441 ;; text.  This is necessary for the left table to grow or shrink
442 ;; horizontally without breaking the right table in the following
443 ;; example.
444 ;;
445 ;;                          +-----+-----+-----+
446 ;;  +-----+-----+           |     |     |     |
447 ;;  |     |     |           +-----+-----+-----+
448 ;;  +-----+-----+           |     |     |     |
449 ;;                          +-----+-----+-----+
450 ;;
451 ;;
452 ;; -------------------------
453 ;; Cell contents formatting:
454 ;; -------------------------
455 ;;
456 ;; The cell contents are formatted by filling a paragraph immediately
457 ;; after characters are inserted into or deleted from a cell.  Because
458 ;; of this, cell contents always remain fit inside a cell neatly.  One
459 ;; drawback of this is that users do not have full control over
460 ;; spacing between words and line breaking.  Only one space can be
461 ;; entered between words and up to two spaces between sentences.  For
462 ;; a newline to be effective the new line must form a beginning of
463 ;; paragraph, otherwise it'll automatically be merged with the
464 ;; previous line in a same paragraph.  To form a new paragraph the
465 ;; line must start with some space characters or immediately follow a
466 ;; blank line.  Here is a typical example of how to list items within
467 ;; a cell.  Without a space at the beginning of each line the items
468 ;; can not stand on their own.
469 ;;
470 ;; +---------------------------------+
471 ;; |Each one of the following three  |
472 ;; |items starts with a space        |
473 ;; |character thus forms a paragraph |
474 ;; |of its own.  Limitations in cell |
475 ;; |contents formatting are:         |
476 ;; |                                 |
477 ;; | 1. Only one space between words.|
478 ;; | 2. Up to two spaces between     |
479 ;; |sentences.                       |
480 ;; | 3. A paragraph must start with  |
481 ;; |spaces or follow a blank line.   |
482 ;; |                                 |
483 ;; |This paragraph stays away from   |
484 ;; |the item 3 because there is a    |
485 ;; |blank line between them.         |
486 ;; +---------------------------------+
487 ;;
488 ;; In the normal operation table cell width grows automatically when
489 ;; certain word has to be folded into the next line if the width had
490 ;; not been increased.  This normal operation is useful and
491 ;; appropriate for most of the time, however, it is sometimes useful
492 ;; or necessary to fix the width of table and width of table cells.
493 ;; For this purpose the package provides fixed width mode.  You can
494 ;; toggle between fixed width mode and normal mode by "C-!".
495 ;;
496 ;; Here is a simple example of the fixed width mode.  Suppose we have
497 ;; a table like this one.
498 ;;
499 ;; +-----+
500 ;; |     |
501 ;; +-----+
502 ;;
503 ;; In normal mode if you type a word "antidisestablishmentarianism" it
504 ;; grows the cell horizontally like this.
505 ;;
506 ;; +----------------------------+
507 ;; |antidisestablishmentarianism|
508 ;; +----------------------------+
509 ;;
510 ;;  In the fixed width mode the same action produces the following
511 ;;  result.  The folded locations are indicated by a continuation
512 ;;  character (`\' is the default).  The continuation character is
513 ;;  treated specially so it is recommended to choose a character that
514 ;;  does not appear elsewhere in table cells.  This character is
515 ;;  configurable via customization and is kept in the variable
516 ;;  `table-word-continuation-char'.  The continuation character is
517 ;;  treated specially only in the fixed width mode and has no special
518 ;;  meaning in the normal mode however.
519 ;;
520 ;; +-----+
521 ;; |anti\|
522 ;; |dise\|
523 ;; |stab\|
524 ;; |lish\|
525 ;; |ment\|
526 ;; |aria\|
527 ;; |nism |
528 ;; +-----+
529 ;;
530 ;;
531 ;; -------------------
532 ;; Cell Justification:
533 ;; -------------------
534 ;;
535 ;; By default the cell contents are filled with left justification and
536 ;; no vertical justification.  A paragraph can be justified
537 ;; individually but only horizontally.  Paragraph justification is for
538 ;; appearance only and does not change any structural information
539 ;; while cell justification affects table's structural information.
540 ;; For cell justification a user can select horizontal justification
541 ;; and vertical justification independently.  Horizontal justification
542 ;; must be one of the three 'left, 'center or 'right.  Vertical
543 ;; justification can be 'top, 'middle, 'bottom or 'none.  When a cell
544 ;; is justified, that information is recorded as a part of text
545 ;; property therefore the information is persistent as long as the
546 ;; cell remains within the Emacs world.  Even copying tables by region
547 ;; and rectangle manipulation commands preserve this information.
548 ;; However, once the table text is saved as a file and the buffer is
549 ;; killed the justification information vanishes permanently.  To
550 ;; alleviate this shortcoming without forcing users to save and
551 ;; maintain a separate attribute file, the table code detects
552 ;; justification of each cell when recognizing a table.  This
553 ;; detection is done by guessing the justification by looking at the
554 ;; appearance of the cell contents.  Since it is a guessing work it
555 ;; does not guarantee the perfectness but it is designed to be
556 ;; practically good enough.  The guessing algorithm is implemented in
557 ;; the function `table--detect-cell-alignment'.  If you have better
558 ;; algorithm or idea any suggestion is welcome.
559 ;;
560 ;;
561 ;; -----
562 ;; Todo: (in the order of priority, some are just possibility)
563 ;; -----
564 ;;
565 ;; Fix compatibilities with other input method than quail
566 ;; Resolve conflict with flyspell
567 ;; Use mouse for resizing cells
568 ;; A mechanism to link cells internally
569 ;; Consider the use of variable width font under Emacs 21
570 ;; Consider the use of `:box' face attribute under Emacs 21
571 ;; Consider the use of `modification-hooks' text property instead of
572 ;; rebinding the keymap
573 ;; Maybe provide complete XEmacs support in the future however the
574 ;; "extent" is the single largest obstacle lying ahead, read the
575 ;; document in Emacs info.
576 ;; (eval '(progn (require 'info) (Info-find-node "elisp" "Not Intervals")))
577 ;;
578 ;;
579 ;; ---------------
580 ;; Acknowledgment:
581 ;; ---------------
582 ;;
583 ;; Table would not have been possible without the help and
584 ;; encouragement of the following spirited contributors.
585 ;;
586 ;; Paul Georgief <georgief@igpp.ucsd.edu> has been the best tester
587 ;; of the code as well as the constructive criticizer.
588 ;;
589 ;; Gerd Moellmann <gerd@gnu.org> gave me useful suggestions from Emacs
590 ;; 21 point of view.