[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Toggling the same key combination between two options
From: |
etay . meiri |
Subject: |
Re: Toggling the same key combination between two options |
Date: |
Thu, 11 Sep 2008 12:27:48 -0700 (PDT) |
User-agent: |
G2/1.0 |
Thanks a lot, Pascal.
The function you provided works well for the example with the F12.
However, when I go into gud-mode and hit F9 (which is configured using
(local-set-toggling-key (kbd "<f9>") 'gud-break 'gud-remove)) it tells
me that F9 is undefined. I tried changing 'local-set-key' to 'define-
key gud-mode-map' but it did not work.
Any idea?
Thanks,
-Etay
On Sep 11, 9:44 pm, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> etay.me...@gmail.com writes:
> > Hi,
>
> > I have F8 and F9 mapped to gud-remove and gud-break (respectively) in
> > gud-mode.
> > I'd like to mimic the behaviour of Visual Studio where F9 toggles
> > between setting and removing the breakpoint. Is it possible to
> > configure emacs so that it will toggle between the two bindings every
> > time the key is pressed?
>
> (defun local-set-toggling-key (key cmd1 cmd2)
> (interactive "KSet key locally:
> CSet key %s locally to command:
> CToggling key %s locally to command: ")
> (let ((on (gensym))
> (off (gensym)))
> (setf (symbol-function on)
> `(lambda ()
> (interactive)
> (funcall ',cmd1)
> (local-set-key ',key ',off))
> (symbol-function off)
> `(lambda ()
> (interactive)
> (funcall ',cmd2)
> (local-set-key ',key ',on)))
> (local-set-key key on)))
>
> ;; To test:
> ;; (local-set-toggling-key (kbd "<f12>")
> ;; (lambda () (interactive) (insert "a"))
> ;; (lambda () (interactive) (insert "b")))
>
> (local-set-toggling-key (kbd "<f9>") 'gud-break 'gud-remove)
>
> --
> __Pascal Bourguignon__ http://www.informatimago.com/
>
> "A TRUE Klingon warrior does not comment his code!"