Function: org-export-table-cell-width

org-export-table-cell-width is a byte-compiled function defined in ox.el.gz.

Signature

(org-export-table-cell-width TABLE-CELL INFO)

Documentation

Return TABLE-CELL contents width.

INFO is a plist used as the communication channel.

Return value is the width given by the last width cookie in the same column as TABLE-CELL, or nil.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox.el.gz
(defun org-export-table-cell-width (table-cell info)
  "Return TABLE-CELL contents width.

INFO is a plist used as the communication channel.

Return value is the width given by the last width cookie in the
same column as TABLE-CELL, or nil."
  (let* ((row (org-element-parent table-cell))
	 (table (org-element-parent row))
	 (cells (org-element-contents row))
	 (columns (length cells))
	 (column (- columns (length (memq table-cell cells))))
	 (cache (or (plist-get info :table-cell-width-cache)
		    (let ((table (make-hash-table :test #'eq)))
		      (plist-put info :table-cell-width-cache table)
		      table)))
	 (width-vector (or (gethash table cache)
			   (puthash table (make-vector columns 'empty) cache))))
    ;; Table rows may not have the same number of cells.  Extend
    ;; WIDTH-VECTOR appropriately if we encounter a row larger than
    ;; expected.
    (when (>= column (length width-vector))
      (setq width-vector
	    (vconcat width-vector
		     (make-list (- (1+ column) (length width-vector))
				'empty)))
      (puthash table width-vector cache))
    (pcase (aref width-vector column)
      (`empty
       (catch 'found
	 (dolist (row (org-element-contents table))
	   (when (org-export-table-row-is-special-p row info)
	     ;; In a special row, try to find a width cookie at
	     ;; COLUMN.  The following checks avoid expanding
	     ;; unnecessarily the cell with `org-export-data'.
	     (pcase (org-element-contents
		     (elt (org-element-contents row) column))
	       (`(,(and (pred stringp) cookie))
		(when (string-match "\\`<[lrc]?\\([0-9]+\\)>\\'" cookie)
		  (let ((w (string-to-number (match-string 1 cookie))))
		    (throw 'found (aset width-vector column w))))))))
	 (aset width-vector column nil)))
      (value value))))