Function: org-table-toggle-column-width

org-table-toggle-column-width is an autoloaded, interactive and byte-compiled function defined in org-table.el.gz.

Signature

(org-table-toggle-column-width &optional ARG)

Documentation

Shrink or expand current column in an Org table.

If a width cookie specifies a width W for the column, the first W visible characters are displayed. Otherwise, the column is shrunk to a single character.

When point is before the first column or after the last one, ask for the columns to shrink or expand, as a list of ranges. A column range can be one of the following patterns:

  N column N only
  N-M every column between N and M (both inclusive)
  N- every column between N (inclusive) and the last column
  -M every column between the first one and M (inclusive)
  - every column

When optional argument ARG is a string, use it as white space separated list of column ranges.

When called with C-u (universal-argument) prefix, call org-table-shrink, i.e., shrink columns with a width cookie and expand the others.

When called with C-u (universal-argument) C-u (universal-argument) prefix, expand all columns.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-table.el.gz
;;;###autoload
(defun org-table-toggle-column-width (&optional arg)
  "Shrink or expand current column in an Org table.

If a width cookie specifies a width W for the column, the first
W visible characters are displayed.  Otherwise, the column is
shrunk to a single character.

When point is before the first column or after the last one, ask
for the columns to shrink or expand, as a list of ranges.
A column range can be one of the following patterns:

  N    column N only
  N-M  every column between N and M (both inclusive)
  N-   every column between N (inclusive) and the last column
  -M   every column between the first one and M (inclusive)
  -    every column

When optional argument ARG is a string, use it as white space
separated list of column ranges.

When called with `\\[universal-argument]' prefix, call \
`org-table-shrink', i.e.,
shrink columns with a width cookie and expand the others.

When called with `\\[universal-argument] \\[universal-argument]' \
prefix, expand all columns."
  (interactive "P")
  (unless (org-at-table-p) (user-error "Not in a table"))
  (let* ((begin (org-table-begin))
	 (end (org-table-end))
	 ;; Compute an upper bound for the number of columns.
	 ;; Nonexistent columns are ignored anyway.
	 (max-columns (/ (- (line-end-position) (line-beginning-position)) 2))
	 (shrunk (org-table--list-shrunk-columns))
	 (columns
	  (pcase arg
	    (`nil
	     (if (save-excursion
		   (skip-chars-backward "^|" (line-beginning-position))
		   (or (bolp) (looking-at-p "[ \t]*$")))
		 ;; Point is either before first column or past last
		 ;; one.  Ask for columns to operate on.
		 (org-table--read-column-selection
		  (read-string "Column ranges (e.g. 2-4 6-): ")
		  max-columns)
	       (list (org-table-current-column))))
	    ((pred stringp) (org-table--read-column-selection arg max-columns))
	    ((or `(4) `(16)) nil)
	    (_ (user-error "Invalid argument: %S" arg)))))
    (pcase arg
      (`(4) (org-table-shrink begin end))
      (`(16) (org-table-expand begin end))
      (_
       (org-table-expand begin end)
       (org-table--shrink-columns
	(cl-set-exclusive-or columns shrunk) begin end)))))