* Redefine "(" and ")" keys in every mode
@ 2009-01-03 15:31 TheLonelyStar
2009-01-03 21:57 ` Drew Adams
2009-01-04 0:01 ` Andy Stewart
0 siblings, 2 replies; 5+ messages in thread
From: TheLonelyStar @ 2009-01-03 15:31 UTC (permalink / raw)
To: Help-gnu-emacs
Hi,
I use the following functions (bellow) for redifine the insertions if ( and
).
The Idea is: When I type (, I want () inserted. When I type ) and the next
character is ), I want to just jump over it.
The Problem is: This works, as long as the mode I am in does not overwrite
the "(" or ")" key.
And, at the same time, when the mode overwrites this keys, it normaly has a
reason for it.
Has somebody an Idea how this can be done, so that it works in every mode?
Thanks!
Nathan
The functions:
-----------------------------------
(defun bracket (arg)
(interactive "*P")
(insert "()")
(backward-char))
(define-key global-map (kbd "(") 'bracket)
;;Jump after character on insertion
(defun end-insertion (arg)
(interactive "*p")
(if (looking-at (concat "[\n \t]*" (this-command-keys))) (goto-char
(match-end 0)) (insert (this-command-keys)) (indent-according-to-mode))
)
(define-key global-map (kbd ")") 'end-insertion)
(define-key c-mode-base-map (kbd ")") 'end-insertion)
------------------------------
--
View this message in context: http://www.nabble.com/Redefine-%22%28%22-and-%22%29%22-keys-in-every-mode-tp21265910p21265910.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: Redefine "(" and ")" keys in every mode
2009-01-03 15:31 Redefine "(" and ")" keys in every mode TheLonelyStar
@ 2009-01-03 21:57 ` Drew Adams
2009-01-04 0:01 ` Andy Stewart
1 sibling, 0 replies; 5+ messages in thread
From: Drew Adams @ 2009-01-03 21:57 UTC (permalink / raw)
To: 'TheLonelyStar', Help-gnu-emacs
> I use the following functions (bellow) for redifine the
> insertions if ( and ). The Idea is: When I type (, I want ()
> inserted. When I type ) and the next character is ), I want
> to just jump over it.
See commands `insert-parentheses' (`M-(' in Emacs Lisp mode),
`move-past-close-and-reindent' (`M-)' in Emacs Lisp mode), `insert-pair', and
`delete-pair'.
See also:
http://www.emacswiki.org/emacs/ElectricPair
http://www.emacswiki.org/emacs/parenthesis.el
http://www.emacswiki.org/emacs/SkeletonMode#toc11
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Redefine "(" and ")" keys in every mode
2009-01-03 15:31 Redefine "(" and ")" keys in every mode TheLonelyStar
2009-01-03 21:57 ` Drew Adams
@ 2009-01-04 0:01 ` Andy Stewart
2009-01-04 0:19 ` Drew Adams
1 sibling, 1 reply; 5+ messages in thread
From: Andy Stewart @ 2009-01-04 0:01 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
I recommend you install paredit.el with Emacs.
It is a minor mode for performing structured editing of S-expression
data.
Of course, it can insert () when you type (, and type ) jump next if
have next one.
You can find it at: http://www.emacswiki.org/emacs/ParEdit
Regards,
-- Andy
TheLonelyStar <nabble2@lonely-star.org> writes:
> Hi,
>
> I use the following functions (bellow) for redifine the insertions if ( and
> ).
> The Idea is: When I type (, I want () inserted. When I type ) and the next
> character is ), I want to just jump over it.
>
> The Problem is: This works, as long as the mode I am in does not overwrite
> the "(" or ")" key.
> And, at the same time, when the mode overwrites this keys, it normaly has a
> reason for it.
>
> Has somebody an Idea how this can be done, so that it works in every mode?
> Thanks!
> Nathan
>
> The functions:
> -----------------------------------
> (defun bracket (arg)
> (interactive "*P")
> (insert "()")
> (backward-char))
> (define-key global-map (kbd "(") 'bracket)
>
> ;;Jump after character on insertion
> (defun end-insertion (arg)
> (interactive "*p")
> (if (looking-at (concat "[\n \t]*" (this-command-keys))) (goto-char
> (match-end 0)) (insert (this-command-keys)) (indent-according-to-mode))
> )
>
> (define-key global-map (kbd ")") 'end-insertion)
> (define-key c-mode-base-map (kbd ")") 'end-insertion)
> ------------------------------
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: Redefine "(" and ")" keys in every mode
2009-01-04 0:01 ` Andy Stewart
@ 2009-01-04 0:19 ` Drew Adams
0 siblings, 0 replies; 5+ messages in thread
From: Drew Adams @ 2009-01-04 0:19 UTC (permalink / raw)
To: 'Andy Stewart', help-gnu-emacs
> I recommend you install paredit.el with Emacs.
> It is a minor mode for performing structured editing of S-expression
> data. Of course, it can insert () when you type (, and type ) jump
> next if have next one. You can find it at:
> http://www.emacswiki.org/emacs/ParEdit
Thanks; I forgot that one. I've added the others I mentioned to
CategoryParentheses, which might provide additional help about this.
http://www.emacswiki.org/emacs/CategoryParentheses
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Redefine "(" and ")" keys in every mode
[not found] <mailman.3849.1231013327.26697.help-gnu-emacs@gnu.org>
@ 2009-01-05 2:26 ` Xah Lee
0 siblings, 0 replies; 5+ messages in thread
From: Xah Lee @ 2009-01-05 2:26 UTC (permalink / raw)
To: help-gnu-emacs
On Jan 3, 7:31 am, TheLonelyStar <nabb...@lonely-star.org> wrote:
> Hi,
>
> I use the following functions (bellow) for redifine the insertions if ( and
> ).
> The Idea is: When I type (, I want () inserted. When I type ) and the next
> character is ), I want to just jump over it.
>
> The Problem is: This works, as long as the mode I am in does not overwrite
> the "(" or ")" key.
> And, at the same time, when the mode overwrites this keys, it normaly has a
> reason for it.
>
> Has somebody an Idea how this can be done, so that it works in every mode?
> Thanks!
> Nathan
>
> The functions:
> -----------------------------------
> (defun bracket (arg)
> (interactive "*P")
> (insert "()")
> (backward-char))
> (define-key global-map (kbd "(") 'bracket)
>
> ;;Jump after character on insertion
> (defun end-insertion (arg)
> (interactive "*p")
> (if (looking-at (concat "[\n \t]*" (this-command-keys))) (goto-char
> (match-end 0)) (insert (this-command-keys)) (indent-according-to-mode))
> )
>
> (define-key global-map (kbd ")") 'end-insertion)
> (define-key c-mode-base-map (kbd ")") 'end-insertion)
to answer your question, you need to use hook on modes that use keys
that you defined in global-map. See here:
• How To Reclaim Keybindings In Emacs
http://xahlee.org/emacs/ergonomic_emacs_keybinding_minibuffer.html
-----------------
I also have all matching pairs inserted together.
The way i do it is to use the Hyper key together with homerow keys
under my right hand.
The hyper is set to the Start key on Microsoft keyboard. The {}()[]
are qwerty's J, K, L.
The above is my setup. For detail, i'm using Mac OS X, and Microsoft's
ergonomic keyboard, and Dvorak layout (set in OS)... so the following
elisp code may seem complicated.
(setq mac-option-modifier 'hyper)
(global-set-key (kbd "H-h") (lambda () (interactive) (insert "{}")
(backward-char 1)))
(global-set-key (kbd "H-t") (lambda () (interactive) (insert "()")
(backward-char 1)))
(global-set-key (kbd "H-n") (lambda () (interactive) (insert "[]")
(backward-char 1)))
You can see my other matching pairs setup for “”‘’«»‹›"", as well as
easier to press keys for += and bunch of other unicode keys at:
http://xahlee.org/emacs/xah_emacs_init.html
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-01-05 2:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-03 15:31 Redefine "(" and ")" keys in every mode TheLonelyStar
2009-01-03 21:57 ` Drew Adams
2009-01-04 0:01 ` Andy Stewart
2009-01-04 0:19 ` Drew Adams
[not found] <mailman.3849.1231013327.26697.help-gnu-emacs@gnu.org>
2009-01-05 2:26 ` Xah Lee
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).