Function: org-table-wrap-region
org-table-wrap-region is an autoloaded, interactive and byte-compiled
function defined in org-table.el.gz.
Signature
(org-table-wrap-region ARG)
Documentation
Wrap several fields in a column like a paragraph.
This is useful if you'd like to spread the contents of a field over several lines, in order to keep the table compact.
If there is an active region, and both point and mark are in the same column,
the text in the column is wrapped to minimum width for the given number of
lines. Generally, this makes the table more compact. A prefix ARG may be
used to change the number of desired lines. For example, C-2 M-x org-table-wrap-region (org-table-wrap-region)
formats the selected text to two lines. If the region was longer than two
lines, the remaining lines remain empty. A negative prefix argument reduces
the current number of lines by that amount. The wrapped text is pasted back
into the table. If you formatted it to more lines than it was before, fields
further down in the table get overwritten - so you might need to make space in
the table first.
If there is no region, the current field is split at the cursor position and the text fragment to the right of the cursor is prepended to the field one line down.
If there is no region, but you specify a prefix ARG, the current field gets blank, and the content is appended to the field above.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-table.el.gz
;;;###autoload
(defun org-table-wrap-region (arg)
"Wrap several fields in a column like a paragraph.
This is useful if you'd like to spread the contents of a field over several
lines, in order to keep the table compact.
If there is an active region, and both point and mark are in the same column,
the text in the column is wrapped to minimum width for the given number of
lines. Generally, this makes the table more compact. A prefix ARG may be
used to change the number of desired lines. For example, \
`C-2 \\[org-table-wrap-region]'
formats the selected text to two lines. If the region was longer than two
lines, the remaining lines remain empty. A negative prefix argument reduces
the current number of lines by that amount. The wrapped text is pasted back
into the table. If you formatted it to more lines than it was before, fields
further down in the table get overwritten - so you might need to make space in
the table first.
If there is no region, the current field is split at the cursor position and
the text fragment to the right of the cursor is prepended to the field one
line down.
If there is no region, but you specify a prefix ARG, the current field gets
blank, and the content is appended to the field above."
(interactive "P")
(org-table-check-inside-data-field)
(if (org-region-active-p)
;; There is a region: fill as a paragraph.
(let ((start (region-beginning)))
(save-restriction
(narrow-to-region
(save-excursion (goto-char start) (move-beginning-of-line 1))
(save-excursion (org-forward-paragraph) (point)))
(org-table-cut-region (region-beginning) (region-end))
(when (> (length (car org-table-clip)) 1)
(user-error "Region must be limited to single column"))
(let ((nlines (cond ((not arg) (length org-table-clip))
((< arg 1) (+ (length org-table-clip) arg))
(t arg))))
(setq org-table-clip
(mapcar #'list
(org-wrap (mapconcat #'car org-table-clip " ")
nil
nlines))))
(goto-char start)
(org-table-paste-rectangle))
(org-table-align))
;; No region, split the current field at point.
(unless (org-get-alist-option org-M-RET-may-split-line 'table)
(skip-chars-forward "^\r\n|"))
(cond
(arg ; Combine with field above.
(let ((s (org-table-blank-field))
(col (org-table-current-column)))
(forward-line -1)
(while (org-at-table-hline-p) (forward-line -1))
(org-table-goto-column col)
(skip-chars-forward "^|")
(skip-chars-backward " ")
(insert " " (org-trim s))
(org-table-align)))
((looking-at "\\([^|]+\\)|") ; Split field.
(let ((s (match-string 1)))
(replace-match " |")
(goto-char (match-beginning 0))
(org-table-next-row)
(insert (org-trim s) " ")
(org-table-align)))
(t (org-table-next-row)))))