From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: sokobania.01@gmail.com Newsgroups: gmane.emacs.help Subject: Re: How to bind the same function to different keys with different behaviours? Date: Wed, 13 Jan 2016 06:01:09 -0800 (PST) Message-ID: References: <427779ff-2eaf-46e0-b23f-f385f7b4c0e6@googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1452693930 30557 80.91.229.3 (13 Jan 2016 14:05:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 13 Jan 2016 14:05:30 +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 15:05:24 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 1aJM36-0004tz-N2 for geh-help-gnu-emacs@m.gmane.org; Wed, 13 Jan 2016 15:05:20 +0100 Original-Received: from localhost ([::1]:37325 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJM36-0003gX-1o for geh-help-gnu-emacs@m.gmane.org; Wed, 13 Jan 2016 09:05:20 -0500 X-Received: by 10.129.110.7 with SMTP id j7mr115942935ywc.26.1452693669464; Wed, 13 Jan 2016 06:01:09 -0800 (PST) X-Received: by 10.50.124.1 with SMTP id me1mr593275igb.2.1452693669434; Wed, 13 Jan 2016 06:01:09 -0800 (PST) Original-Path: usenet.stanford.edu!94no4896280qgt.1!news-out.google.com!kr2ni3846igb.0!nntp.google.com!h5no3884103igh.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=83.155.135.167; posting-account=6AmU8QoAAABkSb2sbJisGlnlR_egh2hP Original-NNTP-Posting-Host: 83.155.135.167 User-Agent: G2/1.0 Injection-Date: Wed, 13 Jan 2016 14:01:09 +0000 Original-Xref: usenet.stanford.edu gnu.emacs.help:216420 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:108710 Archived-At: Le mercredi 13 janvier 2016 14:28:27 UTC+1, to...@tuxteam.de a =E9crit=A0: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 >=20 > On Wed, Jan 13, 2016 at 04:55:40AM -0800, I 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. > >=20 > > I want to bind the keys [A-Z] to `my-self-insert-command' with somethin= g like: > > (for key from ?A to ?Z do > > (bind-key my-mode-map key 'my-self-insert-command)) > >=20 > > This function kind of inserts the current key pressed under some condit= ions. > >=20 > > So far, I don't know how to get acces to the current key pressed from w= ithin `my-self-insert-command'. > >=20 > > Is this possible? > >=20 > >=20 > > If it is not possible, I'll do something like: > >=20 > > (for key from ?A to ?Z do > > (bind-key my-mode-map key (lambda () (my-self-insert-command key)))) >=20 > self-insert-command can do it -- so can you, then :-) >=20 > To find out (it helps to have the Emacs sources around, you do `C-h f' > self-insert-command, and Emacs tells you: >=20 > "self-insert-command is an interactive built-in function in `C source > code'. >=20 > It is bound to many ordinary text characters. > [...]" >=20 > 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'. >=20 > Lo and behold, Elisp has a corresponding variable `last-command-event' > where you can look up what triggered you `my-self-insert-command' Exactly what I was looking for! As I rarely download emacs sources, I would not have found it! Thanks a lot!