Function: table-with-cache-buffer
table-with-cache-buffer is a macro defined in table.el.gz.
Signature
(table-with-cache-buffer &rest BODY)
Documentation
Execute the forms in BODY with table cache buffer as the current buffer.
This macro simplifies the rest of the work greatly by condensing the common idiom used in many of the cell manipulation functions. It does not return any meaningful value.
Save the current buffer and set the cache buffer as the current
buffer. Move the point to the cache buffer coordinate
table-cell-cache-point-coordinate. After BODY forms are executed,
the paragraph is filled as long as table-inhibit-auto-fill-paragraph
remains nil. BODY can set it to t when it does not want to fill the
paragraph. If necessary the cell width and height are extended as the
consequence of cell content modification by the BODY. Then the
current buffer is restored to the original one. The last cache point
coordinate is stored in table-cell-cache-point-coordinate. The
original buffer's point is moved to the location that corresponds to
the last cache point coordinate.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/table.el.gz
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Macros
;;
(defmacro table-with-cache-buffer (&rest body)
"Execute the forms in BODY with table cache buffer as the current buffer.
This macro simplifies the rest of the work greatly by condensing the
common idiom used in many of the cell manipulation functions. It does
not return any meaningful value.
Save the current buffer and set the cache buffer as the current
buffer. Move the point to the cache buffer coordinate
`table-cell-cache-point-coordinate'. After BODY forms are executed,
the paragraph is filled as long as `table-inhibit-auto-fill-paragraph'
remains nil. BODY can set it to t when it does not want to fill the
paragraph. If necessary the cell width and height are extended as the
consequence of cell content modification by the BODY. Then the
current buffer is restored to the original one. The last cache point
coordinate is stored in `table-cell-cache-point-coordinate'. The
original buffer's point is moved to the location that corresponds to
the last cache point coordinate."
(declare (debug (body)) (indent 0))
(let ((height-expansion (make-symbol "height-expansion-var-symbol"))
(width-expansion (make-symbol "width-expansion-var-symbol"))
(fixed-width (make-symbol "fixed-width")))
`(let ((,fixed-width table-fixed-width-mode)
,height-expansion ,width-expansion)
;; make sure cache has valid data unless it is explicitly inhibited.
(unless table-inhibit-update
(table-recognize-cell))
(with-current-buffer (get-buffer-create table-cache-buffer-name)
(let ((table-fixed-width-mode ,fixed-width))
;; Go to the cell coordinate based on
;; `table-cell-cache-point-coordinate'.
(set-mark (table--goto-coordinate table-cell-cache-mark-coordinate))
(table--goto-coordinate table-cell-cache-point-coordinate)
(table--untabify-line)
;; Always reset before executing body forms because
;; auto-fill behavior is the default.
(setq table-inhibit-auto-fill-paragraph nil)
;; Do the body
,@body
;; Fill paragraph unless the body does not want to by
;; setting `table-inhibit-auto-fill-paragraph'.
(unless table-inhibit-auto-fill-paragraph
(if (and table-cell-info-justify
(not (eq table-cell-info-justify 'left)))
(table--fill-region (point-min) (point-max))
(table--fill-region
(save-excursion (forward-paragraph -1) (point))
(save-excursion (forward-paragraph 1) (point)))))
;; Keep the updated cell coordinate.
(setq table-cell-cache-point-coordinate (table--get-coordinate))
;; Determine the cell width expansion.
(setq ,width-expansion (table--measure-max-width))
(if (<= ,width-expansion table-cell-info-width) nil
(table--fill-region (point-min) (point-max) ,width-expansion)
;; Keep the updated cell coordinate.
(setq table-cell-cache-point-coordinate (table--get-coordinate)))
(setq ,width-expansion (- ,width-expansion table-cell-info-width))
;; Determine the cell height expansion.
(if (looking-at "\\s *\\'") nil
(goto-char (point-min))
(if (re-search-forward "\\(\\s *\\)\\'" nil t)
(goto-char (match-beginning 1))))
(setq ,height-expansion (- (cdr (table--get-coordinate)) (1- table-cell-info-height)))))
;; now back to the table buffer.
;; expand the cell width in the table buffer if necessary.
(if (> ,width-expansion 0)
(table-widen-cell ,width-expansion 'no-copy 'no-update))
;; expand the cell height in the table buffer if necessary.
(if (> ,height-expansion 0)
(table-heighten-cell ,height-expansion 'no-copy 'no-update))
;; do valign
(with-current-buffer (get-buffer-create table-cache-buffer-name)
(table--goto-coordinate table-cell-cache-point-coordinate)
(setq table-cell-cache-point-coordinate (table--valign)))
;; move the point in the table buffer to the location that corresponds to
;; the location in the cell cache buffer
(table--goto-coordinate (table--transcoord-cache-to-table table-cell-cache-point-coordinate))
;; set up the update timer unless it is explicitly inhibited.
(unless table-inhibit-update
(table--update-cell)))))