Re: [FEATURE REQUEST] auto insert close paren
Surendra Singhi <[email protected]> Wed, 09 Mar 2005 19:24:18 -0700
| Newsgroups | gmane.emacs.auc-tex |
|---|---|
| Message-ID | <[email protected]> |
Masayuki Ataka wrote:
>
> When we write open paren `(', automatically close paren `)' is
> inserted and cursor is move into inside them. This should be
> worked on similar symbols.
>
> ex.
> ( -> (-!-)
> $ -> $-!-$
> \[ -> \[ -!- \]
> \{ -> \{-!-\}
> \left( -> \left( -!- \right)
> \bigl( -> \bigl( -!- \bigr)
> \bigl\langle -> \bigl\langle -!- \bigr\rangle
>
> `-!-' means a cursor.
>
I have written code to do a part of above:
This will insert closing pair for (,$,[,",{.
Do you want closing pairs to be inserted for "\[" and "\( also?
And what is \left(, \bigl(, etc.?
One drawback of this code is that unlike in eclipse, if the user also
type a closing pair the automatically inserted closing pair is not removed.
(require 'skeleton)
(defun self-insert-pair()
"Insert characters (,{,[,\",$ and their closing counterparts, and
then put the cursor in the middle position."
(interactive)
(setq skeleton-pair t)
(let ((char last-command-char))
(case char
(?\( (skeleton-insert '(nil "(" _ ")")))
(?\[ (skeleton-insert '(nil "[" _ "]")))
(?\$ (skeleton-pair-insert-maybe nil))
(?\{ (skeleton-insert '(nil "{" _ "}")))
(?\" (skeleton-pair-insert-maybe nil)))))
(local-set-key [\(] 'self-insert-pair)
(local-set-key [\$] 'self-insert-pair)
(local-set-key [\{] 'self-insert-pair)
(local-set-key [\[] 'self-insert-pair)
(local-set-key [\"] 'self-insert-pair)
--
Surendra Singhi
www.public.asu.edu/~sksinghi/
"O thou my friend! The prosperity of Crime is like unto the lightning,
whose traitorous brilliancies embellish the atmosphere but for an
instant, in order to hurl into death's very depths the luckless one they
have dazzled." -- Marquis de Sade