Function: table-query-dimension

table-query-dimension is an autoloaded, interactive and byte-compiled function defined in table.el.gz.

Signature

(table-query-dimension &optional WHERE)

Documentation

Return the dimension of the current cell and the current table.

The result is a list (cw ch tw th c r cells) where cw is the cell width, ch is the cell height, tw is the table width, th is the table height, c is the number of columns, r is the number of rows and cells is the total number of cells. The cell dimension excludes the cell frame while the table dimension includes the table frame. The columns and the rows are counted by the number of cell boundaries. Therefore the number tends to be larger than it appears for the tables with non-uniform cell structure (heavily spanned and split). When optional WHERE is provided the cell and table at that location is reported.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/table.el.gz
;;;###autoload
(defun table-query-dimension (&optional where)
  "Return the dimension of the current cell and the current table.
The result is a list (cw ch tw th c r cells) where cw is the cell
width, ch is the cell height, tw is the table width, th is the table
height, c is the number of columns, r is the number of rows and cells
is the total number of cells.  The cell dimension excludes the cell
frame while the table dimension includes the table frame.  The columns
and the rows are counted by the number of cell boundaries.  Therefore
the number tends to be larger than it appears for the tables with
non-uniform cell structure (heavily spanned and split).  When optional
WHERE is provided the cell and table at that location is reported."
  (interactive)
  (save-excursion
    (if where (goto-char where))
    (let ((starting-cell (table--probe-cell))
	  cell table-lu table-rb col-list row-list (cells 0))
      (if (null starting-cell) nil
	(setq table-lu (car starting-cell))
	(setq table-rb (cdr starting-cell))
	(setq col-list (cons (car (table--get-coordinate (car starting-cell))) nil))
	(setq row-list (cons (cdr (table--get-coordinate (car starting-cell))) nil))
	(and (called-interactively-p 'interactive)
	     (message "Computing cell dimension..."))
	(while
	    (progn
	      (table-forward-cell 1 t)
	      (setq cells (1+ cells))
	      (and (setq cell (table--probe-cell))
		   (not (equal cell starting-cell))))
	  (if (< (car cell) table-lu)
	      (setq table-lu (car cell)))
	  (if (> (cdr cell) table-rb)
	      (setq table-rb (cdr cell)))
	  (let ((lu-coordinate (table--get-coordinate (car cell))))
	    (if (memq (car lu-coordinate) col-list) nil
	      (setq col-list (cons (car lu-coordinate) col-list)))
	    (if (memq (cdr lu-coordinate) row-list) nil
	      (setq row-list (cons (cdr lu-coordinate) row-list)))))
	(let* ((cell-lu-coordinate (table--get-coordinate (car starting-cell)))
	       (cell-rb-coordinate (table--get-coordinate (cdr starting-cell)))
	       (table-lu-coordinate (table--get-coordinate table-lu))
	       (table-rb-coordinate (table--get-coordinate table-rb))
	       (cw (- (car cell-rb-coordinate) (car cell-lu-coordinate)))
	       (ch (1+ (- (cdr cell-rb-coordinate) (cdr cell-lu-coordinate))))
	       (tw (+ 2 (- (car table-rb-coordinate) (car table-lu-coordinate))))
	       (th (+ 3 (- (cdr table-rb-coordinate) (cdr table-lu-coordinate))))
	       (c (length col-list))
	       (r (length row-list)))
	  (and (called-interactively-p 'interactive)
	       (message "Cell: (%dw, %dh), Table: (%dw, %dh), Dim: (%dc, %dr), Total Cells: %d" cw ch tw th c r cells))
	  (list cw ch tw th c r cells))))))