Filling area for selecting a rectangle?

I would like to do something like fill-region, except that I want to select the region of the rectangle and wrap only the text inside it and leave it within the rectangle. Is there any way to do this?

+4
source share
1 answer

Edit: Ah, I knew that I had come across this ability before.

The cua rectangle editing cua provide this feature.

So first enable cua-selection-mode . That good stuff in CUA without a copy / cut / paste key is changing, so you might want to constantly:

 (cua-selection-mode 1) 

And then C-RET mark the corner, move the point to the opposite corner and Cq as usual to fill. C-RET again to exit rectangle mode.

CUA's rectangle editing is pretty amazing. Read about it in the comment Mx find-library RET cua-base RET . Find the heading "CUA Rectangle Support".

Original answer:

 (defun my-fill-rectangle (start end) "`fill-region' within the confines of a rectangle." (interactive "*r") (let* ((indent-tabs-mode nil) (content (delete-extract-rectangle start end))) (goto-char start) (insert-rectangle (with-temp-buffer (setq indent-tabs-mode nil fill-column (length (car content))) (insert-rectangle content) (fill-region (point-min) (point-max)) (goto-char (point-max)) (move-to-column fill-column t) (extract-rectangle (point-min) (point)))))) 
+7
source

All Articles