aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2021-12-01 19:49:07 +0100
committerLars Ingebrigtsen2021-12-01 19:49:13 +0100
commitcbcf8a616e515de22bb2b6cc40daa74c30ee2414 (patch)
treeb927208da7b183fc81b0197736345f9b60524cc1
parente2e2dd4890f7baba31faf667b343a34e68455f23 (diff)
downloademacs-cbcf8a616e515de22bb2b6cc40daa74c30ee2414.tar.gz
emacs-cbcf8a616e515de22bb2b6cc40daa74c30ee2414.zip
Fix table-fixed-width-mode when typing fast
* lisp/textmodes/table.el (table-with-cache-buffer): Use the value of table-fixed-width-mode in the correct buffer (bug#26701).
-rw-r--r--lisp/textmodes/table.el102
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.
1201Normally it should be nil for allowing automatic cell width expansion
1202that widens a cell when it is necessary. When non-nil, typing in a
1203cell does not automatically expand the cell width. A word that is too
1204long to fit in a cell is chopped into multiple lines. The chopped
1205location is indicated by `table-word-continuation-char'. This
1206variable's value can be toggled by \\[table-fixed-width-mode] at
1207run-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
1219the last cache point coordinate." 1234the 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.
2828Normally it should be nil for allowing automatic cell width expansion
2829that widens a cell when it is necessary. When non-nil, typing in a
2830cell does not automatically expand the cell width. A word that is too
2831long to fit in a cell is chopped into multiple lines. The chopped
2832location is indicated by `table-word-continuation-char'. This
2833variable's value can be toggled by \\[table-fixed-width-mode] at
2834run-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.
2843The result is a list (cw ch tw th c r cells) where cw is the cell 2849The result is a list (cw ch tw th c r cells) where cw is the cell