diff options
| -rw-r--r-- | lisp/textmodes/table.el | 102 |
1 files changed, 54 insertions, 48 deletions
diff --git a/lisp/textmodes/table.el b/lisp/textmodes/table.el index fef5ad2c7ac..ca99d562e40 100644 --- a/lisp/textmodes/table.el +++ b/lisp/textmodes/table.el | |||
| @@ -1195,6 +1195,21 @@ executing body forms.") | |||
| 1195 | (easy-menu-add-item (current-global-map) | 1195 | (easy-menu-add-item (current-global-map) |
| 1196 | '("menu-bar" "tools") table-global-menu-map) | 1196 | '("menu-bar" "tools") table-global-menu-map) |
| 1197 | 1197 | ||
| 1198 | ;;;###autoload | ||
| 1199 | (define-minor-mode table-fixed-width-mode | ||
| 1200 | "Cell width is fixed when this is non-nil. | ||
| 1201 | Normally it should be nil for allowing automatic cell width expansion | ||
| 1202 | that widens a cell when it is necessary. When non-nil, typing in a | ||
| 1203 | cell does not automatically expand the cell width. A word that is too | ||
| 1204 | long to fit in a cell is chopped into multiple lines. The chopped | ||
| 1205 | location is indicated by `table-word-continuation-char'. This | ||
| 1206 | variable's value can be toggled by \\[table-fixed-width-mode] at | ||
| 1207 | run-time." | ||
| 1208 | :tag "Fix Cell Width" | ||
| 1209 | :group 'table | ||
| 1210 | (table--finish-delayed-tasks) | ||
| 1211 | (table--update-cell-face)) | ||
| 1212 | |||
| 1198 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1213 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1199 | ;; | 1214 | ;; |
| 1200 | ;; Macros | 1215 | ;; Macros |
| @@ -1219,43 +1234,49 @@ original buffer's point is moved to the location that corresponds to | |||
| 1219 | the last cache point coordinate." | 1234 | the last cache point coordinate." |
| 1220 | (declare (debug (body)) (indent 0)) | 1235 | (declare (debug (body)) (indent 0)) |
| 1221 | (let ((height-expansion (make-symbol "height-expansion-var-symbol")) | 1236 | (let ((height-expansion (make-symbol "height-expansion-var-symbol")) |
| 1222 | (width-expansion (make-symbol "width-expansion-var-symbol"))) | 1237 | (width-expansion (make-symbol "width-expansion-var-symbol")) |
| 1223 | `(let (,height-expansion ,width-expansion) | 1238 | (fixed-width (make-symbol "fixed-width"))) |
| 1239 | `(let ((,fixed-width table-fixed-width-mode) | ||
| 1240 | ,height-expansion ,width-expansion) | ||
| 1224 | ;; make sure cache has valid data unless it is explicitly inhibited. | 1241 | ;; make sure cache has valid data unless it is explicitly inhibited. |
| 1225 | (unless table-inhibit-update | 1242 | (unless table-inhibit-update |
| 1226 | (table-recognize-cell)) | 1243 | (table-recognize-cell)) |
| 1227 | (with-current-buffer (get-buffer-create table-cache-buffer-name) | 1244 | (with-current-buffer (get-buffer-create table-cache-buffer-name) |
| 1228 | ;; goto the cell coordinate based on `table-cell-cache-point-coordinate'. | 1245 | (let ((table-fixed-width-mode ,fixed-width)) |
| 1229 | (set-mark (table--goto-coordinate table-cell-cache-mark-coordinate)) | 1246 | ;; Go to the cell coordinate based on |
| 1230 | (table--goto-coordinate table-cell-cache-point-coordinate) | 1247 | ;; `table-cell-cache-point-coordinate'. |
| 1231 | (table--untabify-line) | 1248 | (set-mark (table--goto-coordinate table-cell-cache-mark-coordinate)) |
| 1232 | ;; always reset before executing body forms because auto-fill behavior is the default. | 1249 | (table--goto-coordinate table-cell-cache-point-coordinate) |
| 1233 | (setq table-inhibit-auto-fill-paragraph nil) | 1250 | (table--untabify-line) |
| 1234 | ;; do the body | 1251 | ;; Always reset before executing body forms because |
| 1235 | ,@body | 1252 | ;; auto-fill behavior is the default. |
| 1236 | ;; fill paragraph unless the body does not want to by setting `table-inhibit-auto-fill-paragraph'. | 1253 | (setq table-inhibit-auto-fill-paragraph nil) |
| 1237 | (unless table-inhibit-auto-fill-paragraph | 1254 | ;; Do the body |
| 1238 | (if (and table-cell-info-justify | 1255 | ,@body |
| 1239 | (not (eq table-cell-info-justify 'left))) | 1256 | ;; Fill paragraph unless the body does not want to by |
| 1240 | (table--fill-region (point-min) (point-max)) | 1257 | ;; setting `table-inhibit-auto-fill-paragraph'. |
| 1241 | (table--fill-region | 1258 | (unless table-inhibit-auto-fill-paragraph |
| 1242 | (save-excursion (forward-paragraph -1) (point)) | 1259 | (if (and table-cell-info-justify |
| 1243 | (save-excursion (forward-paragraph 1) (point))))) | 1260 | (not (eq table-cell-info-justify 'left))) |
| 1244 | ;; keep the updated cell coordinate. | 1261 | (table--fill-region (point-min) (point-max)) |
| 1245 | (setq table-cell-cache-point-coordinate (table--get-coordinate)) | 1262 | (table--fill-region |
| 1246 | ;; determine the cell width expansion. | 1263 | (save-excursion (forward-paragraph -1) (point)) |
| 1247 | (setq ,width-expansion (table--measure-max-width)) | 1264 | (save-excursion (forward-paragraph 1) (point))))) |
| 1248 | (if (<= ,width-expansion table-cell-info-width) nil | 1265 | ;; Keep the updated cell coordinate. |
| 1249 | (table--fill-region (point-min) (point-max) ,width-expansion) | 1266 | (setq table-cell-cache-point-coordinate (table--get-coordinate)) |
| 1250 | ;; keep the updated cell coordinate. | 1267 | ;; Determine the cell width expansion. |
| 1251 | (setq table-cell-cache-point-coordinate (table--get-coordinate))) | 1268 | (setq ,width-expansion (table--measure-max-width)) |
| 1252 | (setq ,width-expansion (- ,width-expansion table-cell-info-width)) | 1269 | (if (<= ,width-expansion table-cell-info-width) nil |
| 1253 | ;; determine the cell height expansion. | 1270 | (table--fill-region (point-min) (point-max) ,width-expansion) |
| 1254 | (if (looking-at "\\s *\\'") nil | 1271 | ;; Keep the updated cell coordinate. |
| 1255 | (goto-char (point-min)) | 1272 | (setq table-cell-cache-point-coordinate (table--get-coordinate))) |
| 1256 | (if (re-search-forward "\\(\\s *\\)\\'" nil t) | 1273 | (setq ,width-expansion (- ,width-expansion table-cell-info-width)) |
| 1257 | (goto-char (match-beginning 1)))) | 1274 | ;; Determine the cell height expansion. |
| 1258 | (setq ,height-expansion (- (cdr (table--get-coordinate)) (1- table-cell-info-height)))) | 1275 | (if (looking-at "\\s *\\'") nil |
| 1276 | (goto-char (point-min)) | ||
| 1277 | (if (re-search-forward "\\(\\s *\\)\\'" nil t) | ||
| 1278 | (goto-char (match-beginning 1)))) | ||
| 1279 | (setq ,height-expansion (- (cdr (table--get-coordinate)) (1- table-cell-info-height))))) | ||
| 1259 | ;; now back to the table buffer. | 1280 | ;; now back to the table buffer. |
| 1260 | ;; expand the cell width in the table buffer if necessary. | 1281 | ;; expand the cell width in the table buffer if necessary. |
| 1261 | (if (> ,width-expansion 0) | 1282 | (if (> ,width-expansion 0) |
| @@ -2823,21 +2844,6 @@ or `top', `middle', `bottom' or `none' for vertical." | |||
| 2823 | (table--justify-cell-contents justify)))))) | 2844 | (table--justify-cell-contents justify)))))) |
| 2824 | 2845 | ||
| 2825 | ;;;###autoload | 2846 | ;;;###autoload |
| 2826 | (define-minor-mode table-fixed-width-mode | ||
| 2827 | "Cell width is fixed when this is non-nil. | ||
| 2828 | Normally it should be nil for allowing automatic cell width expansion | ||
| 2829 | that widens a cell when it is necessary. When non-nil, typing in a | ||
| 2830 | cell does not automatically expand the cell width. A word that is too | ||
| 2831 | long to fit in a cell is chopped into multiple lines. The chopped | ||
| 2832 | location is indicated by `table-word-continuation-char'. This | ||
| 2833 | variable's value can be toggled by \\[table-fixed-width-mode] at | ||
| 2834 | run-time." | ||
| 2835 | :tag "Fix Cell Width" | ||
| 2836 | :group 'table | ||
| 2837 | (table--finish-delayed-tasks) | ||
| 2838 | (table--update-cell-face)) | ||
| 2839 | |||
| 2840 | ;;;###autoload | ||
| 2841 | (defun table-query-dimension (&optional where) | 2847 | (defun table-query-dimension (&optional where) |
| 2842 | "Return the dimension of the current cell and the current table. | 2848 | "Return the dimension of the current cell and the current table. |
| 2843 | The result is a list (cw ch tw th c r cells) where cw is the cell | 2849 | The result is a list (cw ch tw th c r cells) where cw is the cell |