help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: local key swap? alternatives?


From: Kevin Rodgers
Subject: Re: local key swap? alternatives?
Date: Thu, 01 Sep 2005 10:49:04 -0600
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]