[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Redefine "(" and ")" keys in every mode
From: |
Andy Stewart |
Subject: |
Re: Redefine "(" and ")" keys in every mode |
Date: |
Sun, 04 Jan 2009 08:01:48 +0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
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)
> ------------------------------