[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: local key swap? alternatives?
From: |
Francisco Borges |
Subject: |
Re: local key swap? alternatives? |
Date: |
Wed, 7 Sep 2005 15:53:25 +0200 |
User-agent: |
Mutt/1.5.9i |
ยป On Thu, Sep 01, 2005 at 10:49AM -0600, Kevin Rodgers wrote:
> Francisco Borges wrote:
> > Long ago I came with the idea to swap keys in LaTeX buffers to be able
> > to type popular LaTeX characters without SHIFT, namely $%^&*()_{}.
> How about:
>
> (defun swap-keys (key-1 key-2 &optional keymap)
> "*Swap the bindings of KEY-1 and KEY-2.
> Optional arg KEYMAP defaults to the global keymap; with a prefix arg,
> the local keymap."
> (interactive (list (read-key-sequence "Swap key: ")
> (read-key-sequence "Swap with key: ")
> (if current-prefix-arg
> (current-local-map)
> (current-global-map))))
> (let ((binding-1 (lookup-key keymap key-1))
> (binding-2 (lookup-key keymap key-2)))
> (define-key keymap key-1 binding-2)
> (define-key keymap key-2 binding-1)
> (when (interactive-p)
> (message "%s runs the command %s; %s runs the command %s"
> key-1 (lookup-key keymap key-1 t)
> key-2 (lookup-key keymap key-2 t)))))
> (swap-keys "$" "4" latex-mode-map)
> (swap-keys "%" "5" latex-mode-map)
That does not work because both keys are bound to
self-insert-command. That's the reason I had failed to do it myself.
I (finally) solved the problem by doing something as ugly as:
(defun my-four ()
(interactive)
(insert-char (string-to-char "4") 1))
(defun my-dollar ()
(interactive)
(insert-char (string-to-char "$") 1))
(local-set-key "$" (quote my-four))
(local-set-key "4" (quote my-dollar))
Would there be a better way to do it? I don't really know Lisp...
I think that the right thing to do is to use a function such as the one
you send and treat self-insert-command cases specially, but with my
knowledge of Lisp making these changes to the code above would take more
than the free time I have to spend on it...
Cheers,
Francisco.
- local key swap? alternatives?, Francisco Borges, 2005/09/01
- Re: local key swap? alternatives?, Kevin Rodgers, 2005/09/01
- Re: local key swap? alternatives?,
Francisco Borges <=
- Re: local key swap? alternatives?, Kevin Rodgers, 2005/09/07
- Re: local key swap? alternatives?, Francisco Borges, 2005/09/08
- Message not available
- Re: local key swap? alternatives?, Stefan Monnier, 2005/09/09
- Re: local key swap? alternatives?, Francisco Borges, 2005/09/09
- Message not available
- Re: local key swap? alternatives?, Stefan Monnier, 2005/09/09