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)