From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#43709: minibuffer keybinding cheatsheet and launcher [CODE SUBMISSION] Date: Thu, 01 Oct 2020 09:51:36 -0400 Message-ID: References: <20200929165957.ibj67dnyaem6nezg@E15-2016.optimum.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4406"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 43709@debbugs.gnu.org To: Boruch Baum Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 01 15:52:17 2020 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 1kNz0K-00012k-Uv for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 01 Oct 2020 15:52:17 +0200 Original-Received: from localhost ([::1]:42688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNz0K-0005cJ-11 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 01 Oct 2020 09:52:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNz06-0005c2-5B for bug-gnu-emacs@gnu.org; Thu, 01 Oct 2020 09:52:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51671) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kNz05-0003g3-Qf for bug-gnu-emacs@gnu.org; Thu, 01 Oct 2020 09:52:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kNz05-00025T-OJ for bug-gnu-emacs@gnu.org; Thu, 01 Oct 2020 09:52:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 01 Oct 2020 13:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 43709 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 43709-submit@debbugs.gnu.org id=B43709.16015603098005 (code B ref 43709); Thu, 01 Oct 2020 13:52:01 +0000 Original-Received: (at 43709) by debbugs.gnu.org; 1 Oct 2020 13:51:49 +0000 Original-Received: from localhost ([127.0.0.1]:34984 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kNyzs-000253-NS for submit@debbugs.gnu.org; Thu, 01 Oct 2020 09:51:49 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:63523) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kNyzp-00024o-SG for 43709@debbugs.gnu.org; Thu, 01 Oct 2020 09:51:47 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id F398B1002CF; Thu, 1 Oct 2020 09:51:39 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id D6E381001D2; Thu, 1 Oct 2020 09:51:37 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1601560297; bh=wTxiU2h5F3+F+OxMS/MpKykS6uZ7doXIgPUTSfRrMkk=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=l5c7Im19L4DzvPJxwt0MJhdYy1okHW5wKMcTGOu4pjLxX652HkReOckA3QCOclFpg a01QWHKHuXtdDEjMwCt9JUThZLMTmfz/YbQZOuCPpjmrWOtecN81bpWn3vwtrQ60wF G8BAfSjgMfqFiWQQrfHdxEjuyJSK/euCE5HbkaBM4/RlT9MH6hIX9rcph+fH5wC4No 1tZHauh8OYi+MDKHXRlEA4I1Su1eLqcqYUncQsPpP56hyDCMt5z3AXZvwGJwVV2vnJ Pw4FMLHEZhJ5wCdMp6Bn96mXmHszChfnm0yaXBFQrNT7YR23NSbSqNUIrr3zKP8oRb ftApw2kX8MVzg== Original-Received: from alfajor (unknown [45.72.232.131]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A38E6120225; Thu, 1 Oct 2020 09:51:37 -0400 (EDT) In-Reply-To: <20200929165957.ibj67dnyaem6nezg@E15-2016.optimum.net> (Boruch Baum's message of "Tue, 29 Sep 2020 12:59:57 -0400") 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" Xref: news.gmane.io gmane.emacs.bugs:189520 Archived-At: > If you've ever used packages such as `ivy' or `magit', you've probably > benefited from each's custom combination keybinding cheatsheet and > launcher: `hydra' in the case of `ivy', and `transient' for `magit'. The > attached package `key-assist' attempts to offer a generic and very > simple alternative requiring only the `completing-read' function > commonly used in core vanilla emacs. `key-assist' is trivial to > implement "on-the-fly" interactively for any buffer, and > programmatically much simpler to customize that either `hydra' or > `transient'. And did I mention that it only requires `completing-read'? I'm not completely sure what is the intended use scenario. I mean, I understand the package is not 100% ready, so I'm interested to know how you imagine it working *ideally* once the various kinks have been sorted out. [ To see why I say it's not quite ready, here's my experience with it: I just tried it in a fresh new Emacs session, and after `M-x key-assist` (which itself is a problem because most users won't know/bother to run this command way, so we'd need some more "obvious" way to run it) I get a prompt for something and without reading more the description I wouldn't know what the prompt wants (I think this prompt should only appear if requested explicitly) and then it said "no choices found". So I tried again in a dired buffer, where it instead showed me a minibuffer prompt "Select: " with no indication of what it is I should be selecting, after that I hit TAB (because I read that it uses `completing-read`, but for the un-initiated it might not be obvious) at which point it did show me a list of bindings and short descriptions and when I selected the first entry (i.e. `!`) it signal'd an error about wrong number of arguments. ] I do think it would be nice to have something like it, since it's an alternative to the menus which has the advantage of being auto-constructed, doesn't need the mouse, and focuses on the keybindings. It would also be nice to make it usable from minibuffers as well ;-) See some comments below based on a quick look at the code. Stefan > ;; If you've ever used packages such as `ivy' or `magit', you've For those who haven't, it would be good to describe what your package does. > ;;; Dependencies: > > ;; `cl-seq' - For `cl-position', but `cl-lib' is long part of all > ;; modern emcasen. There's no such thing as a `cl-seq` package. There's a `cl-seq.el` file, which is part of the `cl-lib` package. > (require 'cl-seq) ;; cl-member, cl-position Please require `cl-lib` rather than `cl-seq` since which function is implemented in which file of `cl-lib` is an internal detail (e.g. in Emacs-24.1 `cl-seq` does not provide `cl-position` but `cl-lib` still does). > (defun key-assist--get-keybinding (cmd &optional key-map) > "Return a string with CMD's shortest keybinding." > (let (shortest) > (dolist (key (mapcar 'key-description > (where-is-internal > cmd key-map nil t))) > (when (or (not shortest) > (> (length shortest) (length key))) > (setq shortest key))) > shortest)) `where-is-internal` is supposed to return the shortest binding already when asked to return the "firstonly". Your notion of length is slightly different, admittedly, but I wonder what were the concrete cases that motivated doing your own sorting (might be worth adding that as a comment in the code). > (let ((not-found t)) > (mapc (lambda (x) > (when (string-match x (format "%s" cmd)) > (setq not-found nil))) > key-assist-exclude-regexps) > not-found))) You should move the `(format "%s" cmd)` out of the loop (and use `dolist` instead of `mapc`). > ((keymapp spec) > (let (cmd) > (dolist (elem spec) Please use `map-keymap` rather than `dolist` so as to handle all the different keymap formats. > (while (not (setq choice > (cl-position > (substring-no-properties ; Is -no-properties necessary? > (completing-read prompt choices nil t)) > choices :test 'equal)))) Why do you have this loop? Doesn't the `require-match` arg of `completing-read` make it unnecessary? > (funcall (car (nth choice commands)))))) This should probably be `command-execute` rather than `funcall` to fix the wrong-number-of-arguments error I bumped into.