Discussion:
How not inserting a space before auto parentheses?
(too old to reply)
Christoph Martel
2009-02-16 01:06:18 UTC
Permalink
One of the charming features of Emacs is hitting Shift-Meta-( and
inserting a closed pair of parentheses (). However, Emacs inserts a
space before the opening ( and after the closing ). Can I somehow tell
Emacs at least not to do the opening space, so I could type
"testShift-Meta-(" and get "test()"? It would be even more helpful, if
the cursor could be placed between ( and ).
I'd appreciate every hint,
Chris
g.w
2009-02-16 02:12:54 UTC
Permalink
Hi, Christoph
Christoph> One of the charming features of Emacs is hitting
Christoph> Shift-Meta-( and inserting a closed pair of parentheses
Christoph> (). However, Emacs inserts a space before the opening (
Christoph> and after the closing ). Can I somehow tell Emacs at
Christoph> least not to do the opening space, so I could type
Christoph> "testShift-Meta-(" and get "test()"? It would be even
Christoph> more helpful, if the cursor could be placed between ( and
Christoph> ). I'd appreciate every hint, Chris

the following is what I set in my .emacs
(setq parens-require-spaces nil)
;;;;;;;;; some convenient key-binding
(add-to-list 'insert-pair-alist '(?[?]))
(add-to-list 'insert-pair-alist '(?<?>))
(add-to-list 'insert-pair-alist '(?{?}))
(add-to-list 'insert-pair-alist '(?/?/))
(add-to-list 'insert-pair-alist '(?\'?\'))
(add-to-list 'insert-pair-alist '(?\"?\"))
(add-to-list 'insert-pair-alist '(?`?`))
(global-set-key (kbd "M-[") 'insert-pair)
(global-set-key (kbd "C-,") 'beginning-of-buffer)
(global-set-key (kbd "M-<") 'insert-pair)
(global-set-key (kbd "M-{") 'insert-pair)
(global-set-key (kbd "C-{") 'backward-paragraph)
(global-set-key (kbd "C-/") 'insert-pair)
(global-set-key (kbd "M-'") 'insert-pair)
(global-set-key (kbd "M-\"") 'insert-pair)
(global-set-key (kbd "M-`") 'insert-pair)

This is what you'r looking for, "type 'testShift-Meta-(' and get
'test()', with the cursor be placed between ( and )".
Hope this help.

g.w
--
Life is like a prison, can you break it?
Peter Breitfeld
2009-02-16 16:03:24 UTC
Permalink
Post by Christoph Martel
One of the charming features of Emacs is hitting Shift-Meta-( and
inserting a closed pair of parentheses (). However, Emacs inserts a
space before the opening ( and after the closing ). Can I somehow tell
Emacs at least not to do the opening space, so I could type
"testShift-Meta-(" and get "test()"? It would be even more helpful, if
the cursor could be placed between ( and ).
I'd appreciate every hint,
Chris
In my .emacs I have

(setq skeleton-pair t)
(global-set-key "(" 'skeleton-pair-insert-maybe)
(global-set-key "[" 'skeleton-pair-insert-maybe)
(global-set-key "{" 'skeleton-pair-insert-maybe)

Then it' enough to enter a "(" only and to get automically the pair of
parentheses with the cursor placed between.
--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de
d***@gmail.com
2016-08-31 13:51:34 UTC
Permalink
Post by Peter Breitfeld
Post by Christoph Martel
One of the charming features of Emacs is hitting Shift-Meta-( and
inserting a closed pair of parentheses (). However, Emacs inserts a
space before the opening ( and after the closing ). Can I somehow tell
Emacs at least not to do the opening space, so I could type
"testShift-Meta-(" and get "test()"? It would be even more helpful, if
the cursor could be placed between ( and ).
I'd appreciate every hint,
Chris
In my .emacs I have
(setq skeleton-pair t)
(global-set-key "(" 'skeleton-pair-insert-maybe)
(global-set-key "[" 'skeleton-pair-insert-maybe)
(global-set-key "{" 'skeleton-pair-insert-maybe)
Then it' enough to enter a "(" only and to get automically the pair of
parentheses with the cursor placed between.
--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de
Thanks, works just at expected!
Ilan Pillemer
2016-08-31 15:56:16 UTC
Permalink
Post by d***@gmail.com
Post by Peter Breitfeld
Post by Christoph Martel
One of the charming features of Emacs is hitting Shift-Meta-( and
inserting a closed pair of parentheses (). However, Emacs inserts a
space before the opening ( and after the closing ). Can I somehow tell
Emacs at least not to do the opening space, so I could type
"testShift-Meta-(" and get "test()"? It would be even more helpful, if
the cursor could be placed between ( and ).
I'd appreciate every hint,
Chris
In my .emacs I have
(setq skeleton-pair t)
(global-set-key "(" 'skeleton-pair-insert-maybe)
(global-set-key "[" 'skeleton-pair-insert-maybe)
(global-set-key "{" 'skeleton-pair-insert-maybe)
Then it' enough to enter a "(" only and to get automically the pair of
parentheses with the cursor placed between.
--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de
Thanks, works just at expected!
I have just started using smart-parens and that provides similar
functionality and more. Not sure if that's overkill for you though.
--
Ilan
j***@gmail.com
2017-02-18 07:05:26 UTC
Permalink
Post by Peter Breitfeld
Post by Christoph Martel
One of the charming features of Emacs is hitting Shift-Meta-( and
inserting a closed pair of parentheses (). However, Emacs inserts a
space before the opening ( and after the closing ). Can I somehow tell
Emacs at least not to do the opening space, so I could type
"testShift-Meta-(" and get "test()"? It would be even more helpful, if
the cursor could be placed between ( and ).
I'd appreciate every hint,
Chris
In my .emacs I have
(setq skeleton-pair t)
(global-set-key "(" 'skeleton-pair-insert-maybe)
(global-set-key "[" 'skeleton-pair-insert-maybe)
(global-set-key "{" 'skeleton-pair-insert-maybe)
Then it' enough to enter a "(" only and to get automically the pair of
parentheses with the cursor placed between.
--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de
Loading...