用于矩形选择的填充区域?

时间:2012-06-13 04:55:35

标签: emacs

我想做一些像填充区域这样的东西,除了我想要选择一个矩形区域并仅包裹其中的文本,并让它保持在矩形边界内。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:7)

编辑:啊,我知道之前我遇到过这种能力。

cua中的矩形编辑功能提供此功能。

首先启用cua-selection-mode。这是CUA中没有复制/剪切/粘贴密钥更改的好东西,因此您可能需要永久保存它:

(cua-selection-mode 1)

然后 C-RET 标记一个角落,将点移动到对角,然后 C-q 正常填充。 C-RET 再次退出矩形模式。

CUA的矩形编辑非常棒。在 M-x find-library RET cua-base RET 的注释中阅读。寻找“CUA矩形支持”标题。

原始回答:

(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))))))
相关问题