Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!orion.oac.uci.edu!ucivax!megatek!hollen From: hollen@megatek (Dion Hollenbeck) Newsgroups: comp.emacs Subject: Re: toggling key definitions Message-ID: Date: 29 Nov 90 15:32:52 GMT References: <9322@ncar.ucar.edu> Sender: news@megatek.UUCP Organization: Megatek Corporation, San Diego, California Lines: 44 In-reply-to: southern@neit.cgd.ucar.edu's message of 28 Nov 90 19:32:39 GMT In article <9322@ncar.ucar.edu> southern@neit.cgd.ucar.edu writes: > > I would like to use only one key to toggle between the start-kbd-macro > and end-kbd-macro commands such that: > if I currently am not defining a keyboard macro, 7 maps to start-kbd-macro > if I currently am defining a keyboard macro, 7 maps to end-kbd-macro. > Someone suggested a way to do this which required that inside the function which is REALLY bound to the key, test the state of something and then call the appropriate function. Like this: (defun toggle-kbd-macro () "Start or end a keyboard macro." (if defining-kbd-macro (end-kbd-macro) (start-kbd-macro))) This is fine when one has some sort of variable to test, but may be difficult to implement in some cases. I propose a more generic method which will work in all cases regardless of whether variables are present to be tested. It also does not require such variables to be created if not used for any other purposes. The mere act of calling a function indicates the state and from there, that function knows the next state which should be set up. (define-key function-keymap "7" 'my-start-kbd-macro) ; "7" (defun my-start-kbd-macro () "Start keyboard macro and change key state." (define-key function-keymap "7" 'my-end-kbd-macro) ; "7" (start-kbd-macro)) (defun my-end-kbd-macro () "Start keyboard macro and change key state." (define-key function-keymap "7" 'my-start-kbd-macro) ; "7" (end-kbd-macro)) This is used in edt.el to handle the ADVANCE/BACKUP keys. You can look at the code there for more explicit examples if you need. -- Dion Hollenbeck (619) 455-5590 x2814 Megatek Corporation, 9645 Scranton Road, San Diego, CA 92121 uunet!megatek!hollen or hollen@megatek.uucp