From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: repeatable keys, prefix keys [was: Emacs keybindings according to file type] Date: Wed, 23 Sep 2020 10:04:03 -0700 (PDT) Message-ID: <680e46d5-de32-4776-a258-201aa6fe9e2c@default> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37467"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs To: Christopher Dimech , Yuri Khan Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 23 19:04:54 2020 Return-path: Envelope-to: geh-help-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 1kL8CM-0009fr-7u for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 23 Sep 2020 19:04:54 +0200 Original-Received: from localhost ([::1]:39294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kL8CL-0000JV-7S for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 23 Sep 2020 13:04:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35040) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kL8Bj-0000JC-AR for help-gnu-emacs@gnu.org; Wed, 23 Sep 2020 13:04:15 -0400 Original-Received: from userp2120.oracle.com ([156.151.31.85]:51116) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kL8Bf-0006nF-Uw for help-gnu-emacs@gnu.org; Wed, 23 Sep 2020 13:04:14 -0400 Original-Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08NGiiIW064330; Wed, 23 Sep 2020 17:04:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : cc : subject : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=NiaxR58KL7Ttv9uEeKmOIEMKl7DSyTH+KV9t364cVI0=; b=TbeTDPRjZP0gsSjUTlg3rqTTjgceJxxZG0nmpnD9pQO4tHSFR4MVodBseAdhuF8DzkBH ufk4LlpxERytF1RcIS3mbLfbZssADJHT8bGTf3CKsYqt3Ho/3ecAK9a2aQnXvMQfCLjy i6RNaMQ+znWaENugm1k8ZAWNnhS9RMPLWHfiNNc6l9vGMqKp4tJMF8YyYNlflLRBuvzT 4uDOXUNd/PDnR4c9nKORajxB40KsE5xQi9nxhwLajK8fGG4FQIKI7YF7ALiwBbtMxIXI +mEfs9DIhjuje3Cb3csQCIHAF5A1t0BoutqK05VaWGsIB6uC84jQO2oHA/8SySekKl6F UA== Original-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 33ndnuksjx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 23 Sep 2020 17:04:07 +0000 Original-Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08NH0g2f059085; Wed, 23 Sep 2020 17:04:06 GMT Original-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 33nuruydjr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Sep 2020 17:04:06 +0000 Original-Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 08NH45HF009385; Wed, 23 Sep 2020 17:04:05 GMT X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.5056.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9753 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009230131 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9753 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 phishscore=0 adultscore=0 suspectscore=0 bulkscore=0 clxscore=1011 impostorscore=0 mlxlogscore=999 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009230130 Received-SPF: pass client-ip=156.151.31.85; envelope-from=drew.adams@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/23 13:04:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -55 X-Spam_score: -5.6 X-Spam_bar: ----- X-Spam_report: (-5.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.228, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:124160 Archived-At: > For instance one can make it to continue pressing > C-t l f f f to continue moving line downward. >=20 > Any sample code to try out? Sure: (defun repeat-command (command) "Repeat COMMAND." (require 'repeat) ; Define its vars before we let-bind them. (let ((repeat-previous-repeated-command command) (repeat-message-function #'ignore) (last-repeatable-command 'repeat)) (repeat nil))) You can use it with nearly any COMMAND. E.g., to make a repeatable version of command `other-window': =20 (defun other-window-repeat () "Same as `other-window', but repeatable even on a prefix key. E.g., if bound to `C-x o' then you can use `C-x o o o...' to repeat." (interactive) (repeat-command 'other-window)) (global-set-key [remap other-window] 'other-window-repeat) ____ I do this all over the place, where it makes sense. Keyboard keys are scarce. When Emacs decides to bind a key by default - a key that wasn't bound by default before, I often raise these two points: 1. Save naturally repeatable keys for, well, commands that can be repeated, i.e., commands for which it makes sense to be able to just hold down a key to repeat them. 2. Save some keys for prefix keys, as opposed to just sacrificing them for a single command. A prefix key essentially gives you a whole keyboard of possibilities for a single key. Think of all the mileage we get out of the prefix key `C-x'! Of course, adding a prefix key makes a key sequence longer, more complex. Tradeoff. I tend to define lots of keys for features I write, and put them, by groups, on their own keymaps, and then put those keymaps on prefix keys. Even if such a prefix key appears complicated or slow, the fact of using a separate keymap means that a user can easily put it on a different, shorter keymap, or remap it to a more global keymap. E.g., in Bookmark+ there are all of these keymaps on prefix keys by default: bookmark-map C-x x bmkp-annotate-map C-x x a bmkp-set-map C-x x c ("create") bmkp-tags-map C-x x t bmkp-jump-map C-x j bmkp-jump-other-window-map C-x 4 j And it goes on from there. `C-x j t' is a prefix key for jumping to bookmarks with particular tags. `C-x j t *' and `C-x j t +' are prefix keys for jumping to bookmarks with all (*), or some (+), of a given set of tags. `C-x j t % *' and `C-x j t % +' are prefix keys for jumping to bookmarks with tags, all, or some, of which match a given regexp. `%' for regexp, `*' for all (Boolean multiplication), `+' for some (Boolean addition). And so on. These bindings are mnemonic, but more importantly, they're grouped so you can easily move a group to a different prefix key or a global keymap instead. Without using prefix keys, there's no way I could provide key bindings for so many commands, let alone do so in an organized way (discoverable, mnemonic). ____ Now imagine that keys aren't reserved by Emacs this way - repeatable keys for repeatable commands, and some keys available to be used as prefix keys. Imagine if Emacs just predefined `C-x' for a single command (e.g. `cut'). Zillions of keys bound to keymaps under `C-x' would be sacrificed. At the very least, when a new key is decided to be sacrificed by default (vanilla Emacs), it had better be bound to a repeatable command, not one (such as `cut') that it makes no sense to repeat. And even a repeatable key is a sacrifice - consider if `C-x' were bound to, say, `forward-word'. Repeatable, yes, but think of all the bindings now under `C-x' that would be sacrificed. Keyboard keys are precious - scarce. Too many have already been sacrificed to default bindings, I think. Sure, any user or library can redefine any keys. But once blessed as a default vanilla-Emacs key binding, a key is, for practical purposes, kinda off limits for a library. For example, for years I had `bookmark-map' on prefix `C-x p'. I had to change that recently to `C-x x' because Emacs decided to co-opt `C-x p' (& `C-x 4 p') for keys for library `project.el'. (Luckily `C-x x' was still available.) And for years I've had `Do Re Mi' commands on prefix key `C-x t'. I'll now have to change that to some other prefix key, as Emacs has decided to co-opt that prefix for `tab-bar-mode' keys. That's fine. At least Emacs is doing the right thing by using prefix keys (and not top-level keys, which are typically repeatable, but keys under `C-x'). The point is that (1) it's easy to move a keymap from one prefix key to another, and (2) there need to be some prefix keys available to move maps to. Eventually, I imagine that some simple, repeatable keys that have been assigned default Emacs bindings for commands that aren't repeatable, or that aren't super useful, or that don't really need a single-key binding, will be recycled and put to better use: for repeatable commands, as prefix keys, or just unbound by default and left available for libraries. No, I don't have particular suggestions, and no, it's not urgent. But consider `M-!', for example. Sure, `!' is mnemonic for shell. But `M-!' is repeatable (just hold it down), and it makes no sense to repeat `shell-command'. There are other default key bindings like this - essentially wasted. Some commands bound to repeatable keys should be replaced by repeatable versions. I do that for `C-a' and `C-e', for example, so they're similar to `C-n' and `C-p' (repeatable). That kind of change is minimal - it's the least we can do to make things a little saner. And `repeat-command' lets you do this kind of thing easily. Take a look at `C-h b', and see which repeatable keys are bound to non-repeatable commands. Not too many, but there are some. Even `C-w' is "wasted" on a non-repeatable command. Am I suggesting `C-w' should not be bound by default to `kill-region'? Not really. That's not urgent, at least. But hey, keys are limited - the keyboard's a small planet. ;-) And `beginning-of-buffer'. That non-repeatable command's bound by default to two repeatable keys, `M-<' and `C-home'. Both mnemonic (good). But...