From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.devel Subject: RE: Have `define-key` return the keymap Date: Sat, 13 May 2017 07:58:04 -0700 (PDT) Message-ID: <9915c795-9efd-4cd8-aa0d-bc072eb340ee@default> References: <87d1bd7xr2.fsf@drachen> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1494687530 9072 195.159.176.226 (13 May 2017 14:58:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 13 May 2017 14:58:50 +0000 (UTC) Cc: Emacs developers To: Michael Heerdegen , Tianxiang Xiong Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 13 16:58:47 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d9YVK-0002HV-Aa for ged-emacs-devel@m.gmane.org; Sat, 13 May 2017 16:58:46 +0200 Original-Received: from localhost ([::1]:57872 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9YVP-00022G-KF for ged-emacs-devel@m.gmane.org; Sat, 13 May 2017 10:58:51 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9YUp-000229-V6 for emacs-devel@gnu.org; Sat, 13 May 2017 10:58:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d9YUn-0002ZA-0h for emacs-devel@gnu.org; Sat, 13 May 2017 10:58:16 -0400 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:42508) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d9YUm-0002YH-Mz for emacs-devel@gnu.org; Sat, 13 May 2017 10:58:12 -0400 Original-Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v4DEw8ba032543 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 13 May 2017 14:58:08 GMT Original-Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v4DEw8xg005537 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 13 May 2017 14:58:08 GMT Original-Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v4DEw6Gw017251; Sat, 13 May 2017 14:58:06 GMT In-Reply-To: <87d1bd7xr2.fsf@drachen> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6767.5000 (x86)] X-Source-IP: userv0022.oracle.com [156.151.31.74] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 141.146.126.69 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:214821 Archived-At: > > If `define-key` returned the keymap, calls to it could be chained toget= her > > in convenient ways, e.g. > > > > (thread-first (make-sparse-keymap) > > (define-key (kbd "a") #'foo) > > (define-key (kbd "b") #'bar)) >=20 > A different solution would be to define something analog to > `thread-first' that substitutes always the first value as first argument > instead of the subsequent return values (in this case, this is always > the same object). >=20 > A variant of this approach that works without such a new macro: >=20 > (defun my-keybinder (map) > (apply-partially #'define-key map)) >=20 > (let ((map (make-sparse-keymap))) > (cl-flet ((define-key (my-keybinder map))) > (define-key (kbd "a") #'foo) > (define-key (kbd "b") #'bar) > map)) I'm probably missing something, but (to me, so far) all of this has the scent of a solution looking for a problem to solve.