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 $%^&*()_{}.
>
> So I thought of swapping ($,4), (%,5) etc but I wanted it only for
> LaTeX-mode and never figured out how to perform a local key
> swap. Instead I modified lisp/double.el to use doubles as (?4 "$" "4")
> (?5 "%" "5") etc, e.g. hitting '4' once I get '$', hit twice I get '4'.
> To get a decent compromise.
>
> With my last compilation of emacs (22.0.50.1), this has stopped
> working.
>
> Two questions:
>
> 1. Is there an easy way for me to get this to work again?
>
> 2. Would anyone recommend another approach to the problem? Is there a
> way to swap keys locally in Emacs?
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)
--
Kevin Rodgers
_______________________________________________
Help-gnu-emacs mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs