From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: How to bind the same function to different keys with different behaviours? Date: Wed, 13 Jan 2016 13:53:34 +0100 Message-ID: <20160113125334.GA21873@tuxteam.de> References: <427779ff-2eaf-46e0-b23f-f385f7b4c0e6@googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; x-action=pgp-signed X-Trace: ger.gmane.org 1452691718 25589 80.91.229.3 (13 Jan 2016 13:28:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 13 Jan 2016 13:28:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jan 13 14:28:38 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aJLTW-0000zE-71 for geh-help-gnu-emacs@m.gmane.org; Wed, 13 Jan 2016 14:28:34 +0100 Original-Received: from localhost ([::1]:37068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJLTU-0003Gk-Ud for geh-help-gnu-emacs@m.gmane.org; Wed, 13 Jan 2016 08:28:32 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJLTJ-0003Ga-KA for help-gnu-emacs@gnu.org; Wed, 13 Jan 2016 08:28:22 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJLTG-0008CE-DP for help-gnu-emacs@gnu.org; Wed, 13 Jan 2016 08:28:21 -0500 Original-Received: from mail.tuxteam.de ([5.199.139.25]:41187 helo=tomasium.tuxteam.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJLTG-0008A8-7U for help-gnu-emacs@gnu.org; Wed, 13 Jan 2016 08:28:18 -0500 Original-Received: from tomas by tomasium.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1aJKve-0005kg-AD for help-gnu-emacs@gnu.org; Wed, 13 Jan 2016 13:53:34 +0100 In-Reply-To: <427779ff-2eaf-46e0-b23f-f385f7b4c0e6@googlegroups.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 5.199.139.25 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:108709 Archived-At: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wed, Jan 13, 2016 at 04:55:40AM -0800, sokobania.01@gmail.com wrote: > In the basic modemap, the ascii keys are bound to `self-insert-command'. > As it is not an emacs-lisp function, I cannot "copy" its code. > > I want to bind the keys [A-Z] to `my-self-insert-command' with something like: > (for key from ?A to ?Z do > (bind-key my-mode-map key 'my-self-insert-command)) > > This function kind of inserts the current key pressed under some conditions. > > So far, I don't know how to get acces to the current key pressed from within `my-self-insert-command'. > > Is this possible? > > > If it is not possible, I'll do something like: > > (for key from ?A to ?Z do > (bind-key my-mode-map key (lambda () (my-self-insert-command key)))) self-insert-command can do it -- so can you, then :-) To find out (it helps to have the Emacs sources around, you do `C-h f' self-insert-command, and Emacs tells you: "self-insert-command is an interactive built-in function in `C source code'. It is bound to many ordinary text characters. [...]" The `C source code' above is a link, and if you have the Emacs sources around, it'll take you to the relevant C function. There you see that it references some variable `last_command_event'. Lo and behold, Elisp has a corresponding variable `last-command-event' where you can look up what triggered you `my-self-insert-command' Hope this gives you a pointer to play with. Regards - -- t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlaWSM4ACgkQBcgs9XrR2kYE9ACfXJjyH/ywu6THAYaXF660c7fd +2AAmgMHhyXb5LuE9hgGGMOlbiUS2XwO =X/1y -----END PGP SIGNATURE-----