开发者

emacs: Change case of a rectangle

What would be simplest way to change the case of a rectangle?

None of the short-cuts mentioned in the manual talk about this. Do I have to add a custom binding to do that? And开发者_开发问答 while we are at it, how do I search only within a rectangle?


Here's an implementation of upcase-rectangle, which changes the case to all uppercase. Just replace the upcase with downcase or capitalize or whatever custom case transformation you want:

(defun upcase-rectangle (b e)
  "change chars in rectangle to uppercase"
  (interactive "r")
  (apply-on-rectangle 'upcase-rectangle-line b e))

(defun upcase-rectangle-line (startcol endcol)
  (when (= (move-to-column startcol) startcol)
    (upcase-region (point)
                   (progn (move-to-column endcol 'coerce)
                          (point)))))


It's easy with using cua-mode's rectangle selection support:

(setq cua-enable-cua-keys nil)  ; enable only CUA's rectangle selections
(cua-mode t)

You can then select rectangles by pressing C-RET and moving the cursor. To upcase that region, just use the usual upcase-region command, bound to M-U by default.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜