From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Scott Frazer Newsgroups: gmane.emacs.help Subject: Re: Toggling the same key combination between two options Date: Thu, 11 Sep 2008 16:25:33 -0400 Organization: Ye 'Ol Disorganized NNTPCache groupie Message-ID: <1221164733.411102@sj-nntpcache-2.cisco.com> References: <87tzcmldy2.fsf@hubble.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1221165661 25930 80.91.229.12 (11 Sep 2008 20:41:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Sep 2008 20:41:01 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Sep 11 22:41:57 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Kdsyx-0007B6-Mk for geh-help-gnu-emacs@m.gmane.org; Thu, 11 Sep 2008 22:41:39 +0200 Original-Received: from localhost ([127.0.0.1]:43661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kdsxx-0000DH-AH for geh-help-gnu-emacs@m.gmane.org; Thu, 11 Sep 2008 16:40:37 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe08.iad.POSTED!7564ea0f!not-for-mail User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) Original-Newsgroups: gnu.emacs.help In-Reply-To: <87tzcmldy2.fsf@hubble.informatimago.com> Cache-Post-Path: sj-nntpcache-2.cisco.com!unknown@scfrazer-wxp.cisco.com X-Cache: nntpcache 3.0.2 (see http://www.nntpcache.com/) Original-Lines: 49 Original-X-Complaints-To: newsadmin@cisco.com Original-NNTP-Posting-Date: Thu, 11 Sep 2008 20:25:33 UTC Original-Xref: news.stanford.edu gnu.emacs.help:162110 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:57453 Archived-At: 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 "") > ;; (lambda () (interactive) (insert "a")) > ;; (lambda () (interactive) (insert "b"))) > > > (local-set-toggling-key (kbd "") '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