From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel Subject: Re: Have `define-key` return the keymap Date: Sat, 13 May 2017 14:21:53 +0200 Message-ID: <87d1bd7xr2.fsf@drachen> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1494678127 3356 195.159.176.226 (13 May 2017 12:22:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 13 May 2017 12:22:07 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: Emacs developers To: Tianxiang Xiong Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 13 14:22:03 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 1d9W3f-0000hg-8c for ged-emacs-devel@m.gmane.org; Sat, 13 May 2017 14:22:03 +0200 Original-Received: from localhost ([::1]:57497 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9W3h-0007Kz-IB for ged-emacs-devel@m.gmane.org; Sat, 13 May 2017 08:22:05 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9W3a-0007JT-UC for emacs-devel@gnu.org; Sat, 13 May 2017 08:21:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d9W3W-0001Tt-Vz for emacs-devel@gnu.org; Sat, 13 May 2017 08:21:58 -0400 Original-Received: from mout.web.de ([212.227.17.12]:59702) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d9W3W-0001Q7-Kr for emacs-devel@gnu.org; Sat, 13 May 2017 08:21:54 -0400 Original-Received: from drachen.dragon ([92.208.94.183]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0M4ZPc-1dwmkU3XEC-00yeXa; Sat, 13 May 2017 14:21:50 +0200 In-Reply-To: (Tianxiang Xiong's message of "Sat, 13 May 2017 01:19:17 -0700") X-Provags-ID: V03:K0:9g+qJw2GGvGX1iKXlRw+F0ohrMTIWCDVx4cC361IE1AR/KlrOzq ID99gaO9eqCp4TCPBgpiJG+mRTaWZBTGjVMH2nNXCcW3hsalPzu3QGVES1jRDQ8Iht3WnXv 1sh7N7JZFXu31eH3+maP0o2dqIkUJchBMOsRVsfLoeZIne1t5h89yOZvljuy8xMhiGvPfrO Wb8ceqYcZn6gLUIL7tsLw== X-UI-Out-Filterresults: notjunk:1;V01:K0:v8rZdShuvP0=:MO/HpbPiNp2D7NLrkhKBIh 57j7d6G5d2EE5qCvmQXYrXkxAheLNXAjzvGjo00AfvDcobM89qTKpympBRTFZTqmQi9o3C+bf Ja04Df9Yitzr/AYxuMUyuHY6RC4NH98n5sjtX80Goepemq0/mJY7epL6HAnWAST9i0ZUVUV6j cNH1ChBRpPcIlxEEJ7zKQ2bwR0Wt+Jsxxes/FfSz26m03u2oAMCmOleboZpUfi3k/OytpAjun qzBMhZeNCOsk8hvORsGS2RkYjb1iD7LYcxRaUOm170cfyPz9Iu+RqZ768ulspnLM/vgOma+C1 e5JQP8oikg/jRHECHEM2tIQdaHX9A2O2Qb7TBzwKZkdhGNkhpHB3T6CEeoRYuNCAb2n3hMiRp ss2wDGXGmAHNMkGDMKe8aXC06SaCuNID1p8Y41IuZ/N7JnPOA0mrMRWBcSNGlQGbOZogvKjfJ 8utGwXUO2D0f3OQrYYZ5wKQSZRHcJV7c3dVSarSVzqu2w9h8brSiYMFR10BO1iQuEwXd+J6x+ OUT0XoQFZm5JK+tsAmFvDwqy5g7SU4i5gMTp0OyhaKFXopYiT+WGFjoR/AG/f3tmSwPug037p VZTuTG7Ikg9PBnxkP1J3DD0zoO0GxLhij2aX0nyof8z90SRlWN7kdv438MwHfyJhXIO0zdpdy aMdOSIDYa+3zePH23qemDgNh0SoTDMdplBVufkAEew0D1e1dPyNSPcGmHpWfQ9xH3KSe8T/Kx e6xUaJfp/9wWayLzouC59lptJ2kzq14LWu3pecE2ZGtsNmN9oOkEVDt7NR5qZwwv2aSH8cSw X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.12 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:214815 Archived-At: Tianxiang Xiong writes: > If `define-key` returned the keymap, calls to it could be chained together in > convenient ways, e.g. > > ``` > (thread-first (make-sparse-keymap) > (define-key (kbd "a") #'foo) > (define-key (kbd "b") #'bar)) > ``` 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). A variant of this approach that works without such a new macro: #+begin_src emacs-lisp (defun my-keybinder (map) (apply-partially #'define-key map)) (let ((map (make-sparse-keymap))) (cl-flet ((define-key (my-keybinder map))) (define-key (kbd "a") #'foo) (define-key (kbd "b") #'bar) map)) #+end_src Michael.