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: Scott Frazer
Subject: Re: Toggling the same key combination between two options
Date: Thu, 11 Sep 2008 16:25:33 -0400
User-agent: Thunderbird 2.0.0.16 (Windows/20080708)

Pascal J. Bourguignon wrote:
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)


That is pretty cool, but I don't think it's going to do what the OP
intends.  He's going to need some context to decide whether to turn
the breakpoint on or off, i.e. if there is a breakpoint on the current
line turn it off, if there isn't then turn one on.

It should be pretty easy to write, but I am not familiar with the GUD.
I assume there is some function to tell if there is a breakpoint on
the current line or not ....

Scott


reply via email to

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