Emacs tips: parenthesizing

To help people get more out of Emacs use, I’ve decided to start putting up occasional Emacs Tips posts. Here’s the first one:

You can surround one or more s-expressions with parentheses by giving the number of expressions as a prefix argument, then typing M-(

Further tip: if you’re at the end of the expression or expressions that you want to parenthesize, use a negative numeric argument.

Example:
You’ve just entered
sum(x)
in some programming language, and you want to turn it into sqrt(sum(x)). The cursor is just after the closing parenthesis. Type
M-- M-2 M-(
(that is, Meta-minus Meta-2 Meta-OpenParenthesis)
and it will place the parentheses around the expressions, and leave point just inside the new parentheses. Now you can move back one character (C-b), or, if you’ve switched to thinking in structure-related commands like I have, M-C-u (move up one level of parenthesis) and enter the outer function name.

Advertisements

Post a Comment

Required fields are marked *

*
*

%d bloggers like this: