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

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

Re: Toggling the same key combination between two options


From: Pascal J. Bourguignon
Subject: Re: Toggling the same key combination between two options
Date: Thu, 11 Sep 2008 20:44:53 +0200
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.2 (gnu/linux)

etay.meiri@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!"


reply via email to

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