How does one make M-( the default behavior for typing an opening "(" character? I want Emacs to automatically insert the closing ")" after the cursor when I type a "(" character regardless of whether it's part of an M-key combination. Additionaly, I want to extend this behavior to quotes, subquotes, brackets and braces. Typing M-( is a pain, and there don't appear to be any comparable forms for those other characters.
+5
A:
I don't write much elisp myself, but this is something I cribbed off somebody. The code goes into your .emacs.
(setq skeleton-pair t)
(setq skeleton-pair-on-word t) ; apply skeleton trick even in front of a word.
(global-set-key "[" 'skeleton-pair-insert-maybe)
(global-set-key "{" 'skeleton-pair-insert-maybe)
(global-set-key "(" 'skeleton-pair-insert-maybe)
(global-set-key "\"" 'skeleton-pair-insert-maybe)
vinc456
2009-04-05 05:56:01
This is exactly what I was looking for; thank you.
2009-04-05 05:59:42
Thanks - I didn't know about skeleton-pair-on-word.
Bill White
2009-04-05 10:39:11
+2
A:
"(" is bound to self-insert-command
while M-'(' is insert-parenthesis
. You can reverse that simply by using global-set-key
or define-key
to bind "(" to insert-parenthesis
.
Charlie Martin
2009-04-05 05:57:08
+3
A:
Check out paredit.el which keeps parens/braces/quotes balanced as you wish, and also does offers many other features to assist with s-exp manipulation. If you're going to be writing Lisp code (as your name implies) you will probably want to use this library eventually.
Brian Carper
2009-04-05 06:49:57