* Toggling the same key combination between two options
@ 2008-09-11 18:15 etay.meiri
2008-09-11 18:44 ` Pascal J. Bourguignon
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: etay.meiri @ 2008-09-11 18:15 UTC (permalink / raw)
To: help-gnu-emacs
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?
Thanks a lot,
-Etay
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Toggling the same key combination between two options
2008-09-11 18:15 Toggling the same key combination between two options etay.meiri
@ 2008-09-11 18:44 ` Pascal J. Bourguignon
2008-09-11 19:27 ` etay.meiri
2008-09-11 20:25 ` Scott Frazer
2008-09-12 14:23 ` Nick Roberts
2008-09-12 22:06 ` E.L.K.
2 siblings, 2 replies; 10+ messages in thread
From: Pascal J. Bourguignon @ 2008-09-11 18:44 UTC (permalink / raw)
To: help-gnu-emacs
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!"
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Toggling the same key combination between two options
2008-09-11 18:44 ` Pascal J. Bourguignon
@ 2008-09-11 19:27 ` etay.meiri
2008-09-11 20:25 ` Scott Frazer
1 sibling, 0 replies; 10+ messages in thread
From: etay.meiri @ 2008-09-11 19:27 UTC (permalink / raw)
To: help-gnu-emacs
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!"
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Toggling the same key combination between two options
2008-09-11 18:44 ` Pascal J. Bourguignon
2008-09-11 19:27 ` etay.meiri
@ 2008-09-11 20:25 ` Scott Frazer
1 sibling, 0 replies; 10+ messages in thread
From: Scott Frazer @ 2008-09-11 20:25 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Toggling the same key combination between two options
2008-09-11 18:15 Toggling the same key combination between two options etay.meiri
2008-09-11 18:44 ` Pascal J. Bourguignon
@ 2008-09-12 14:23 ` Nick Roberts
2008-09-12 22:06 ` E.L.K.
2 siblings, 0 replies; 10+ messages in thread
From: Nick Roberts @ 2008-09-12 14:23 UTC (permalink / raw)
To: etay.meiri; +Cc: help-gnu-emacs
> 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?
Assuming that you're using Emacs 22.1 or later you can do this by clicking on
the fringe/margin using mouse-1 (gdb-mouse-set-clear-breakpoint). If you
really want to use F9, e.g., from a console, you can adapt this function:
(define-key gud-minor-mode-map [f9] 'gdb-set-clear-breakpoint)
(defun gdb-set-clear-breakpoint ()
(interactive)
(if (or (buffer-file-name) (eq major-mode 'gdb-assembler-mode))
(if (or
(let ((start (- (line-beginning-position) 1))
(end (+ (line-end-position) 1)))
(catch 'breakpoint
(dolist (overlay (overlays-in start end))
(if (overlay-get overlay 'put-break)
(throw 'breakpoint t)))))
(eq (car (fringe-bitmaps-at-pos)) 'breakpoint))
(gud-remove nil)
(gud-break nil))))
which will set or clear the breakpoint on the line at point (the location of
the active cursor).
--
Nick http://www.inet.net.nz/~nickrob
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Toggling the same key combination between two options
2008-09-11 18:15 Toggling the same key combination between two options etay.meiri
2008-09-11 18:44 ` Pascal J. Bourguignon
2008-09-12 14:23 ` Nick Roberts
@ 2008-09-12 22:06 ` E.L.K.
2008-09-12 22:12 ` Lennart Borgman (gmail)
2008-09-12 22:51 ` Toggling the same key combination between two options Nick Roberts
2 siblings, 2 replies; 10+ messages in thread
From: E.L.K. @ 2008-09-12 22:06 UTC (permalink / raw)
To: help-gnu-emacs
> 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?
IIRC, there is function, called gdb-toggle-breakpoint, which can
be what you need.
But it will work only with gdb, I think.
--
E.L.K.
Saturday, 13 of September, 2008, 1:04
зы. C_U_L8r!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Toggling the same key combination between two options
2008-09-12 22:06 ` E.L.K.
@ 2008-09-12 22:12 ` Lennart Borgman (gmail)
2008-09-12 22:53 ` gdb-toggle-breakpoint [was Re: Toggling the same key combination between two options] Nick Roberts
2008-09-12 22:51 ` Toggling the same key combination between two options Nick Roberts
1 sibling, 1 reply; 10+ messages in thread
From: Lennart Borgman (gmail) @ 2008-09-12 22:12 UTC (permalink / raw)
To: help-gnu-emacs
E.L.K. wrote:
> IIRC, there is function, called gdb-toggle-breakpoint, which can
> be what you need.
>
> But it will work only with gdb, I think.
Sounds like an oversigt. Maybe you can report it as a bug?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Toggling the same key combination between two options
2008-09-12 22:06 ` E.L.K.
2008-09-12 22:12 ` Lennart Borgman (gmail)
@ 2008-09-12 22:51 ` Nick Roberts
1 sibling, 0 replies; 10+ messages in thread
From: Nick Roberts @ 2008-09-12 22:51 UTC (permalink / raw)
To: E.L.K.; +Cc: help-gnu-emacs
> > 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?
>
> IIRC, there is function, called gdb-toggle-breakpoint, which can
> be what you need.
This function doesn't set/clear breakoints but enables/disables them. It
also works from the breakpoints buffer, not the source buffer.
--
Nick http://www.inet.net.nz/~nickrob
^ permalink raw reply [flat|nested] 10+ messages in thread
* gdb-toggle-breakpoint [was Re: Toggling the same key combination between two options]
2008-09-12 22:12 ` Lennart Borgman (gmail)
@ 2008-09-12 22:53 ` Nick Roberts
2008-09-12 23:09 ` Lennart Borgman (gmail)
0 siblings, 1 reply; 10+ messages in thread
From: Nick Roberts @ 2008-09-12 22:53 UTC (permalink / raw)
To: Lennart Borgman (gmail); +Cc: help-gnu-emacs
Lennart Borgman (gmail) writes:
> E.L.K. wrote:
> > IIRC, there is function, called gdb-toggle-breakpoint, which can
> > be what you need.
> >
> > But it will work only with gdb, I think.
>
> Sounds like an oversigt. Maybe you can report it as a bug?
Please don't report it as a bug. It seems entirely reasonable to me
that gdb-toggle-breakpoint should only work with gdb.
--
Nick http://www.inet.net.nz/~nickrob
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: gdb-toggle-breakpoint [was Re: Toggling the same key combination between two options]
2008-09-12 22:53 ` gdb-toggle-breakpoint [was Re: Toggling the same key combination between two options] Nick Roberts
@ 2008-09-12 23:09 ` Lennart Borgman (gmail)
0 siblings, 0 replies; 10+ messages in thread
From: Lennart Borgman (gmail) @ 2008-09-12 23:09 UTC (permalink / raw)
To: Nick Roberts; +Cc: help-gnu-emacs
Nick Roberts wrote:
> Lennart Borgman (gmail) writes:
> > E.L.K. wrote:
> > > IIRC, there is function, called gdb-toggle-breakpoint, which can
> > > be what you need.
> > >
> > > But it will work only with gdb, I think.
> >
> > Sounds like an oversigt. Maybe you can report it as a bug?
>
> Please don't report it as a bug. It seems entirely reasonable to me
> that gdb-toggle-breakpoint should only work with gdb.
Eh, yes, but shouldn't there be something on a higher level too, the gud
level? Or is there already something? Perhaps it can't be written?
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2008-09-12 23:09 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-11 18:15 Toggling the same key combination between two options etay.meiri
2008-09-11 18:44 ` Pascal J. Bourguignon
2008-09-11 19:27 ` etay.meiri
2008-09-11 20:25 ` Scott Frazer
2008-09-12 14:23 ` Nick Roberts
2008-09-12 22:06 ` E.L.K.
2008-09-12 22:12 ` Lennart Borgman (gmail)
2008-09-12 22:53 ` gdb-toggle-breakpoint [was Re: Toggling the same key combination between two options] Nick Roberts
2008-09-12 23:09 ` Lennart Borgman (gmail)
2008-09-12 22:51 ` Toggling the same key combination between two options Nick Roberts
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).