From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: etay.meiri@gmail.com Newsgroups: gmane.emacs.help Subject: Re: Toggling the same key combination between two options Date: Thu, 11 Sep 2008 12:27:48 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <87tzcmldy2.fsf@hubble.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1221162536 13720 80.91.229.12 (11 Sep 2008 19:48:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Sep 2008 19:48:56 +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 21:49:52 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 1Kds8G-0004PE-1K for geh-help-gnu-emacs@m.gmane.org; Thu, 11 Sep 2008 21:47:12 +0200 Original-Received: from localhost ([127.0.0.1]:50404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kds7F-00046h-95 for geh-help-gnu-emacs@m.gmane.org; Thu, 11 Sep 2008 15:46:09 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!postnews.google.com!c65g2000hsa.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 58 Original-NNTP-Posting-Host: 217.132.131.2 Original-X-Trace: posting.google.com 1221161269 26785 127.0.0.1 (11 Sep 2008 19:27:49 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Thu, 11 Sep 2008 19:27:49 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c65g2000hsa.googlegroups.com; posting-host=217.132.131.2; posting-account=aYPwpgoAAABJuXxIZDkDtoDErg2phi4C User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1,gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:162105 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:57448 Archived-At: 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 "") '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=A0pm, 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) > =A0 (interactive "KSet key locally: > CSet key %s locally to command: > CToggling key %s locally to command: ") > =A0 (let ((on =A0(gensym)) > =A0 =A0 =A0 =A0 (off (gensym))) > =A0 =A0 (setf (symbol-function on) > =A0 =A0 =A0 =A0 =A0 `(lambda () > =A0 =A0 =A0 =A0 =A0 =A0 =A0(interactive) > =A0 =A0 =A0 =A0 =A0 =A0 =A0(funcall ',cmd1) > =A0 =A0 =A0 =A0 =A0 =A0 =A0(local-set-key ',key ',off)) > =A0 =A0 =A0 =A0 =A0 (symbol-function off) > =A0 =A0 =A0 =A0 =A0 `(lambda () > =A0 =A0 =A0 =A0 =A0 =A0 =A0(interactive) > =A0 =A0 =A0 =A0 =A0 =A0 =A0(funcall ',cmd2) > =A0 =A0 =A0 =A0 =A0 =A0 =A0(local-set-key ',key ',on))) > =A0 =A0 (local-set-key key on))) > > ;; To test: > ;; (local-set-toggling-key (kbd "") > ;; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (lambda () (interactiv= e) (insert "a")) > ;; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (lambda () (interactiv= e) (insert "b"))) > > (local-set-toggling-key (kbd "") 'gud-break 'gud-remove) > > -- > __Pascal Bourguignon__ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0http://www.= informatimago.com/ > > "A TRUE Klingon warrior does not comment his code!"