ยป 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. _______________________________________________ Help-gnu-emacs mailing list Help-gnu-emacs@gnu.org http://lists.gnu.org/mailman/listinfo/help-gnu-emacs