From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.bugs Subject: bug#18729: [PATCH] subr.el (set-key): New macro making creating new bindings more concise. Date: Mon, 27 Oct 2014 18:52:58 +0100 Organization: http://mina86.com/ Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1414432464 23521 80.91.229.3 (27 Oct 2014 17:54:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 27 Oct 2014 17:54:24 +0000 (UTC) Cc: 18729@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 27 18:54:17 2014 Return-path: Envelope-to: geb-bug-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 1XioUi-0007fV-My for geb-bug-gnu-emacs@m.gmane.org; Mon, 27 Oct 2014 18:54:16 +0100 Original-Received: from localhost ([::1]:35232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XioUi-0005nn-Bu for geb-bug-gnu-emacs@m.gmane.org; Mon, 27 Oct 2014 13:54:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XioUZ-0005ll-Ej for bug-gnu-emacs@gnu.org; Mon, 27 Oct 2014 13:54:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XioUU-0008Kj-Qe for bug-gnu-emacs@gnu.org; Mon, 27 Oct 2014 13:54:07 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44839) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XioUU-0008Kf-Mx for bug-gnu-emacs@gnu.org; Mon, 27 Oct 2014 13:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XioUU-0000Lx-6z for bug-gnu-emacs@gnu.org; Mon, 27 Oct 2014 13:54:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michal Nazarewicz Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 27 Oct 2014 17:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18729 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 18729-submit@debbugs.gnu.org id=B18729.14144323921296 (code B ref 18729); Mon, 27 Oct 2014 17:54:02 +0000 Original-Received: (at 18729) by debbugs.gnu.org; 27 Oct 2014 17:53:12 +0000 Original-Received: from localhost ([127.0.0.1]:36937 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XioTf-0000Kq-Db for submit@debbugs.gnu.org; Mon, 27 Oct 2014 13:53:11 -0400 Original-Received: from mail-lb0-f178.google.com ([209.85.217.178]:49011) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XioTd-0000Kc-IS for 18729@debbugs.gnu.org; Mon, 27 Oct 2014 13:53:10 -0400 Original-Received: by mail-lb0-f178.google.com with SMTP id f15so2611220lbj.9 for <18729@debbugs.gnu.org>; Mon, 27 Oct 2014 10:53:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:in-reply-to:organization:references :user-agent:face:date:message-id:mime-version:content-type :content-transfer-encoding; bh=rd/Itn8gazkBXdem1c6WkLjDc5pk2152W0YOKtwr5Uc=; b=BWPBlrrmXq8D/0PKsziN/0vEEO92zif1VxQr7kO0NDBq90ZtAKCTlLSnK3QdnsWh78 V365/5Zs04w3dRlxhDmy6ctyliCtoZzVAKzpzykBmrX1UHvwhbc7LOOEALETffneDjpj 6XYu67sToumEiGtZ9Fi2Y1fAoWgaVorKsY+hvN4YL8a4u/bEFrLjmRfOGz30Ro9Sdlns L6EYnjaSydLplAhiZbYfdBo/whzhcaAXKrjREhbGnnnyc7ufn0PGk7dsFhwfSM2NoEKP b3fMnTmuX/uRV9uuTPbtaRRaiN6o48cTBl2LoAow3Hnt9vHOVeCiZG0FcDqtQHOfpOLj qv/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:in-reply-to :organization:references:user-agent:face:date:message-id :mime-version:content-type:content-transfer-encoding; bh=rd/Itn8gazkBXdem1c6WkLjDc5pk2152W0YOKtwr5Uc=; b=CP/TVZJGsYl8ES7h8cc6WtSX/EOoG9eu3B55q9QkXbAlfVBvo2u4eij4XkZSzJYS0I y2MC/pKYFKMNyKcXSbL5cbGhL0gevwxNFy665LVh9xXoQaWzPDQL55Z/R6+B0HM1+lOs VDI9ig4e6iI2a7uiCQ4cbO/9cINCg4QumHoZK8AvP/EcSgF0M+vdgXAjjXxmq6ck9ZwP brFAUYiICpWgvd9O+6m0u2hk+uS/EY8Aq9TIbgf43qsDUbkQCpPSWjUQ7tN45ZElxoWK iusO8ZaXS0t4jkNXcJQjR2RMrWgbl2tZkONfUI1VDMe43hNSpFWQar5QahxjK1DnYAoH NFrA== X-Gm-Message-State: ALoCoQmAgCczcW+b6QxmULsUbluETAtm2UIY33y+3jFXFtHiXA7DfhqNyKiHYpoA6Pu3Rj5t/5/c X-Received: by 10.112.54.229 with SMTP id m5mr544871lbp.11.1414432383123; Mon, 27 Oct 2014 10:53:03 -0700 (PDT) Original-Received: from mpn-glaptop.roam.corp.google.com ([2620:0:105f:311:c591:ee2f:2bfd:d982]) by mx.google.com with ESMTPSA id pr7sm5211784lbc.18.2014.10.27.10.53.00 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 27 Oct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jHwkKTFHDWfPniR 4iw5vJaw2nzSjfq2zffcE/GDjRC2dn0J0XwPAbDL84TvaFCJEU4Oml9pRyEUhR3Cl2t01AoEjRbs0sYugp14/4X5n4pU4EHHnMAAAAAElFTkSuQmCC X-PGP: 50751FF4 X-PGP-FP: AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 X-Hashcash: 1:20:141027:18729@debbugs.gnu.org::5Lz+AR/zG6C3YYoM:00000000000000000000000000000000000000000w5r X-Hashcash: 1:20:141027:monnier@iro.umontreal.ca::C7VpggVjfZlnycPT:0000000000000000000000000000000000000ERhJ X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:95167 On Thu, Oct 16 2014, Stefan Monnier wrote: >> (I would still argue :args syntax is also convenient though). > > The :args syntax has the problem that it can only be explained/defined > by explaining how args work for functions and how `interactive' works, > so from a conceptual point of view (say, explaining to someone who doesn't > know Elisp yet) it's not really simpler than the full (lambda > ...) form. IOW the only gain is a few characters. Admittedly, that was my main reason for set-key. ;) >>> (define-key MAP KEY '(dired "foo")) > [...] >> Thing I'm worried about here is that the function will not get >> byte-compiled, whereas with set-key macro it will. Also, I'm not >> entirely sure whether the function should use lexical-binding. > > Indeed, that's incompatible with lexical-binding. > As you know, I find this to be a *major* downer. But the only > alternative would be to define a new macro (like you've done), which > implies a larger change, and added complexity: since we're not > going to deprecate define-key, it means we'd simply have yet another > slightly different way to define key bindings. I already dislike > global-set-key and local-set-key, FWIW. > > I think if we want to make it easier for users to customize > key-bindings, we should take a step back and look at the > larger picture, trying to see exactly what it is that's hard. The problem I was solving was that I'm too lazy to type =E2=80=9Clambda=E2= =80=9D or =E2=80=9Cinteractive=E2=80=9D. ;) Similarly to set-key I also have a add-la= mbda-hook macro, e.g.: (add-lambda-hook 'kill-emacs-hook (auto-byte-compile-file t)) So for me it would make sense to have a more concise way of writing lambda functions. Perhaps for example: ------------- >8 ------------------------------------------------------- (defun lambda-builder (body &optional interactive) (let (args) (let ((split (memq '-> body))) (when split (while (not (eq body split)) (push (car body) args) (setq body (cdr body))) (when (and interactive (not (symbolp (car args)))) (setq interactive (list 'interactive (car args)) args (cdr args))) (setq body (cdr body) args (nreverse args)))) (cons 'lambda (cons args (if interactive (cons interactive body) body))= ))) (defmacro =CE=BB (&rest body) (lambda-builder body)) (defmacro =CE=9B (&rest body) (lambda-builder body '(interactive))) (=CE=BB x y -> (+ x y)) =3D> (lambda (x y) (+ x y)) (=CE=9B (dired "foo")) =3D> (lambda nil (interactive) (dired "foo")) (=CE=9B x "p" -> (dired "foo")) =3D> (lambda (x) (interactive "p") (insert (number-to-string x))) ------------- >8 ------------------------------------------------------- Admittedly though, typing Greek lambda is not easy on non-Greek layouts, but my first choice of (\x y -> (+ x y)) or even (\ x y -> (+ x y)) won't work without possibly backwards incompatible changes to the parser. If anon thinks this makes sense, some other symbol could be chosen as well. > Maybe then we'll get a need for something that's substantially different > from define-key (and in which your ideas can then easily be integrated). > > I'm thinking of things like tweaking key-bindings via Customize, and/or > being able to specify keybindings for specific major modes (without > needing to go through add-hook or eval-after-load), ... If we are willing to assume that `foo-map' is defined when `foo-hook' runs, this should be easily done. For `foo-map' variables where this is not the case `put' could be used. Something like: (defun set-key-in-hook (map key command) (if (or (not (symbolp map)) (boundp map)) (define-key map key command) (let ((hook (or (get map 'define-key-hook) (let ((name (symbol-name map))) (when (string-match "^\\(..*\\)\\(?:-map\\)$" name) (intern (concat (match-string 1 name) "-hook"))))))) (if hook (add-hook hook (lambda () (define-key map key command))) (error "Unable to find hook for %s" map))))) --=20 Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=3D./ `o ..o | Computer Science, Micha=C5=82 =E2=80=9Cmina86=E2=80=9D Nazarewicz = (o o) ooo +------ooO--(_)--Ooo--