Cua in emacs

I recently started investigating cua-mode, one of emac’s built-in minor modes. It does several things; the first is to rebind some keys to be more friendly to users familiar with conventions such as C-x, C-z, etc. I don’t use these, having become familiar with emacs commands for these, but if you haven’t mastered emac’s built-in keys it may help. Cua enables transient-mark mode and does it’s keybindings only take effect when the mark is highlighted, so it should not interfere with your regular keybindings *too* much, although it was still annoying while I was trying them out.

There are two other items that cua uses that are much more interesting to me: cua’s rectangles and the global mark. Once you have enabled the cua minor mode, C-RET will start selection of a rectangle. Unlike selecting a rectangle by setting a mark, this will highlight only the rectangle you are selecting. You can expand the rectangle in any direction, using RET to switch which corner you are expanding from. If you type with a rectangle selected, the string you type is inserted at the edge of the rectangle, for every line. Which edge depends on which corner you have selected. All your normal rectangle commands also work: killing, yanking, etc. It also handles tab characters much more gracefully than just setting the mark and converting a region to a rectangle.

Cua’s global mark is another feature that is sometimes useful, though not as often as the rectangle selection. The way it works is this: Once you set the global mark, text you type will go into that location, not the current point. While a good idea and sometimes useful, it is not as developed as I’d like. It does not function exactly as the point does: I would like functions that look around points would instead look around the global mark. For example, yasnippet expansion does not work, and
neither does pabbrev-mode. I also have some problems with inserting spaces that I haven’t tracked down yet that I believe are set by CEDET that conflict. It is still somewhat useful if you need to reference another part of a long buffer while typing, but some development could make it much more useful. Of course, having everything that references the point actually reference the global mark sounds pretty hard: I tried with some advice, but it didn’t work out. Oh well.

To enable cua, put the following in your .emacs file:

(setq cua-enable-cua-keys nil)
(cua-mode)

The first line will tell cua not to set its compatibility keybindings. The second enables the cua-mode rectangle selection and global-mark. Once there are in your .emacs and evaluated, you’re good to go!

Tags: ,

One Response to “Cua in emacs”

  1. [...] about before restarting my .emacs file: pabbrev and cua. The links for those posts are here and here respectively. Pabbrev is a mode for predictive expansion, which is incredibly useful. Cua is a mode [...]

Leave a Reply