• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/emacs-93/emacs/lisp/textmodes/

Lines Matching +defs:table +defs:string

0 ;;; table.el --- create and edit WYSIWYG text based embedded tables
34 ;; This package provides text based table creation and editing
37 ;; ones seen in modern WYSIWYG word processors. A table is a
41 ;; this document. Once a table is recognized, editing operation
42 ;; inside a table cell is confined into that specific cell's
50 ;; a table cells are implemented by using keymap text property
63 ;; table package development. May the code be with me! In the
66 ;; table editing tasks in Emacs. Many people must have experienced
70 ;; most difficult part of dealing with table editing in Emacs probably
77 ;; deletion of a character to a table cell can be trapped by a
103 ;; out of a cell the table buffer contents and the cache buffer
106 ;; mechanism is firmly implemented the rest of table features grew in
108 ;; Emacs internals appreciate this table package more. Because it
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,
123 ;; numbers for each of them. Play with the resulted table for a
125 ;; and "Table" in the menu bar when the point is in a table cell.
128 ;; `table-insert'. The document includes a short tutorial. When you
136 ;; (require 'table)
141 ;; without having table information saved along with the text itself.
143 ;; (add-hook 'text-mode-hook 'table-recognize)
145 ;; Following is a table of entry points and brief description of each
157 ;; |`table-insert' |Insert a table consisting of grid |
162 ;; |`table-insert-row' |Insert row(s) of cells before the |
166 ;; |`table-insert-column' |Insert column(s) of cells before |
170 ;; |`table-delete-row' |Delete row(s) of cells. The row |
174 ;; |`table-delete-column' |Delete column(s) of cells. The |
178 ;; |`table-recognize' |Recognize all tables in the |
179 ;; |`table-unrecognize' |current buffer and |
182 ;; |`table-recognize-region' |Recognize all the cells in a |
183 ;; |`table-unrecognize-region' |region and activate/inactivate |
186 ;; |`table-recognize-table' |Recognize all the cells in a |
187 ;; |`table-unrecognize-table' |single table and |
190 ;; |`table-recognize-cell' |Recognize a cell. Find a cell |
191 ;; |`table-unrecognize-cell' |which contains the current point |
194 ;; |`table-forward-cell' |Move point to the next Nth cell in|
195 ;; | |a table. |
197 ;; |`table-backward-cell' |Move point to the previous Nth |
198 ;; | |cell in a table. |
200 ;; |`table-span-cell' |Span the current cell toward the |
206 ;; |`table-split-cell-vertically' |Split the current cell vertically |
210 ;; |`table-split-cell-horizontally'|Split the current cell |
215 ;; |`table-split-cell' |Split the current cell vertically |
220 ;; |`table-heighten-cell' |Heighten the current cell. |
222 ;; |`table-shorten-cell' |Shorten the current cell. |
224 ;; |`table-widen-cell' |Widen the current cell. |
226 ;; |`table-narrow-cell' |Narrow the current cell. |
228 ;; |`table-fixed-width-mode' |Toggle fixed width mode. In the |
239 ;; |`table-query-dimension' |Compute and report the current |
240 ;; | |cell dimension, current table |
242 ;; | |columns and rows in the table. |
244 ;; |`table-generate-source' |Generate the source of the current|
245 ;; | |table in the specified language |
249 ;; |`table-insert-sequence' |Travel cells forward while |
251 ;; | |string into each cell. |
253 ;; |`table-capture' |Convert plain text into a table by|
256 ;; |`table-release' |Convert a table into plain text by|
257 ;; | |removing the frame from a table. |
259 ;; |`table-justify' |Justify the contents of cell(s). |
265 ;; You may find that some of commonly expected table commands are
270 ;; all a table is still a part of text in the buffer. Only the
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
284 ;; keymap inside a table cell by way of keymap text property. Some of
286 ;; replaced with the table specific version of corresponding commands.
288 ;; `table-command-remap-alist' declared below. This alist is
290 ;; better understanding of using this package. In addition, table
291 ;; cells have some table specific bindings for cell navigation and
293 ;; constant `table-cell-bindings'. Those key bound functions are
295 ;; therefore they have special prefix, *table-- instead of table-, for
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
304 ;; customizable via `table-command-prefix', as the prefix key
334 ;; | "C-#" |Report cell and table dimension. |
336 ;; | "C-^" |Generate the source in a language from the current table. |
343 ;; When using `table-cell-map-hook' do not use `local-set-key'.
345 ;; (add-hook 'table-cell-map-hook
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'
355 ;; (add-hook 'table-cell-map-hook
357 ;; (define-key table-cell-map [<key sequence>] '<function>))))
363 ;; If a menu system is available a group of table specific menu items,
367 ;; of tables, such as to insert a table, to insert rows and columns,
369 ;; point is placed inside of a table cell a table specific menu item
371 ;; menu give full control on table manipulation that include cell
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
388 ;; definition of a table and the cells inside the table is reasonably
391 ;; table is a rectangular text area completely filled with valid
396 ;; table-cell-vertical-char `|' or table-cell-intersection-char `+'.
398 ;; table-cell-horizontal-char `-' or table-cell-intersection-char `+'.
400 ;; table-cell-intersection-char `+'. A cell must contain at least one
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
422 ;; non-rectangle cell 3. non-rectangle table 4. zero width/height
435 ;; are not predictable and will most likely start destroying the table
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
488 ;; In the normal operation table cell width grows automatically when
492 ;; or necessary to fix the width of table and width of table cells.
497 ;; a table like this one.
514 ;; does not appear elsewhere in table cells. This character is
516 ;; `table-word-continuation-char'. The continuation character is
539 ;; while cell justification affects table's structural information.
548 ;; However, once the table text is saved as a file and the buffer is
551 ;; maintain a separate attribute file, the table code detects
552 ;; justification of each cell when recognizing a table. This
557 ;; the function `table--detect-cell-alignment'. If you have better
593 ;; attempt of implementing the table feature to Emacs. This greatly
607 ;; asked for CALS table source generation and helped me following
637 ;; (defun table--point-in-cell-p (&optional location)))
644 (defgroup table nil
645 "Text based table manipulation utilities.
646 See `table-insert' for examples about how to use."
648 :prefix "table-"
655 (defgroup table-hooks nil
656 "Hooks for table manipulation utilities."
657 :group 'table)
659 (defcustom table-time-before-update 0.2
663 cell contents. When the contents of a table cell changes repetitively
671 :group 'table)
673 (defcustom table-time-before-reformat 0.2
674 "*Time in seconds before reformatting the table.
675 This many seconds must pass in addition to `table-time-before-update'
676 before the table is updated with newly widened width or heightened
680 :group 'table)
682 (defcustom table-command-prefix [(control c) (control c)]
683 "*Key sequence to be used as prefix for table command key bindings."
686 :group 'table)
688 (defface table-cell
694 "*Face used for table cell contents."
696 :group 'table)
698 (defcustom table-cell-horizontal-chars "-="
699 "*Characters that may be used for table cell's horizontal border line."
701 :type 'string
702 :group 'table)
704 (defcustom table-cell-vertical-char ?\|
705 "*Character that forms table cell's vertical border line."
708 :group 'table)
710 (defcustom table-cell-intersection-char ?\+
711 "*Character that forms table cell's corner."
714 :group 'table)
716 (defcustom table-word-continuation-char ?\\
719 that is when `table-fixed-width-mode' is non-nil . In the fixed width
726 :group 'table)
728 (defun table-set-table-fixed-width-mode (variable value)
732 (defun table-initialize-table-fixed-width-mode (variable value)
735 (defcustom table-fixed-width-mode nil
741 location is indicated by `table-word-continuation-char'. This
742 variable's value can be toggled by \\[table-fixed-width-mode] at
746 :initialize 'table-initialize-table-fixed-width-mode
747 :set 'table-set-table-fixed-width-mode
748 :group 'table)
750 (defcustom table-detect-cell-alignment t
754 whole. This applies to `table-recognize', `table-recognize-region'
755 and `table-recognize-table' but not to `table-recognize-cell'."
758 :group 'table)
760 (defcustom table-dest-buffer-name "table"
763 :type 'string
764 :group 'table)
766 (defcustom table-html-delegate-spacing-to-user-agent nil
771 :group 'table)
773 (defcustom table-html-th-rows 0
777 :group 'table)
779 (defcustom table-html-th-columns 0
783 :group 'table)
785 (defcustom table-html-table-attribute "border=\"1\""
786 "*Table attribute that applies to the table in HTML generation."
787 :tag "HTML table attribute"
788 :type 'string
789 :group 'table)
791 (defcustom table-html-cell-attribute ""
796 :type 'string
797 :group 'table)
799 (defcustom table-cals-thead-rows 1
800 "*Number of top rows to become header rows in CALS table."
803 :group 'table)
806 (defcustom table-cell-map-hook nil
807 "*Normal hooks run when finishing construction of `table-cell-map'.
808 User can modify `table-cell-map' by adding custom functions here."
811 :group 'table-hooks)
813 (defcustom table-disable-incompatibility-warning nil
818 :group 'table)
820 (defcustom table-abort-recognition-when-input-pending t
827 :group 'table)
830 (defcustom table-load-hook nil
831 "*List of functions to be called after the table is first loaded."
833 :group 'table-hooks)
836 (defcustom table-point-entered-cell-hook nil
837 "*List of functions to be called after point entered a table cell."
839 :group 'table-hooks)
842 (defcustom table-point-left-cell-hook nil
843 "*List of functions to be called after point left a table cell."
845 :group 'table-hooks)
847 (defvar table-yank-handler '(nil nil t nil)
850 (setplist 'table-disable-incompatibility-warning nil)
852 (defvar table-disable-menu (null (and (locate-library "easymenu")
855 "*When non-nil, use of menu by table package is disabled.
856 It must be set before loading this package `table.el' for the first
869 (defconst table-paragraph-start "[ \t\n\f]"
871 (defconst table-cache-buffer-name " *table cell cache*"
873 (defvar table-cell-info-lu-coordinate nil
875 (defvar table-cell-info-rb-coordinate nil
877 (defvar table-cell-info-width nil
879 (defvar table-cell-info-height nil
881 (defvar table-cell-info-justify nil
883 (defvar table-cell-info-valign nil
885 (defvar table-cell-self-insert-command-count 0
887 (defvar table-cell-map nil
888 "Keymap for table cell contents.")
889 (defvar table-cell-global-map-alist nil
890 "Alist of copy of global maps that are substituted in `table-cell-map'.")
891 (defvar table-global-menu-map nil
893 (defvar table-cell-menu-map nil
895 (defvar table-cell-buffer nil
896 "Buffer that contains the table cell.")
897 (defvar table-cell-cache-point-coordinate nil
899 (defvar table-cell-cache-mark-coordinate nil
901 (defvar table-cell-entered-state nil
903 (defvar table-update-timer nil
905 (defvar table-widen-timer nil
907 (defvar table-heighten-timer nil
909 (defvar table-inhibit-update nil
911 It inhibits `table-with-cache-buffer' to update data in both direction, cell to cache and cache to cell.")
912 (defvar table-inhibit-auto-fill-paragraph nil
913 "Non-nil inhibits auto fill paragraph when `table-with-cache-buffer' exits.
914 This is always set to nil at the entry to `table-with-cache-buffer' before executing body forms.")
915 (defvar table-mode-indicator nil
919 (make-variable-buffer-local 'table-mode-indicator)
920 (unless (assq table-mode-indicator minor-mode-alist)
921 (push '(table-mode-indicator (table-fixed-width-mode " Fixed-Table" " Table"))
924 (defconst table-source-languages '(html latex cals)
926 (defvar table-source-info-plist nil
935 (defvar table-cell-span-direction-history '("right"))
936 (defvar table-cell-split-orientation-history '("horizontally"))
937 (defvar table-cell-split-contents-to-history '("split"))
938 (defvar table-insert-row-column-history '("row"))
939 (defvar table-justify-history '("center"))
940 (defvar table-columns-history '("3"))
941 (defvar table-rows-history '("3"))
942 (defvar table-cell-width-history '("5"))
943 (defvar table-cell-height-history '("1"))
944 (defvar table-source-caption-history '("Table"))
945 (defvar table-sequence-string-history '("0"))
946 (defvar table-sequence-count-history '("0"))
947 (defvar table-sequence-increment-history '("1"))
948 (defvar table-sequence-interval-history '("1"))
949 (defvar table-sequence-justify-history '("left"))
950 (defvar table-source-language-history '("html"))
951 (defvar table-col-delim-regexp-history '(""))
952 (defvar table-row-delim-regexp-history '(""))
953 (defvar table-capture-justify-history '("left"))
954 (defvar table-capture-min-cell-width-history '("5"))
955 (defvar table-capture-columns-history '(""))
956 (defvar table-target-history '("cell"))
958 ;;; Some entries in `table-cell-bindings' are duplicated in
959 ;;; `table-command-remap-alist'. There is a good reason for
962 ;;; directly for `*table--cell-newline' ensures that the correct enter
963 ;;; operation in a table cell. However
964 ;;; `table-command-remap-alist' has an additional role than
965 ;;; replacing commands. It is also used to construct a table command
969 ;;; refill the table cache. If the command were not listed fast
971 (defconst table-cell-bindings
972 '(([(control i)] . table-forward-cell)
973 ([(control I)] . table-backward-cell)
974 ([tab] . table-forward-cell)
975 ([(shift backtab)] . table-backward-cell) ; for HPUX console keyboard
976 ([(shift iso-lefttab)] . table-backward-cell) ; shift-tab on a microsoft natural keyboard and redhat linux
977 ([(shift tab)] . table-backward-cell)
978 ([return] . *table--cell-newline)
979 ([(control m)] . *table--cell-newline)
980 ([(control j)] . *table--cell-newline-and-indent)
981 ([mouse-3] . *table--present-cell-popup-menu)
982 ([(control ?>)] . table-widen-cell)
983 ([(control ?<)] . table-narrow-cell)
984 ([(control ?})] . table-heighten-cell)
985 ([(control ?{)] . table-shorten-cell)
986 ([(control ?-)] . table-split-cell-vertically)
987 ([(control ?|)] . table-split-cell-horizontally)
988 ([(control ?*)] . table-span-cell)
989 ([(control ?+)] . table-insert-row-column)
990 ([(control ?!)] . table-fixed-width-mode)
991 ([(control ?#)] . table-query-dimension)
992 ([(control ?^)] . table-generate-source)
993 ([(control ?:)] . table-justify)
995 "Bindings for table cell commands.")
997 (defvar table-command-remap-alist
998 '((self-insert-command . *table--cell-self-insert-command)
999 (completion-separator-self-insert-autofilling . *table--cell-self-insert-command)
1000 (completion-separator-self-insert-command . *table--cell-self-insert-command)
1001 (delete-char . *table--cell-delete-char)
1002 (delete-backward-char . *table--cell-delete-backward-char)
1003 (backward-delete-char . *table--cell-delete-backward-char)
1004 (backward-delete-char-untabify . *table--cell-delete-backward-char)
1005 (newline . *table--cell-newline)
1006 (newline-and-indent . *table--cell-newline-and-indent)
1007 (open-line . *table--cell-open-line)
1008 (quoted-insert . *table--cell-quoted-insert)
1009 (describe-mode . *table--cell-describe-mode)
1010 (describe-bindings . *table--cell-describe-bindings)
1011 (dabbrev-expand . *table--cell-dabbrev-expand)
1012 (dabbrev-completion . *table--cell-dabbrev-completion))
1015 (defvar table-command-list nil
1017 ;; construct the real contents of the `table-command-list'
1018 (let ((remap-alist table-command-remap-alist))
1019 (setq table-command-list nil)
1021 (setq table-command-list (cons (cdar remap-alist) table-command-list))
1024 (defconst table-global-menu
1027 ["a Table..." table-insert
1028 :active (and (not buffer-read-only) (not (table--probe-cell)))
1029 :help "Insert a text based table at point"]
1030 ["Row" table-insert-row
1031 :active (table--row-column-insertion-point-p)
1032 :help "Insert row(s) of cells in table"]
1033 ["Column" table-insert-column
1034 :active (table--row-column-insertion-point-p 'column)
1035 :help "Insert column(s) of cells in table"])
1038 ["in Buffer" table-recognize
1041 ["in Region" table-recognize-region
1044 ["a Table" table-recognize-table
1045 :active (table--probe-cell)
1046 :help "Recognize a table at point"]
1047 ["a Cell" table-recognize-cell
1048 :active (let ((cell (table--probe-cell)))
1049 (and cell (null (table--at-cell-p (car cell)))))
1052 ["in Buffer" table-unrecognize
1055 ["in Region" table-unrecognize-region
1058 ["a Table" table-unrecognize-table
1059 :active (table--probe-cell)
1060 :help "Unrecognize the current table"]
1061 ["a Cell" table-unrecognize-cell
1062 :active (let ((cell (table--probe-cell)))
1063 (and cell (table--at-cell-p (car cell))))
1066 ["Capture Region" table-capture
1067 :active (and (not buffer-read-only) mark-active (not (eq (mark t) (point))) (not (table--probe-cell)))
1068 :help "Capture text in the current region as a table"]
1069 ["Release" table-release
1070 :active (table--editable-cell-p)
1071 :help "Release the current table as plain text"]))
1073 (defconst table-cell-menu
1076 ["Row" table-insert-row
1077 :active (table--row-column-insertion-point-p)
1078 :help "Insert row(s) of cells in table"]
1079 ["Column" table-insert-column
1080 :active (table--row-column-insertion-point-p 'column)
1081 :help "Insert column(s) of cells in table"])
1083 ["Row" table-delete-row
1084 :active (table--editable-cell-p)
1085 :help "Delete row(s) of cells in table"]
1086 ["Column" table-delete-column
1087 :active (table--editable-cell-p)
1088 :help "Delete column(s) of cells in table"])
1091 ["Horizontally" table-split-cell-horizontally
1092 :active (table--cell-can-split-horizontally-p)
1094 ["Vertically" table-split-cell-vertically
1095 :active (table--cell-can-split-vertically-p)
1098 ["Right" (table-span-cell 'right)
1099 :active (table--cell-can-span-p 'right)
1101 ["Left" (table-span-cell 'left)
1102 :active (table--cell-can-span-p 'left)
1104 ["Above" (table-span-cell 'above)
1105 :active (table--cell-can-span-p 'above)
1107 ["Below" (table-span-cell 'below)
1108 :active (table--cell-can-span-p 'below)
1112 ["Horizontally" table-narrow-cell
1113 :active (table--editable-cell-p)
1115 ["Vertically" table-shorten-cell
1116 :active (table--editable-cell-p)
1119 ["Horizontally" table-widen-cell
1120 :active (table--editable-cell-p)
1122 ["Vertically" table-heighten-cell
1123 :active (table--editable-cell-p)
1128 ["Left" (table-justify-cell 'left)
1129 :active (table--editable-cell-p)
1131 ["Center" (table-justify-cell 'center)
1132 :active (table--editable-cell-p)
1134 ["Right" (table-justify-cell 'right)
1135 :active (table--editable-cell-p)
1138 ["Top" (table-justify-cell 'top)
1139 :active (table--editable-cell-p)
1141 ["Middle" (table-justify-cell 'middle)
1142 :active (table--editable-cell-p)
1144 ["Bottom" (table-justify-cell 'bottom)
1145 :active (table--editable-cell-p)
1147 ["None" (table-justify-cell 'none)
1148 :active (table--editable-cell-p)
1151 ["Left" (table-justify-row 'left)
1152 :active (table--editable-cell-p)
1154 ["Center" (table-justify-row 'center)
1155 :active (table--editable-cell-p)
1157 ["Right" (table-justify-row 'right)
1158 :active (table--editable-cell-p)
1161 ["Top" (table-justify-row 'top)
1162 :active (table--editable-cell-p)
1164 ["Middle" (table-justify-row 'middle)
1165 :active (table--editable-cell-p)
1167 ["Bottom" (table-justify-row 'bottom)
1168 :active (table--editable-cell-p)
1170 ["None" (table-justify-cell 'none)
1171 :active (table--editable-cell-p)
1174 ["Left" (table-justify-column 'left)
1175 :active (table--editable-cell-p)
1177 ["Center" (table-justify-column 'center)
1178 :active (table--editable-cell-p)
1180 ["Right" (table-justify-column 'right)
1181 :active (table--editable-cell-p)
1184 ["Top" (table-justify-column 'top)
1185 :active (table--editable-cell-p)
1187 ["Middle" (table-justify-column 'middle)
1188 :active (table--editable-cell-p)
1190 ["Bottom" (table-justify-column 'bottom)
1191 :active (table--editable-cell-p)
1193 ["None" (table-justify-cell 'none)
1194 :active (table--editable-cell-p)
1197 ["Left" (table-justify-cell 'left t)
1198 :active (table--editable-cell-p)
1200 ["Center" (table-justify-cell 'center t)
1201 :active (table--editable-cell-p)
1203 ["Right" (table-justify-cell 'right t)
1204 :active (table--editable-cell-p)
1207 ["Query Dimension" table-query-dimension
1208 :active (table--probe-cell)
1209 :help "Get the dimension of the current cell and the current table"]
1210 ["Generate Source" table-generate-source
1211 :active (table--probe-cell)
1212 :help "Generate source of the current table in the specified language"]
1213 ["Insert Sequence" table-insert-sequence
1214 :active (table--editable-cell-p)
1215 :help "Travel cells forward while inserting a specified sequence string in each cell"]
1217 ["a Table" table-unrecognize-table
1218 :active (table--probe-cell)
1219 :help "Unrecognize the current table"]
1220 ["a Cell" table-unrecognize-cell
1221 :active (let ((cell (table--probe-cell)))
1222 (and cell (table--at-cell-p (car cell))))
1224 ["Release" table-release
1225 :active (table--editable-cell-p)
1226 :help "Release the current table as plain text"]
1228 ["Auto Expand Mode" (table-fixed-width-mode -1)
1231 :selected (not table-fixed-width-mode)
1233 ["Fixed Width Mode" (table-fixed-width-mode 1)
1236 :selected table-fixed-width-mode
1239 ["Forward Cell" table-forward-cell
1240 :active (table--probe-cell)
1242 ["Backward Cell" table-backward-cell
1243 :active (table--probe-cell)
1256 (defun table--tweak-menu-for-xemacs (menu)
1259 (mapcar 'table--tweak-menu-for-xemacs menu))
1266 (list table-global-menu table-cell-menu))
1269 ;; register table menu under global tools menu
1270 (unless table-disable-menu
1271 (easy-menu-define table-global-menu-map nil "Table global menu" table-global-menu)
1274 (easy-menu-add-item nil '("Tools") table-global-menu-map))
1276 (easy-menu-add-item (current-global-map) '("menu-bar" "tools") table-global-menu-map)))
1283 (defmacro table-with-cache-buffer (&rest body)
1284 "Execute the forms in BODY with table cache buffer as the current buffer.
1291 `table-cell-cache-point-coordinate'. After BODY forms are executed,
1292 the paragraph is filled as long as `table-inhibit-auto-fill-paragraph'
1297 coordinate is stored in `table-cell-cache-point-coordinate'. The
1304 (unless table-inhibit-update
1305 (table-recognize-cell))
1306 (with-current-buffer (get-buffer-create table-cache-buffer-name)
1307 ;; goto the cell coordinate based on `table-cell-cache-point-coordinate'.
1308 (set-mark (table--goto-coordinate table-cell-cache-mark-coordinate))
1309 (table--goto-coordinate table-cell-cache-point-coordinate)
1310 (table--untabify-line)
1312 (setq table-inhibit-auto-fill-paragraph nil)
1315 ;; fill paragraph unless the body does not want to by setting `table-inhibit-auto-fill-paragraph'.
1316 (unless table-inhibit-auto-fill-paragraph
1317 (if (and table-cell-info-justify
1318 (not (eq table-cell-info-justify 'left)))
1319 (table--fill-region (point-min) (point-max))
1320 (table--fill-region
1324 (setq table-cell-cache-point-coordinate (table--get-coordinate))
1326 (setq ,width-expansion (table--measure-max-width))
1327 (if (<= ,width-expansion table-cell-info-width) nil
1328 (table--fill-region (point-min) (point-max) ,width-expansion)
1330 (setq table-cell-cache-point-coordinate (table--get-coordinate)))
1331 (setq ,width-expansion (- ,width-expansion table-cell-info-width))
1337 (setq ,height-expansion (- (cdr (table--get-coordinate)) (1- table-cell-info-height))))
1338 ;; now back to the table buffer.
1339 ;; expand the cell width in the table buffer if necessary.
1341 (table-widen-cell ,width-expansion 'no-copy 'no-update))
1342 ;; expand the cell height in the table buffer if necessary.
1344 (table-heighten-cell ,height-expansion 'no-copy 'no-update))
1346 (with-current-buffer (get-buffer-create table-cache-buffer-name)
1347 (table--goto-coordinate table-cell-cache-point-coordinate)
1348 (setq table-cell-cache-point-coordinate (table--valign)))
1349 ;; move the point in the table buffer to the location that corresponds to
1351 (table--goto-coordinate (table--transcoord-cache-to-table table-cell-cache-point-coordinate))
1353 (unless table-inhibit-update
1354 (table--update-cell)))))
1357 (put 'table-with-cache-buffer 'edebug-form-spec '(body))
1359 (put 'table-with-cache-buffer 'lisp-indent-function 0)
1365 '("\\<table-with-cache-buffer\\>")))
1367 (defmacro table-put-source-info (prop value)
1369 `(put 'table-source-info-plist ,prop ,value))
1371 (defmacro table-get-source-info (prop)
1373 `(get 'table-source-info-plist ,prop))
1383 (let ((func-symbol (intern (format "*table--cell-%s" command)))
1384 (doc-string (format "Table remapped function for `%s'." command)))
1388 ,doc-string
1390 (let ((table-inhibit-update t)
1392 (table--finish-delayed-tasks)
1393 (table-recognize-cell 'force)
1394 (table-with-cache-buffer
1396 (setq table-inhibit-auto-fill-paragraph t)))))
1397 (setq table-command-remap-alist
1399 table-command-remap-alist))))
1416 (let ((func-symbol (intern (format "*table--cell-%s" command)))
1417 (doc-string (format "Table remapped function for `%s'." command)))
1421 ,doc-string
1423 (table--finish-delayed-tasks)
1424 (table-recognize-cell 'force)
1425 (table-with-cache-buffer
1426 (table--remove-cell-properties (point-min) (point-max))
1427 (table--remove-eol-spaces (point-min) (point-max))
1429 (table--finish-delayed-tasks)))
1430 (setq table-command-remap-alist
1432 table-command-remap-alist))))
1450 (let ((func-symbol (intern (format "*table--cell-%s" command)))
1451 (doc-string (format "Table remapped function for `%s'." command)))
1455 ,doc-string
1457 (table--finish-delayed-tasks)
1458 (table-recognize-cell 'force)
1459 (table-with-cache-buffer
1461 (table--untabify (point-min) (point-max))
1462 (table--fill-region (point-min) (point-max))
1463 (setq table-inhibit-auto-fill-paragraph t))
1464 (table--finish-delayed-tasks)))
1465 (setq table-command-remap-alist
1467 table-command-remap-alist))))
1476 (let ((func-symbol (intern (format "*table--cell-%s" command)))
1477 (doc-string (format "Table remapped function for `%s'." command)))
1481 ,doc-string
1483 (table--finish-delayed-tasks)
1484 (table-recognize-cell 'force)
1485 (table-with-cache-buffer
1486 (let ((fill-column table-cell-info-width))
1488 (setq table-inhibit-auto-fill-paragraph t))
1489 (table--finish-delayed-tasks)))
1490 (setq table-command-remap-alist
1492 table-command-remap-alist))))
1504 (defun table-insert (columns rows &optional cell-width cell-height)
1505 "Insert an editable text table.
1506 Insert a table of specified number of COLUMNS and ROWS. Optional
1508 cell. The cell size is uniform across the table if the specified size
1516 \\[table-insert] inserts a table at the current point location.
1523 Type \\[table-insert] and hit ENTER key. As it asks table
1526 table and the point is automatically moved to the beginning of the
1533 Inside a table cell, there are special key bindings. \\<table-cell-map>
1535 M-9 \\[table-widen-cell] (or \\[universal-argument] 9 \\[table-widen-cell]) widens the first cell by 9 character
1542 Type TAB \\[table-widen-cell] then type TAB M-2 M-7 \\[table-widen-cell] (or \\[universal-argument] 2 7 \\[table-widen-cell]). Typing
1549 If you knew each width of the columns prior to the table creation,
1551 width information to `table-insert'.
1563 first cell. Now type \\[table-heighten-cell] which heighten the row by a line.
1570 Type \\[table-insert-row-column] and tell it to insert a row.
1580 Move the point under the table as shown below.
1591 Type M-x table-insert-row instead of \\[table-insert-row-column]. \\[table-insert-row-column] does not work
1592 when the point is outside of the table. This insertion at
1593 outside of the table effectively appends a row at the end.
1606 Text editing inside the table cell produces reasonably expected
1613 | | |Text editing inside the table |
1621 Inside a table cell has a special keymap.
1623 \\{table-cell-map}
1628 (if (table--probe-cell)
1629 (error "Can't insert a table inside a table"))
1630 (mapcar (function table--read-from-minibuffer)
1631 '(("Number of columns" . table-columns-history)
1632 ("Number of rows" . table-rows-history)
1633 ("Cell width(s)" . table-cell-width-history)
1634 ("Cell height(s)" . table-cell-height-history)))))
1635 (table--make-cell-map)
1637 (if (null cell-width) (setq cell-width (car table-cell-width-history)))
1638 (if (null cell-height) (setq cell-height (car table-cell-height-history)))
1639 (if (stringp columns) (setq columns (string-to-number columns)))
1640 (if (stringp rows) (setq rows (string-to-number rows)))
1641 (if (stringp cell-width) (setq cell-width (table--string-to-number-list cell-width)))
1642 (if (stringp cell-height) (setq cell-height (table--string-to-number-list cell-height)))
1660 (let ((orig-coord (table--get-coordinate))
1661 (coord (table--get-coordinate))
1666 (insert table-cell-intersection-char)
1670 (insert (make-string (car cw) (string-to-char table-cell-horizontal-chars)) table-cell-intersection-char)
1676 (insert table-cell-vertical-char)
1681 (insert (make-string (car cw) ?\s))
1682 (insert table-cell-vertical-char)
1683 (table--put-cell-line-property beg (1- (point))))
1694 ;; now build the table using the prefabricated building blocks
1699 (table--goto-coordinate coord) (setcdr coord (1+ (cdr coord)))
1700 (table--untabify-line (point))
1704 (table--goto-coordinate coord) (setcdr coord (1+ (cdr coord)))
1705 (table--untabify-line (point))
1708 (table--goto-coordinate coord) (setcdr coord (1+ (cdr coord)))
1709 (table--untabify-line (point))
1714 (table--goto-coordinate (table--offset-coordinate orig-coord '(1 . 1)))
1715 (table-recognize-cell 'force)))
1718 (defun table-insert-row (n)
1719 "Insert N table row(s).
1720 When point is in a table the newly inserted row(s) are placed above
1721 the current row. When point is outside of the table it must be below
1722 the table within the table width range, then the newly created row(s)
1723 are appended at the bottom of the table."
1726 (let* ((current-coordinate (table--get-coordinate))
1727 (coord-list (table--cell-list-to-coord-list (table--horizontal-cell-list t nil 'top)))
1728 (append-row (if coord-list nil (setq coord-list (table--find-row-column))))
1729 (cell-height (cdr (table--min-coord-list coord-list)))
1733 (bottom-border-y (1+ (cdr (table--get-coordinate (cdr (table--vertical-cell-list nil t))))))
1734 (vertical-str (string table-cell-vertical-char))
1735 (vertical-str-with-properties (let ((str (string table-cell-vertical-char)))
1736 (table--put-cell-keymap-property 0 (length str) str)
1737 (table--put-cell-rear-nonsticky 0 (length str) str) str))
1739 ;; create the space below for the table to grow
1740 (table--create-growing-space-below (* n (+ 1 cell-height)) coord-list bottom-border-y)
1748 (beg (table--goto-coordinate
1751 (end (table--goto-coordinate
1759 (concat (if exclude-left "" (char-to-string table-cell-intersection-char))
1760 (make-string (- (cadr this) (caar this)) (string-to-char table-cell-horizontal-chars))
1761 (if exclude-right "" (char-to-string table-cell-intersection-char)))
1768 (table--cell-blank-str (- (cadr this) (caar this)))
1775 (table--goto-coordinate (cons (if exclude-left (caar this) (1- (caar this)))
1779 (table--insert-rectangle rect)))
1787 (table--goto-coordinate (table--offset-coordinate (car this) (cons -1 y)))
1788 (delete-char 1) (insert table-cell-intersection-char)
1789 (table--goto-coordinate (table--offset-coordinate (cons (cadr this) (cdar this)) (cons 0 y)))
1790 (delete-char 1) (insert table-cell-intersection-char)
1793 (if (table--goto-coordinate
1796 (table--goto-coordinate current-coordinate))
1798 (table-recognize-cell 'force)))
1801 (defun table-insert-column (n)
1802 "Insert N table column(s).
1803 When point is in a table the newly inserted column(s) are placed left
1804 of the current column. When point is outside of the table it must be
1805 right side of the table within the table height range, then the newly
1806 created column(s) are appended at the right of the table."
1809 (let* ((current-coordinate (table--get-coordinate))
1810 (coord-list (table--cell-list-to-coord-list (table--vertical-cell-list t nil 'left)))
1811 (append-column (if coord-list nil (setq coord-list (table--find-row-column 'column))))
1812 (cell-width (car (table--min-coord-list coord-list)))
1813 (border-str (table--multiply-string (concat (make-string cell-width (string-to-char table-cell-horizontal-chars))
1814 (char-to-string table-cell-intersection-char)) n))
1815 (cell-str (table--multiply-string (concat (table--cell-blank-str cell-width)
1816 (let ((str (string table-cell-vertical-char)))
1817 (table--put-cell-keymap-property 0 (length str) str)
1818 (table--put-cell-rear-nonsticky 0 (length str) str) str)) n))
1823 (right-border-x (car (table--get-coordinate (cdr (table--horizontal-cell-list nil t))))))
1824 ;; push back the affected area above and below this table
1825 (table--horizontally-shift-above-and-below columns-to-extend coord-list)
1839 (let ((coord (table--copy-coordinate beg-coord))
1843 (if (table--goto-coordinate coord 'no-extension)
1844 (table--untabify-line (point)))
1848 ;; cell and to the right border of the table.
1849 (setq rect (extract-rectangle (table--goto-coordinate beg-coord)
1850 (table--goto-coordinate end-coord)))
1851 (delete-rectangle (table--goto-coordinate beg-coord)
1852 (table--goto-coordinate end-coord))
1853 ;; prepend the empty column string at the beginning of each
1854 ;; rectangle string extracted before.
1866 (table--goto-coordinate beg-coord)
1867 (table--insert-rectangle rect)))
1875 (table--goto-coordinate (table--offset-coordinate (car this) (cons x -1)))
1876 (delete-char 1) (insert table-cell-intersection-char)
1877 (table--goto-coordinate (table--offset-coordinate (cons (caar this) (cddr this)) (cons x 1)))
1878 (delete-char 1) (insert table-cell-intersection-char)
1881 (if (table--goto-coordinate
1886 (table--goto-coordinate current-coordinate))
1888 (table-recognize-cell 'force)))
1891 (defun table-insert-row-column (row-column n)
1893 See `table-insert-row' and `table-insert-column'."
1898 (default (car table-insert-row-column-history)))
1906 nil t nil 'table-insert-row-column-history default))))
1909 (table-insert-row n))
1911 (table-insert-column n))))
1914 (defun table-recognize (&optional arg)
1916 Scans the entire buffer and recognizes valid table cells. If the
1919 all the table specific features."
1923 (table-recognize-region (point-min) (point-max) -1)
1928 table-cell-horizontal-chars
1929 table-cell-vertical-char
1930 table-cell-intersection-char))
1933 table-cell-horizontal-chars
1934 table-cell-vertical-char
1935 table-cell-intersection-char)))
1936 ;; `table-recognize-region' is an expensive function so minimize
1937 ;; the search area. A minimum table at least consists of three consecutive
1938 ;; table border characters to begin with such as
1942 ;; and any tables end with a line containing no table border characters
1946 table-abort-recognition-when-input-pending)))
1953 (table-recognize-region beg end arg)))
1957 (defun table-unrecognize ()
1959 (table-recognize -1))
1962 (defun table-recognize-region (beg end &optional arg)
1966 inactive, meaning the tables become plain text and lose all the table
1973 (table--remove-cell-properties beg end)
1977 table-cell-horizontal-chars
1978 table-cell-vertical-char
1979 table-cell-intersection-char))
1981 table-cell-horizontal-chars
1982 table-cell-vertical-char
1983 table-cell-intersection-char))
1987 (remove-text-properties beg end '(table-cell nil))
1990 table-abort-recognition-when-input-pending)))
1998 ((table--at-cell-p (point))
1999 (goto-char (next-single-property-change (point) 'table-cell nil end)))
2001 (let ((cell (table-recognize-cell 'force 'no-copy)))
2002 (if (and cell table-detect-cell-alignment)
2003 (table--detect-cell-alignment cell)))
2009 (defun table-unrecognize-region (beg end)
2011 (table-recognize-region beg end -1))
2014 (defun table-recognize-table (&optional arg)
2015 "Recognize a table at point.
2016 If the optional numeric prefix argument ARG is negative the table
2017 becomes inactive, meaning the table becomes plain text and loses all
2018 the table specific features."
2022 (origin-cell (table--probe-cell))
2028 (table-forward-cell 1 nil unrecognize)
2029 (let ((cell (table--probe-cell)))
2030 (if (and cell table-detect-cell-alignment)
2031 (table--detect-cell-alignment cell))
2035 (defun table-unrecognize-table ()
2037 (table-recognize-table -1))
2040 (defun table-recognize-cell (&optional force no-copy arg)
2041 "Recognize a table cell that contains current point.
2046 plain text and loses all the table specific features."
2048 (table--make-cell-map)
2049 (if (or force (not (memq (table--get-last-command) table-command-list)))
2050 (let* ((cell (table--probe-cell (interactive-p)))
2051 (cache-buffer (get-buffer-create table-cache-buffer-name))
2057 (let ((lu-coordinate (table--get-coordinate (car cell)))
2058 (rb-coordinate (table--get-coordinate (cdr cell))))
2061 (unless (equal table-cell-info-lu-coordinate lu-coordinate)
2062 (table--finish-delayed-tasks))
2063 (setq table-cell-info-lu-coordinate lu-coordinate)
2064 (setq table-cell-info-rb-coordinate rb-coordinate)
2065 (setq table-cell-info-width (- (car table-cell-info-rb-coordinate)
2066 (car table-cell-info-lu-coordinate)))
2067 (setq table-cell-info-height (+ (- (cdr table-cell-info-rb-coordinate)
2068 (cdr table-cell-info-lu-coordinate)) 1))
2069 (setq table-cell-info-justify (table--get-cell-justify-property cell))
2070 (setq table-cell-info-valign (table--get-cell-valign-property cell)))
2071 ;; set/remove table cell properties
2073 (let ((coord (table--get-coordinate (car cell)))
2074 (n table-cell-info-height))
2077 (table--remove-cell-properties
2078 (table--goto-coordinate coord)
2079 (table--goto-coordinate (cons (+ (car coord) table-cell-info-width 1) (cdr coord))))
2082 (table--put-cell-property cell))
2086 (setq table-cell-cache-point-coordinate (table--transcoord-table-to-cache))
2087 (setq table-cell-cache-mark-coordinate (table--transcoord-table-to-cache
2088 (table--get-coordinate (marker-position (mark-marker)))))
2089 (setq table-cell-buffer (current-buffer))
2095 (table--insert-rectangle rectangle)))))
2098 (table--warn-incompatibility))
2102 (defun table-unrecognize-cell ()
2104 (table-recognize-cell nil nil -1))
2107 (defun table-heighten-cell (n &optional no-copy no-update)
2111 heightened in order to keep the rectangular table structure. The
2116 (let* ((coord-list (table--cell-list-to-coord-list (table--horizontal-cell-list t)))
2120 (bottom-border-y (1+ (cdr (table--get-coordinate (cdr (table--vertical-cell-list nil t))))))
2121 (vertical-str (string table-cell-vertical-char))
2122 (vertical-str-with-properties (string table-cell-vertical-char))
2124 (current-coordinate (table--get-coordinate)))
2125 ;; prepare the right vertical string with appropriate properties put
2126 (table--put-cell-keymap-property 0 (length vertical-str-with-properties) vertical-str-with-properties)
2127 ;; create the space below for the table to grow
2128 (table--create-growing-space-below n coord-list bottom-border-y)
2136 (beg (table--goto-coordinate
2139 (end (table--goto-coordinate
2149 (table--cell-blank-str (- (cadr this) (caar this)))
2156 (table--insert-rectangle rect)))
2157 (table--goto-coordinate current-coordinate)
2159 (table-recognize-cell 'force no-copy)
2161 (table--update-cell-heightened))))
2164 (defun table-shorten-cell (n)
2171 table structure."
2174 (table--finish-delayed-tasks)
2175 (let* ((table-inhibit-update t)
2176 (coord-list (table--cell-list-to-coord-list (table--horizontal-cell-list t)))
2181 (bottom-border-y (1+ (cdr (table--get-coordinate (cdr (table--vertical-cell-list nil t))))))
2182 (current-coordinate (table--get-coordinate))
2183 (current-cell-coordinate (table--cell-to-coord (table--probe-cell)))
2192 (table--goto-coordinate (car this))
2193 (table-recognize-cell 'force)
2194 (table-with-cache-buffer
2197 (table--goto-coordinate (cons 0 (1- table-cell-info-height)))
2207 (table--goto-coordinate (cons 0 0))
2223 (table--goto-coordinate (car this))
2224 (table-recognize-cell 'force)
2225 (table-with-cache-buffer
2229 (table--goto-coordinate (cons 0 (1- table-cell-info-height)))
2246 (beg (table--goto-coordinate (cons (caar this) (cdar this))))
2247 (end (table--goto-coordinate (cons (cadr this) bottom-border-y)))
2250 (blank-line (make-string (- (cadr this) (caar this)) ?\s)))
2258 ;; append blank lines below the table
2263 (table--insert-rectangle rect)
2266 (let* ((beg (table--goto-coordinate (cons (1- (caar this)) (cdar this))))
2267 (end (table--goto-coordinate (cons (caar this) bottom-border-y)))
2273 (table--insert-rectangle rect)))
2275 (let* ((beg (table--goto-coordinate (cons (cadr this) (cdar this))))
2276 (end (table--goto-coordinate (cons (1+ (cadr this)) bottom-border-y)))
2282 (table--insert-rectangle rect)))
2291 ;; remove the appended blank lines below the table if they are unnecessary
2292 (table--goto-coordinate (cons 0 (1+ (- bottom-border-y n))))
2293 (table--remove-blank-lines n)
2295 (table--goto-coordinate current-coordinate)
2296 (table-recognize-cell 'force)
2297 (table--update-cell-heightened)
2301 (defun table-widen-cell (n &optional no-copy no-update)
2303 Some other cells in the same table are widen as well to keep the
2304 table's rectangle structure."
2307 (let* ((coord-list (table--cell-list-to-coord-list (table--vertical-cell-list)))
2312 ;; push back the affected area above and below this table
2313 (table--horizontally-shift-above-and-below n (reverse coord-list))
2319 (beg (table--goto-coordinate
2324 (end (table--goto-coordinate
2331 table-cell-horizontal-chars
2332 table-cell-intersection-char
2333 table-cell-intersection-char))
2334 (blank (table--cell-blank-str))
2340 (if (string-match border (car tmp))
2348 (let ((coord (table--get-coordinate beg))
2352 (if (table--goto-coordinate coord 'no-extension)
2353 (table--untabify-line (point)))
2361 (table--insert-rectangle rectangle))
2363 (table-recognize-cell 'force no-copy)
2365 (table--update-cell-widened))))
2368 (defun table-narrow-cell (n)
2370 Some other cells in the same table are narrowed as well to keep the
2371 table's rectangle structure."
2374 (table--finish-delayed-tasks)
2375 (let* ((coord-list (table--cell-list-to-coord-list (table--vertical-cell-list)))
2376 (current-cell (table--cell-to-coord (table--probe-cell)))
2377 (current-coordinate (table--get-coordinate))
2384 (table-inhibit-update t)
2386 (table--goto-coordinate (car cell))
2387 (table-recognize-cell 'force)
2388 (table-with-cache-buffer
2389 (table--fill-region (point-min) (point-max) (- table-cell-info-width n))
2390 (if (< (setq cell-n (- table-cell-info-width (table--measure-max-width))) n)
2393 (setq table-inhibit-auto-fill-paragraph t))))
2396 ;; we need to have valid frame structure in order for table-with-cache-buffer
2401 (table-inhibit-update t)
2404 (if currentp (table--goto-coordinate current-coordinate)
2405 (table--goto-coordinate (car cell)))
2406 (table-recognize-cell 'force)
2407 (setq old-height table-cell-info-height)
2408 (table-with-cache-buffer
2409 (let ((out-of-bound (>= (- (car current-coordinate) (car table-cell-info-lu-coordinate))
2410 (- table-cell-info-width n)))
2415 (table--fill-region (point-min) (point-max) (- table-cell-info-width n))
2417 (setq current-coordinate (table--transcoord-cache-to-table))
2419 (+ (car table-cell-info-lu-coordinate) (- table-cell-info-width n 1))))))
2420 (setq table-inhibit-auto-fill-paragraph t))
2421 (table--update-cell 'now)
2424 (if currentp (setq current-coordinate (table--get-coordinate))
2425 (if (and (> table-cell-info-height old-height)
2426 (> (cdr current-coordinate) (cdr table-cell-info-lu-coordinate)))
2428 (- table-cell-info-height old-height)))))
2431 ;; been heightened so recompute them by table--vertical-cell-list.
2432 (table--goto-coordinate current-coordinate)
2433 (setq coord-list (table--cell-list-to-coord-list (table--vertical-cell-list)))
2434 ;; push in the affected area above and below this table so that things
2435 ;; on the right side of the table are shifted horizontally neatly.
2436 (table--horizontally-shift-above-and-below (- n) (reverse coord-list))
2446 (table--goto-coordinate
2451 (table--goto-coordinate
2456 (table--goto-coordinate current-coordinate)
2458 (table-recognize-cell 'force)
2462 (defun table-forward-cell (&optional arg no-recognize unrecognize)
2471 \\[table-recognize] and go to cells in the following tables and press
2472 \\[table-forward-cell] or TAB key.
2500 ;; the doc string. It is quite tricky. The tables above do not
2506 (table--finish-delayed-tasks)
2508 (let* ((pivot (table--probe-cell 'abort-on-error))
2511 (while (and (setq cell (table--goto-coordinate
2512 (cons (if (> arg 0) (1+ (car (table--get-coordinate (cdr cell))))
2513 (1- (car (table--get-coordinate (car cell)))))
2514 (cdr (table--get-coordinate (car pivot)))) 'no-extension))
2515 (setq cell (table--probe-cell))
2516 (/= (cdr (table--get-coordinate (car cell)))
2517 (cdr (table--get-coordinate (car pivot))))))
2522 (while (and (table--goto-coordinate
2523 (cons (if (> arg 0) (1- (car (table--get-coordinate (car edge))))
2524 (1+ (car (table--get-coordinate (cdr edge)))))
2525 (cdr (table--get-coordinate (car pivot)))) 'no-extension)
2526 (setq cell (table--probe-cell))
2529 (or (and (table--goto-coordinate
2530 (cons (car (table--get-coordinate (cdr edge)))
2531 (1- (cdr (table--get-coordinate (car edge))))))
2532 (table--probe-cell))
2537 (and (table--goto-coordinate
2538 (cons (car (table--get-coordinate (if (> arg 0) (car cell)
2540 (if (> arg 0) (+ 2 (cdr (table--get-coordinate (cdr cell))))
2541 (1- (cdr (table--get-coordinate (car pivot)))))) 'no-extension)
2542 (setq below/above (table--probe-cell))
2545 (< (cdr (table--get-coordinate (car below/above)))
2546 (cdr (table--get-coordinate (car tip))))
2547 (> (cdr (table--get-coordinate (car below/above)))
2548 (cdr (table--get-coordinate (car tip))))))
2550 (and (setq cell (table--goto-coordinate
2551 (cons (if (> arg 0) (1+ (car (table--get-coordinate (cdr cell))))
2552 (1- (car (table--get-coordinate (car cell)))))
2553 (if (> arg 0) (cdr (table--get-coordinate (car pivot)))
2554 (1- (cdr (table--get-coordinate (car pivot)))))) 'no-extension))
2555 (setq cell (table--probe-cell))))
2558 (while (and (table--goto-coordinate
2559 (cons (if (> arg 0) (car (table--get-coordinate (car edge)))
2560 (car (table--get-coordinate (cdr edge))))
2561 (if (> arg 0) (1- (cdr (table--get-coordinate (car edge))))
2562 (+ 2 (cdr (table--get-coordinate (cdr edge)))))) 'no-extension)
2563 (setq cell (table--probe-cell))
2568 (while (and (table--goto-coordinate
2569 (cons (1- (car (table--get-coordinate (car cell))))
2570 (cdr (table--get-coordinate (cdr cell)))) 'no-extension)
2571 (setq cell (table--probe-cell)))
2572 (if (> (cdr (table--get-coordinate (car cell)))
2573 (cdr (table--get-coordinate (car edge))))
2578 (table-recognize-cell 'force nil (if unrecognize -1 nil)))) ; refill the cache with new cell contents
2581 (defun table-backward-cell (&optional arg)
2587 (table-forward-cell (- arg)))
2590 (defun table-span-cell (direction)
2599 (if (table--cell-can-span-p d)
2605 (default-direction (if (member (list (car table-cell-span-direction-history)) direction-list)
2606 (car table-cell-span-direction-history)
2612 nil t nil 'table-cell-span-direction-history default-direction))))))
2616 (table-recognize-cell 'force)
2617 (unless (table--cell-can-span-p direction)
2623 (table--goto-coordinate
2624 (cons (car table-cell-info-rb-coordinate)
2625 (1- (cdr table-cell-info-lu-coordinate))) 'no-extension)))
2628 (table--goto-coordinate
2629 (cons (1- (car table-cell-info-lu-coordinate))
2630 (1+ (cdr table-cell-info-rb-coordinate))) 'no-extension)))
2633 (table--goto-coordinate
2634 (cons (1- (car table-cell-info-lu-coordinate))
2635 (1- (cdr table-cell-info-lu-coordinate))) 'no-extension)))))
2639 (table--goto-coordinate
2640 (cons (car table-cell-info-lu-coordinate)
2641 (1+ (cdr table-cell-info-rb-coordinate))) 'no-extension)))
2644 (table--goto-coordinate
2645 (cons (1+ (car table-cell-info-rb-coordinate))
2646 (1- (cdr table-cell-info-lu-coordinate))) 'no-extension)))
2649 (table--goto-coordinate
2650 (cons (1+ (car table-cell-info-rb-coordinate))
2651 (1+ (cdr table-cell-info-rb-coordinate))) 'no-extension))))))
2662 (looking-at (regexp-quote (char-to-string table-cell-vertical-char)))))
2667 (looking-at (regexp-quote (char-to-string table-cell-vertical-char))))))
2670 (char-to-string table-cell-intersection-char)
2671 (substring table-cell-horizontal-chars 0 1))
2674 (setq rectangle (cons (table--cell-blank-str 1) rectangle))
2678 (char-to-string table-cell-intersection-char)
2679 (substring table-cell-horizontal-chars 0 1))
2683 (table--insert-rectangle rectangle))
2689 (string-to-list table-cell-horizontal-chars)))))
2690 table-cell-intersection-char
2691 table-cell-vertical-char)
2692 (table--cell-blank-str (- end beg 2))
2694 (string-to-list table-cell-horizontal-chars)))
2695 table-cell-intersection-char
2696 table-cell-vertical-char))))
2698 (table-recognize-cell 'force)
2700 (table-with-cache-buffer
2701 (table--fill-region (point-min) (point-max))
2702 (setq table-inhibit-auto-fill-paragraph t)))))
2705 (defun table-split-cell-vertically ()
2709 (table-recognize-cell 'force)
2710 (let ((point-y (cdr (table--get-coordinate))))
2711 (unless (table--cell-can-split-vertically-p)
2713 (let* ((old-coordinate (table--get-coordinate))
2715 (beg (table--goto-coordinate
2716 (cons (1- (car table-cell-info-lu-coordinate))
2718 (end (table--goto-coordinate
2719 (cons (1+ (car table-cell-info-rb-coordinate))
2722 (when (= (cdr old-coordinate) (cdr table-cell-info-rb-coordinate))
2723 (table--goto-coordinate old-coordinate)
2724 (table-heighten-cell 1 'no-copy 'no-update))
2727 (insert table-cell-intersection-char
2728 (make-string table-cell-info-width (string-to-char table-cell-horizontal-chars))
2729 table-cell-intersection-char)
2730 (table--goto-coordinate old-coordinate)
2733 (setq old-coordinate (table--get-coordinate))
2734 (table-recognize-cell 'force)
2735 (unless (string-match "^\\s *$" line)
2736 (table-with-cache-buffer
2740 (setq table-inhibit-auto-fill-paragraph t)))
2741 (table--update-cell 'now) ;; can't defer this operation
2742 (table--goto-coordinate old-coordinate)
2744 (table-recognize-cell 'force))))
2747 (defun table-split-cell-horizontally ()
2751 (table-recognize-cell 'force)
2752 (let* ((o-coordinate (table--get-coordinate))
2756 (right-edge (= (car o-coordinate) (1- (car table-cell-info-rb-coordinate)))))
2757 (unless (table--cell-can-split-horizontally-p)
2759 (let ((table-inhibit-update t))
2760 (table-with-cache-buffer
2761 (setq cell-coordinate (table--get-coordinate))
2766 (setq table-inhibit-auto-fill-paragraph t)))
2770 (default (car table-cell-split-contents-to-history)))
2780 nil t nil 'table-cell-split-contents-to-history default)))))))
2782 (table-with-cache-buffer
2784 (setq table-inhibit-auto-fill-paragraph t)))
2785 (table--update-cell 'now)
2786 (setq beg (table--goto-coordinate
2788 (1- (cdr table-cell-info-lu-coordinate)))))
2789 (setq end (table--goto-coordinate
2791 (1+ (cdr table-cell-info-rb-coordinate)))))
2792 (setq rectangle (cons (char-to-string table-cell-intersection-char) nil))
2793 (let ((n table-cell-info-height))
2795 (setq rectangle (cons (char-to-string table-cell-vertical-char) rectangle))))
2796 (setq rectangle (cons (char-to-string table-cell-intersection-char) rectangle))
2801 (table--insert-rectangle rectangle)
2802 (table--goto-coordinate o-coordinate)
2807 (table-widen-cell 1)))
2810 (table-recognize-cell 'force)
2811 (table-with-cache-buffer
2815 (let ((o-coord (table--get-coordinate))
2820 (unless (let ((cl (mapcar (lambda (s) (string= s " ")) strip-rect)))
2822 (table--uniform-list-p cl)))
2824 (table--insert-rectangle strip-rect)
2825 (table--goto-coordinate o-coord)))
2829 (table--goto-coordinate cell-coordinate)
2830 (table--fill-region (point-min) (point-max))
2836 (setq table-inhibit-auto-fill-paragraph t))
2837 (table--update-cell 'now)) ;; can't defer this operation
2838 (table-recognize-cell 'force)))
2841 (defun table-split-cell (orientation)
2848 (default (car table-cell-split-orientation-history)))
2852 nil t nil 'table-cell-split-orientation-history default))))))
2857 (table-split-cell-horizontally)
2858 (table-split-cell-vertically)))
2861 (defun table-justify (what justify)
2868 (default (car table-target-history)))
2872 nil t nil 'table-target-history default))))
2873 (table--query-justification)))
2874 (funcall (intern (concat "table-justify-" (symbol-name what))) justify))
2877 (defun table-justify-cell (justify &optional paragraph)
2884 (list (table--query-justification)))
2885 (table--finish-delayed-tasks)
2886 (table-recognize-cell 'force)
2887 (table--justify-cell-contents justify paragraph))
2890 (defun table-justify-row (justify)
2895 (list (table--query-justification)))
2896 (let((cell-list (table--horizontal-cell-list nil nil 'top)))
2897 (table--finish-delayed-tasks)
2903 (table-recognize-cell 'force)
2904 (table--justify-cell-contents justify))))))
2907 (defun table-justify-column (justify)
2912 (list (table--query-justification)))
2913 (let((cell-list (table--vertical-cell-list nil nil 'left)))
2914 (table--finish-delayed-tasks)
2920 (table-recognize-cell 'force)
2921 (table--justify-cell-contents justify))))))
2924 (defun table-fixed-width-mode (&optional arg)
2930 (table--finish-delayed-tasks)
2931 (setq table-fixed-width-mode
2933 (not table-fixed-width-mode)
2935 (table--update-cell-face))
2938 (defun table-query-dimension (&optional where)
2939 "Return the dimension of the current cell and the current table.
2941 width, ch is the cell height, tw is the table width, th is the table
2944 frame while the table dimension includes the table frame. The columns
2948 WHERE is provided the cell and table at that location is reported."
2952 (let ((starting-cell (table--probe-cell))
2953 cell table-lu table-rb col-list row-list (cells 0))
2955 (setq table-lu (car starting-cell))
2956 (setq table-rb (cdr starting-cell))
2957 (setq col-list (cons (car (table--get-coordinate (car starting-cell))) nil))
2958 (setq row-list (cons (cdr (table--get-coordinate (car starting-cell))) nil))
2963 (table-forward-cell 1 t)
2965 (and (setq cell (table--probe-cell))
2967 (if (< (car cell) table-lu)
2968 (setq table-lu (car cell)))
2969 (if (> (cdr cell) table-rb)
2970 (setq table-rb (cdr cell)))
2971 (let ((lu-coordinate (table--get-coordinate (car cell))))
2976 (let* ((cell-lu-coordinate (table--get-coordinate (car starting-cell)))
2977 (cell-rb-coordinate (table--get-coordinate (cdr starting-cell)))
2978 (table-lu-coordinate (table--get-coordinate table-lu))
2979 (table-rb-coordinate (table--get-coordinate table-rb))
2982 (tw (+ 2 (- (car table-rb-coordinate) (car table-lu-coordinate))))
2983 (th (+ 3 (- (cdr table-rb-coordinate) (cdr table-lu-coordinate))))
2991 (defun table-generate-source (language &optional dest-buffer caption)
2992 "Generate source of the current table in the specified language.
2994 structure of the table. It must be either 'html, 'latex or 'cals.
2997 buffer specified in `table-dest-buffer-name' is used. In this case
3015 http://www.oreilly.com/catalog/docbook/chapter/book/table.html#AEN114751
3018 (let* ((dummy (unless (table--probe-cell) (error "Table not found here")))
3020 (default (car table-source-language-history))
3024 table-source-languages)
3025 nil t nil 'table-source-language-history default))))
3028 (read-buffer "Destination buffer: " (concat table-dest-buffer-name "." language))
3029 (table--read-from-minibuffer '("Table Caption" . table-source-caption-history)))))
3030 (let ((default-buffer-name (concat table-dest-buffer-name "." (symbol-name language))))
3031 (unless (or (interactive-p) (table--probe-cell)) (error "Table not found here"))
3034 (if (string= (buffer-name dest-buffer) default-buffer-name)
3038 (let ((starting-cell (table--probe-cell))
3040 ;; first analyze the table structure and prepare:
3047 (setq col-list (cons (car (table--get-coordinate (car starting-cell))) nil))
3048 (setq row-list (cons (cdr (table--get-coordinate (car starting-cell))) nil))
3055 (message "Analyzing table...%c" (aref wheel i))
3059 (table-forward-cell 1 t)
3060 (and (setq cell (table--probe-cell))
3066 (let ((lu-coordinate (table--get-coordinate (car cell))))
3075 (setplist 'table-source-info-plist nil)
3079 (table--generate-source-prologue dest-buffer language caption col-list row-list)
3083 (table--generate-source-scan-lines dest-buffer language origin-cell tail-cell col-list row-list))
3085 ;; scan by table cells
3086 (table--generate-source-scan-rows dest-buffer language origin-cell col-list row-list)))
3088 (table--generate-source-epilogue dest-buffer language col-list row-list))
3094 (and (string= (buffer-name dest-buffer) default-buffer-name)
3106 (defun table--generate-source-prologue (dest-buffer language caption col-list row-list)
3111 (insert (format "<!-- This HTML table template is generated by emacs %s -->\n" emacs-version)
3112 (format "<table %s>\n" table-html-table-attribute)
3114 (not (string= caption "")))
3118 (insert (format "%% This LaTeX table template is generated by emacs %s\n" emacs-version)
3122 (insert (format "<!-- This CALS table template is generated by emacs %s -->\n" emacs-version)
3123 "<table frame=\"all\">\n")
3125 (not (string= caption "")))
3128 (table-put-source-info 'colspec-marker (point-marker))
3129 (table-put-source-info 'row-type (if (zerop table-cals-thead-rows) "tbody" "thead"))
3130 (set-marker-insertion-type (table-get-source-info 'colspec-marker) nil) ;; insert after
3131 (insert (format " <%s valign=\"top\">\n" (table-get-source-info 'row-type))))
3134 (defun table--generate-source-epilogue (dest-buffer language col-list row-list)
3139 (insert "</table>\n"))
3143 (set-marker-insertion-type (table-get-source-info 'colspec-marker) t) ;; insert before
3145 (goto-char (table-get-source-info 'colspec-marker))
3149 (sort (table-get-source-info 'colnum-list) '<)))
3150 (insert (format " </%s>\n </tgroup>\n</table>\n" (table-get-source-info 'row-type))))
3153 (defun table--generate-source-scan-rows (dest-buffer language origin-cell col-list row-list)
3155 (table-put-source-info 'current-row 1)
3164 (table--generate-source-cells-in-a-row dest-buffer language col-list row-list)
3171 (unless (/= (table-get-source-info 'current-row) table-cals-thead-rows)
3172 (insert (format " </%s>\n" (table-get-source-info 'row-type)))
3173 (insert (format " <%s valign=\"top\">\n" (table-put-source-info 'row-type "tbody")))))))
3174 (table-put-source-info 'current-row (1+ (table-get-source-info 'current-row)))
3177 (defun table--generate-source-cells-in-a-row (dest-buffer language col-list row-list)
3179 (table-put-source-info 'current-column 1)
3181 (let* ((cell (table--probe-cell))
3182 (lu (table--get-coordinate (car cell)))
3183 (rb (table--get-coordinate (cdr cell)))
3184 (alignment (table--get-cell-justify-property cell))
3185 (valign (table--get-cell-valign-property cell))
3194 (table-put-source-info 'current-column (1+ (table-get-source-info 'current-column))))
3196 (table-put-source-info 'next-column (1+ (table-get-source-info 'current-column)))
3201 (table-put-source-info 'next-column (1+ (table-get-source-info 'next-column))))
3211 (table-put-source-info
3213 (if (or (<= (table-get-source-info 'current-row) table-html-th-rows)
3214 (<= (table-get-source-info 'current-column) table-html-th-columns))
3216 (if (and table-html-cell-attribute (not (string= table-html-cell-attribute "")))
3217 (insert " " table-html-cell-attribute))
3226 (let ((scol (table-get-source-info 'current-column))
3227 (ecol (+ (table-get-source-info 'current-column) colspan -1)))
3229 (unless (memq col (table-get-source-info 'colnum-list))
3230 (table-put-source-info 'colnum-list
3231 (cons col (table-get-source-info 'colnum-list)))))
3243 (table--generate-source-cell-contents dest-buffer language cell)
3247 (insert (format" </%s>\n" (table-get-source-info 'cell-type))))
3251 (table-forward-cell 1 t)
3252 (table-put-source-info 'current-column (table-get-source-info 'next-column))
3255 (defun table--generate-source-cell-contents (dest-buffer language cell)
3259 (table--insert-rectangle cell-contents)
3260 (table--remove-cell-properties (point-min) (point-max))
3264 (if table-html-delegate-spacing-to-user-agent
3266 (table--remove-eol-spaces (point-min) (point-max))
3276 (unless (and table-html-delegate-spacing-to-user-agent
3281 (table--remove-eol-spaces (point-min) (point-max))
3295 (defun table--cell-horizontal-char-p (c)
3297 (memq c (string-to-list table-cell-horizontal-chars)))
3299 (defun table--generate-source-scan-lines (dest-buffer language origin-cell tail-cell col-list row-list)
3300 "Scan the table line by line.
3302 (let* ((lu-coord (table--get-coordinate (car origin-cell)))
3303 (rb-coord (table--get-coordinate (cdr tail-cell)))
3312 (if border-p (char-after (table--goto-coordinate (cons x y)))
3313 (char-before (table--goto-coordinate (cons x y)))))
3318 (if (and (table--cell-horizontal-char-p (car border-char-list))
3319 (table--uniform-list-p border-char-list))
3324 (if (and start (not (table--cell-horizontal-char-p c)))
3329 (if (and (not start) (table--cell-horizontal-char-p c))
3341 (let ((line (table--buffer-substring-and-trim
3342 (table--goto-coordinate (cons from y))
3343 (table--goto-coordinate (cons to y)))))
3355 (replace-match (concat "$" (match-string 3) "$")) t t)))
3370 (if (eq c table-cell-vertical-char)
3383 (defun table-insert-sequence (str n increment interval justify)
3384 "Travel cells forward while inserting a specified sequence string in each cell.
3385 STR is the base string from which the sequence starts. When STR is an
3386 empty string then each cell content is erased. When STR ends with
3392 entire table. INCREMENT is the increment between adjacent sequence
3397 is placed straight down vertically as long as the table's cell
3399 'right, that specifies justification of the inserted string.
3404 (table-insert 16 3 5 1)
3405 (table-forward-cell 15)
3406 (table-insert-sequence \"D0\" -16 1 1 'center)
3407 (table-forward-cell 16)
3408 (table-insert-sequence \"A[0]\" -16 1 1 'center)
3409 (table-forward-cell 1)
3410 (table-insert-sequence \"-\" 16 0 1 'center))
3413 (table-insert 16 8 5 1)
3414 (table-insert-sequence \"@\" 0 1 2 'right)
3415 (table-forward-cell 1)
3416 (table-insert-sequence \"64\" 0 1 2 'left))
3421 (unless (table--probe-cell) (error "Table not found here"))
3423 "Sequence base string: " (car table-sequence-string-history) nil nil 'table-sequence-string-history)
3424 (string-to-number
3425 (table--read-from-minibuffer
3426 '("How many elements (0: maximum, negative: backward traveling)" . table-sequence-count-history)))
3427 (string-to-number
3428 (table--read-from-minibuffer
3429 '("Increment element by" . table-sequence-increment-history)))
3430 (string-to-number
3431 (table--read-from-minibuffer
3432 '("Cell interval (0: vertical, 1:horizontal)" . table-sequence-interval-history)))
3434 (default (car table-sequence-justify-history)))
3438 nil t nil 'table-sequence-justify-history default)))))))
3439 (unless (or (interactive-p) (table--probe-cell)) (error "Table not found here"))
3440 (string-match "\\([0-9]*\\)\\([]})>]*\\)\\'" str)
3444 (index (match-string 1 str))
3445 (fmt (format "%%%s%dd" (if (eq (string-to-char index) ?0) "0" "") (length index)))
3446 (postfix (match-string 2 str))
3447 (dim (table-query-dimension))
3451 (if (string= index "")
3454 (if (string= prefix "")
3456 (setq index (string-to-number index)))
3465 (table-with-cache-buffer
3472 (table--fill-region (point-min) (point) table-cell-info-width justify)
3473 (setq table-cell-info-justify justify))
3474 (setq table-inhibit-auto-fill-paragraph t))
3475 (table--update-cell 'now)
3478 (if (and prefix (string= postfix ""))
3481 (char-to-string
3482 (+ (string-to-char (substring prefix len-1)) increment)))))))
3484 (table-forward-cell direction t)
3488 (table-recognize-cell 'force)
3494 (defun table-delete-row (n)
3500 (let ((orig-coord (table--get-coordinate))
3501 (bt-coord (table--get-coordinate (cdr (table--vertical-cell-list nil 'first-only))))
3506 (unless (table--probe-cell)
3508 (let ((cell-list (table--horizontal-cell-list 'left-to-right)))
3510 (and (table--uniform-list-p
3511 (mapcar (lambda (cell) (cdr (table--get-coordinate (car cell)))) cell-list))
3512 (table--uniform-list-p
3513 (mapcar (lambda (cell) (cdr (table--get-coordinate (cdr cell)))) cell-list)))
3516 (setq lu-coord (table--get-coordinate (caar cell-list))))
3517 (setq rb-coord (table--get-coordinate (cdar (last cell-list))))
3518 (table--goto-coordinate (cons (car orig-coord) (+ 2 (cdr rb-coord))))))
3521 (table--goto-coordinate (cons (1- (car lu-coord)) (1+ (cdr rb-coord))))
3522 (table--goto-coordinate (cons (1+ (car rb-coord)) (1+ (cdr bt-coord))))))
3525 (table--goto-coordinate (cons (1- (car lu-coord)) (1- (cdr lu-coord))))
3526 (table--goto-coordinate (cons (1+ (car rb-coord)) (1+ (cdr bt-coord)))))
3527 (table--goto-coordinate (cons (1- (car lu-coord)) (1- (cdr lu-coord))))
3529 (table--insert-rectangle
3531 (make-string (+ 2 (- (car rb-coord) (car lu-coord))) ?\s))))
3532 ;; remove the appended blank lines below the table if they are unnecessary
3533 (table--goto-coordinate (cons 0 (- (cdr bt-coord) (- (cdr rb-coord) (cdr lu-coord)))))
3534 (table--remove-blank-lines (+ 2 (- (cdr rb-coord) (cdr lu-coord))))
3539 (table--goto-coordinate coord)
3541 (or (and (table--goto-coordinate (cons (car coord) (1- (cdr coord))) 'no-extension)
3542 (looking-at (regexp-quote (char-to-string table-cell-vertical-char))))
3543 (and (table--goto-coordinate (cons (car coord) (1+ (cdr coord))) 'no-extension)
3544 (looking-at (regexp-quote (char-to-string table-cell-vertical-char))))))
3547 (insert table-cell-intersection-char))
3549 (insert (string-to-char table-cell-horizontal-chars)))
3553 (table--goto-coordinate (cons (car orig-coord) (cdr lu-coord)))))
3556 (defun table-delete-column (n)
3562 (let ((orig-coord (table--get-coordinate))
3567 (unless (table--probe-cell)
3569 (let ((cell-list (table--vertical-cell-list 'top-to-bottom)))
3571 (and (table--uniform-list-p
3572 (mapcar (function (lambda (cell) (car (table--get-coordinate (car cell))))) cell-list))
3573 (table--uniform-list-p
3574 (mapcar (function (lambda (cell) (car (table--get-coordinate (cdr cell))))) cell-list)))
3577 (setq lu-coord (table--get-coordinate (caar cell-list))))
3578 (setq rb-coord (table--get-coordinate (cdar (last cell-list))))
3579 (table--goto-coordinate (cons (1+ (car rb-coord)) (cdr orig-coord)))))
3582 (table--goto-coordinate (cons (car lu-coord) (1- (cdr lu-coord))))
3583 (table--goto-coordinate (cons (1+ (car rb-coord)) (1+ (cdr rb-coord)))))
3588 (table--goto-coordinate coord)
3590 (or (and (table--goto-coordinate (cons (1- (car coord)) (cdr coord)) 'no-extension)
3592 (string-to-list table-cell-horizontal-chars))))
3593 (and (table--goto-coordinate (cons (1+ (car coord)) (cdr coord)) 'no-extension)
3595 (string-to-list table-cell-horizontal-chars))))))
3598 (insert table-cell-intersection-char))
3600 (insert table-cell-vertical-char))
3604 (table--goto-coordinate (cons (car lu-coord) (cdr orig-coord)))))
3607 (defun table-capture (beg end &optional col-delim-regexp row-delim-regexp justify min-cell-width columns)
3608 "Convert plain text into a table by capturing the text in the region.
3609 Create a table with the text in region as cell contents. BEG and END
3610 specify the region. The text in the region is replaced with a table.
3611 The removed text is inserted in the table. When optional
3615 columns and rows of the table automatically. If COL-DELIM-REGEXP and
3616 ROW-DELIM-REGEXP are omitted the result table has only one cell and
3630 Running `table-capture' on above 3 line region with COL-DELIM-REGEXP
3631 \",\" and ROW-DELIM-REGEXP \"\\n\" creates the following table. In
3652 This example shows how a table can be used for text layout editing.
3653 Let `table-capture' capture the following region starting from
3655 name headers. This time specify empty string for both
3658 -!-`table-capture' is a powerful command however mastering its power
3665 non-table text and then forms a table out
3669 creates a single cell table. The text in
3673 Now the entire content is captured in a cell which is itself a table
3677 |`table-capture' is a powerful command however mastering its power|
3684 | non-table text and then forms a table out |
3688 | creates a single cell table. The text in |
3693 By splitting the cell appropriately we now have a table consisting of
3698 |`table-capture' is a powerful command however mastering its power|
3705 | |non-table text and then forms a table out |
3709 | |creates a single cell table. The text in |
3714 By applying `table-release', which does the opposite process, the
3715 contents become once again plain text. `table-release' works as
3716 companion command to `table-capture' this way.
3722 (if (table--probe-cell)
3723 (error "Can't insert a table inside a table"))
3728 (car table-col-delim-regexp-history) nil nil 'table-col-delim-regexp-history))
3731 (car table-row-delim-regexp-history) nil nil 'table-row-delim-regexp-history))
3733 (default (car table-capture-justify-history)))
3734 (if (and (string= col-delim-regexp "") (string= row-delim-regexp "")) 'left
3739 nil t nil 'table-capture-justify-history default)))))
3740 (if (and (string= col-delim-regexp "") (string= row-delim-regexp "")) "1"
3741 (table--read-from-minibuffer '("Minimum cell width" . table-capture-min-cell-width-history)))
3742 (if (and (not (string= col-delim-regexp "")) (string= row-delim-regexp ""))
3743 (string-to-number
3744 (table--read-from-minibuffer '("Number of columns" . 'table-capture-columns-history)))
3748 (if (string= col-delim-regexp "") (setq col-delim-regexp nil))
3749 (if (string= row-delim-regexp "") (setq row-delim-regexp nil))
3780 ((and (match-string 1) (not (string= (match-string 1) "")))
3793 ((and (match-string 4) (not (string= (match-string 4) "")))
3804 (append cell-list (list (match-string 0))))
3811 ;; finalize the table dimension
3817 ;; when dimensions are not specified default to a single cell table
3828 ;; insert the table
3835 (table--remove-eol-spaces (point-min) (point-max))
3836 (table--untabify (point-min) (point-max))
3837 (setq width (table--measure-max-width))
3838 (setq height (1+ (table--current-line (point-max))))
3840 (table-insert cols rows width height)
3841 (table-with-cache-buffer
3843 (setq table-inhibit-auto-fill-paragraph t)))
3845 (table-insert cols rows min-cell-width 1)
3857 (table-with-cache-buffer
3860 (setq table-cell-info-justify justify)))
3861 (table-forward-cell 1))))))
3864 (defun table-release ()
3865 "Convert a table into plain text by removing the frame from a table.
3866 Remove the frame from a table and inactivate the table. This command
3867 converts a table into plain text without frames. It is a companion to
3868 `table-capture' which does the opposite process."
3870 (let ((origin-cell (table--probe-cell))
3871 table-lu table-rb)
3881 (table-forward-cell 1 nil 'unrecognize)
3882 (let ((cell (table--probe-cell)))
3883 (if (or (null table-lu)
3884 (< (car cell) table-lu))
3885 (setq table-lu (car cell)))
3886 (if (or (null table-rb)
3887 (> (cdr cell) table-rb))
3888 (setq table-rb (cdr cell)))
3890 (let* ((lu-coord (table--get-coordinate table-lu))
3891 (rb-coord (table--get-coordinate table-rb))
3892 (lu (table--goto-coordinate (table--offset-coordinate lu-coord '(-1 . -1)))))
3893 (table--spacify-frame)
3895 (delete-rectangle lu (table--goto-coordinate (cons (car lu-coord) (cdr rb-coord))))
3896 (table--remove-eol-spaces
3897 (table--goto-coordinate (cons 0 (1- (cdr lu-coord))))
3898 (table--goto-coordinate rb-coord) nil t)))
3906 (defun table--make-cell-map ()
3907 "Make the table cell keymap if it does not exist yet."
3909 (table--update-cell-face)
3910 (unless table-cell-map
3912 (remap-alist table-command-remap-alist))
3913 ;; table-command-prefix mode specific bindings
3914 (if (vectorp table-command-prefix)
3922 (define-key map (vconcat table-command-prefix seq) (cdr binding))))))
3923 table-cell-bindings))
3927 table-cell-bindings)
3928 ;; remap normal commands to table specific version
3933 (setq table-cell-map map)
3934 (fset 'table-cell-map map)))
3935 ;; add menu for table cells
3936 (unless table-disable-menu
3937 (easy-menu-define table-cell-menu-map table-cell-map "Table cell menu" table-cell-menu)
3939 (easy-menu-add table-cell-menu)))
3940 (run-hooks 'table-cell-map-hook))
3944 (add-hook 'after-init-hook 'table--make-cell-map t)
3946 (defun *table--cell-self-insert-command ()
3949 (let ((char (table--unibyte-char-to-multibyte last-command-char)))
3952 (setq table-cell-self-insert-command-count 0)
3954 (if (>= table-cell-self-insert-command-count 19)
3955 (setq table-cell-self-insert-command-count 0)
3957 (setq table-cell-self-insert-command-count (1+ table-cell-self-insert-command-count))))))
3958 (table--cell-insert-char char overwrite-mode)))
3960 (defun *table--cell-delete-backward-char (n)
3963 (*table--cell-delete-char (- n)))
3965 (defun *table--cell-newline (&optional indent)
3968 (table-with-cache-buffer
3980 (setq table-inhibit-auto-fill-paragraph t)))))
3982 (defun *table--cell-open-line (n)
3985 (table-with-cache-buffer
3987 (insert (make-string n ?\n))
3988 (table--fill-region (point) (point))
3989 (setq table-inhibit-auto-fill-paragraph t))))
3991 (defun *table--cell-newline-and-indent ()
3994 (*table--cell-newline t))
3996 (defun *table--cell-delete-char (n)
4000 (table-with-cache-buffer
4004 (let ((coordinate (table--get-coordinate)))
4007 (table--goto-coordinate (cons (1- table-cell-info-width) (1- (cdr coordinate))))
4014 (setq table-inhibit-auto-fill-paragraph t))
4015 (let ((coordinate (table--get-coordinate))
4020 (table--remove-eol-spaces (point-min) (point-max))
4025 (and table-fixed-width-mode
4026 (string-match "^\n" deleted)
4027 (equal (char-before) table-word-continuation-char)
4032 (/= (cdr coordinate) (cdr (table--get-coordinate)))
4047 (setq table-inhibit-auto-fill-paragraph t))
4051 (defun *table--cell-quoted-insert (arg)
4054 (let ((char (table--unibyte-char-to-multibyte (read-quoted-char))))
4056 (table--cell-insert-char char nil)
4059 (defun *table--cell-describe-mode ()
4062 (if (not (table--point-in-cell-p))
4071 editing behaviors. Editing operations in a table produces confined
4076 In the normal mode the table preserves word continuity. Which means
4078 table will occasionally grow the cell width. On the other hand, when
4082 specified in the variable `table-word-continuation-char'.
4086 (defun *table--cell-describe-bindings ()
4089 (if (not (table--point-in-cell-p))
4101 table-cell-bindings)
4104 (defun *table--cell-dabbrev-expand (arg)
4108 (char-to-string table-cell-vertical-char)
4109 (char-to-string table-cell-intersection-char)
4111 (table-with-cache-buffer
4114 (defun *table--cell-dabbrev-completion (&optional arg)
4117 (error "`dabbrev-completion' is incompatible with table")
4119 (char-to-string table-cell-vertical-char)
4120 (char-to-string table-cell-intersection-char)
4122 (table-with-cache-buffer
4125 (defun *table--present-cell-popup-menu (event)
4128 (unless table-disable-menu
4131 (let ((item-list (x-popup-menu event table-cell-menu-map))
4132 (func table-cell-menu-map))
4144 (defun table--update-cell (&optional now)
4145 "Update the table cell contents.
4148 cache buffer into the designated cell in the table buffer."
4149 (if (null table-update-timer) nil
4150 (table--cancel-timer table-update-timer)
4151 (setq table-update-timer nil))
4157 (setq table-update-timer
4158 (table--set-timer table-time-before-update
4159 (function table--update-cell)
4162 (set-buffer table-cell-buffer)
4163 (let ((cache-buffer (get-buffer-create table-cache-buffer-name))
4164 (org-coord (table--get-coordinate))
4165 (in-cell (equal (table--cell-to-coord (table--probe-cell))
4166 (cons table-cell-info-lu-coordinate table-cell-info-rb-coordinate)))
4172 (table--goto-coordinate (cons table-cell-info-width (1- table-cell-info-height)))))
4173 (set-buffer table-cell-buffer)
4174 (delete-rectangle (table--goto-coordinate table-cell-info-lu-coordinate)
4175 (table--goto-coordinate table-cell-info-rb-coordinate))
4176 (table--goto-coordinate table-cell-info-lu-coordinate)
4177 (table--insert-rectangle rectangle)
4178 (let* ((cell (table--probe-cell))) ; must probe again in case of wide characters
4179 (table--put-cell-property cell)
4180 (table--put-cell-justify-property cell table-cell-info-justify)
4181 (table--put-cell-valign-property cell table-cell-info-valign))
4182 (table--goto-coordinate
4184 (table--transcoord-cache-to-table table-cell-cache-point-coordinate)
4190 (defun table--update-cell-widened (&optional now)
4192 (if (null table-widen-timer) nil
4193 (table--cancel-timer table-widen-timer)
4194 (setq table-widen-timer nil))
4196 (setq table-widen-timer
4197 (table--set-timer (+ table-time-before-update table-time-before-reformat)
4198 (function table--update-cell-widened)
4201 (if table-update-timer
4202 (table--update-cell 'now))
4203 (set-buffer table-cell-buffer)
4204 (let* ((current-coordinate (table--get-coordinate))
4205 (current-cell-coordinate (table--cell-to-coord (table--probe-cell)))
4207 (table--goto-coordinate table-cell-info-lu-coordinate)
4208 (table--cell-list-to-coord-list (table--vertical-cell-list)))))
4212 (if currentp (table--goto-coordinate current-coordinate)
4213 (table--goto-coordinate (car cell-coord)))
4214 (table-recognize-cell 'froce)
4215 (let ((table-inhibit-update t))
4216 (table-with-cache-buffer
4221 (table--fill-region (point-min) (point-max))
4223 (setq current-coordinate (table--transcoord-cache-to-table))))))
4224 (table--update-cell 'now)
4226 (table--goto-coordinate current-coordinate)
4227 (table-recognize-cell 'froce)))))
4229 (defun table--update-cell-heightened (&optional now)
4231 (if (null table-heighten-timer) nil
4232 (table--cancel-timer table-heighten-timer)
4233 (setq table-heighten-timer nil))
4235 (setq table-heighten-timer
4236 (table--set-timer (+ table-time-before-update table-time-before-reformat)
4237 (function table--update-cell-heightened)
4240 (if table-update-timer
4241 (table--update-cell 'now))
4242 (if table-widen-timer
4243 (table--update-cell-widened 'now))
4244 (set-buffer table-cell-buffer)
4245 (let* ((current-coordinate (table--get-coordinate))
4246 (current-cell-coordinate (table--cell-to-coord (table--probe-cell)))
4248 (table--goto-coordinate table-cell-info-lu-coordinate)
4249 (table--cell-list-to-coord-list (table--horizontal-cell-list)))))
4253 (if currentp (table--goto-coordinate current-coordinate)
4254 (table--goto-coordinate (car cell-coord)))
4255 (table-recognize-cell 'froce)
4256 (let ((table-inhibit-update t))
4257 (table-with-cache-buffer
4262 (table--valign)
4264 (setq current-coordinate (table--transcoord-cache-to-table))))))
4265 (table--update-cell 'now)
4267 (table--goto-coordinate current-coordinate)
4268 (table-recognize-cell 'froce)))))
4275 (defun table-goto-top-left-corner ()
4276 "Move point to top left corner of the current table and return the char position."
4277 (table--goto-coordinate
4279 (1- (car (table--get-coordinate (car (table--horizontal-cell-list t t)))))
4280 (1- (cdr (table--get-coordinate (car (table--vertical-cell-list t t))))))))
4282 (defun table-goto-top-right-corner ()
4283 "Move point to top right corner of the current table and return the char position."
4284 (table--goto-coordinate
4286 (car (table--get-coordinate (cdr (table--horizontal-cell-list nil t))))
4287 (1- (cdr (table--get-coordinate (car (table--vertical-cell-list t t))))))))
4289 (defun table-goto-bottom-left-corner ()
4290 "Move point to bottom left corner of the current table and return the char position."
4291 (table--goto-coordinate
4293 (1- (car (table--get-coordinate (car (table--horizontal-cell-list t t)))))
4294 (1+ (cdr (table--get-coordinate (cdr (table--vertical-cell-list nil t))))))))
4296 (defun table-goto-bottom-right-corner ()
4297 "Move point to bottom right corner of the current table and return the char position."
4298 (table--goto-coordinate
4300 (car (table--get-coordinate (cdr (table--horizontal-cell-list nil t))))
4301 (1+ (cdr (table--get-coordinate (cdr (table--vertical-cell-list nil t))))))))
4303 (defun table-call-interactively (function &optional recoard-flag keys)
4304 "Call FUNCTION, or a table version of it if applicable.
4306 (let ((table-func (intern-soft (format "*table--cell-%s" function))))
4308 (if (and table-func
4309 (table--point-in-cell-p))
4310 table-func
4313 (defun table-funcall (function &rest arguments)
4314 "Call FUNCTION, or a table version of it if applicable.
4316 (let ((table-func (intern-soft (format "*table--cell-%s" function))))
4318 (if (and table-func
4319 (table--point-in-cell-p))
4320 table-func
4324 (defmacro table-apply (function &rest arguments)
4325 "Call FUNCTION, or a table version of it if applicable.
4327 (let ((table-func (make-symbol "table-func")))
4328 `(let ((,table-func (intern-soft (format "*table--cell-%s" ,function))))
4330 (if (and ,table-func
4331 (table--point-in-cell-p))
4332 ,table-func
4341 (defun table--read-from-minibuffer (prompt-history)
4343 PROMPT-HISTORY is a cons cell which car is the prompt string and the
4355 (defun table--unibyte-char-to-multibyte (char)
4368 (defun table--buffer-substring-and-trim (beg end)
4377 (table--remove-cell-properties
4381 (defun table--valign ()
4385 (if (or (null table-cell-info-valign)
4386 (eq table-cell-info-valign 'none))
4387 (table--get-coordinate)
4392 (table--current-line)))
4395 (setq tmp (table--current-line)))
4402 (cond ((eq table-cell-info-valign 'middle)
4403 (insert (make-string (/ (- table-cell-info-height content-height) 2) ?\n)))
4404 ((eq table-cell-info-valign 'bottom)
4405 (insert (make-string (- table-cell-info-height content-height) ?\n))))
4406 (table--goto-coordinate (cons table-cell-info-width (1- table-cell-info-height)))
4411 (let ((coord (table--get-coordinate)))
4412 (unless (< (cdr coord) table-cell-info-height)
4413 (setcdr coord (1- table-cell-info-height))
4414 (table--goto-coordinate coord))
4417 (defun table--query-justification ()
4420 (default (car table-justify-history)))
4424 nil t nil 'table-justify-history default)))))
4426 (defun table--spacify-frame ()
4427 "Spacify table frame.
4430 (append (string-to-list table-cell-horizontal-chars)
4431 (list table-cell-intersection-char table-cell-vertical-char))))
4435 ((eq (char-after) table-cell-intersection-char)
4441 (table--spacify-frame))))
4444 ((table--cell-horizontal-char-p (char-after))
4448 (table--cell-horizontal-char-p (char-after)))))
4449 ((eq (char-after) table-cell-vertical-char)
4456 (eq (char-after) table-cell-vertical-char))))))
4459 (defun table--remove-blank-lines (n)
4461 For adjusting below area of the table when the table is shortened."
4478 (defun table--uniform-list-p (l)
4487 (defun table--detect-cell-alignment (cell)
4500 (table--insert-rectangle cell-contents)
4539 (table--put-cell-justify-property cell justify)
4540 (table--put-cell-valign-property cell valign)))
4542 (defun table--string-to-number-list (str)
4546 (while (string-match "[-0-9.]+" str idx)
4548 (setq nl (cons (string-to-number (match-string 0 str)) nl)))
4551 (defun table--justify-cell-contents (justify &optional paragraph)
4556 (table-with-cache-buffer
4559 (fill-column table-cell-info-width)
4564 (setq table-cell-info-valign
4566 (setq table-cell-info-justify justify)))
4575 (table--valign)
4576 (table--remove-eol-spaces beg end 'bol)
4577 (let ((paragraph-start table-paragraph-start))
4578 (fill-region beg end table-cell-info-justify))))
4579 (setq table-inhibit-auto-fill-paragraph t)
4581 (table--update-cell 'now))
4583 (defun table--horizontally-shift-above-and-below (columns-to-extend top-to-bottom-coord-list)
4584 "Horizontally shift outside contents right above and right below of the table.
4585 This function moves the surrounding text outside of the table so that
4586 they match the horizontal growth/shrink of the table. It also
4587 untabify the shift affected area including the right side of the table
4589 specifies the number of columns the table grows, or shrinks if
4591 list. This list can be any vertical list within the table."
4594 (table--goto-coordinate (caar top-to-bottom-coord-list))
4595 (let* ((cell (table--horizontal-cell-list nil 'first-only 'top))
4596 (coord (cons (car (table--get-coordinate (cdr cell)))
4597 (cdr (table--get-coordinate (car cell))))))
4601 (while (and (table--goto-coordinate coord 'no-extension)
4605 (table--untabify-line)
4607 (table--untabify-line (point))
4608 (insert (make-string columns-to-extend ?\s)))
4610 (table--goto-coordinate (caar (last top-to-bottom-coord-list)))
4611 (let ((coord (table--get-coordinate (cdr (table--horizontal-cell-list nil 'first-only 'bottom)))))
4615 (while (and (table--goto-coordinate coord 'no-extension)
4619 (table--untabify-line)
4621 (table--untabify-line (point))
4622 (insert (make-string columns-to-extend ?\s)))
4625 (table--untabify-line (table--goto-coordinate beg-coord 'no-extension))
4628 (defun table--create-growing-space-below (lines-to-extend left-to-right-coord-list bottom-border-y)
4629 "Create growing space below the table.
4630 This function creates growing space below the table slightly
4633 1. When the first line below the table is a complete blank line it
4636 bottom line of the table it inserts a line consisting of prefix alone.
4637 3. Otherwise it deletes the rectangular contents where table will
4641 (prefix (and (table--goto-coordinate (cons 0 bottom-border-y))
4645 (table--goto-coordinate
4651 (table--goto-coordinate (cons 0 y))
4659 (table--goto-coordinate (cons (1- (caar (car left-to-right-coord-list))) y))
4660 (table--goto-coordinate (cons (1+ (cadr (car (last left-to-right-coord-list)))) y))))))
4663 (defun table--untabify-line (&optional from)
4669 (let ((current-coordinate (table--get-coordinate)))
4670 (table--untabify (or from (progn (beginning-of-line) (point)))
4672 (table--goto-coordinate current-coordinate)))
4674 (defun table--untabify (beg end)
4681 (defun table--multiply-string (string multiplier)
4682 "Multiply string and return it."
4685 (setq ret-str (concat ret-str string))
4689 (defun table--line-column-position (line column)
4696 (defun table--row-column-insertion-point-p (&optional columnp)
4699 (or (get-text-property (point) 'table-cell)
4703 (table--line-column-position -1 column)
4704 'table-cell t)
4705 (text-property-any (line-beginning-position) (point) 'table-cell t)
4707 (table--line-column-position 1 column)
4708 'table-cell t))
4709 (text-property-any (table--line-column-position -2 column)
4710 (table--line-column-position -2 (+ 2 column))
4711 'table-cell t))))))
4713 (defun table--find-row-column (&optional columnp no-error)
4714 "Search table and return a cell coordinate list of row or column."
4715 (let ((current-coordinate (table--get-coordinate)))
4718 (let ((coord (table--get-coordinate)))
4725 (table--goto-coordinate coord 'no-extension 'no-tab-expansion)
4727 table-cell-horizontal-chars
4728 table-cell-vertical-char
4729 table-cell-intersection-char))))
4734 (if (table--probe-cell)
4735 (throw 'end (table--cell-list-to-coord-list (if columnp
4736 (table--vertical-cell-list t nil 'left)
4737 (table--horizontal-cell-list t nil 'top))))
4738 (table--goto-coordinate (table--offset-coordinate coord (if columnp '(0 . 1) '(1 . 0)))
4740 (if (table--probe-cell)
4741 (throw 'end (table--cell-list-to-coord-list (if columnp
4742 (table--vertical-cell-list t nil 'left)
4743 (table--horizontal-cell-list t nil 'top)))))))))
4744 (table--goto-coordinate current-coordinate)
4748 (defun table--min-coord-list (coord-list)
4768 (defun table--cell-can-split-horizontally-p ()
4771 (let ((point-x (car (table--get-coordinate))))
4772 (table-recognize-cell 'force)
4773 (and (> point-x (car table-cell-info-lu-coordinate))
4774 (<= point-x (1- (car table-cell-info-rb-coordinate)))))))
4776 (defun table--cell-can-split-vertically-p ()
4779 (let ((point-y (cdr (table--get-coordinate))))
4780 (table-recognize-cell 'force)
4781 (and (> point-y (cdr table-cell-info-lu-coordinate))
4782 (<= point-y (cdr table-cell-info-rb-coordinate))))))
4784 (defun table--cell-can-span-p (direction)
4786 (table-recognize-cell 'force)
4788 (table--probe-cell)
4792 (table--goto-coordinate
4793 (cons (cond ((eq direction 'right) (1+ (car table-cell-info-rb-coordinate)))
4794 ((eq direction 'left) (1- (car table-cell-info-lu-coordinate)))
4795 (t (car table-cell-info-lu-coordinate)))
4796 (cond ((eq direction 'above) (- (cdr table-cell-info-lu-coordinate) 2))
4797 ((eq direction 'below) (+ (cdr table-cell-info-rb-coordinate) 2))
4798 (t (cdr table-cell-info-lu-coordinate)))) 'no-extension)
4799 (table--probe-cell))))
4802 (table--goto-coordinate
4803 (cons (cond ((eq direction 'right) (1+ (car table-cell-info-rb-coordinate)))
4804 ((eq direction 'left) (1- (car table-cell-info-lu-coordinate)))
4805 (t (car table-cell-info-rb-coordinate)))
4806 (cond ((eq direction 'above) (- (cdr table-cell-info-lu-coordinate) 2))
4807 ((eq direction 'below) (+ (cdr table-cell-info-rb-coordinate) 2))
4808 (t (cdr table-cell-info-rb-coordinate)))) 'no-extension)
4809 (table--probe-cell)))))
4814 (and (= (cdr (table--get-coordinate (car cell)))
4815 (cdr table-cell-info-lu-coordinate))
4816 (= (cdr (table--get-coordinate (cdr cell)))
4817 (cdr table-cell-info-rb-coordinate)))
4818 (and (= (car (table--get-coordinate (car cell)))
4819 (car table-cell-info-lu-coordinate))
4820 (= (car (table--get-coordinate (cdr cell)))
4821 (car table-cell-info-rb-coordinate))))))))
4823 (defun table--cell-insert-char (char &optional overwrite)
4824 "Insert CHAR inside a table cell."
4829 (mark-coordinate (table--transcoord-table-to-cache (table--get-coordinate (mark t)))))
4830 (table-with-cache-buffer
4833 (<= (car mark-coordinate) table-cell-info-width)
4835 (<= (cdr mark-coordinate) table-cell-info-height)
4837 (delete-region (point) (table--goto-coordinate mark-coordinate))))
4839 (let ((coordinate (table--get-coordinate)))
4840 (setq table-inhibit-auto-fill-paragraph t)
4841 (if (>= (car coordinate) table-cell-info-width)
4842 (if (>= (cdr coordinate) (1- table-cell-info-height))
4854 (if (and table-fixed-width-mode
4859 (regexp-quote (char-to-string table-word-continuation-char))
4864 (let ((coordinate (table--get-coordinate)))
4865 (if (< (car coordinate) table-cell-info-width)
4867 (insert (make-string (forward-line 1) ?\n))
4869 (setq table-inhibit-auto-fill-paragraph t))
4886 (defun table--finish-delayed-tasks ()
4888 (if table-update-timer
4889 (table--update-cell 'now))
4890 (if table-widen-timer
4891 (table--update-cell-widened 'now))
4892 (if table-heighten-timer
4893 (table--update-cell-heightened 'now)))
4895 (defmacro table--log (&rest body)
4902 (defun table--measure-max-width (&optional unlimited)
4922 (defun table--cell-to-coord (cell)
4925 (cons (table--get-coordinate (car cell))
4926 (table--get-coordinate (cdr cell)))
4929 (defun table--cell-list-to-coord-list (cell-list)
4941 (cons (table--cell-to-coord cell) coord-list))))
4944 (defun table--test-cell-list (&optional horizontal reverse first-only pivot)
4945 "For testing `table--vertical-cell-list' and `table--horizontal-cell-list'."
4946 (let* ((current-coordinate (table--get-coordinate))
4948 (table--horizontal-cell-list reverse first-only pivot)
4949 (table--vertical-cell-list reverse first-only pivot)))
4956 (table-with-cache-buffer
4959 (setq table-inhibit-auto-fill-paragraph t))
4960 (table--finish-delayed-tasks)))
4961 (table--goto-coordinate current-coordinate)))
4963 (defun table--vertical-cell-list (&optional top-to-bottom first-only pivot internal-dir internal-list internal-px)
4964 "Return a vertical cell list from the table.
4969 top of the table. If optional argument TOP-TO-BOTTOM is non-nil the
4970 order is reversed as from top to bottom of the table. If optional
4979 (let* ((cell (table--probe-cell))
4980 (lu-coordinate (table--get-coordinate (car cell)))
4981 (rb-coordinate (table--get-coordinate (cdr cell)))
4990 (table--goto-coordinate (cons px (if top-to-bottom by ty)) 'no-extension 'no-tab-expansion)
4991 (setq internal-list (table--vertical-cell-list top-to-bottom first-only nil 'up nil px)))
4998 (table--goto-coordinate (cons px (if top-to-bottom ty by)) 'no-extension 'no-tab-expansion)
4999 (setq internal-list (table--vertical-cell-list top-to-bottom nil nil 'down internal-list px)))
5003 (defun table--horizontal-cell-list (&optional left-to-right first-only pivot internal-dir internal-list internal-py)
5004 "Return a horizontal cell list from the table.
5009 left of the table. If optional argument LEFT-TO-RIGHT is non-nil the
5010 order is reversed as from left to right of the table. If optional
5019 (let* ((cell (table--probe-cell))
5020 (lu-coordinate (table--get-coordinate (car cell)))
5021 (rb-coordinate (table--get-coordinate (cdr cell)))
5030 (table--goto-coordinate (cons (if left-to-right rx lx) py) 'no-extension 'no-tab-expansion)
5031 (setq internal-list (table--horizontal-cell-list left-to-right first-only nil 'left nil py)))
5038 (table--goto-coordinate (cons (if left-to-right lx rx) py) 'no-extension 'no-tab-expansion)
5039 (setq internal-list (table--horizontal-cell-list left-to-right nil nil 'right internal-list py)))
5043 (defun table--point-in-cell-p (&optional location)
5044 "Return t when point is in a valid table cell in the current buffer.
5046 (and (table--at-cell-p (or location (point)))
5050 (table--probe-cell))
5051 (table--probe-cell))))
5053 (defun table--region-in-cell-p (beg end)
5054 "Return t when location BEG and END are in a valid table cell in the current buffer."
5055 (and (table--at-cell-p (min beg end))
5057 (let ((cell-beg (progn (goto-char beg) (table--probe-cell))))
5059 (equal cell-beg (progn (goto-char end) (table--probe-cell))))))))
5061 (defun table--at-cell-p (position &optional object at-column)
5062 "Returns non-nil if POSITION has table-cell property in OBJECT.
5066 (setq position (table--str-index-at-column object position)))
5067 (get-text-property position 'table-cell object))
5069 (defun table--probe-cell-left-up ()
5075 (let ((vertical-str (regexp-quote (char-to-string table-cell-vertical-char)))
5076 (intersection-str (regexp-quote (char-to-string table-cell-intersection-char)))
5077 (v-border (format "[%c%c]" table-cell-vertical-char table-cell-intersection-char))
5078 (h-border (format "[%s%c]" table-cell-horizontal-chars table-cell-intersection-char))
5107 (defun table--probe-cell-right-bottom ()
5113 (let ((vertical-str (regexp-quote (char-to-string table-cell-vertical-char)))
5114 (intersection-str (regexp-quote (char-to-string table-cell-intersection-char)))
5115 (v-border (format "[%c%c]" table-cell-vertical-char table-cell-intersection-char))
5116 (h-border (format "[%s%c]" table-cell-horizontal-chars table-cell-intersection-char))
5149 (defun table--editable-cell-p (&optional abort-on-error)
5151 (get-text-property (point) 'table-cell)))
5153 (defun table--probe-cell (&optional abort-on-error)
5154 "Probes a table cell around the point.
5155 Searches for the left upper corner and the right bottom corner of a table
5166 table-cell-horizontal-chars
5167 table-cell-vertical-char
5168 table-cell-intersection-char)))
5171 (and (setq lu (table--probe-cell-left-up))
5172 (setq rb (table--probe-cell-right-bottom))))
5175 (let ((lu-coordinate (table--get-coordinate lu))
5176 (rb-coordinate (table--get-coordinate rb)))
5178 (and (string-match
5182 (table--goto-coordinate
5186 (table--goto-coordinate
5189 (string-match
5193 (table--goto-coordinate
5197 (table--goto-coordinate
5205 (defun table--insert-rectangle (rectangle)
5221 (defun table--put-cell-property (cell)
5227 (let ((lu (table--get-coordinate (car cell)))
5228 (rb (table--get-coordinate (cdr cell))))
5231 (let ((beg (table--goto-coordinate lu 'no-extension))
5232 (end (table--goto-coordinate (cons (car rb) (cdr lu)))))
5233 (table--put-cell-line-property beg end))
5235 (table--put-cell-justify-property cell table-cell-info-justify)
5236 (table--put-cell-valign-property cell table-cell-info-valign))))
5238 (defun table--put-cell-line-property (beg end &optional object)
5244 (table--put-cell-content-property beg end object)
5245 (table--put-cell-keymap-property end (1+ end) object)
5246 (table--put-cell-indicator-property end (1+ end) object)
5247 (table--put-cell-rear-nonsticky end (1+ end) object))
5249 (defun table--put-cell-content-property (beg end &optional object)
5251 (table--put-cell-keymap-property beg end object)
5252 (table--put-cell-indicator-property beg end object)
5253 (table--put-cell-face-property beg end object)
5254 (table--put-cell-point-entered/left-property beg end object))
5256 (defun table--put-cell-indicator-property (beg end &optional object)
5257 "Put cell property which indicates that the location is within a table cell."
5258 (put-text-property beg end 'table-cell t object)
5259 (put-text-property beg end 'yank-handler table-yank-handler object))
5261 (defun table--put-cell-face-property (beg end &optional object)
5263 (put-text-property beg end 'face 'table-cell object))
5265 (defun table--put-cell-keymap-property (beg end &optional object)
5267 (put-text-property beg end 'keymap 'table-cell-map object))
5269 (defun table--put-cell-rear-nonsticky (beg end &optional object)
5273 (defun table--put-cell-point-entered/left-property (beg end &optional object)
5275 (put-text-property beg end 'point-entered 'table--point-entered-cell-function object)
5276 (put-text-property beg end 'point-left 'table--point-left-cell-function object))
5278 (defun table--remove-cell-properties (beg end &optional object)
5283 (let ((next (next-single-property-change beg 'table-cell object end)))
5284 (if (get-text-property beg 'table-cell object)
5287 'table-cell nil
5288 'table-justify nil
5289 'table-valign nil
5299 (defun table--update-cell-face ()
5302 (set-face-property 'table-cell 'underline table-fixed-width-mode)
5303 (set-face-inverse-video-p 'table-cell table-fixed-width-mode)))
5305 (table--update-cell-face)
5307 (defun table--get-property (cell property)
5312 (defun table--get-cell-justify-property (cell)
5314 (table--get-property cell 'table-justify))
5316 (defun table--get-cell-valign-property (cell)
5318 (table--get-property cell 'table-valign))
5320 (defun table--put-property (cell property value)
5327 (defun table--put-cell-justify-property (cell justify)
5329 (table--put-property cell 'table-justify justify))
5331 (defun table--put-cell-valign-property (cell valign)
5333 (table--put-property cell 'table-valign valign))
5335 (defun table--point-entered-cell-function (&optional old-point new-point)
5340 (unless table-cell-entered-state
5341 (setq table-cell-entered-state t)
5342 (setq table-mode-indicator t)
5344 (table--warn-incompatibility)
5345 (run-hooks 'table-point-entered-cell-hook))))
5347 (defun table--point-left-cell-function (&optional old-point new-point)
5352 (when table-cell-entered-state
5353 (setq table-cell-entered-state nil)
5354 (setq table-mode-indicator nil)
5356 (run-hooks 'table-point-left-cell-hook))))
5358 (defun table--warn-incompatibility ()
5360 This feature is disabled when `table-disable-incompatibility-warning'
5362 (unless (and table-disable-incompatibility-warning
5365 (not (get 'table-disable-incompatibility-warning 'xemacs)))
5366 (put 'table-disable-incompatibility-warning 'xemacs t)
5367 (display-warning 'table
5373 and any undo operation of table exhibit some known strange problems,
5381 (not (get 'table-disable-incompatibility-warning 'flyspell)))
5382 (put 'table-disable-incompatibility-warning 'flyspell t)
5383 (display-warning 'table
5387 Flyspell minor mode is known to be incompatible with this table
5395 (defun table--cell-blank-str (&optional n)
5396 "Return blank table cell string of length N."
5397 (let ((str (make-string (or n 1) ?\s)))
5398 (table--put-cell-content-property 0 (length str) str)
5401 (defun table--remove-eol-spaces (beg end &optional bol force)
5426 (defun table--fill-region (beg end &optional col justify)
5427 "Fill paragraphs in table cell cache.
5429 (let ((fill-column (or col table-cell-info-width))
5436 (setq justify (or justify table-cell-info-justify))
5441 (table--remove-eol-spaces (point-min) (point-max))
5442 (if table-fixed-width-mode
5443 (table--fill-region-strictly marker-beg marker-end)
5444 (let ((paragraph-start table-paragraph-start))
5451 (defun table--fill-region-strictly (beg end)
5454 chopped location is indicated with table-word-continuation-char."
5462 (format "[^%c ]\\(" table-word-continuation-char)
5463 (regexp-quote (char-to-string table-word-continuation-char))
5468 (let ((paragraph-start table-paragraph-start))
5480 (insert-before-markers (if (equal (char-before) ?\s) ?\s table-word-continuation-char)
5484 (defun table--goto-coordinate (coordinate &optional no-extension no-tab-expansion)
5521 (defun table--copy-coordinate (coord)
5525 (defun table--get-coordinate (&optional where)
5533 (table--current-line))))
5535 (defun table--current-line (&optional location)
5542 (defun table--transcoord-table-to-cache (&optional coordinate)
5543 "Transpose COORDINATE from table coordinate system to cache coordinate system.
5545 (table--offset-coordinate
5546 (or coordinate (table--get-coordinate))
5547 table-cell-info-lu-coordinate
5550 (defun table--transcoord-cache-to-table (&optional coordinate)
5551 "Transpose COORDINATE from cache coordinate system to table coordinate system.
5553 (table--offset-coordinate
5554 (or coordinate (table--get-coordinate))
5555 table-cell-info-lu-coordinate))
5557 (defun table--offset-coordinate (coordinate offset &optional negative)
5565 (defun table--char-in-str-at-column (str column)
5568 (let ((idx (table--str-index-at-column str column)))
5572 (defun table--str-index-at-column (str column)
5585 (defun table--set-timer (seconds func args)
5595 (defun table--cancel-timer (timer)
5601 (defun table--get-last-command ()
5607 (run-hooks 'table-load-hook)
5609 (provide 'table)
5621 ;;; table.el ends here