Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

swapping [] and () in elisp

11 views
Skip to first unread message

Marco Baringer

unread,
Sep 17, 2002, 2:58:06 PM9/17/02
to

i am trying to find a way in elisp to swap the [] and () keys.

all i have to do is:

1) get the old definition from the local-map, or if none exists, from
the global map.

2) redefine the keys so that they call the swapped definition. setup
last-command-char and use call-interactively so that everything
works as it should.

so, to make (kbd "[") act like (kbd "(") here's what i do: (assuming
MODE-MAP is the key map to switch)

(let ((orig-open-square (or (lookup-key mode-map "[")
(lookup-key global-map "["))))
(define-key mode-map "("
(lambda ()
(interactive)
(setq last-command-char ?\[)
(call-interactively orig-open-square [?\[]))))

my problem is how to deal with ORIG-OPEN-SQUARE. by the time the (kbd
"(") key gets pressed the definition of orig-open-sqaure is gone. if i
make orig-open-square buffer-local then i get infiinte loops as i end
up setting the key to something which calls itself. i'd like a
mode-local variable or something of a way to say "this keymap has
already been modified, don't do it again."

p.s. - please do not mention the xmodmap/registry manipulation. 1)
they don't work on my powerbook. 2) i can't modify other the registry
on other people's machines, but i can modify the .emacs.

--
-Marco
Ring the bells that still can ring.
Forget your perfect offering.
There is a crack in everything.
That's how the light gets in.
-Leonard Cohen

Stefan Monnier <foo@acm.com>

unread,
Sep 17, 2002, 3:12:30 PM9/17/02
to
>>>>> "Marco" == Marco Baringer <em...@bese.it> writes:
> i am trying to find a way in elisp to swap the [] and () keys.

Check out keyboard-translate.


Stefan

Marco Baringer

unread,
Sep 17, 2002, 3:37:25 PM9/17/02
to

that would work too :)

thanks.

0 new messages