From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#72460: [patch] add commands for setting keyboard translations interactively Date: Mon, 19 Aug 2024 10:42:43 -0400 Message-ID: References: Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22235"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 72460@debbugs.gnu.org To: hugo@heagren.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 19 16:43:33 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sg3bZ-0005d1-0V for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 19 Aug 2024 16:43:33 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sg3bO-0000S3-IO; Mon, 19 Aug 2024 10:43:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sg3bM-0000QD-Mx for bug-gnu-emacs@gnu.org; Mon, 19 Aug 2024 10:43:20 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sg3bM-0004HB-Cr for bug-gnu-emacs@gnu.org; Mon, 19 Aug 2024 10:43:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=56Lgc553y7T+17eVSWeoHNOUs1HGLs3/CvX+ZnJansE=; b=Kv1uOERcvrtgIrvdrOner0ZE0G1btQgYDxR9d/3bN21SMVq6Q/wm4W+wZQhjYybQmUVhtllxeAbDg0l2WkcBE++c4La/h2CdMxQ3w5EFa27aJeReviNR/d4FSXrggnNelfNWpuEbzMvmzv7WYSNAZKV+SRmlLvsIOyavyXbSTbYGoxB+DUPX0xvNm9YWTXnz7R+yNAZeVbgNHEvyVjFnrsxvP1uylnoyIUuWLTK55ueZf/5OjtDRxGFScZhIBuN9qhXQLB8J+b2DZ1LWcZOKE2T6C37VTB1scTOi7n6w4nkJE3h06IhhDXKv0mYibUXfjKxCto1tzcASg4HFkSvK8A==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sg3c1-0006Sq-Vn for bug-gnu-emacs@gnu.org; Mon, 19 Aug 2024 10:44:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 19 Aug 2024 14:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72460 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 72460-submit@debbugs.gnu.org id=B72460.172407862024812 (code B ref 72460); Mon, 19 Aug 2024 14:44:01 +0000 Original-Received: (at 72460) by debbugs.gnu.org; 19 Aug 2024 14:43:40 +0000 Original-Received: from localhost ([127.0.0.1]:58915 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sg3bg-0006S8-5t for submit@debbugs.gnu.org; Mon, 19 Aug 2024 10:43:40 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:61090) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sg3be-0006Rm-94 for 72460@debbugs.gnu.org; Mon, 19 Aug 2024 10:43:39 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 9C589441BF6; Mon, 19 Aug 2024 10:42:49 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1724078568; bh=aNHRY/kGONHXEeSTX5zgkXd/wvthXqWW7jG33EnjuOQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=geOKPsoupJFe3Yi3RcaER5GFnBSbZVcgRcTcqSgxpab1QIBayF9CMB8h8NWq2jlSC D/Nq2yt7Hn80x9wlY6Oi6mK4P9aNKYVBNv8lBXKONbGj/6KYTXC+N3xnTuh9f9DPho 7RrPqy+hgjD2gKXMSZtJIgeYc/I+xFYIkqH4yrOxs5r5WdV1uRepZ7bg37GLWOGspr +pvINltQZ35nJ0kuaowDWF3UsVw22Ie0C4ln4ZuVv8PI87A7lA1Sig3Llh2VBocqkd nvCtxlULx/qyZ5fKrPtt7RKQbU8h3qSyjjuFeby98KIOtx1uCQCP665nWbT8DIEdIF OajeCeiIK3t6Q== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 0150B441B16; Mon, 19 Aug 2024 10:42:48 -0400 (EDT) Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id E5E0612045A; Mon, 19 Aug 2024 10:42:47 -0400 (EDT) In-Reply-To: (hugo@heagren.com's message of "Sun, 04 Aug 2024 13:16:29 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:290395 Archived-At: > I find this sort of thing useful for cases where I want to use > something other than space as a word separator (e.g. when typing lots > of function names), or when for a long period I want to use the symbol > which is usually on the shift of a key (i.e. I know I want to type "+" > a lot, but not "="). Interesting. I can see that `keyboard-translate-table` is indeed a cheap way to implement it. [ This said, it applies at a very low level (directly inside `read-event`) and only to "characters" (e.g. not to the `tab` or `return` keys), which can make it both maybe too powerful and yet not flexible enough. ] > + (interactive `(,(key-description `[,(read-char "From: ")]) > + ,(key-description `[,(read-char "To: ")]))) [ Personally, I'd add a comment lamenting the fact that `keymap-*` functions force us to use `key-description` here only for that to be undone by `key-parse`. ] > +(defcustom key-translate-selection-function #'key-select-translation Do we need this? > +pair in `keyboard-translate-table', and return a vector containing only > +the FROM key of the selected pair (e.g. if the selected pair translates > +\"=\" to \"+\", the function should return the vector [61])" Why not return just the char rather than a vector containing the char? > +(defun key-translate-remove (from) > + "Remove translation of FROM from `keyboard-translate-table'. > + > +FROM must satisfy `key-valid-p'. If FROM has no entry in > +`keyboard-translate-table', this has no effect." > + (interactive (list (key-description > + (funcall key-translate-selection-function)))) > + (set-char-table-range > + keyboard-translate-table (aref (key-parse from) 0) nil)) If FROM maps to a sequence of length != 1, we'll either signal an ugly error or silently ignore the rest. Any reason why you didn't make FROM be a simple character? Stefan