GNU bug report logs - #68929
[PATCH] Copy which-key from GNU ELPA into core

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Jeremy Bryant <jb@HIDDEN>; Keywords: patch; Done: Eli Zaretskii <eliz@HIDDEN>; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 15 Apr 2024 11:14:19 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 15 07:14:18 2024
Received: from localhost ([127.0.0.1]:36955 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rwKHq-0000TV-Qp
	for submit <at> debbugs.gnu.org; Mon, 15 Apr 2024 07:14:18 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:55606)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1rwKHf-0000Rg-S7
 for 68929 <at> debbugs.gnu.org; Mon, 15 Apr 2024 07:14:07 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1rwKHN-000851-Hp; Mon, 15 Apr 2024 07:13:41 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=eGNhZ6XmxVdtXbE8OuGaTfFsfazFCh0IE+Ya6h/ANpU=; b=Bglkf16wLv4U
 QVbc6lFrlRaqOxrMp373xYWjey6hhf04U+6ss6OQYawFsnSSvbXIXZg7aEAebaWvYTs324/IF3Aqh
 oYUxD2ybCwDHxh+XkQh1dV16b0QlpePK7XJhU7jxRh66IWdiEGS1tIElkBcZhZ5NDAYJLq/YoJ0lG
 gG+wP+xNnnHHXTVemyIpM1LUE/6QxStq2Bb/Q2AAy7pjG3658pzOzBbdomACqzAWHPQfllHqGoyY3
 cLZyu5m7uwtNzJuFq+dFn511/A4kzAGjLWf/YVfjjSwCYpDM14gCIT99tq4F5CWQ5G88AiM8LDl04
 h226gIUD1phWhNLSZrs0CA==;
Date: Mon, 15 Apr 2024 14:13:30 +0300
Message-Id: <86ttk2lvz9.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
In-Reply-To: <87plurzk6v.fsf@HIDDEN> (message from Jeremy Bryant on
 Sun, 14 Apr 2024 22:52:08 +0100)
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
References: <871q9rvqbi.fsf@HIDDEN> <87mssc65y8.fsf@HIDDEN>
 <87y1bwrll4.fsf@HIDDEN> <86h6ijxzjk.fsf@HIDDEN>
 <87msrh4kkc.fsf@HIDDEN> <87jzml3rlz.fsf@HIDDEN>
 <87wmp2ibjj.fsf@HIDDEN> <871q78i9kb.fsf@HIDDEN>
 <86y19gmevj.fsf@HIDDEN> <87plurzk6v.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68929
Cc: philipk@HIDDEN, 68929 <at> debbugs.gnu.org, monnier@HIDDEN,
 justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Jeremy Bryant <jb@HIDDEN>
> Cc: philipk@HIDDEN,  68929 <at> debbugs.gnu.org,  monnier@HIDDEN,
>   justin@HIDDEN
> Date: Sun, 14 Apr 2024 22:52:08 +0100
> 
> > Is line length the only issue you are looking at?  What about other
> > requirements of our logs and ChangeLog files, including those imposed
> > by authors.el?  The most problematic issue is when the file names
> > and/or its leading directories in the log message don't fit the actual
> > place and name of the file in the tree.  Did you look at those issues?
> > They typically come up when preparing a release tarball, and are quite
> > annoying at that time, especially if there are a lot of them, because
> > they require manual fixes.
> 
> Yes, sorry, I have only looked at the line length because it came up as
> a blocker.
> 
> As far as the file names, this appears stable, but the place in the tree
> would move as part of this proposed integration, to be in
> lisp/which-key.el rather than at the root as is the case for the ELPA
> version.  Is this a problem and how was it resolved with other moves
> from ELPA to core?

Sorry, I don't remember the details.  I probably fixed some issues by
hand, and for some others added/modified the relevant data structures
in admin/authors.el, which see.

> Upon inspection, the earlier historical commits do not generally conform to the
> Changelog format.
> How to investigate any issues for authors.el?  Is there a function try
> and run?

The function is "M-x authors", defined in admin/authors.el.  It first
updates ChangeLog.4, and then attempts the regenerate AUTHORS; you
will need to "git reset" to return to the current versions once you
are finished.  The following extract from admin/make-tarball.txt gives
some guidance, and more information is available in comments to
authors.el:

    After "M-x authors" finishes, if there is an "*Authors Errors*"
    buffer, address the issues.  If there was a ChangeLog typo, fix
    the relevant entry.  If a file was deleted or renamed, consider
    adding an appropriate entry to variables authors-ignored-files,
    authors-valid-file-names, or authors-renamed-files-alist in
    authors.el.  If some authors are "ignored", consider adding
    entries to the author-aliases variable.

    If necessary, repeat 'C-u M-x authors' after making those changes.

If you see too many problems than you can handle, feel free to give up
on them and leave them until the first pretest.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 15 Apr 2024 08:39:55 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 15 04:39:55 2024
Received: from localhost ([127.0.0.1]:36649 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rwHsY-0000K1-Nn
	for submit <at> debbugs.gnu.org; Mon, 15 Apr 2024 04:39:55 -0400
Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]:60626)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <mattias.engdegard@HIDDEN>) id 1rwHsW-0000Im-TZ
 for 68929 <at> debbugs.gnu.org; Mon, 15 Apr 2024 04:39:53 -0400
Received: by mail-lf1-x12b.google.com with SMTP id
 2adb3069b0e04-516d727074eso3744593e87.0
 for <68929 <at> debbugs.gnu.org>; Mon, 15 Apr 2024 01:39:41 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1713170375; x=1713775175; darn=debbugs.gnu.org;
 h=to:references:message-id:content-transfer-encoding:cc:date
 :in-reply-to:from:subject:mime-version:sender:from:to:cc:subject
 :date:message-id:reply-to;
 bh=ibUWb8V8nLDAM/21Xnq9q4/OLVm5aPU80N7r/Fh/J4E=;
 b=JDVtFet6nTCvqAbTxngr+3DkMVawVBp/YDjZWlzZHo16J+5h49I+WsvTXyEzcDmuPK
 LNeRqCuwyt0FZZFZGoRcGvtF8Quj7Js4dr5UHIyz9CDiZQ9mjjgyyrEIZd6cpxDH/5If
 j3K0cx3DHO68pTrwsF0oWirPifZZZ57zjAlnnt5E8PEmuX6cHyEsCG+wq00SdFQIA4el
 98w8IqPvhNAEfurQXptsTbHprBay070NBCZrpMYDpTBosNiwfMC6ojtlmWG2p586U7wz
 tHPGps2UhXT6yBVmW93FovUNhmaieOITiaLaPe8ach3O8IevjBAp3UxdOl8bfzNr7dd8
 EMCg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1713170375; x=1713775175;
 h=to:references:message-id:content-transfer-encoding:cc:date
 :in-reply-to:from:subject:mime-version:sender:x-gm-message-state
 :from:to:cc:subject:date:message-id:reply-to;
 bh=ibUWb8V8nLDAM/21Xnq9q4/OLVm5aPU80N7r/Fh/J4E=;
 b=cd7nSky5WK+ZS5YsM8rmFkRef5aelIL09GU4Osh8B/gRoF1rdkXKAyeTcCZIft3B2f
 sR2oSHeUHCUxDf+0xRVHtQN2JOdPh62Ul0xKXyHBtnHiw2jxeB3BPrUz7SyTLXvz7BUe
 fSoU0Mdug8UJbbeuJY1xJTqrQWPolBp3dUgiDMssCMcCFfHeSSbdio7ZqfdM63EcdI6r
 IbmHcZsCpZr4oeG/U8td+OjMIuiKTX/+EsxsDvztJCVyecl4UVWDsAe67c9PCi0slPAW
 mrxMTwfruwvfE4wmLFFIeIYqiWzZAwB7kVHb+yYjjov7JDC18QDadRSwGGn9czPx9ePo
 7rLg==
X-Gm-Message-State: AOJu0Yw4pZkjsfAbn7NXoMSHZlPLtTJpnFD3GqGB5+DS4H5V68/rlcmX
 Dcu+6X7g9BPW4n7uE2Zs2n1b2OJjNtZcx4nG7eA+klO2J0XL9Pp/OJS35w==
X-Google-Smtp-Source: AGHT+IERg3F+VGefswzLX8BhmWlCGh7QqH8HUQFP2qCmMg+tYc953yqdrIeGqdOOvUZHfqN7CqWRCA==
X-Received: by 2002:a05:6512:ac6:b0:518:df4b:40e9 with SMTP id
 n6-20020a0565120ac600b00518df4b40e9mr2137681lfu.4.1713170374981; 
 Mon, 15 Apr 2024 01:39:34 -0700 (PDT)
Received: from smtpclient.apple (c80-217-1-132.bredband.tele2.se.
 [80.217.1.132]) by smtp.gmail.com with ESMTPSA id
 z18-20020a056512371200b00518cf9ca6besm375868lfr.232.2024.04.15.01.39.34
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Mon, 15 Apr 2024 01:39:34 -0700 (PDT)
Content-Type: text/plain;
	charset=us-ascii
Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\))
Subject: Re: bug#68929: which-key tests from GNU ELPA into core
From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= <mattias.engdegard@HIDDEN>
In-Reply-To: <87edb7zjz3.fsf@HIDDEN>
Date: Mon, 15 Apr 2024 10:39:33 +0200
Content-Transfer-Encoding: quoted-printable
Message-Id: <50125497-B489-4541-81A1-3DC1F1F9D6A3@HIDDEN>
References: <RT-Ticket-2038816@HIDDEN> <87zfvl8r4e.fsf@HIDDEN>
 <874jdspsqb.fsf@HIDDEN> <877cio8fzf.fsf@HIDDEN>
 <87o7bkcrnq.fsf@HIDDEN> <jwvsf0wqrqg.fsf-monnier+emacs@HIDDEN>
 <87r0fugl5o.fsf@HIDDEN> <jwvle613zk7.fsf-monnier+emacs@HIDDEN>
 <rt-4.2.16-14-g9a593ee-16065-1711725597-1342.2038816-6-0@HIDDEN>
 <87h6g6jthh.fsf@HIDDEN>
 <rt-4.2.16-14-g9a593ee-24903-1712948497-1603.2038816-5-0@HIDDEN>
 <jwvjzl25qpv.fsf-monnier+emacs@HIDDEN> <87edb7zjz3.fsf@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
X-Mailer: Apple Mail (2.3654.120.0.1.15)
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 68929
Cc: 68929 <at> debbugs.gnu.org, Justin Burkett <justin@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

14 apr. 2024 kl. 23.56 skrev Jeremy Bryant <jb@HIDDEN>:

> Mattias,
> I understand you have expertise on the testing infrastructure, do you
> have any comments on any work required to change this file or would it
> be good to go 'as is'?

Well it looks all right as far as I can tell from a quick glance, but =
you are the one with domain knowledge here.

=46rom the dept. of unimportant details: you may want to update the =
copyright year, and bug references such as "#109" could perhaps be =
annotated so that it's clear where to look (maybe use the full URL).





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 14 Apr 2024 21:57:12 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Apr 14 17:57:12 2024
Received: from localhost ([127.0.0.1]:36358 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rw7qZ-0008MO-Hy
	for submit <at> debbugs.gnu.org; Sun, 14 Apr 2024 17:57:11 -0400
Received: from out-181.mta1.migadu.com ([95.215.58.181]:48479)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jb@HIDDEN>) id 1rw7qW-0008LW-Nw
 for 68929 <at> debbugs.gnu.org; Sun, 14 Apr 2024 17:57:09 -0400
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net;
 s=key1; t=1713131811;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:mime-version:mime-version:content-type:content-type:
 references:references; bh=ZzKHCUAuyBa3E1GnpDg5hmcLGFvpUBcN5E/1ebm3gUU=;
 b=tVMYnl5GZTQFyCcTbix0fIX76IGoLSP4LLpU1iAkwId1Qk2u9n1//VPajs4Tja1+bv0sYK
 BTLHsvbOCTNG/Rs/WAuEj8EaeuD8wFTN/pupN/ALKevv/4+wK/Y6dZUDzQJZdTEgbeN6lT
 GgXMQ7py1gCd4I7ocZsVURXNs79rM2X8tCpPgX188TPEZbBSjzfFPaZZbKFhnHqhN5I19R
 Obi1gxOeGLUKgxQznZ9HlP+8rQF8MZPO7nvNo89BEA9NtTi455lZCHEG0YOEgw4kLiZwuG
 f6zirhjK2u3tAgDybfSakc2RwU2u/UPQxKiB3p3vUYrn1pg/GoIzrTJkxnr7Vw==
From: Jeremy Bryant <jb@HIDDEN>
To: Mattias =?utf-8?Q?Engdeg=C3=A5rd?= <mattias.engdegard@HIDDEN>,
 Mattias =?utf-8?Q?Engdeg=C3=A5rd?=
 <mattiase@HIDDEN>, 68929 <at> debbugs.gnu.org, Justin Burkett
 <justin@HIDDEN>
Subject: Fwd: Re: bug#68929: which-key tests from GNU ELPA into core
References: <RT-Ticket-2038816@HIDDEN> <87zfvl8r4e.fsf@HIDDEN>
 <874jdspsqb.fsf@HIDDEN> <877cio8fzf.fsf@HIDDEN>
 <87o7bkcrnq.fsf@HIDDEN>
 <jwvsf0wqrqg.fsf-monnier+emacs@HIDDEN>
 <87r0fugl5o.fsf@HIDDEN>
 <jwvle613zk7.fsf-monnier+emacs@HIDDEN>
 <rt-4.2.16-14-g9a593ee-16065-1711725597-1342.2038816-6-0@HIDDEN>
 <87h6g6jthh.fsf@HIDDEN>
 <rt-4.2.16-14-g9a593ee-24903-1712948497-1603.2038816-5-0@HIDDEN>
 <jwvjzl25qpv.fsf-monnier+emacs@HIDDEN>
Date: Sun, 14 Apr 2024 22:56:48 +0100
Message-ID: <87edb7zjz3.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Migadu-Flow: FLOW_OUT
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 68929
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain


-------------------- Start of forwarded message --------------------
From: Jeremy Bryant <jb@HIDDEN>
To: Philip Kaludercic <philipk@HIDDEN>
Cc: Eli Zaretskii <eliz@HIDDEN>,  68929 <at> debbugs.gnu.org,
  monnier@HIDDEN,  justin@HIDDEN
Subject: Re: bug#68929: which-key tests from GNU ELPA into core
Date: Fri, 12 Apr 2024 21:18:59 +0100


--=-=-=
Content-Type: multipart/mixed; boundary="==-=-="

--==-=-=
Content-Type: text/plain
Content-Disposition: inline

Philip,

Attached is the test file for which-key, are any changes necessary prior
to the move to core?

Thanks in advance
Jeremy


--==-=-=
Content-Type: application/emacs-lisp
Content-Disposition: attachment; filename=which-key-tests.el
Content-Transfer-Encoding: quoted-printable

;;; which-key-tests.el --- Tests for which-key.el -*- lexical-binding: t; -=
*-

;; Copyright (C) 2017-2021  Free Software Foundation, Inc.

;; Author: Justin Burkett <justin@HIDDEN>
;; Maintainer: Justin Burkett <justin@HIDDEN>

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Tests for which-key.el

;;; Code:

(require 'which-key)
(require 'ert)

(ert-deftest which-key-test--keymap-based-bindings ()
  (let ((map (make-sparse-keymap))
        (prefix-map (make-sparse-keymap)))
    (define-key prefix-map "x" #'ignore)
    (define-key map "\C-a" 'complete)
    (define-key map "\C-b" prefix-map)
    (which-key-add-keymap-based-replacements map
      "C-a" '("mycomplete" . complete)
      "C-b" "mymap"
      "C-c" "mymap2")
    (define-key map "\C-ca" 'foo)
    (should (equal
             (which-key--get-keymap-bindings map)
             '(("C-a" . "mycomplete")
               ("C-b" . "group:mymap")
               ("C-c" . "group:mymap2"))))))

(ert-deftest which-key-test--named-prefix-keymap ()
  (define-prefix-command 'which-key-test--named-map)
  (let ((map (make-sparse-keymap)))
    (define-key map "\C-a" 'which-key-test--named-map)
    (should (equal
             (which-key--get-keymap-bindings map)
             '(("C-a" . "which-key-test--named-map"))))))

(ert-deftest which-key-test--prefix-declaration ()
  "Test `which-key-declare-prefixes' and
`which-key-declare-prefixes-for-mode'. See Bug #109."
  (let* ((major-mode 'test-mode)
         which-key-replacement-alist)
    (which-key-add-key-based-replacements
      "SPC C-c" '("complete" . "complete title")
      "SPC C-k" "cancel")
    (which-key-add-major-mode-key-based-replacements 'test-mode
      "C-c C-c" '("complete" . "complete title")
      "C-c C-k" "cancel")
    (should (equal
             (which-key--maybe-replace '("SPC C-k" . ""))
             '("SPC C-k" . "cancel")))
    (should (equal
             (which-key--maybe-replace '("C-c C-c" . ""))
             '("C-c C-c" . "complete")))))

(ert-deftest which-key-test--maybe-replace ()
  "Test `which-key--maybe-replace'. See #154"
  (let ((which-key-replacement-alist
         '((("C-c [a-d]" . nil) . ("C-c a" . "c-c a"))
           (("C-c .+" . nil) . ("C-c *" . "c-c *"))))
        (test-mode-1 't)
        (test-mode-2 'nil)
        which-key-allow-multiple-replacements)
    (which-key-add-key-based-replacements
      "C-c ." "test ."
      "SPC ." "SPC ."
      "C-c \\" "regexp quoting"
      "C-c [" "bad regexp"
      "SPC t1" (lambda (kb)
                 (cons (car kb)
                       (if test-mode-1
                           "[x] test mode"
                         "[ ] test mode")))
      "SPC t2" (lambda (kb)
                 (cons (car kb)
                       (if test-mode-2
                           "[x] test mode"
                         "[ ] test mode"))))
    (should (equal
             (which-key--maybe-replace '("C-c g" . "test"))
             '("C-c *" . "c-c *")))
    (should (equal
             (which-key--maybe-replace '("C-c b" . "test"))
             '("C-c a" . "c-c a")))
    (should (equal
             (which-key--maybe-replace '("C-c ." . "not test ."))
             '("C-c ." . "test .")))
    (should (not
             (equal
              (which-key--maybe-replace '("C-c +" . "not test ."))
              '("C-c ." . "test ."))))
    (should (equal
             (which-key--maybe-replace '("C-c [" . "orig bad regexp"))
             '("C-c [" . "bad regexp")))
    (should (equal
             (which-key--maybe-replace '("C-c \\" . "pre quoting"))
             '("C-c \\" . "regexp quoting")))
    ;; see #155
    (should (equal
             (which-key--maybe-replace '("SPC . ." . "don't replace"))
             '("SPC . ." . "don't replace")))
    (should (equal
             (which-key--maybe-replace '("SPC t 1" . "test mode"))
             '("SPC t 1" . "[x] test mode")))
    (should (equal
             (which-key--maybe-replace '("SPC t 2" . "test mode"))
             '("SPC t 2" . "[ ] test mode")))))

(ert-deftest which-key-test--maybe-replace-multiple ()
  "Test `which-key-allow-multiple-replacements'. See #156."
  (let ((which-key-replacement-alist
         '(((nil . "helm") . (nil . "HLM"))
           ((nil . "projectile") . (nil . "PRJTL"))))
        (which-key-allow-multiple-replacements t))
    (should (equal
             (which-key--maybe-replace '("C-c C-c" . "helm-x"))
             '("C-c C-c" . "HLM-x")))
    (should (equal
             (which-key--maybe-replace '("C-c C-c" . "projectile-x"))
             '("C-c C-c" . "PRJTL-x")))
    (should (equal
             (which-key--maybe-replace '("C-c C-c" . "helm-projectile-x"))
             '("C-c C-c" . "HLM-PRJTL-x")))))

(ert-deftest which-key-test--key-extraction ()
  "Test `which-key--extract-key'. See #161."
  (should (equal (which-key--extract-key "SPC a") "a"))
  (should (equal (which-key--extract-key "C-x a") "a"))
  (should (equal (which-key--extract-key "<left> b a") "a"))
  (should (equal (which-key--extract-key "<left> a .. c") "a .. c"))
  (should (equal (which-key--extract-key "M-a a .. c") "a .. c")))

(ert-deftest which-key-test--get-keymap-bindings ()
  (skip-unless (require 'evil nil t))
  (defvar evil-local-mode)
  (defvar evil-state)
  (declare-function evil-define-key* "ext:evil")
  (let ((map (make-sparse-keymap))
        (evil-local-mode t)
        (evil-state 'normal)
        which-key-replacement-alist)
    (define-key map [which-key-a] '(which-key "blah"))
    (define-key map "b" #'ignore)
    (define-key map "c" "c")
    (define-key map "dd" "dd")
    (define-key map "eee" "eee")
    (define-key map "f" [123 45 6])
    (define-key map (kbd "M-g g") "M-gg")
    (evil-define-key* 'normal map (kbd "C-h") "C-h-normal")
    (evil-define-key* 'insert map (kbd "C-h") "C-h-insert")
    (should (equal
             (sort (which-key--get-keymap-bindings map)
                   (lambda (a b) (string-lessp (car a) (car b))))
             '(("M-g" . "prefix")
               ("c" . "c")
               ("d" . "prefix")
               ("e" . "prefix")
               ("f" . "{ - C-f"))))
    (should (equal
             (sort (which-key--get-keymap-bindings map nil nil nil nil t)
                   (lambda (a b) (string-lessp (car a) (car b))))
             '(("C-h" . "C-h-normal")
               ("M-g" . "prefix")
               ("c" . "c")
               ("d" . "prefix")
               ("e" . "prefix")
               ("f" . "{ - C-f"))))
    (should (equal
             (sort (which-key--get-keymap-bindings map nil nil nil t)
                   (lambda (a b) (string-lessp (car a) (car b))))
             '(("M-g g" . "M-gg")
               ("c" . "c")
               ("d d" . "dd")
               ("e e e" . "eee")
               ("f" . "{ - C-f"))))))

(ert-deftest which-key-test--nil-replacement ()
  (let ((which-key-replacement-alist
         '(((nil . "winum-select-window-[1-9]") . t))))
    (should (equal
             (which-key--maybe-replace '("C-c C-c" . "winum-select-window-1=
"))
             '()))))

(ert-deftest which-key-test--key-sorting ()
  (let ((keys '(("a" . "z")
                ("A" . "Z")
                ("b" . "y")
                ("B" . "Y")
                ("p" . "prefix")
                ("SPC" . "x")
                ("C-a" . "w"))))
    (let ((which-key-sort-uppercase-first t))
      (should
       (equal
        (mapcar #'car (sort (copy-sequence keys) #'which-key-key-order))
        '("SPC" "A" "B" "a" "b" "p" "C-a"))))
    (let (which-key-sort-uppercase-first)
      (should
       (equal
        (mapcar #'car (sort (copy-sequence keys) #'which-key-key-order))
        '("SPC" "a" "b" "p" "A" "B" "C-a"))))
    (let ((which-key-sort-uppercase-first t))
      (should
       (equal
        (mapcar #'car (sort (copy-sequence keys) #'which-key-key-order-alph=
a))
        '("SPC" "A" "a" "B" "b" "p" "C-a"))))
    (let (which-key-sort-uppercase-first)
      (should
       (equal
        (mapcar #'car (sort (copy-sequence keys) #'which-key-key-order-alph=
a))
        '("SPC" "a" "A" "b" "B" "p" "C-a"))))
    (let ((which-key-sort-uppercase-first t))
      (should
       (equal
        (mapcar #'car (sort (copy-sequence keys)
                            #'which-key-prefix-then-key-order))
        '("SPC" "A" "B" "a" "b" "C-a" "p"))))
    (let (which-key-sort-uppercase-first)
      (should
       (equal
        (mapcar #'car (sort (copy-sequence keys)
                            #'which-key-prefix-then-key-order))
        '("SPC" "a" "b" "A" "B" "C-a" "p"))))
    (let ((which-key-sort-uppercase-first t))
      (should
       (equal
        (mapcar 'car (sort (copy-sequence keys)
                           #'which-key-prefix-then-key-order-reverse))
        '("p" "SPC" "A" "B" "a" "b" "C-a"))))
    (let (which-key-sort-uppercase-first)
      (should
       (equal
        (mapcar #'car (sort (copy-sequence keys)
                            #'which-key-prefix-then-key-order-reverse))
        '("p" "SPC" "a" "b" "A" "B" "C-a"))))
    (let ((which-key-sort-uppercase-first t))
      (should
       (equal
        (mapcar #'car (sort (copy-sequence keys)
                            #'which-key-description-order))
        '("p" "C-a" "SPC" "b" "B" "a" "A"))))
    (let (which-key-sort-uppercase-first)
      (should
       (equal
        (mapcar #'car (sort (copy-sequence keys)
                            #'which-key-description-order))
        '("p" "C-a" "SPC" "b" "B" "a" "A"))))))

(provide 'which-key-tests)
;;; which-key-tests.el ends here

--==-=-=--

--=-=-=
Content-Type: text/plain

-------------------- End of forwarded message --------------------

Mattias,
I understand you have expertise on the testing infrastructure, do you
have any comments on any work required to change this file or would it
be good to go 'as is'?
Thanks in advance
Jeremy 

--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 14 Apr 2024 21:52:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Apr 14 17:52:32 2024
Received: from localhost ([127.0.0.1]:36352 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rw7m3-0007Zf-IZ
	for submit <at> debbugs.gnu.org; Sun, 14 Apr 2024 17:52:32 -0400
Received: from out-177.mta1.migadu.com ([95.215.58.177]:45957)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jb@HIDDEN>) id 1rw7lz-0007Xo-Vh
 for 68929 <at> debbugs.gnu.org; Sun, 14 Apr 2024 17:52:29 -0400
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net;
 s=key1; t=1713131530;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to:references:references;
 bh=61mgSz4VVZyi3nVTFEBAdR7X2L8OSmgx4ee08bOAhfk=;
 b=RC1wS5XBGUjXTdo7DlQgz47RBSv6uTtBHkVLIXv5/x5rGioCL/pX9s+pljebuVg6zXREGl
 eG6koVtMEqM44Hpx1R8yeSHl9vr9fLRc/fMCadtTkKOvN7EDmUchi6rJ6Z57LR8YCS/eNv
 fxw2LNASOViKUgeMP46hhZCbp0zNOixnatxb/4mIZNwjyl+s7T1QQ11NomI6SrEUYNDD87
 7nJN4TmER7Sa4qt8R4mXCOMF/PtLH4Bji8Vg5gKhH4ds+SZYmccYcFue5HqP6TF+EKFj4y
 hSBMouPQas5qVtxbApxaIVdQfpIGBZeAQ9e+0R49hns/F5VjAUNlPFnkorRIFA==
From: Jeremy Bryant <jb@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
In-Reply-To: <86y19gmevj.fsf@HIDDEN> (Eli Zaretskii's message of "Sun, 14 Apr
 2024 13:13:04 +0300")
References: <871q9rvqbi.fsf@HIDDEN> <87mssc65y8.fsf@HIDDEN>
 <87y1bwrll4.fsf@HIDDEN> <86h6ijxzjk.fsf@HIDDEN>
 <87msrh4kkc.fsf@HIDDEN> <87jzml3rlz.fsf@HIDDEN>
 <87wmp2ibjj.fsf@HIDDEN> <871q78i9kb.fsf@HIDDEN>
 <86y19gmevj.fsf@HIDDEN>
Date: Sun, 14 Apr 2024 22:52:08 +0100
Message-ID: <87plurzk6v.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Migadu-Flow: FLOW_OUT
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 68929
Cc: philipk@HIDDEN, 68929 <at> debbugs.gnu.org, monnier@HIDDEN,
 justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Eli Zaretskii <eliz@HIDDEN> writes:

>> From: Jeremy Bryant <jb@HIDDEN>
>> Cc: Eli Zaretskii <eliz@HIDDEN>,  68929 <at> debbugs.gnu.org,
>>   monnier@HIDDEN,  justin@HIDDEN
>> Date: Sun, 14 Apr 2024 10:21:24 +0100
>> 
>> > I am currently looking at the merging of history, there appear to be 2
>> > historical commits which exceed the line length in CONTRIBUTE.  
>> > If there is a recommended way to change them please let me know.
>> 
>> I have worked out the change command that work locally to allow these 2 historical
>> commits to be merged.  (with thanks to Stefan)
>> 
>> git merge --no-verify --allow-unrelated-histories --no-edit
>> which-key-integration/which-key-prepare-integration
>> 
>> 
>> FYI the two exceptions were below.  Allowing these would preserve the
>> copyright assignment tracking.
>> $ git log --oneline | awk 'length($0)>78+8'
>> ;; :group 'which-key |ad8eb57 Merge branch 'better-window-sizes' of
>> https://github.com/bmag/emacs-which-key into better-window-sizes
>> ;; :type 'string) |1fd43dc Merge branch 'frame-popup' of
>> https://github.com/bmag/emacs-which-key into pr12
>
> Is line length the only issue you are looking at?  What about other
> requirements of our logs and ChangeLog files, including those imposed
> by authors.el?  The most problematic issue is when the file names
> and/or its leading directories in the log message don't fit the actual
> place and name of the file in the tree.  Did you look at those issues?
> They typically come up when preparing a release tarball, and are quite
> annoying at that time, especially if there are a lot of them, because
> they require manual fixes.

Yes, sorry, I have only looked at the line length because it came up as
a blocker.

As far as the file names, this appears stable, but the place in the tree
would move as part of this proposed integration, to be in
lisp/which-key.el rather than at the root as is the case for the ELPA
version.  Is this a problem and how was it resolved with other moves
from ELPA to core?

Upon inspection, the earlier historical commits do not generally conform to the
Changelog format.
How to investigate any issues for authors.el?  Is there a function try
and run?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 14 Apr 2024 10:13:46 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Apr 14 06:13:45 2024
Received: from localhost ([127.0.0.1]:34369 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rvwrg-00059y-Vk
	for submit <at> debbugs.gnu.org; Sun, 14 Apr 2024 06:13:44 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:50958)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1rvwrU-00057m-Aq
 for 68929 <at> debbugs.gnu.org; Sun, 14 Apr 2024 06:13:31 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1rvwrD-0006rE-0Y; Sun, 14 Apr 2024 06:13:07 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=SydmIJFWl0+tQiAKLMDjoAxkGxi1NOk4UT2UPatvq/M=; b=eLtsL+nqA5Z5
 qAzzyHrDDFExYShjxTwnpKVy6oA813DfxLCrs87w4XJZtQ8rLce3FAGJz8Qa+h9NAEPVOSls9IB0u
 pOJ7KOj07UvvyAn1zvNid/1HeZ8qub3O9HU0NIjVJiI9JFHP6zB4BSyEvsqR+TT7E9uOtc7QJKHCN
 kARwG4AibaFZOJs645DzchUzxk3FqGWmrLj+kj/KYWUPTHH8rFrOkay0XoamJ+fBwqJNCmP53J+CF
 W980TWXf4EZ8dZayWTNYrt/xkPjv1Fn1f9VQ50nJSHEErD1A6OSD6TuAn0i6IkbFHCMp8L4scAx6r
 s2wsb+YIyd9AhIEG47p+2g==;
Date: Sun, 14 Apr 2024 13:13:04 +0300
Message-Id: <86y19gmevj.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
In-Reply-To: <871q78i9kb.fsf@HIDDEN> (message from Jeremy Bryant on
 Sun, 14 Apr 2024 10:21:24 +0100)
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
References: <871q9rvqbi.fsf@HIDDEN> <87mssc65y8.fsf@HIDDEN>
 <87y1bwrll4.fsf@HIDDEN> <86h6ijxzjk.fsf@HIDDEN>
 <87msrh4kkc.fsf@HIDDEN> <87jzml3rlz.fsf@HIDDEN>
 <87wmp2ibjj.fsf@HIDDEN> <871q78i9kb.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68929
Cc: philipk@HIDDEN, 68929 <at> debbugs.gnu.org, monnier@HIDDEN,
 justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Jeremy Bryant <jb@HIDDEN>
> Cc: Eli Zaretskii <eliz@HIDDEN>,  68929 <at> debbugs.gnu.org,
>   monnier@HIDDEN,  justin@HIDDEN
> Date: Sun, 14 Apr 2024 10:21:24 +0100
> 
> > I am currently looking at the merging of history, there appear to be 2
> > historical commits which exceed the line length in CONTRIBUTE.  
> > If there is a recommended way to change them please let me know.
> 
> I have worked out the change command that work locally to allow these 2 historical
> commits to be merged.  (with thanks to Stefan)
> 
> git merge --no-verify --allow-unrelated-histories --no-edit
> which-key-integration/which-key-prepare-integration
> 
> 
> FYI the two exceptions were below.  Allowing these would preserve the
> copyright assignment tracking.
> $ git log --oneline | awk 'length($0)>78+8'
> ;; :group 'which-key |ad8eb57 Merge branch 'better-window-sizes' of
> https://github.com/bmag/emacs-which-key into better-window-sizes
> ;; :type 'string) |1fd43dc Merge branch 'frame-popup' of
> https://github.com/bmag/emacs-which-key into pr12

Is line length the only issue you are looking at?  What about other
requirements of our logs and ChangeLog files, including those imposed
by authors.el?  The most problematic issue is when the file names
and/or its leading directories in the log message don't fit the actual
place and name of the file in the tree.  Did you look at those issues?
They typically come up when preparing a release tarball, and are quite
annoying at that time, especially if there are a lot of them, because
they require manual fixes.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 14 Apr 2024 09:21:50 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Apr 14 05:21:50 2024
Received: from localhost ([127.0.0.1]:34292 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rvw3Y-0005b8-6i
	for submit <at> debbugs.gnu.org; Sun, 14 Apr 2024 05:21:49 -0400
Received: from out-183.mta1.migadu.com ([95.215.58.183]:21590)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jb@HIDDEN>) id 1rvw3U-0005Zc-Db
 for 68929 <at> debbugs.gnu.org; Sun, 14 Apr 2024 05:21:45 -0400
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net;
 s=key1; t=1713086486;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to:references:references;
 bh=YSl/WrnfwasIuQvCl0UwHEj9Yxlj7jK219VC5OZmjHA=;
 b=R/cRmjpZ/IWLq1HggjqCS0AMwxLX0m7hovI0B0ybDfRAeA1oqo1C0YXoMIp2CwhHiRsH+C
 W+UKb4KFbQhQe7fytGxVC1TijOzSxnwBTVcbx6LY0BDEqo7DBGZhUScrK6bEgWFzCnmp32
 a5IeEfBHq1drn/MB4SNnL/me8rD2O3YwsGvMZvgSuqDl+HKTuasyyBjghm/0pEsc20Rm2J
 HN3AK7JlPZ5mwhcl7XJ/PdqWgwNASh/fbBiXELcwW4dAyUdd3eHkPPa840jG5k1y3yT/4H
 onbRj47RiAsUFpQTit0He/5rmrVySLutatwAkHSAwi4yi76WH8dAXZct8tRe1g==
From: Jeremy Bryant <jb@HIDDEN>
To: Philip Kaludercic <philipk@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
In-Reply-To: <87wmp2ibjj.fsf@HIDDEN> (Jeremy Bryant's message of
 "Fri, 12 Apr 2024 21:14:08 +0100")
References: <871q9rvqbi.fsf@HIDDEN> <87mssc65y8.fsf@HIDDEN>
 <87y1bwrll4.fsf@HIDDEN> <86h6ijxzjk.fsf@HIDDEN>
 <87msrh4kkc.fsf@HIDDEN> <87jzml3rlz.fsf@HIDDEN>
 <87wmp2ibjj.fsf@HIDDEN>
Date: Sun, 14 Apr 2024 10:21:24 +0100
Message-ID: <871q78i9kb.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Migadu-Flow: FLOW_OUT
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 68929
Cc: Eli Zaretskii <eliz@HIDDEN>, 68929 <at> debbugs.gnu.org,
 monnier@HIDDEN, justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Jeremy Bryant <jb@HIDDEN> writes:
> Here is the current status on the road to adapting which-key code to
> merge into Emacs, and in adapting the code to the coding conventions and
> requirements for maintainability,
>
> I've followed comments from Eli and then Philip, there have been
> around 65 patches submitted upstream
> https://github.com/justbur/emacs-which-key/commits/master/
>
> Many thanks to Philip for the detailed code review and the many
> clarifications off-list, and to Justin, the author, for examining and
> merging the patches in preparation for this.
>
> I am currently looking at the merging of history, there appear to be 2
> historical commits which exceed the line length in CONTRIBUTE.  
> If there is a recommended way to change them please let me know.

I have worked out the change command that work locally to allow these 2 historical
commits to be merged.  (with thanks to Stefan)

git merge --no-verify --allow-unrelated-histories --no-edit
which-key-integration/which-key-prepare-integration


FYI the two exceptions were below.  Allowing these would preserve the
copyright assignment tracking.
$ git log --oneline | awk 'length($0)>78+8'
;; :group 'which-key |ad8eb57 Merge branch 'better-window-sizes' of
https://github.com/bmag/emacs-which-key into better-window-sizes
;; :type 'string) |1fd43dc Merge branch 'frame-popup' of
https://github.com/bmag/emacs-which-key into pr12

>
> The latest version is attached, if there are any more comments they are
> welcome.
>
> [2. application/emacs-lisp; which-key.el]...




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 12 Apr 2024 20:41:09 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Apr 12 16:41:09 2024
Received: from localhost ([127.0.0.1]:59670 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rvNhp-0005jQ-RN
	for submit <at> debbugs.gnu.org; Fri, 12 Apr 2024 16:41:09 -0400
Received: from mout01.posteo.de ([185.67.36.65]:59475)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <philipk@HIDDEN>) id 1rvNhm-0005hH-30
 for 68929 <at> debbugs.gnu.org; Fri, 12 Apr 2024 16:41:03 -0400
Received: from submission (posteo.de [185.67.36.169]) 
 by mout01.posteo.de (Postfix) with ESMTPS id C97CB240028
 for <68929 <at> debbugs.gnu.org>; Fri, 12 Apr 2024 22:40:45 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1712954445; bh=2e1+Wt/208r6qab7TvgLn6Hc902bMBkvB4FuUWig41I=;
 h=From:To:Cc:Subject:OpenPGP:Date:Message-ID:MIME-Version:
 Content-Type:Content-Transfer-Encoding:From;
 b=JjVN+vCazrsEVsWjXZ3QCDqTjEoHWxXmM5B57pi45VCCl8aTT52Wwy3MrIfaHtA/H
 RaMpYO0BseBv6nOuyRKjeBlUtyJDMKzxwlbWZPJXQkwbk8OoYW9cdIMGBxl36mva2S
 c0dPficQ2ZABO/FhpR3nmBkoIvIBOa8wcdz+pko+1f0meBYxsSMjS59yTr5lPhaqfZ
 ecOoCL5M2HzjtkIJngq0vAuGOUH5fPI8XL05Fjr3QfFw3oMMMzFpTbF+Rz3UEmD4Xp
 1Zox7p7uftyUHLrAZ+98m/uVX4YGZZUxD3EgnrX75oeNnunELStFt+L6WVrKpFZ6c2
 rqpz7viDg/VVw==
Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4VGT3c1rW3z6tyh;
 Fri, 12 Apr 2024 22:40:44 +0200 (CEST)
From: Philip Kaludercic <philipk@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
Subject: Re: bug#68929: which-key tests from GNU ELPA into core
In-Reply-To: <87r0faibbg.fsf@HIDDEN> (Jeremy Bryant's message of
 "Fri, 12 Apr 2024 21:18:59 +0100")
References: <871q9rvqbi.fsf@HIDDEN> <87mssc65y8.fsf@HIDDEN>
 <87y1bwrll4.fsf@HIDDEN> <86h6ijxzjk.fsf@HIDDEN>
 <87msrh4kkc.fsf@HIDDEN> <87jzml3rlz.fsf@HIDDEN>
 <87r0faibbg.fsf@HIDDEN>
OpenPGP: id=7126E1DE2F0CE35C770BED01F2C3CC513DB89F66;
 url="https://keys.openpgp.org/vks/v1/by-fingerprint/7126E1DE2F0CE35C770BED01F2C3CC513DB89F66";
 preference=signencrypt
Date: Fri, 12 Apr 2024 20:40:43 +0000
Message-ID: <87edbafh6c.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68929
Cc: Eli Zaretskii <eliz@HIDDEN>, 68929 <at> debbugs.gnu.org,
 monnier@HIDDEN, justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Jeremy Bryant <jb@HIDDEN> writes:

> Philip,
>
> Attached is the test file for which-key, are any changes necessary prior
> to the move to core?

I have to admit that I am not too well versed with Emacs testing
infrastructure.  Someone else (perhaps Mattias Engdeg=C3=A5rd) would probab=
ly
be in a better position to help you here.

> Thanks in advance
> Jeremy

--=20
	Philip Kaludercic on peregrine




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.
bug unarchived. Request was from Jeremy Bryant <jb@HIDDEN> to control <at> debbugs.gnu.org. Full text available.
bug archived. Request was from Debbugs Internal Request <help-debbugs@HIDDEN> to internal_control <at> debbugs.gnu.org. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 2 Mar 2024 09:34:23 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 02 04:34:23 2024
Received: from localhost ([127.0.0.1]:38044 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rgLl9-0004rw-NM
	for submit <at> debbugs.gnu.org; Sat, 02 Mar 2024 04:34:23 -0500
Received: from mout02.posteo.de ([185.67.36.66]:54619)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <philipk@HIDDEN>) id 1rgLl7-0004re-Fc
 for 68929 <at> debbugs.gnu.org; Sat, 02 Mar 2024 04:34:22 -0500
Received: from submission (posteo.de [185.67.36.169]) 
 by mout02.posteo.de (Postfix) with ESMTPS id 087ED240104
 for <68929 <at> debbugs.gnu.org>; Sat,  2 Mar 2024 10:33:46 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1709372027; bh=vkKny6cwsdYIZvOG9jn1EW6kJaDdveSDG4+o5ty49Fg=;
 h=From:To:Cc:Subject:OpenPGP:Date:Message-ID:MIME-Version:
 Content-Type:Content-Transfer-Encoding:From;
 b=PxoVJDSSMdS42R+UoGjeYdsXzISEEOX5T+iNj0vZQVfNktWT05u2kogMFsOmJUj22
 b16cPSeeJ6ZEoHYmBxkl3z2kkt356sU3trz8AcO4qexDsGSMT/ZjSqGGAZ7IUyB3dW
 ZhYQalfO/qnRQ9/SR6CnCWayYHi0L/DSIno/yCJHW08kzsoMxJLMTk2CB8JEVpffBr
 1V/W+uG73yyLDSfUNUB9WSiiKo0cQ525n/KJEsM8dBZt2xqncZWTVgPCxwg/GLIurf
 qd4urYDu384Fj5ZoIRVAP27U4qLs69pCNtPgoMPdmi8GVvlqPriNWwVLyt05eDOLaW
 Zdwo7H74q8uDg==
Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4Tn0Bx36dnz9rxG;
 Sat,  2 Mar 2024 10:33:45 +0100 (CET)
From: Philip Kaludercic <philipk@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
In-Reply-To: <87msrh4kkc.fsf@HIDDEN> (Jeremy Bryant's message of
 "Fri, 01 Mar 2024 23:08:19 +0000")
References: <871q9rvqbi.fsf@HIDDEN> <87mssc65y8.fsf@HIDDEN>
 <87y1bwrll4.fsf@HIDDEN> <86h6ijxzjk.fsf@HIDDEN>
 <87msrh4kkc.fsf@HIDDEN>
OpenPGP: id=7126E1DE2F0CE35C770BED01F2C3CC513DB89F66;
 url="https://keys.openpgp.org/vks/v1/by-fingerprint/7126E1DE2F0CE35C770BED01F2C3CC513DB89F66";
 preference=signencrypt
Date: Sat, 02 Mar 2024 09:33:44 +0000
Message-ID: <87jzml3rlz.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Debbugs-Envelope-To: 68929
Cc: Eli Zaretskii <eliz@HIDDEN>, 68929 <at> debbugs.gnu.org,
 monnier@HIDDEN, justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>


[...]

> * The vast majority of improvements requested by Philip; defcustoms
> changes, docstrings, sharp-quoted elements, pure function, third party
> libs, declare, memq, string-join, null-bindings etc) Missing are some
> elements I'm less familiar with, such as design choices related to
> deffaces.
>
> These are currently in the form of individual patches in the upstream
> git repo (thus attached only for convenience).  Using the 'preserving
> history' approach described by Stefan M, this could be moved to core,
> thus preserving the commits thus allowing checking of contributor FSF
> attribution.
>
>
> If there are certain elements you feel deserve further work, all
> feedback welcome.

Ok, but I might be repeating myself, because I don't recall everything
from my last response.

> WDYT?
>
>
> ;;; which-key.el --- Display available keybindings in popup  -*- lexical-=
binding: t; -*-
>
> ;; Copyright (C) 2017-2024  Free Software Foundation, Inc.
>
> ;; Author: Justin Burkett <justin@HIDDEN>
> ;; Maintainer: Justin Burkett <justin@HIDDEN>
> ;; Version: 3.6.0
> ;; Keywords:
> ;; Package-Requires: ((emacs "24.4"))
>
> ;; This program is free software; you can redistribute it and/or modify
> ;; it under the terms of the GNU General Public License as published by
> ;; the Free Software Foundation, either version 3 of the License, or
> ;; (at your option) any later version.
>
> ;; This program is distributed in the hope that it will be useful,
> ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
> ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> ;; GNU General Public License for more details.
>
> ;; You should have received a copy of the GNU General Public License
> ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
>
> ;;; Commentary:
>
> ;; which-key provides the minor mode which-key-mode for Emacs.  The mode =
displays
> ;; the key bindings following your currently entered incomplete command (a
> ;; prefix) in a popup.  For example, after enabling the minor mode if you=
 enter
> ;; C-x and wait for the default of 1 second the minibuffer will expand wi=
th all
> ;; of the available key bindings that follow C-x (or as many as space all=
ows
> ;; given your settings).  This includes prefixes like C-x 8 which are sho=
wn in a
> ;; different face.  Screenshots of what the popup will look like along wi=
th
> ;; information about additional features can be found at
> ;; https://github.com/justbur/emacs-which-key.
> ;;
>
> ;;; Code:
>
> (require 'cl-lib)
> (require 'button)
> (require 'regexp-opt)

It shouldn't be necessary to require regexp-opt, especially seeing as
all instances will be optimised away by the byte compiler.

> ;; For compiler
> (defvar evil-operator-shortcut-map)
> (defvar evil-operator-state-map)
> (defvar evil-motion-state-map)
> (defvar golden-ratio-mode)
> (declare-function evil-get-command-property "ext:evil-common.el")

So what was the conclusion on the question of support for external
packages inside of which-key?

> ;;; Options
>
> (defgroup which-key nil
>   "Customization options for which-key-mode."
>   :group 'help
>   :prefix "which-key-")
>
> (defcustom which-key-idle-delay 1.0
>   "Delay (in seconds) for which-key buffer to popup.
> This variable should be set before activating `which-key-mode'.
>
> A value of zero might lead to issues, so a non-zero value is
> recommended
> (see https://github.com/justbur/emacs-which-key/issues/134)."
>   :group 'which-key

Not sure if I mentioned this or not, but all :group attributes can be
left away, since a defcustom will default to the last group you defined.

>   :type 'float
>   :version "1.0")
>
> (defcustom which-key-idle-secondary-delay nil
>   "Seconds to wait for which-key to pop up after initial display.
> This makes it possible to shorten the delay for subsequent popups
> in the same key sequence. The default is for this value to be
> nil, which disables this behavior."
>   :group 'which-key
>   :type '(choice float (const :tag "Disabled" nil))
>   :version "1.0")
>
> (defcustom which-key-echo-keystrokes (if (and echo-keystrokes
>                                               (> (+ echo-keystrokes 0.01)
>                                                  which-key-idle-delay))
>                                          (/ (float which-key-idle-delay) =
4)
>                                        echo-keystrokes)
>   "Value to use for `echo-keystrokes'.
> This only applies if `which-key-popup-type' is minibuffer or
> `which-key-show-prefix' is echo.  It needs to be less than
> `which-key-idle-delay' or else the keystroke echo will erase the
> which-key popup."
>   :group 'which-key
>   :type 'float
>   :version "1.0")
>
> (defcustom which-key-max-description-length 27
>   "Truncate the description of keys to this length.
> Either nil (no truncation), an integer (truncate after that many
> characters), a float (use that fraction of the available width),
> or a function, which takes one argument, the available width in
> characters, and whose return value has one of the types mentioned
> before.  Truncation is done using `which-key-ellipsis'."
>   :group 'which-key
>   :type '(choice (const :tag "Disable truncation" nil)
> 		 (integer :tag "Width in characters")
> 		 (float :tag "Use fraction of available width")
> 		 function)
>   :version "1.0")
>
> (defcustom which-key-min-column-description-width 0
>   "Every column should at least have this width."
>   :group 'which-key
>   :type 'natnum
>   :version "1.0")
>
> (defcustom which-key-add-column-padding 0
>   "Additional spaces to add to the left of each key column."
>   :group 'which-key
>   :type 'integer
>   :version "1.0")
>
> (defcustom which-key-unicode-correction 3
>   "Correction for wide unicode characters.
> Since we measure width in terms of the number of characters,
> Unicode characters that are wider than ASCII characters throw off
> the calculation for available width in the which-key buffer.  This
> variable allows you to adjust for the wide unicode characters by
> artificially reducing the available width in the buffer.
>
> The default of 3 means allow for the total extra width
> contributed by any wide unicode characters to be up to one
> additional ASCII character in the which-key buffer.  Increase this
> number if you are seeing characters get cutoff on the right side
> of the which-key popup."
>   :group 'which-key
>   :type 'integer
>   :version "1.0")
>
> (defcustom which-key-dont-use-unicode nil

I believe I mentioned this as well, but if not, I'd like to advocate for
setting this to non-nil by default, just because using unicode by
default could be tricky, if the user doesn't have the right fonts
installed, making everything look off.  ASCII seems to be the safer
default.

>   "If non-nil, don't use any unicode characters in default setup.
> For affected settings, see `which-key-replacement-alist', `which-key-elli=
psis'
> 'which-key-separator'."
>   :group 'which-key
>   :type 'boolean
>   :version "1.0")
>
> (defcustom which-key-separator
>   (if which-key-dont-use-unicode " : " " =E2=86=92 ")
>   "Separator to use between key and description.
> Default is \" =E2=86=92 \", unless `which-key-dont-use-unicode' is non
> nil, in which case the default is \" : \"."
>   :group 'which-key
>   :type 'string
>   :version "1.0")

If the default value of this option relies on
`which-key-dont-use-unicode', shouldn't you add a :set-after here?

>
> (defcustom which-key-ellipsis
>   (if which-key-dont-use-unicode ".." "=E2=80=A6")
>   "Ellipsis to use when truncating.
> Default is \"=E2=80=A6\", unless `which-key-dont-use-unicode' is non nil,
> in which case the default is \"..\".  This can also be the empty
> string to truncate without using any ellipsis."
>   :group 'which-key
>   :type 'string
>   :version "1.0")
>
> (defcustom which-key-prefix-prefix "+"
>   "Prefix string to indicate a key bound to a keymap.
> Default is \"+\"."
>   :group 'which-key
>   :type 'string
>   :version "1.0")
>
> (defcustom which-key-compute-remaps nil
>   "If non-nil, show remapped commands.
> This applies to commands that have been remapped given the
> currently active keymaps."
>   :group 'which-key
>   :type 'boolean
>   :version "1.0")
>
> (defcustom which-key-replacement-alist
>   (delq nil

Regardless of the value of `which-key-dont-use-unicode', it seems to me
that the list will never contain a nil that has to be removed.  If
`which-key-dont-use-unicode' is nil, then an empty list is spliced,
which won't add a nil, otherwise a single non-nil element is added.

>         `(((nil . "which-key-show-next-page-no-cycle") . (nil . "wk next =
pg"))
>           ,@(unless which-key-dont-use-unicode
>               '((("<left>") . ("=E2=86=90"))
>                 (("<right>") . ("=E2=86=92"))))
>           (("<\\([[:alnum:]-]+\\)>") . ("\\1"))))
>   "ALIST for manipulating display of binding descriptions.
> Each element of the list is a nested cons cell with the format
>
> \(MATCH CONS . REPLACEMENT\).
>
> The MATCH CONS determines when a replacement should occur and
> REPLACEMENT determines how the replacement should occur. Each may
> have the format \(KEY REGEXP . BINDING REGEXP\). For the
> replacement to apply the key binding must match both the KEY
> REGEXP and the BINDING REGEXP. A value of nil in either position
> can be used to match every possibility. The replacement is
> performed by using `replace-regexp-in-string' on the KEY REGEXP
> from the MATCH CONS and REPLACEMENT when it is a cons cell, and
> then similarly for the BINDING REGEXP. A nil value in the BINDING
> REGEXP position cancels the replacement. For example, the entry
>
> \(\(nil . \"Prefix Command\"\) . \(nil . \"prefix\"\)\)
>
> matches any binding with the descriptions \"Prefix Command\" and
> replaces the description with \"prefix\", ignoring the
> corresponding key.
>
> REPLACEMENT may also be a function taking a cons cell
> \(KEY . BINDING\) and producing a new corresponding cons cell.
>
> If REPLACEMENT is anything other than a cons cell \(and non nil\)
> the key binding is ignored by which-key.
>
> Finally, you can multiple replacements to occur for a given key
> binding by setting `which-key-allow-multiple-replacements' to a
> non-nil value."
>   :group 'which-key
>   :type '(alist :key-type (cons (choice regexp (const nil))
>                                 (choice regexp (const nil)))
>                 :value-type (cons (choice string (const nil))
>                                   (choice string (const nil))))
>   :version "1.0")
>
> (defcustom which-key-allow-multiple-replacements nil
>   "Allow a key binding to be modified by multiple elements.
> When non-nil, this allows a single key binding to match multiple
> patterns in `which-key-replacement-alist'. When nil, only the
> first match is used to perform replacements from
> `which-key-replacement-alist'."
>   :group 'which-key
>   :type 'boolean
>   :version "1.0")
>
> (defcustom which-key-show-docstrings nil
>   "If non-nil, show each command's docstring in the which-key popup.
> This will only display the docstring up to the first line
> break. If you set this variable to the symbol docstring-only,
> then the command's name with be omitted. You probably also want
> to adjust `which-key-max-description-length' at the same time if
> you use this feature."
>   :group 'which-key
>   :type '(radio
>           (const :tag "Do not show docstrings" nil)
>           (const :tag "Add docstring to command names" t)
>           (const :tag "Replace command name with docstring" docstring-onl=
y))
>   :version "1.0")
>
> (defcustom which-key-highlighted-command-list '()
>   "Rules used to highlight certain commands.
> If the element is a string, assume it is a regexp pattern for
> matching command names and use
> `which-key-highlighted-command-face' for any matching names. If
> the element is a cons cell, it should take the form (regexp .
> face to apply)."
>   :group 'which-key
>   :type  '(repeat (choice string (cons regexp face)))
>   :version "1.0")
>
> (defcustom which-key-special-keys '()
>   "These keys will automatically be truncated to one character.
> They also have `which-key-special-key-face' applied to them. This
> is disabled by default. An example configuration is
>
> \(setq which-key-special-keys \\=3D'(\"SPC\" \"TAB\" \"RET\" \"ESC\" \"DE=
L\")\)"
>   :group 'which-key
>   :type '(repeat string)
>   :version "1.0")
>
> (defcustom which-key-buffer-name " *which-key*"

Is it supposed to be a hidden buffer?  If so, why?

>   "Name of which-key buffer."
>   :group 'which-key
>   :type 'string
>   :version "1.0")
>
> (defcustom which-key-show-prefix 'echo
>   "Whether to and where to display the current prefix sequence.
> Possible choices are echo for echo area (the default), left, top
> and nil. Nil turns the feature off."
>   :group 'which-key
>   :type '(radio (const :tag "Left of the keys" left)
>                 (const :tag "In the first line" top)
>                 (const :tag "In the last line" bottom)
>                 (const :tag "In the echo area" echo)
>                 (const :tag "In the mode-line" mode-line)
>                 (const :tag "Hide" nil))
>   :version "1.0")
>
> (defcustom which-key-popup-type 'side-window
>   "Supported types are minibuffer, side-window, frame, and custom."
>   :group 'which-key
>   :type '(radio (const :tag "Show in minibuffer" minibuffer)
>                 (const :tag "Show in side window" side-window)
>                 (const :tag "Show in popup frame" frame)
>                 (const :tag "Use your custom display functions" custom))
>   :version "1.0")
>
> (defcustom which-key-min-display-lines 1
>   "Minimum number of horizontal lines to display in the which-key buffer."
>   :group 'which-key
>   :type 'integer
>   :version "1.0")
>
> (defcustom which-key-max-display-columns nil
>   "Maximum number of columns to display in the which-key buffer.
> A value of nil means don't impose a maximum."
>   :group 'which-key
>   :type '(choice integer (const :tag "Unbounded" nil))
>   :version "1.0")
>
> (defcustom which-key-side-window-location 'bottom
>   "Location of which-key popup when `which-key-popup-type' is side-window.
> Should be one of top, bottom, left or right.  You can also specify
> a list of two locations, like (right bottom).  In this case, the
> first location is tried.  If there is not enough room, the second
> location is tried."
>   :group 'which-key
>   :type '(radio (const right)
>                 (const bottom)
>                 (const left)
>                 (const top)
>                 (const (right bottom))
>                 (const (bottom right)))
>   :version "1.0")
>
> (defcustom which-key-side-window-slot 0
>   "The `slot' to use for `display-buffer-in-side-window'.
> This applies when `which-key-popup-type' is `side-window'.
> Quoting from the docstring of `display-buffer-in-side-window',
>
> `slot' if non-nil, specifies the window slot where to display
> BUFFER.  A value of zero or nil means use the middle slot on the
> specified side.  A negative value means use a slot
> preceding (that is, above or on the left of) the middle slot.  A
> positive value means use a slot following (that is, below or on
> the right of) the middle slot.  The default is zero."
>   :group 'which-key
>   :type 'integer
>   :version "1.0")
>
> (defcustom which-key-side-window-max-width 0.333
>   "Maximum width of which-key popup when type is side-window.
> This variable can also be a number between 0 and 1. In that case,
> it denotes a percentage out of the frame's width."
>   :group 'which-key
>   :type 'float
>   :version "1.0")
>
> (defcustom which-key-side-window-max-height 0.25
>   "Maximum height of which-key popup when type is side-window.
> This variable can also be a number between 0 and 1. In that case, it deno=
tes
> a percentage out of the frame's height."
>   :group 'which-key
>   :type 'float
>   :version "1.0")
>
> (defcustom which-key-frame-max-width 60
>   "Maximum width of which-key popup when type is frame."
>   :group 'which-key
>   :type 'integer
>   :version "1.0")
>
> (defcustom which-key-frame-max-height 20
>   "Maximum height of which-key popup when type is frame."
>   :group 'which-key
>   :type 'integer
>   :version "1.0")

These two also sound like natnums?

>
> (defcustom which-key-allow-imprecise-window-fit (not (display-graphic-p))
>   "Allow which-key to use a simpler method for resizing the popup.
> If you are noticing lag when the which-key popup displays turning
> this on may help.
>
> See https://github.com/justbur/emacs-which-key/issues/130
> and https://github.com/justbur/emacs-which-key/issues/225."
>   :group 'which-key
>   :type 'boolean
>   :version "1.0")
>
> (defcustom which-key-show-remaining-keys nil
>   "Show remaining keys in last slot, when keys are hidden."
>   :group 'which-key
>   :type '(radio (const :tag "Yes" t)
>                 (const :tag "No" nil))
>   :version "1.0")
>
> (defcustom which-key-sort-order 'which-key-key-order

If this is a function, then it should be sharp-quoted.

>   "Order in which the key bindings are sorted.
> If nil, do not resort the output from `describe-buffer-bindings'
> which groups by mode. Ordering options
> are
>
> 1. `which-key-key-order': by key (default)
> 2. `which-key-key-order-alpha': by key using alphabetical order
> 3. `which-key-description-order': by description
> 4. `which-key-prefix-then-key-order': prefix (no prefix first) then key
> 5. `which-key-local-then-key-order': local binding then key
>
> See the README and the docstrings for those functions for more
> information."
>   :group 'which-key
>   :type '(choice (function-item which-key-key-order)
>                  (function-item which-key-key-order-alpha)
>                  (function-item which-key-description-order)
>                  (function-item which-key-prefix-then-key-order)
>                  (function-item which-key-local-then-key-order))
>   :version "1.0")
>
> (defcustom which-key-sort-uppercase-first t
>   "If non-nil, uppercase comes before lowercase in sorting.
> This applies to the function chosen in
> `which-key-sort-order'. Otherwise, the order is reversed."
>   :group 'which-key
>   :type 'boolean
>   :version "1.0")
>
> (defcustom which-key-paging-prefixes '()
>   "Enable paging for these prefixes."

Some more documentation would be useful here, since I find it difficult
to imagine what possible values could be.

>   :group 'which-key
>   :type '(repeat string)
>   :version "1.0")
>
> (defcustom which-key-paging-key "<f5>"
>   "Key to use for changing pages.
> Bound after each of the prefixes in `which-key-paging-prefixes'"
>   :group 'which-key
>   :type 'string

If it is a single key, then why use a string as the type here, and not
replace the default value with (kbd "<f5>")?

>   :version "1.0")
>
> ;; (defcustom which-key-undo-key nil
> ;;   "Key (string) to use for undoing keypresses. Bound recursively
> ;; in each of the maps in `which-key-undo-keymaps'."
> ;;   :group 'which-key
> ;;   :type 'string)
>
> ;; (defcustom which-key-undo-keymaps '()
> ;;   "Keymaps in which to bind `which-key-undo-key'"
> ;;   :group 'which-key
> ;;   :type '(repeat symbol))
>
> (defcustom which-key-use-C-h-commands t
>   "Use C-h (`help-char') for paging if non-nil.
> Normally `help-char' after a prefix calls
> `describe-prefix-bindings'. This changes that command to a
> which-key paging command when which-key-mode is active."
>   :group 'which-key
>   :type 'boolean
>   :version "1.0")
>
> (defcustom which-key-show-early-on-C-h nil
>   "Allow C-h (`help-char') to trigger which-key popup before timer.
> Show the which-key buffer if `help-char' is pressed in the middle
> of a prefix before the which-key buffer would normally be
> triggered by the time. If combined with the following settings,
> which-key will effectively only show when triggered \"manually\"
> using C-h.
>
> \(setq `which-key-idle-delay' 10000)
> \(setq `which-key-idle-secondary-delay' 0.05)
>
> Note that `which-key-idle-delay' should be set before turning on
> `which-key-mode'."
>   :group 'which-key
>   :type 'boolean
>   :version "1.0")
>
> (defcustom which-key-is-verbose nil
>   "Whether to warn about potential mistakes in configuration."
>   :group 'which-key
>   :type 'boolean
>   :version "1.0")
>
> (defcustom which-key-preserve-window-configuration nil
>   "Save and restore window configuration around which-key popup display.
> If non-nil, save window configuration before which-key buffer is
> shown and restore it after which-key buffer is hidden. It
> prevents which-key from changing window position of visible
> buffers.  Only takken into account when popup type is
> side-window."
>   :group
>   'which-key
>   :type 'boolean
>   :version "1.0")
>
> (defvar which-key-C-h-map-prompt
>   (concat " \\<which-key-C-h-map>"
>           " \\[which-key-show-next-page-cycle]"
>           which-key-separator "next-page,"
>           " \\[which-key-show-previous-page-cycle]"
>           which-key-separator "previous-page,"
>           " \\[which-key-undo-key]"
>           which-key-separator "undo-key,"
>           " \\[which-key-toggle-docstrings]"
>           which-key-separator "toggle-docstrings,"
>           " \\[which-key-show-standard-help]"
>           which-key-separator "help,"
>           " \\[which-key-abort]"
>           which-key-separator "abort"
>           " 1..9"
>           which-key-separator "digit-arg")
>   "Prompt to display when invoking `which-key-C-h-map'.
> This string is fed into `substitute-command-keys'")
>
> (defvar which-key-C-h-map
>   (let ((map (make-sparse-keymap)))
>     (dolist (bind `(("\C-a" . which-key-abort)
>                     ("a" . which-key-abort)
>                     ("\C-d" . which-key-toggle-docstrings)
>                     ("d" . which-key-toggle-docstrings)
>                     (,(vector help-char) . which-key-show-standard-help)
>                     ("h" . which-key-show-standard-help)
>                     ("\C-n" . which-key-show-next-page-cycle)
>                     ("n" . which-key-show-next-page-cycle)
>                     ("\C-p" . which-key-show-previous-page-cycle)
>                     ("p" . which-key-show-previous-page-cycle)
>                     ("\C-u" . which-key-undo-key)
>                     ("u" . which-key-undo-key)
>                     ("1" . which-key-digit-argument)
>                     ("2" . which-key-digit-argument)
>                     ("3" . which-key-digit-argument)
>                     ("4" . which-key-digit-argument)
>                     ("5" . which-key-digit-argument)
>                     ("6" . which-key-digit-argument)
>                     ("7" . which-key-digit-argument)
>                     ("8" . which-key-digit-argument)
>                     ("9" . which-key-digit-argument)))
>       (define-key map (car bind) (cdr bind)))
>     map)
>   "Keymap for C-h commands.")

If this is going to be added to the core, then why not use `defvar-keymap'?

>
> (defvar which-key--paging-functions
>   (list #'which-key-C-h-dispatch
> 	#'which-key-manual-update
> 	#'which-key-turn-page
> 	#'which-key-show-next-page-cycle
> 	#'which-key-show-next-page-no-cycle
> 	#'which-key-show-previous-page-cycle
> 	#'which-key-show-previous-page-no-cycle
> 	#'which-key-undo-key
> 	#'which-key-undo))

Avoid indenting these lines using tabs.

>
> (defvar which-key-persistent-popup nil
>   "Whether or not to disable `which-key--hide-popup'.")
>
> (defcustom which-key-hide-alt-key-translations t
>   "Hide key translations using Alt key if non nil.
> These translations are not relevant most of the times since a lot
> of terminals issue META modifier for the Alt key.
>
> See http://www.gnu.org/software/emacs/manual/html_node/emacs/Modifier-Key=
s.html"

References like these should be replaced by something like "Info node
`(emacs) Modifier Keys'".

>   :group 'which-key
>   :type 'boolean
>   :version "1.0")
>
> (defcustom which-key-delay-functions nil
>   "List of functions that may delay the which-key popup.
> A list of functions that may decide whether to delay the
> which-key popup based on the current incomplete key
> sequence. Each function in the list is run with two arguments,
> the current key sequence as produced by `key-description' and the
> length of the key sequence. If the popup should be delayed based
> on that key sequence, the function should return the delay time
> in seconds. Returning nil means no delay. The first function in
> this list to return a value is the value that is used.
>
> The delay time is effectively added to the normal
> `which-key-idle-delay'."
>   :group 'which-key
>   :type '(repeat function)
>   :version "1.0")
>
> (defcustom which-key-allow-regexps nil
>   "A list of regexp strings to use to filter key sequences.
> When non-nil, for a key sequence to trigger the which-key popup
> it must match one of the regexps in this list.  The format of the
> key sequences is what is produced by `key-description'."
>   :group 'which-key
>   :type '(repeat regexp)
>   :version "1.0")
>
> (defcustom which-key-inhibit-regexps nil
>   "A list of regexp strings to use to filter key sequences.
> When non-nil, for a key sequence to trigger the which-key popup
> it cannot match one of the regexps in this list. The format of
> the key sequences is what is produced by `key-description'."
>   :group 'which-key
>   :type '(repeat regexp)
>   :version "1.0")
>
> (defcustom which-key-show-transient-maps nil
>   "Show keymaps created by `set-transient-map' when applicable.
>
> More specifically, detect when `overriding-terminal-local-map' is
> set (this is the keymap used by `set-transient-map') and display
> it."
>   :group 'which-key
>   :type 'boolean
>   :version "1.0")
>
> (make-obsolete-variable
>  'which-key-enable-extended-define-key
>  "which-key-enable-extended-define-key is obsolete and has no effect."
>  "2021-06-21")
>
> ;; Hooks
> (defcustom which-key-init-buffer-hook '()
>   "Hook run when which-key buffer is initialized."
>   :group 'which-key
>   :type 'hook
>   :version "1.0")
>
> ;;;; Faces
>
> (defgroup which-key-faces nil
>   "Faces for which-key-mode"
>   :group 'which-key
>   :prefix "which-key-")
>
> (defface which-key-key-face
>   '((t . (:inherit font-lock-constant-face)))
>   "Face for which-key keys"
>   :group 'which-key-faces
>   :version "1.0")
>
> (defface which-key-separator-face
>   '((t . (:inherit font-lock-comment-face)))
>   "Face for the separator (default separator is an arrow)"
>   :group 'which-key-faces
>   :version "1.0")
>
> (defface which-key-note-face
>   '((t . (:inherit which-key-separator-face)))
>   "Face for notes or hints occasionally provided"
>   :group 'which-key-faces
>   :version "1.0")
>
> (defface which-key-command-description-face
>   '((t . (:inherit font-lock-function-name-face)))
>   "Face for the key description when it is a command"
>   :group 'which-key-faces
>   :version "1.0")
>
> (defface which-key-local-map-description-face
>   '((t . (:inherit which-key-command-description-face)))
>   "Face for the key description when it is found in `current-local-map'"
>   :group 'which-key-faces
>   :version "1.0")
>
> (defface which-key-highlighted-command-face
>   '((t . (:inherit which-key-command-description-face :underline t)))
>   "Default face for the command description when it is a command
> and it matches a string in `which-key-highlighted-command-list'."
>   :group 'which-key-faces
>   :version "1.0")
>
> (defface which-key-group-description-face
>   '((t . (:inherit font-lock-keyword-face)))
>   "Face for the key description when it is a group or prefix."
>   :group 'which-key-faces
>   :version "1.0")

These were the design-choices you meant above?  I guess we can leave it
for now, I have been planning to work on adding more "semantic" faces,
if I ever get around to that, where after I hope that it should be
obvious what faces to use here.=20

>
> (defface which-key-special-key-face
>   '((t . (:inherit which-key-key-face :inverse-video t :weight bold)))
>   "Face for special keys (SPC, TAB, RET)"
>   :group 'which-key-faces
>   :version "1.0")
>
> (defface which-key-docstring-face
>   '((t . (:inherit which-key-note-face)))
>   "Face for docstrings."
>   :group 'which-key-faces
>   :version "1.0")
>
> ;;;; Custom popup

Shouldn't these options occur earlier in the file, along with the other
user options?

> (defcustom which-key-custom-popup-max-dimensions-function nil
>   "Set a custom max-dimensions function.
> Will be passed the width of the active window and is expected to
> return the maximum height in lines and width in characters of the
> which-key popup in the form a cons cell (height . width)."
>   :group 'which-key
>   :type '(choice function (const nil))
>   :version "1.0")
>
> (defcustom which-key-custom-hide-popup-function nil
>   "Set a custom hide-popup function.
> It takes no arguments and the return value is ignored."
>   :group 'which-key
>   :type '(choice function (const nil))
>   :version "1.0")
>
> (defcustom which-key-custom-show-popup-function nil
>   "Set a custom show-popup function.
> Will be passed the required dimensions in the form (height .
> width) in lines and characters respectively.  The return value is
> ignored."
>   :group 'which-key
>   :type '(choice function (const nil))
>   :version "1.0")
>
> (defcustom which-key-lighter " WK"
>   "Minor mode lighter to use in the mode-line."
>   :group 'which-key
>   :type 'string
>   :version "1.0")
>
> (defvar which-key-inhibit nil
>   "Prevent which-key from popping up momentarily.
> This can be used by setting this to a non-nil value for the
> execution of a command, as in
>
> \(let \(\(which-key-inhibit t\)\)
> ...\)")
>
> (defcustom which-key-inhibit-display-hook nil
>   "Hook run before display of which-key popup.
> Each function in the hook is run before displaying the which-key
> popup. If any function returns a non-nil value, the popup will
> not display."
>   :group 'which-key
>   :type 'hook
>   :version "1.0")
>
> (defvar which-key-keymap-history nil
>   "History of keymap selections.
> Used in functions like `which-key-show-keymap'.")
>
> ;;; Internal Vars
>
> (defvar which-key--buffer nil
>   "Holds reference to which-key buffer.")
> (defvar which-key--timer nil
>   "Holds reference to open window timer.")
> (defvar which-key--secondary-timer-active nil
>   "Non-nil if the secondary timer is active.")
> (defvar which-key--paging-timer nil
>   "Holds reference to timer for paging.")
> (defvar which-key--frame nil
>   "Holds reference to which-key frame.
> Used when `which-key-popup-type' is frame.")
> (defvar which-key--echo-keystrokes-backup nil
>   "Backup the initial value of `echo-keystrokes'.")
> (defvar which-key--prefix-help-cmd-backup nil
>   "Backup the value of `prefix-help-command'.")
> (defvar which-key--last-try-2-loc nil
>   "Last location of side-window when two locations used.")
> (defvar which-key--automatic-display nil
>   "Non-nil if popup was triggered with automatic update.")
> (defvar which-key--debug-buffer-name nil
>   "If non-nil, use this buffer for debug messages.")
> (defvar which-key--multiple-locations nil)
> (defvar which-key--inhibit-next-operator-popup nil)
> (defvar which-key--prior-show-keymap-args nil)
> (defvar which-key--previous-frame-size nil)
> (defvar which-key--prefix-title-alist nil)
> (defvar which-key--evil-keys-regexp (eval-when-compile
>                                       (regexp-opt '("-state"))))
> (defvar which-key--ignore-non-evil-keys-regexp
>   (eval-when-compile
>     (regexp-opt '("mouse-" "wheel-" "remap" "drag-" "scroll-bar"
>                   "select-window" "switch-frame" "which-key"))))

The regexp-opt's in the above lines also don't need the eval-when-compile.

> (defvar which-key--ignore-keys-regexp
>   (regexp-opt '("mouse-" "wheel-" "remap" "drag-" "scroll-bar"
>                 "select-window" "switch-frame" "-state"
>                 "which-key")))
>
> (defvar which-key--pages-obj nil)
> (cl-defstruct which-key--pages
>   pages
>   height
>   widths
>   keys/page
>   page-nums
>   num-pages
>   total-keys
>   prefix
>   prefix-title)
>
> (defvar which-key--saved-window-configuration nil)
>
> (defun which-key--rotate (list n)
>   (let* ((len (length list))
>          (n (if (< n 0) (+ len n) n))
>          (n (mod n len)))
>     (append (last list (- len n)) (butlast list (- len n)))))

This can be slightly simplified to

--8<---------------cut here---------------start------------->8---
(defun which-key--rotate0 (list n)
  (let* ((len (length list))
         (n (- len (mod n len))))
    (append (last list n) (butlast list n))))
--8<---------------cut here---------------end--------------->8---


>
> (defun which-key--pages-set-current-page (pages-obj n)
>   (setf (which-key--pages-pages pages-obj)
>         (which-key--rotate (which-key--pages-pages pages-obj) n))
>   (setf (which-key--pages-widths pages-obj)
>         (which-key--rotate (which-key--pages-widths pages-obj) n))
>   (setf (which-key--pages-keys/page pages-obj)
>         (which-key--rotate (which-key--pages-keys/page pages-obj) n))
>   (setf (which-key--pages-page-nums pages-obj)
>         (which-key--rotate (which-key--pages-page-nums pages-obj) n))
>   pages-obj)
>
> (defsubst which-key--on-first-page ()
>   (=3D (which-key--pages-page-nums which-key--pages-obj) 1))
>
> (defsubst which-key--on-last-page ()
>   (=3D (which-key--pages-page-nums which-key--pages-obj)
>      (which-key--pages-num-pages which-key--pages-obj)))
>
> (defsubst which-key--current-prefix ()
>   (and which-key--pages-obj
>        (which-key--pages-prefix which-key--pages-obj)))
>
> (defmacro which-key--debug-message (&rest msg)
>   `(when which-key--debug-buffer-name
>      (let ((buf (get-buffer-create which-key--debug-buffer-name))
>            (fmt-msg (format ,@msg)))
>        (with-current-buffer buf
>          (goto-char (point-max))
>          (insert "\n" fmt-msg "\n")))))
>
> (defsubst which-key--safe-lookup-key (keymap key)
>   "Version of `lookup-key' that allows KEYMAP to be nil.
> Also convert numeric results of `lookup-key' to nil. KEY is not
> checked."
>   (when (keymapp keymap)
>     (let ((result (lookup-key keymap key)))
>       (when (and result (not (numberp result)))
>         result))))

Arguably you can replace the `when' expression with just (and (not
(numberp result)) result).

>
> (defsubst which-key--safe-lookup-key-description (keymap key)
>   "Version of `lookup-key' that allows KEYMAP to be nil.
> Also convert numeric results of `lookup-key' to nil. KEY
> should be formatted as an input for `kbd'."
>   (let ((key (ignore-errors (kbd key))))
>     (when (and key (keymapp keymap))
>       (let ((result (lookup-key keymap key)))
>         (when (and result (not (numberp result)))
>           result)))))

Here as well.

> ;;; Third-party library support
>
> (defun which-key--this-command-keys ()
>   "Version of `this-single-command-keys' corrected for key-chords."
>   (let ((this-command-keys (this-single-command-keys)))
>     (when (and (vectorp this-command-keys)
>                (> (length this-command-keys) 0)
>                (eq (aref this-command-keys 0) 'key-chord)
>                (bound-and-true-p key-chord-mode))
>       (setq this-command-keys (this-single-command-raw-keys)))
>     this-command-keys))
>
> (defcustom which-key-this-command-keys-function 'which-key--this-command-=
keys
>   "Function used to retrieve current key sequence.
> The purpose of allowing this variable to be customized is to
> allow which-key to support packages that insert non-standard
> 'keys' into the key sequence being read by emacs."
>   :group 'which-key
>   :type 'function
>   :version "1.0")
>
>
> ;;;; Evil
>
> (defvar evil-state nil)
>
> (defcustom which-key-allow-evil-operators (boundp 'evil-this-operator)
>   "Allow popup to show for evil operators.
> The popup is normally inhibited in the middle of commands, but
> setting this to non-nil will override this behavior for evil
> operators."
>   :group 'which-key
>   :type 'boolean
>   :version "1.0")
>
> (defcustom which-key-show-operator-state-maps nil
>   "Show the keys following an evil command that reads a motion.
> These are commands typically mapped to keys such as \"y\", \"d\"
> and \"c\" from normal state. This is experimental, because there
> might be some valid keys missing and it might be showing some
> invalid keys."
>   :group 'which-key
>   :type 'boolean
>   :version "1.0")
>
> (defun which-key-evil-this-operator-p ()
>   (and which-key-allow-evil-operators
>        (bound-and-true-p evil-this-operator)))
>
> (add-hook 'which-key-inhibit-display-hook
>           'which-key-evil-this-operator-p)
>
> ;;;; God-mode
>
> (defvar which-key--god-mode-support-enabled nil
>   "Support god-mode if non-nil.")
>
> (defvar which-key--god-mode-key-string nil
>   "String to use for god-mode support.")
>
> (defun which-key--god-mode-lookup-command-advice (orig-fun arg1 &rest arg=
s)
>   (setq which-key--god-mode-key-string arg1)
>   (unwind-protect
>       (apply orig-fun arg1 args)
>     (when (bound-and-true-p which-key-mode)
>       (which-key--hide-popup))))
>
> (defun which-key--god-mode-this-command-keys ()
>   "Version of `this-single-command-keys' corrected for god-mode."
>   (let ((this-command-keys (this-single-command-keys)))
>     (when (and which-key--god-mode-support-enabled
>                (bound-and-true-p god-local-mode)
>                (eq this-command 'god-mode-self-insert))
>       (setq this-command-keys (when which-key--god-mode-key-string
>                                 (kbd which-key--god-mode-key-string))))
>     this-command-keys))
>
> (defun which-key-god-mode-self-insert-p ()
>   (and which-key--god-mode-support-enabled
>        (bound-and-true-p god-local-mode)
>        (eq this-command 'god-mode-self-insert)))
>
> (defun which-key-enable-god-mode-support (&optional disable)
>   "Enable support for god-mode if non-nil.
> This is experimental, so you need to explicitly opt-in for
> now.  Please report any problems at github.  If DISABLE is non-nil
> disable support."
>   (interactive "P")
>   (setq which-key--god-mode-support-enabled (null disable))
>   (if disable
>       (progn
>         (advice-remove 'god-mode-lookup-command
>                        #'which-key--god-mode-lookup-command-advice)
>         (setq which-key-this-command-keys-function
>               'which-key--this-command-keys)
>         (remove-hook 'which-key-inhibit-display-hook
>                      'which-key-god-mode-self-insert-p))
>     (advice-add 'god-mode-lookup-command :around
>                 #'which-key--god-mode-lookup-command-advice)
>     (setq which-key-this-command-keys-function
>           'which-key--god-mode-this-command-keys)
>     (add-hook 'which-key-inhibit-display-hook
>               'which-key-god-mode-self-insert-p)))
>
> ;;; Mode
>
> ;;;###autoload
> (define-minor-mode which-key-mode
>   "Toggle which-key-mode."
>   :global t
>   :group 'which-key
>   :lighter which-key-lighter
>   :keymap (let ((map (make-sparse-keymap)))
>             (mapc
>              (lambda (prefix)
>                (define-key map
>                  (kbd (concat prefix " " which-key-paging-key))

As mentioned above, if which-key-paging-key were a key, then you could
just just vconcat here, and would reduce the danger of running into
peculiar edge-cases with `kbd'.

>                  #'which-key-C-h-dispatch))
>              which-key-paging-prefixes)
>             map)
>   (if which-key-mode
>       (progn
>         (setq which-key--echo-keystrokes-backup echo-keystrokes)
>         (when (or (eq which-key-show-prefix 'echo)
>                   (eq which-key-popup-type 'minibuffer))
>           (which-key--setup-echo-keystrokes))
>         (unless (member prefix-help-command which-key--paging-functions)
>           (setq which-key--prefix-help-cmd-backup prefix-help-command))
>         (when (or which-key-use-C-h-commands
>                   which-key-show-early-on-C-h)
>           (setq prefix-help-command #'which-key-C-h-dispatch))
>         (when which-key-show-remaining-keys
>           (add-hook 'pre-command-hook #'which-key--lighter-restore))
>         (add-hook 'pre-command-hook #'which-key--hide-popup)
>         (add-hook 'window-size-change-functions
>                   #'which-key--hide-popup-on-frame-size-change)
>         (which-key--start-timer))
>     (setq echo-keystrokes which-key--echo-keystrokes-backup)
>     (when which-key--prefix-help-cmd-backup
>       (setq prefix-help-command which-key--prefix-help-cmd-backup))
>     (when which-key-show-remaining-keys
>       (remove-hook 'pre-command-hook #'which-key--lighter-restore))
>     (remove-hook 'pre-command-hook #'which-key--hide-popup)
>     (remove-hook 'window-size-change-functions
>                  #'which-key--hide-popup-on-frame-size-change)
>     (which-key--stop-timer)))
>
> (defun which-key--init-buffer ()
>   "Initialize which-key buffer"
>   (unless (buffer-live-p which-key--buffer)
>     (setq which-key--buffer (get-buffer-create which-key-buffer-name))
>     (with-current-buffer which-key--buffer
>       ;; suppress confusing minibuffer message
>       (let (message-log-max)

I guess what you want here is to bind `inhibit-message'.

>         (toggle-truncate-lines 1)
>         (message ""))
>       (setq-local cursor-type nil)
>       (setq-local cursor-in-non-selected-windows nil)
>       (setq-local mode-line-format nil)
>       (setq-local header-line-format nil)
>       (setq-local word-wrap nil)
>       (setq-local show-trailing-whitespace nil)

FWIW you can set multiple variables using setq-local in a single
expression.

>       (run-hooks 'which-key-init-buffer-hook))))
>
> (defun which-key--setup-echo-keystrokes ()
>   "Reduce `echo-keystrokes' if necessary.
> It will interfere if set too high."
>   (when (and echo-keystrokes
>              (> (abs (- echo-keystrokes which-key-echo-keystrokes)) 0.000=
001))
>     (if (> which-key-idle-delay which-key-echo-keystrokes)
>         (setq echo-keystrokes which-key-echo-keystrokes)
>       (setq which-key-echo-keystrokes (/ (float which-key-idle-delay) 4)
>             echo-keystrokes which-key-echo-keystrokes))))
>
> (defun which-key-remove-default-unicode-chars ()
>   "Remove default unicode chars from settings.
> Use of `which-key-dont-use-unicode' is preferred to this
> function, but it's included here in case someone cannot set that
> variable early enough in their configuration, if they are using a
> starter kit for example."
>   (when (string-equal which-key-separator " =E2=86=92 ")
>     (setq which-key-separator " : ")))
>
> ;;; Default configuration functions for use by users.
>
> ;;;###autoload
> (defun which-key-setup-side-window-right ()
>   "Set up side-window on right."
>   (interactive)
>   (setq which-key-popup-type 'side-window
>         which-key-side-window-location 'right
>         which-key-show-prefix 'top))
>
> ;;;###autoload
> (defun which-key-setup-side-window-right-bottom ()
>   "Set up side-window on right if space allows.
> Otherwise, use bottom."
>   (interactive)
>   (setq which-key-popup-type 'side-window
>         which-key-side-window-location '(right bottom)
>         which-key-show-prefix 'top))
>
> ;;;###autoload
> (defun which-key-setup-side-window-bottom ()
>   "Set up side-window that opens on bottom."
>   (interactive)
>   (which-key--setup-echo-keystrokes)
>   (setq which-key-popup-type 'side-window
>         which-key-side-window-location 'bottom
>         which-key-show-prefix 'echo))
>
> ;;;###autoload
> (defun which-key-setup-minibuffer ()
>   "Set up minibuffer display.
> Do not use this setup if you use the paging commands.  Instead use
> `which-key-setup-side-window-bottom', which is nearly identical
> but more functional."
>   (interactive)
>   (which-key--setup-echo-keystrokes)
>   (setq which-key-popup-type 'minibuffer
>         which-key-show-prefix 'left))
>
> ;;; Helper functions to modify replacement lists.
>
> ;;;###autoload
> (defun which-key-add-keymap-based-replacements (keymap key replacement &r=
est more)
>   "Replace the description of KEY using REPLACEMENT in KEYMAP.
> KEY should take a format suitable for use in `kbd'. REPLACEMENT
> should be a cons cell of the form \(STRING . COMMAND\) for each
> REPLACEMENT, where STRING is the replacement string and COMMAND
> is a symbol corresponding to the intended command to be
> replaced. COMMAND can be nil if the binding corresponds to a key
> prefix. An example is
>
> \(which-key-add-keymap-based-replacements global-map
>   \"C-x w\" \\=3D'\(\"Save as\" . write-file\)\).
>
> For backwards compatibility, REPLACEMENT can also be a string,
> but the above format is preferred, and the option to use a string
> for REPLACEMENT will eventually be removed."
>   (while key
>     (let ((def
>            (cond
>             ((consp replacement) replacement)
>             ((stringp replacement)
>              (cons replacement
>                    (or (which-key--safe-lookup-key-description keymap key)
>                        (make-sparse-keymap))))
>             (t
>              (user-error "Replacement is neither a cons cell or a string"=
)))))
>       (define-key keymap (kbd key) def))
>     (setq key (pop more)
>           replacement (pop more))))
> (put 'which-key-add-keymap-based-replacements 'lisp-indent-function 'defu=
n)

Replace this with a

  (declare (indent defun))

at the beginning of the function definition.

>
> ;;;###autoload
> (defun which-key-add-key-based-replacements
>     (key-sequence replacement &rest more)
>   "Replace the description of KEY-SEQUENCE with REPLACEMENT.
> KEY-SEQUENCE is a string suitable for use in `kbd'. REPLACEMENT
> may either be a string, as in
>
> \(which-key-add-key-based-replacements \"C-x 1\" \"maximize\"\)
>
> a cons of two strings as in
>
> \(which-key-add-key-based-replacements \"C-x 8\"
>                                         \\=3D'(\"unicode\" . \"Unicode ke=
ys\")\)
>
> or a function that takes a \(KEY . BINDING\) cons and returns a
> replacement.
>
> In the second case, the second string is used to provide a longer
> name for the keys under a prefix.
>
> MORE allows you to specifcy additional KEY REPLACEMENT pairs.  All
> replacements are added to `which-key-replacement-alist'."
>   ;; TODO: Make interactive
>   (while key-sequence
>     ;; normalize key sequences before adding
>     (let ((key-seq (key-description (kbd key-sequence)))
>           (replace (or (and (functionp replacement) replacement)
>                        (car-safe replacement)
>                        replacement)))
>       (push (cons (cons (concat "\\`" (regexp-quote key-seq) "\\'") nil)
>                   (if (functionp replace) replace (cons nil replace)))
>             which-key-replacement-alist)
>       (when (and (not (functionp replacement)) (consp replacement))
>         (push (cons key-seq (cdr-safe replacement))
>               which-key--prefix-title-alist)))
>     (setq key-sequence (pop more) replacement (pop more))))
> (put 'which-key-add-key-based-replacements 'lisp-indent-function 'defun)

Here as well.

>
> ;;;###autoload
> (defun which-key-add-major-mode-key-based-replacements
>     (mode key-sequence replacement &rest more)
>   "Functions like `which-key-add-key-based-replacements'.
> The difference is that MODE specifies the `major-mode' that must
> be active for KEY-SEQUENCE and REPLACEMENT (MORE contains
> addition KEY-SEQUENCE REPLACEMENT pairs) to apply."
>   (declare (indent defun))

... as has been done here!

>   ;; TODO: Make interactive

Should this be resolved?

>   (when (not (symbolp mode))
>     (error "MODE should be a symbol corresponding to a value of major-mod=
e"))

Why not mention the mode in the error message?

  (error "`%S' should be a symbol corresponding to a value of major-mode" m=
ode)

>   (let ((mode-alist
>          (or (cdr-safe (assq mode which-key-replacement-alist)) (list)))
>         (title-mode-alist
>          (or (cdr-safe (assq mode which-key--prefix-title-alist)) (list))=
))
>     (while key-sequence
>       ;; normalize key sequences before adding
>       (let ((key-seq (key-description (kbd key-sequence)))
>             (replace (or (and (functionp replacement) replacement)
>                          (car-safe replacement)
>                          replacement)))
>         (push (cons (cons (concat "\\`" (regexp-quote key-seq) "\\'") nil)
>                     (if (functionp replace) replace (cons nil replace)))
>               mode-alist)
>         (when (and (not (functionp replacement)) (consp replacement))
>           (push (cons key-seq (cdr-safe replacement))
>                 title-mode-alist)))
>       (setq key-sequence (pop more) replacement (pop more)))
>     (if (assq mode which-key-replacement-alist)
>         (setcdr (assq mode which-key-replacement-alist) mode-alist)
>       (push (cons mode mode-alist) which-key-replacement-alist))
>     (if (assq mode which-key--prefix-title-alist)
>         (setcdr (assq mode which-key--prefix-title-alist) title-mode-alis=
t)
>       (push (cons mode title-mode-alist) which-key--prefix-title-alist))))
>
> (defun which-key-define-key-recursively (map key def &optional at-root)
>   "Recursively bind KEY in MAP to DEF on every level of MAP except the fi=
rst.
> If AT-ROOT is non-nil the binding is also placed at the root of MAP."
>   (when at-root (define-key map key def))
>   (map-keymap
>    (lambda (_ev df)
>      (when (keymapp df)
>        (which-key-define-key-recursively df key def t)))
>    map))
>
> ;;; Functions for computing window sizes
>
> (defun which-key--text-width-to-total (text-width)
>   "Convert window TEXT-WIDTH to window total-width.
> TEXT-WIDTH is the desired text width of the window.  The function
> calculates what total width is required for a window in the
> selected to have a text-width of TEXT-WIDTH columns.  The
> calculation considers possible fringes and scroll bars.  This
> function assumes that the desired window has the same character
> width as the frame."
>   (let ((char-width (frame-char-width)))
>     (+ text-width
>        (/ (frame-fringe-width) char-width)
>        (/ (frame-scroll-bar-width) char-width)
>        (if (which-key--char-enlarged-p) 1 0)
>        ;; add padding to account for possible wide (unicode) characters
>        3)))
>
> (defun which-key--total-width-to-text (total-width)
>   "Convert window TOTAL-WIDTH to window text-width.
> TOTAL-WIDTH is the desired total width of the window.  The function calcu=
lates
> what text width fits such a window.  The calculation considers possible f=
ringes
> and scroll bars.  This function assumes that the desired window has the s=
ame
> character width as the frame."
>   (let ((char-width (frame-char-width)))
>     (- total-width
>        (/ (frame-fringe-width) char-width)
>        (/ (frame-scroll-bar-width) char-width)
>        (if (which-key--char-enlarged-p) 1 0)
>        ;; add padding to account for possible wide (unicode) characters
>        3)))
>
> (defun which-key--char-enlarged-p (&optional _frame)
>   (> (frame-char-width)
>      (/ (float (frame-pixel-width)) (window-total-width (frame-root-windo=
w)))))
>
> (defun which-key--char-reduced-p (&optional _frame)
>   (< (frame-char-width)
>      (/ (float (frame-pixel-width)) (window-total-width (frame-root-windo=
w)))))
>
> (defun which-key--char-exact-p (&optional _frame)
>   (=3D (frame-char-width)
>      (/ (float (frame-pixel-width)) (window-total-width (frame-root-windo=
w)))))
>
> (defun which-key--width-or-percentage-to-width (width-or-percentage)
>   "Return window total width.
> If WIDTH-OR-PERCENTAGE is a whole number, return it unchanged.  Otherwise=
, it
> should be a percentage (a number between 0 and 1) out of the frame's widt=
h.
> More precisely, it should be a percentage out of the frame's root window's
> total width."
>   (if (wholenump width-or-percentage)

I personally find wholenump confusing, due to the apparent ambiguity as
to what a "whole number" is (whether they are integers or naturals).
E.g. (wholenump -3) returns nil, because it is just an alias for
`natnump'.  Hence I recommend using `natnump'.

>       width-or-percentage
>     (round (* width-or-percentage (window-total-width (frame-root-window)=
)))))
>
> (defun which-key--height-or-percentage-to-height (height-or-percentage)
>   "Return window total height.
> If HEIGHT-OR-PERCENTAGE is a whole number, return it unchanged.  Otherwis=
e, it
> should be a percentage (a number between 0 and 1) out of the frame's heig=
ht.
> More precisely, it should be a percentage out of the frame's root window's
> total height."
>   (if (wholenump height-or-percentage)
>       height-or-percentage
>     (round (* height-or-percentage (window-total-height (frame-root-windo=
w))))))
>
> (defun which-key--frame-size-changed-p ()
>   "Non-nil if a change in frame size is detected."
>   (let ((new-size (cons (frame-width) (frame-height))))
>     (cond ((null which-key--previous-frame-size)
>            (setq which-key--previous-frame-size new-size)
>            nil)
>           ((not (equal which-key--previous-frame-size new-size))
>            (setq which-key--previous-frame-size new-size)))))
>
> ;;; Show/hide which-key buffer
>
> (defun which-key--hide-popup ()
>   "This function is called to hide the which-key buffer."
>   (unless (or which-key-persistent-popup
>               (member real-this-command which-key--paging-functions))
>     (setq which-key--last-try-2-loc nil)
>     (setq which-key--pages-obj nil)
>     (setq which-key--automatic-display nil)
>     (setq which-key--prior-show-keymap-args nil)
>     (when (and which-key-idle-secondary-delay which-key--secondary-timer-=
active)
>       (which-key--start-timer))
>     (which-key--lighter-restore)
>     (which-key--hide-popup-ignore-command)))
>
> (defun which-key--hide-popup-ignore-command ()
>   "`which-key--hide-popup' without the check of `real-this-command'."
>   (cl-case which-key-popup-type
>     ;; Not necessary to hide minibuffer
>     ;; (minibuffer (which-key--hide-buffer-minibuffer))
>     (side-window (which-key--hide-buffer-side-window))
>     (frame (which-key--hide-buffer-frame))
>     (custom (funcall which-key-custom-hide-popup-function))))
>
> (defun which-key--hide-popup-on-frame-size-change (&optional _)
>   "Hide which-key popup if the frame is resized (to trigger a new popup)."
>   (when (which-key--frame-size-changed-p)
>     (which-key--hide-popup)))
>
> (defun which-key--hide-buffer-side-window ()
>   "Hide which-key buffer when side-window popup is used."
>   (when (buffer-live-p which-key--buffer)
>     ;; in case which-key buffer was shown in an existing window, `quit-wi=
ndow'
>     ;; will re-show the previous buffer, instead of closing the window
>     (quit-windows-on which-key--buffer)
>     (when (and which-key-preserve-window-configuration
>                which-key--saved-window-configuration)
>       (set-window-configuration which-key--saved-window-configuration)
>       (setq which-key--saved-window-configuration nil))))
>
> (defun which-key--hide-buffer-frame ()
>   "Hide which-key buffer when frame popup is used."
>   (when (frame-live-p which-key--frame)
>     (delete-frame which-key--frame)))
>
> (defun which-key--popup-showing-p ()
>   (and (bufferp which-key--buffer)
>        (or (window-live-p (get-buffer-window which-key--buffer))
>            (let ((window (get-buffer-window which-key--buffer t)))
>              (and (window-live-p window)
>                   (frame-visible-p (window-frame window)))))))
>
> (defun which-key--show-popup (act-popup-dim)
>   "Show the which-key buffer.
> ACT-POPUP-DIM includes the dimensions, (height . width) of the
> buffer text to be displayed in the popup.  Return nil if no window
> is shown, or if there is no need to start the closing timer."
>   (when (and (> (car act-popup-dim) 0)
>              (> (cdr act-popup-dim) 0))
>     (cl-case which-key-popup-type
>       ;; Not called for minibuffer
>       ;; (minibuffer (which-key--show-buffer-minibuffer act-popup-dim))
>       (side-window (which-key--show-buffer-side-window act-popup-dim))
>       (frame (which-key--show-buffer-frame act-popup-dim))
>       (custom (funcall which-key-custom-show-popup-function act-popup-dim=
)))))
>
> (defun which-key--fit-buffer-to-window-horizontally
>     (&optional window &rest params)
>   "Slightly modified version of `fit-buffer-to-window'.
> Use &rest params because `fit-buffer-to-window' has a different
> call signature in different emacs versions"
>   (let ((fit-window-to-buffer-horizontally t)
>         (window-min-height 1))
>     (apply #'fit-window-to-buffer window params)))
>
> (defun which-key--show-buffer-side-window (act-popup-dim)
>   "Show which-key buffer when popup type is side-window."
>   (when (and which-key-preserve-window-configuration
>              (not which-key--saved-window-configuration))
>     (setq which-key--saved-window-configuration (current-window-configura=
tion)))
>   (let* ((height (car act-popup-dim))
>          (width (cdr act-popup-dim))
>          (alist
>           (if which-key-allow-imprecise-window-fit
>               `((window-width .  ,(which-key--text-width-to-total width))
>                 (window-height . ,height)
>                 (side . ,which-key-side-window-location)
>                 (slot . ,which-key-side-window-slot))
>             `((window-width . which-key--fit-buffer-to-window-horizontall=
y)
>               (window-height . (lambda (w) (fit-window-to-buffer w nil 1)=
))
>               (side . ,which-key-side-window-location)
>               (slot . ,which-key-side-window-slot)))))
>     ;; Previously used `display-buffer-in-major-side-window' here, but
>     ;; apparently that is meant to be an internal function. See emacs bug=
 #24828
>     ;; and advice given there.
>     (cond
>      ((eq which-key--multiple-locations t)
>       ;; possibly want to switch sides in this case so we can't reuse the=
 window
>       (delete-windows-on which-key--buffer)
>       (display-buffer-in-side-window which-key--buffer alist))
>      ((get-buffer-window which-key--buffer)
>       (display-buffer-reuse-window which-key--buffer alist))
>      (t
>       (display-buffer-in-side-window which-key--buffer alist)))))
>
> (defun which-key--show-buffer-frame (act-popup-dim)
>   "Show which-key buffer when popup type is frame."
>   (let* (;(orig-window (selected-window))
>          (frame-height (+ (car act-popup-dim)
>                           (if (with-current-buffer which-key--buffer
>                                 mode-line-format)
>                               1
>                             0)))
>          ;; without adding 2, frame sometimes isn't wide enough for the b=
uffer.
>          ;; this is probably because of the fringes. however, setting fri=
nges
>          ;; sizes to 0 (instead of adding 2) didn't always make the frame=
 wide
>          ;; enough. don't know why it is so.
>          (frame-width (+ (cdr act-popup-dim) 2))
>          (new-window (if (and (frame-live-p which-key--frame)
>                               (eq which-key--buffer
>                                   (window-buffer
>                                    (frame-root-window which-key--frame))))
>                          (which-key--show-buffer-reuse-frame
>                           frame-height frame-width)
>                        (which-key--show-buffer-new-frame
>                         frame-height frame-width))))
>     (when new-window
>       ;; display successful
>       (setq which-key--frame (window-frame new-window))
>       new-window)))
>
> (defun which-key--show-buffer-new-frame (frame-height frame-width)
>   "Helper for `which-key--show-buffer-frame'."
>   (let* ((frame-params `((height . ,frame-height)
>                          (width . ,frame-width)
>                          ;; tell the window manager to respect the given =
sizes
>                          (user-size . t)
>                          ;; which-key frame doesn't need a minibuffer
>                          (minibuffer . nil)
>                          (name . "which-key")
>                          ;; no need for scroll bars in which-key frame
>                          (vertical-scroll-bars . nil)
>                          ;; (left-fringe . 0)
>                          ;; (right-fringe . 0)
>                          ;; (right-divider-width . 0)
>                          ;; make sure frame is visible
>                          (visibility . t)))
>          (alist `((pop-up-frame-parameters . ,frame-params)))
>          (orig-frame (selected-frame))
>          (new-window (display-buffer-pop-up-frame which-key--buffer alist=
)))
>     (when new-window
>       ;; display successful
>       (redirect-frame-focus (window-frame new-window) orig-frame)
>       new-window)))
>
> (defun which-key--show-buffer-reuse-frame (frame-height frame-width)
>   "Helper for `which-key--show-buffer-frame'."
>   (let ((window
>          (display-buffer-reuse-window
>           which-key--buffer `((reusable-frames . ,which-key--frame)))))
>     (when window
>       ;; display successful
>       (set-frame-size (window-frame window) frame-width frame-height)
>       window)))
>
> ;;; Max dimension of available window functions
>
> (defun which-key--popup-max-dimensions ()
>   "Return maximum dimension available for popup.
> Dimesion functions should return the maximum possible (height
> . width) of the intended popup. SELECTED-WINDOW-WIDTH is the
> width of currently active window, not the which-key buffer
> window."
>   (cl-case which-key-popup-type

Should this be an cl-ecase?

>     (minibuffer (which-key--minibuffer-max-dimensions))
>     (side-window (which-key--side-window-max-dimensions))
>     (frame (which-key--frame-max-dimensions))
>     (custom (funcall which-key-custom-popup-max-dimensions-function
>                      (window-width)))))
>
> (defun which-key--minibuffer-max-dimensions ()
>   "Return max-dimensions of minibuffer (height . width).
> Measured in lines and characters respectively."
>   (cons
>    ;; height
>    (if (floatp max-mini-window-height)
>        (floor (* (frame-text-lines)
>                  max-mini-window-height))
>      max-mini-window-height)
>    ;; width
>    (max 0 (- (frame-text-cols) which-key-unicode-correction))))
>
> (defun which-key--side-window-max-dimensions ()
>   "Return max-dimensions of the side-window popup.
> The return value should be (height . width) in lines and
> characters respectively."
>   (cons
>    ;; height
>    (if (member which-key-side-window-location '(left right))
>        ;; 1 is a kludge to make sure there is no overlap
>        (- (frame-height) (window-text-height (minibuffer-window)) 1)
>      ;; (window-mode-line-height which-key--window))
>      ;; FIXME: change to something like
>      ;; (min which-*-height (calculate-max-height))
>      (which-key--height-or-percentage-to-height
>       which-key-side-window-max-height))
>    ;; width
>    (max 0
>         (- (if (memq which-key-side-window-location '(left right))
>                (which-key--total-width-to-text
>                 (which-key--width-or-percentage-to-width
>                  which-key-side-window-max-width))
>              (which-key--total-width-to-text
>               (which-key--width-or-percentage-to-width
>                1.0)))
>            which-key-unicode-correction))))
>
> (defun which-key--frame-max-dimensions ()
>   "Return max-dimensions of the frame popup.
> The return value should be (height . width) in lines and
> characters respectively."
>   (cons which-key-frame-max-height which-key-frame-max-width))
>
> ;;; Sorting functions
>
> (defun which-key--string< (a b &optional alpha)
>   (let ((da (downcase a))
>         (db (downcase b)))
>     (cond
>      ((and alpha (not which-key-sort-uppercase-first))
>       (if (string-equal da db)
>           (not (string-lessp a b))
>         (string-lessp da db)))
>      ((and alpha which-key-sort-uppercase-first)
>       (if (string-equal da db)
>           (string-lessp a b)
>         (string-lessp da db)))
>      ((not which-key-sort-uppercase-first)
>       (let ((aup (not (string-equal da a)))
>             (bup (not (string-equal db b))))
>         (if (eq aup bup)
>             (string-lessp a b)
>           bup)))
>      (t (string-lessp a b)))))
>
> (defun which-key--key-description< (a b &optional alpha)
>   "Key sorting function.
> Used for `which-key-key-order' and `which-key-key-order-alpha'."
>   (save-match-data
>     (let* ((a (which-key--extract-key a))
>            (b (which-key--extract-key b))
>            (rngrgxp "^\\([^ ]+\\) \\.\\. [^ ]+")
>            (a (if (string-match rngrgxp a) (match-string 1 a) a))
>            (b (if (string-match rngrgxp b) (match-string 1 b) b))
>            (aem? (string-equal a ""))
>            (bem? (string-equal b ""))
>            (a1? (=3D 1 (length a)))
>            (b1? (=3D 1 (length b)))
>            (srgxp "^\\(RET\\|SPC\\|TAB\\|DEL\\|LFD\\|ESC\\|NUL\\)")
>            (asp? (string-match-p srgxp a))
>            (bsp? (string-match-p srgxp b))
>            (prrgxp "^\\(M\\|C\\|S\\|A\\|H\\|s\\)-")
>            (apr? (string-match-p prrgxp a))
>            (bpr? (string-match-p prrgxp b))
>            (afn? (string-match-p "<f[0-9]+>" a))
>            (bfn? (string-match-p "<f[0-9]+>" b)))
>       (cond ((or aem? bem?) (and aem? (not bem?)))
>             ((and asp? bsp?)
>              (if (string-equal (substring a 0 3) (substring b 0 3))
>                  (which-key--key-description<
>                   (substring a 3) (substring b 3) alpha)
>                (which-key--string< a b alpha)))
>             ((or asp? bsp?) asp?)
>             ((and a1? b1?) (which-key--string< a b alpha))
>             ((or a1? b1?) a1?)
>             ((and afn? bfn?)
>              (< (string-to-number
>                  (replace-regexp-in-string "<f\\([0-9]+\\)>" "\\1" a))
>                 (string-to-number
>                  (replace-regexp-in-string "<f\\([0-9]+\\)>" "\\1" b))))
>             ((or afn? bfn?) afn?)
>             ((and apr? bpr?)
>              (if (string-equal (substring a 0 2) (substring b 0 2))
>                  (which-key--key-description<
>                   (substring a 2) (substring b 2) alpha)
>                (which-key--string< a b alpha)))
>             ((or apr? bpr?) apr?)
>             (t (which-key--string< a b alpha))))))
>
> (defsubst which-key-key-order-alpha (acons bcons)
>   "Order key descriptions A and B.
> Order is lexicographic within a \"class\", where the classes and
> the ordering of classes are listed below.
>
> special (SPC,TAB,...) < single char < mod (C-,M-,...) < other.
> Sorts single characters alphabetically with lowercase coming
> before upper."
>   (which-key--key-description< (car acons) (car bcons) t))
>
> (defsubst which-key-key-order (acons bcons)
>   "Order key descriptions A and B.
> Order is lexicographic within a \"class\", where the classes and
> the ordering of classes are listed below.
>
> special (SPC,TAB,...) < single char < mod (C-,M-,...) < other."
>   (which-key--key-description< (car acons) (car bcons)))
>
> (defsubst which-key-description-order (acons bcons)
>   "Order descriptions of A and B.
> Uses `string-lessp' after applying lowercase."
>   (string-lessp (downcase (cdr acons)) (downcase (cdr bcons))))
>
> (defsubst which-key--group-p (description)
>   (or (string-equal description "prefix")
>       (string-match-p "^group:" description)
>       (keymapp (intern description))))
>
> (defun which-key-prefix-then-key-order (acons bcons)
>   "Order prefixes before non-prefixes.
> Within these categories order using `which-key-key-order'."
>   (let ((apref? (which-key--group-p (cdr acons)))
>         (bpref? (which-key--group-p (cdr bcons))))
>     (if (not (eq apref? bpref?))
>         (and (not apref?) bpref?)
>       (which-key-key-order acons bcons))))
>
> (defun which-key-prefix-then-key-order-reverse (acons bcons)
>   "Order prefixes before non-prefixes.
> Within these categories order using `which-key-key-order'."
>   (let ((apref? (which-key--group-p (cdr acons)))
>         (bpref? (which-key--group-p (cdr bcons))))
>     (if (not (eq apref? bpref?))
>         (and apref? (not bpref?))
>       (which-key-key-order acons bcons))))
>
> (defun which-key-local-then-key-order (acons bcons)
>   "Order local bindings before non-local ones.
> Within these categories order using `which-key-key-order'."
>   (let ((aloc? (which-key--local-binding-p acons))
>         (bloc? (which-key--local-binding-p bcons)))
>     (if (not (eq aloc? bloc?))
>         (and aloc? (not bloc?))
>       (which-key-key-order acons bcons))))
>
> ;;; Functions for retrieving and formatting keys
>
> (defsubst which-key--string-width (maybe-string)
>   "If MAYBE-STRING is a string use `which-key--string-width' o/w return 0=
."
>   (if (stringp maybe-string) (string-width maybe-string) 0))
>
> (defsubst which-key--butlast-string (str)
>   (string-join (butlast (split-string str)) " "))
>
> (defun which-key--match-replacement (key-binding replacement)
>   ;; these are mode specific ones to ignore. The mode specific case is
>   ;; handled in the selection of alist
>   (when (and (consp key-binding) (not (symbolp (car replacement))))
>     (let ((key-regexp (caar replacement))
>           (binding-regexp (cdar replacement))
>           case-fold-search)

I think an explicit binding of nil would be nice here, from a
readability standpoint.

>       (and (or (null key-regexp)
>                (string-match-p key-regexp
>                                (car key-binding)))
>            (or (null binding-regexp)
>                (string-match-p binding-regexp
>                                (cdr key-binding)))))))
>
> (defsubst which-key--replace-in-binding (key-binding repl)
>   (cond ((or (not (consp repl)) (null (cdr repl)))
>          key-binding)
>         ((functionp (cdr repl))
>          (funcall (cdr repl) key-binding))
>         ((consp (cdr repl))
>          (cons
>           (cond ((and (caar repl) (cadr repl))
>                  (replace-regexp-in-string
>                   (caar repl) (cadr repl) (car key-binding) t))
>                 ((cadr repl) (cadr repl))
>                 (t (car key-binding)))
>           (cond ((and (cdar repl) (cddr repl))
>                  (replace-regexp-in-string
>                   (cdar repl) (cddr repl) (cdr key-binding) t))
>                 ((cddr repl) (cddr repl))
>                 (t (cdr key-binding)))))))
>
> (defun which-key--replace-in-repl-list-once (key-binding repls)
>   (cl-dolist (repl repls)
>     (when (which-key--match-replacement key-binding repl)
>       (cl-return `(replaced . ,(which-key--replace-in-binding key-binding=
 repl))))))
>
> (defun which-key--replace-in-repl-list-many (key-binding repls)
>   (let (found)
>     (dolist (repl repls)
>       (when (which-key--match-replacement key-binding repl)
>         (setq found 't)

Don't quote t.

>         (setq key-binding (which-key--replace-in-binding key-binding repl=
))))
>     (when found `(replaced . ,key-binding))))
>
> (defun which-key--maybe-replace (key-binding)
>   "Use `which-key--replacement-alist' to maybe replace KEY-BINDING.
> KEY-BINDING is a cons cell of the form \(KEY . BINDING\) each of
> which are strings.  KEY is of the form produced by `key-binding'."
>   (let* ((replacer (if which-key-allow-multiple-replacements
>                        #'which-key--replace-in-repl-list-many
>                      #'which-key--replace-in-repl-list-once)))
>     (pcase

Here also, `pcase-exhaustive'?

>         (apply replacer
>                (list key-binding
>                      (cdr-safe (assq major-mode which-key-replacement-ali=
st))))
>       (`(replaced . ,repl)
>        (if which-key-allow-multiple-replacements
>            (pcase (apply replacer (list repl which-key-replacement-alist))
>              (`(replaced . ,repl) repl)
>              ('() repl))
>          repl))
>       ('()
>        (pcase (apply replacer (list key-binding which-key-replacement-ali=
st))
>          (`(replaced . ,repl) repl)
>          ('() key-binding))))))
>
> (defsubst which-key--current-key-list (&optional key-str)
>   (append (listify-key-sequence (which-key--current-prefix))
>           (when key-str
>             (listify-key-sequence (kbd key-str)))))
>
> (defsubst which-key--current-key-string (&optional key-str)
>   (key-description (which-key--current-key-list key-str)))
>
> (defun which-key--local-binding-p (keydesc)
>   (eq (which-key--safe-lookup-key-description
>        (current-local-map)
>        (which-key--current-key-string (car keydesc)))
>       (intern (cdr keydesc))))
>
> (defun which-key--map-binding-p (map keydesc)
>   "Does MAP contain KEYDESC =3D (key . binding)?"
>   (or
>    (when (bound-and-true-p evil-state)
>      (let ((lookup
>             (which-key--safe-lookup-key-description
>              map
>              (which-key--current-key-string
>               (format "<%s-state> %s" evil-state (car keydesc))))))
>        (or (eq lookup (intern (cdr keydesc)))
>            (and (keymapp lookup) (string=3D (cdr keydesc) "Prefix Command=
")))))
>    (let ((lookup
>           (which-key--safe-lookup-key-description
>            map (which-key--current-key-string (car keydesc)))))
>      (or (eq lookup (intern (cdr keydesc)))
>          (and (keymapp lookup) (string=3D (cdr keydesc) "Prefix Command")=
)))))
>
> (defun which-key--maybe-get-prefix-title (keys)
>   "KEYS is a string produced by `key-description'.
> A title is possibly returned using
> `which-key--prefix-title-alist'.  An empty string is returned if
> no title exists."
>   (cond
>    ((not (string-equal keys ""))
>     (let* ((title-res
>             (cdr-safe (assoc-string keys which-key--prefix-title-alist)))
>            (repl-res
>             (cdr-safe (which-key--maybe-replace (cons keys ""))))
>            (binding (key-binding (kbd keys)))
>            (alternate (when (and binding (symbolp binding))
>                         (symbol-name binding))))
>       (cond (title-res title-res)
>             ((not (string-equal repl-res "")) repl-res)

See also `string-empty-p'.

>             ((and (eq which-key-show-prefix 'echo) alternate)
>              alternate)
>             ((and (member which-key-show-prefix '(bottom top mode-line))
>                   (eq which-key-side-window-location 'bottom)
>                   echo-keystrokes)
>              (if alternate alternate
>                (concat "Following " keys)))
>             (t ""))))
>    (t "")))
>
> (defun which-key--propertize (string &rest properties)
>   "Version of `propertize' that checks type of STRING."
>   (when (stringp string)
>     (apply #'propertize string properties)))

Is there any place where tolerating STRING being nil is used?  It seems
to me like the kind of thing, that could easily let bugs slip by
unnoticed and pop up later.

>
> (defun which-key--propertize-key (key)
>   "Add a face to KEY.
> If KEY contains any \"special keys\" defined in
> `which-key-special-keys' then truncate and add the corresponding
> `which-key-special-key-face'."
>   (let ((key-w-face (which-key--propertize key 'face 'which-key-key-face))
>         (regexp (concat "\\("
>                         (mapconcat #'identity which-key-special-keys
>                                    "\\|")
>                         "\\)"))
>         case-fold-search)

Here also binding nil explicitly would be nice.

>     (save-match-data
>       (if (and which-key-special-keys
>                (string-match regexp key))
>           (let ((beg (match-beginning 0)) (end (match-end 0)))
>             (concat (substring key-w-face 0 beg)
>                     (which-key--propertize (substring key-w-face beg (1+ =
beg))
>                                            'face 'which-key-special-key-f=
ace)
>                     (substring key-w-face end
>                                (which-key--string-width key-w-face))))
>         key-w-face))))
>
> (defsubst which-key--truncate-description (desc avl-width)
>   "Truncate DESC description to `which-key-max-description-length'."
>   (let* ((max which-key-max-description-length)
> 	 (max (cl-etypecase max
> 		(null nil)
> 		(integer max)
> 		(float (truncate (* max avl-width)))
> 		(function (let ((val (funcall max avl-width)))
> 			    (if (floatp val) (truncate val) val))))))
>     (if (and max (> (length desc) max))
>         (let ((dots (and (not (equal which-key-ellipsis ""))
> 			 (which-key--propertize
> 			  which-key-ellipsis 'face
> 			  (get-text-property (1- (length desc)) 'face desc)))))
> 	  (if dots
>               (concat (substring desc 0 (- max (length dots))) dots)
> 	    (substring desc 0 max)))
>       desc)))

There are also tabs here that should be replaced.

>
> (defun which-key--highlight-face (description)
>   "Return the highlight face for DESCRIPTION if it has one."
>   (let (face)
>     (dolist (el which-key-highlighted-command-list)
>       (unless face
>         (cond ((consp el)
>                (when (string-match-p (car el) description)
>                  (setq face (cdr el))))
>               ((stringp el)
>                (when (string-match-p el description)
>                  (setq face 'which-key-highlighted-command-face)))
>               (t
>                (message "which-key: warning: element %s of \
> which-key-highlighted-command-list is not a string or a cons
> cell" el)))))
>     face))
>
> (defun which-key--propertize-description
>     (description group local hl-face &optional original-description)
>   "Add face to DESCRIPTION.
> The face chosen depends on whether the description represents a
> group or a command. Also make some minor adjustments to the
> description string, like removing a \"group:\" prefix.
>
> ORIGINAL-DESCRIPTION is the description given by
> `describe-buffer-bindings'."
>   (when description
>     (let* ((desc description)
>            (desc (if (string-match-p "^group:" desc)
>                      (substring desc 6) desc))
>            (desc (if group (concat which-key-prefix-prefix desc) desc)))
>       (make-text-button
>        desc nil
>        'face (cond (hl-face hl-face)
>                    (group 'which-key-group-description-face)
>                    (local 'which-key-local-map-description-face)
>                    (t 'which-key-command-description-face))
>        'help-echo (cond
>                    ((and original-description
>                          (fboundp (intern original-description))
>                          (documentation (intern original-description))
>                          ;; tooltip-mode doesn't exist in emacs-nox
>                          (boundp 'tooltip-mode) tooltip-mode)
>                     (documentation (intern original-description)))
>                    ((and original-description
>                          (fboundp (intern original-description))
>                          (documentation (intern original-description))
>                          (let* ((doc (documentation
>                                       (intern original-description)))
>                                 (str (replace-regexp-in-string "\n" " " d=
oc))
>                                 (max (floor (* (frame-width) 0.8))))
>                            (if (> (length str) max)
>                                (concat (substring str 0 max) "...")
>                              str)))))))))
>
> (defun which-key--extract-key (key-str)
>   "Pull the last key (or key range) out of KEY-STR."
>   (save-match-data
>     (let ((key-range-regexp "\\`.*\\([^ \t]+ \\.\\. [^ \t]+\\)\\'"))
>       (if (string-match key-range-regexp key-str)
>           (match-string 1 key-str)
>         (car (last (split-string key-str " ")))))))
>
> (defun which-key--maybe-add-docstring (current original)
>   "Maybe concat a docstring to CURRENT and return result.
> Specifically, do this if ORIGINAL is a command with a docstring
> and `which-key-show-docstrings' is non-nil.  If
> `which-key-show-docstrings' is the symbol docstring-only, just
> return the docstring."
>   (let* ((orig-sym (intern original))
>          (doc (when (commandp orig-sym)
>                 (documentation orig-sym)))
>          (doc (when doc
>                 (replace-regexp-in-string
>                  (concat "^\\(?::"
>                          (regexp-opt '("around" "override"
>                                        "after" "after-until" "after-while"
>                                        "before" "before-until" "before-wh=
ile"
>                                        "filter-args" "filter-return"))
>                          " advice: [^\n]+\n"
>                          "\\)+\n")
>                  "" doc)))
>          (docstring (when doc
>                       (which-key--propertize (car (split-string doc "\n"))
>                                              'face 'which-key-docstring-f=
ace))))
>     (cond ((not (and which-key-show-docstrings docstring))
>            current)
>           ((eq which-key-show-docstrings 'docstring-only)
>            docstring)
>           (t
>            (format "%s %s" current docstring)))))
>
> (defun which-key--format-and-replace (unformatted &optional preserve-full=
-key)
>   "Make list of key bindings with separators and descriptions.
> Take a list of (key . desc) cons cells in UNFORMATTED, add
> faces and perform replacements according to the three replacement
> alists. Returns a list (key separator description)."
>   (let ((sep-w-face
>          (which-key--propertize which-key-separator
>                                 'face 'which-key-separator-face))
>         (local-map (current-local-map))
> 	(avl-width (cdr (which-key--popup-max-dimensions)))
>         new-list)
>     (dolist (key-binding unformatted)
>       (let* ((keys (car key-binding))
>              (orig-desc (cdr key-binding))
>              (group (which-key--group-p orig-desc))
>              (local (eq (which-key--safe-lookup-key-description
>                          local-map keys)
>                         (intern orig-desc)))
>              (hl-face (which-key--highlight-face orig-desc))
>              (key-binding (which-key--maybe-replace key-binding))
>              (final-desc (which-key--propertize-description
>                           (cdr key-binding) group local hl-face orig-desc=
)))
>         (when final-desc
>           (setq final-desc
>                 (which-key--truncate-description
>                  (which-key--maybe-add-docstring final-desc orig-desc)
> 		 avl-width)))
>         (when (consp key-binding)
>           (push
>            (list (which-key--propertize-key
>                   (if preserve-full-key
>                       (car key-binding)
>                     (which-key--extract-key (car key-binding))))
>                  sep-w-face
>                  final-desc)
>            new-list))))
>     (nreverse new-list)))
>
> (defun which-key--compute-binding (binding)
>   "Replace BINDING with remapped binding if it exists.
> Requires `which-key-compute-remaps' to be non-nil."
>   (let (remap)
>     (if (and which-key-compute-remaps
>              (setq remap (command-remapping binding)))
>         (copy-sequence (symbol-name remap))
>       (copy-sequence (symbol-name binding)))))

Why the `copy-sequence' calls?

>
> (defun which-key--get-menu-item-binding (def)
>   "Retrieve binding for menu-item"
>   ;; see `keymap--menu-item-binding'
>   (let* ((binding (nth 2 def))
>          (plist (nthcdr 3 def))
>          (filter (plist-get plist :filter)))
>     (if filter (funcall filter binding) binding)))
>
> (defun which-key--get-keymap-bindings-1
>     (keymap start &optional prefix filter all ignore-commands)
>   "See `which-key--get-keymap-bindings'."
>   (let ((bindings start)
>         (prefix-map (if prefix (lookup-key keymap prefix) keymap)))
>     (when (keymapp prefix-map)
>       (map-keymap
>        (lambda (ev def)
>          (let* ((key (vconcat prefix (list ev)))
>                 (key-desc (key-description key)))
>            (cond
>             ((assoc key-desc bindings))
>             ((and (listp ignore-commands) (symbolp def) (memq def ignore-=
commands)))
>             ((or (string-match-p
>                   which-key--ignore-non-evil-keys-regexp key-desc)
>                  (eq ev 'menu-bar)))
>             ((and (keymapp def)
>                   (string-match-p which-key--evil-keys-regexp key-desc)))
>             ((and (keymapp def)
>                   (or all
>                       ;; event 27 is escape, so this will pick up meta
>                       ;; bindings and hopefully not too much more
>                       (and (numberp ev) (=3D ev 27))))

If you are not certain that EV is a number, you could also check both
type and value with a single (eql ev 27).

>              (setq bindings
>                    (which-key--get-keymap-bindings-1
>                     keymap bindings key nil all ignore-commands)))
>             (def
>              (let* ((def (if (eq 'menu-item (car-safe def))
>                              (which-key--get-menu-item-binding def)
>                            def))
>                     (binding
>                      (cons key-desc
>                            (cond
>                             ((symbolp def) (which-key--compute-binding de=
f))
>                             ((keymapp def) "prefix")
>                             ((eq 'lambda (car-safe def)) "lambda")
>                             ((eq 'closure (car-safe def)) "closure")
>                             ((stringp def) def)
>                             ((vectorp def) (key-description def))
>                             ((and (consp def)
>                                   ;; looking for (STRING . DEFN)
>                                   (stringp (car def)))
>                              (concat (when (keymapp (cdr-safe def))
>                                        "group:")
>                                      (car def)))
>                             (t "unknown")))))
>                (when (or (null filter)
>                          (and (functionp filter)
>                               (funcall filter binding)))
>                  (push binding bindings)))))))
>        prefix-map))
>     bindings))
>
> (defun which-key--get-keymap-bindings
>     (keymap &optional start prefix filter all evil)
>   "Retrieve top-level bindings from KEYMAP.
> PREFIX limits bindings to those starting with this key
> sequence.  START is a list of existing bindings to add to.  If ALL
> is non-nil, recursively retrieve all bindings below PREFIX. If
> EVIL is non-nil, extract active evil bidings."
>   (let ((bindings start)
>         (ignore '(self-insert-command ignore ignore-event company-ignore))
>         (evil-map
>          (when (and evil (bound-and-true-p evil-local-mode))
>            (lookup-key keymap (kbd (format "<%s-state>" evil-state))))))
>     (when (keymapp evil-map)
>       (setq bindings (which-key--get-keymap-bindings-1
>                       evil-map bindings prefix filter all ignore)))
>     (which-key--get-keymap-bindings-1
>      keymap bindings prefix filter all ignore)))
>
> (defun which-key--get-current-bindings (&optional prefix filter)
>   "Generate a list of current active bindings."
>   (let (bindings)
>     (dolist (map (current-active-maps t) bindings)
>       (when (cdr map)
>         (setq bindings
>               (which-key--get-keymap-bindings
>                map bindings prefix filter))))))
>
> (defun which-key--get-bindings (&optional prefix keymap filter recursive)
>   "Collect key bindings.
> If KEYMAP is nil, collect from current buffer using the current
> key sequence as a prefix. Otherwise, collect from KEYMAP. FILTER
> is a function to use to filter the bindings. If RECURSIVE is
> non-nil, then bindings are collected recursively for all prefixes."
>   (let* ((unformatted
>           (cond ((keymapp keymap)
>                  (which-key--get-keymap-bindings
>                   keymap nil prefix filter recursive))
>                 (keymap
>                  (error "%s is not a keymap" keymap))
>                 (t
>                  (which-key--get-current-bindings prefix filter)))))
>     (when which-key-sort-order
>       (setq unformatted
>             (sort unformatted which-key-sort-order)))
>     (which-key--format-and-replace unformatted recursive)))
>
> ;;; Functions for laying out which-key buffer pages
>
> (defun which-key--normalize-columns (columns)
>   "Pad COLUMNS to the same length using empty strings."
>   (let ((max-len (cl-reduce (lambda (a x) (max a (length x))) columns
>                             :initial-value 0)))
>     (mapcar
>      (lambda (c)
>        (if (< (length c) max-len)
>            (append c (make-list (- max-len (length c)) ""))
>          c))
>      columns)))

Generally speaking, has there been an attempt to use `:align-to' to
format the columns.

>
> (defsubst which-key--join-columns (columns)
>   "Transpose columns into rows, concat rows into lines and rows into page=
."
>   (let* ((padded (which-key--normalize-columns (nreverse columns)))
>          (rows (apply #'cl-mapcar #'list padded)))
>     (mapconcat (lambda (row) (mapconcat #'identity row " ")) rows "\n")))
>
> (defsubst which-key--max-len (keys index &optional initial-value)
>   "Find the max length of the INDEX element in each of KEYS."
>   (cl-reduce
>    (lambda (x y) (max x (which-key--string-width (nth index y))))
>    keys :initial-value (if initial-value initial-value 0)))
>
> (defun which-key--pad-column (col-keys avl-width)
>   "Pad cells of COL-KEYS to AVL-WIDTH.
> Take a column of (key separator description) COL-KEYS,
> calculate the max width in the column and pad all cells out to
> that width."
>   (let* ((col-key-width  (+ which-key-add-column-padding
>                             (which-key--max-len col-keys 0)))
>          (col-sep-width  (which-key--max-len col-keys 1))
> 	 (avl-width      (- avl-width col-key-width col-sep-width))
>          (col-desc-width (min avl-width
> 			      (which-key--max-len
>                                col-keys 2
> 			       which-key-min-column-description-width)))
>          (col-width      (+ col-key-width col-sep-width col-desc-width))
> 	 (col-format     (concat "%" (int-to-string col-key-width)
>                                  "s%s%-" (int-to-string col-desc-width) "=
s")))
>     (cons col-width
>           (mapcar (lambda (k) (apply #'format col-format k))
> 		  col-keys))))

More tabs here.

> (defun which-key--partition-list (n list)
>   "Partition LIST into N-sized sublists."
>   (let (res)
>     (while list
>       (setq res (cons (cl-subseq list 0 (min n (length list))) res)

See also `take'.

>             list (nthcdr n list)))
>     (nreverse res)))
>
> (defun which-key--list-to-pages (keys avl-lines avl-width)
>   "Convert list of KEYS to columns based on dimensions AVL-LINES and AVL-=
WIDTH.
> Returns a `which-key--pages' object that holds the page strings,
> as well as metadata."
>   (let ((cols-w-widths (mapcar (lambda (c) (which-key--pad-column c avl-w=
idth))
> 			       (which-key--partition-list avl-lines keys)))
>         (page-width 0) (n-pages 0) (n-keys 0) (n-columns 0)
>         page-cols pages page-widths keys/page col)
>     (if (> (apply #'max (mapcar #'car cols-w-widths)) avl-width)

Another idea would be (cl-reduce #'max cols-w-widths :key #'car), to
avoid the `apply' and consing a temporary list.

>         ;; give up if no columns fit
>         nil
>       (while cols-w-widths
>         ;; start new page
>         (cl-incf n-pages)
>         (setq col (pop cols-w-widths))
>         (setq page-cols (list (cdr col)))
>         (setq page-width (car col))
>         (setq n-keys (length (cdr col)))
>         (setq n-columns 1)
>         ;; add additional columns as long as they fit
>         (while (and cols-w-widths
>                     (or (null which-key-max-display-columns)
>                         (< n-columns which-key-max-display-columns))
>                     (<=3D (+ page-width 1 (caar cols-w-widths)) avl-width=
))
>           (setq col (pop cols-w-widths))
>           (push (cdr col) page-cols)
>           (cl-incf page-width (1+ (car col)))
>           (cl-incf n-keys (length (cdr col)))
>           (cl-incf n-columns))
>         (push (which-key--join-columns page-cols) pages)
>         (push n-keys keys/page)
>         (push page-width page-widths))
>       (make-which-key--pages
>        :pages (nreverse pages)
>        :height (if (> n-pages 1) avl-lines (min avl-lines n-keys))
>        :widths (nreverse page-widths)
>        :keys/page (reverse keys/page)
>        :page-nums (number-sequence 1 n-pages)
>        :num-pages n-pages
>        :total-keys (apply #'+ keys/page)))))
>
> (defun which-key--create-pages-1
>     (keys available-lines available-width &optional min-lines vertical)
>   "Create page strings using `which-key--list-to-pages'.
> Will try to find the best number of rows and columns using the
> given dimensions and the length and widths of ITEMS. Use VERTICAL
> if the ITEMS are laid out vertically and the number of columns
> should be minimized."
>   (let ((result (which-key--list-to-pages
>                  keys available-lines available-width))
>         (min-lines (or min-lines 0))
>         found prev-result)
>     (if (or (null result)
>             vertical
>             (> (which-key--pages-num-pages result) 1)
>             (=3D 1 available-lines))
>         result
>       ;; simple search for a fitting page
>       (while (and (> available-lines min-lines)
>                   (not found))
>         (setq available-lines (- available-lines 1)

See also `1-' or `cl-decf'.

>               prev-result result
>               result (which-key--list-to-pages
>                       keys available-lines available-width)
>               found (> (which-key--pages-num-pages result) 1)))
>       (if found prev-result result))))
>
> (defun which-key--create-pages (keys &optional prefix-keys prefix-title)
>   "Create page strings using `which-key--list-to-pages'.
> Will try to find the best number of rows and columns using the
> given dimensions and the length and wdiths of KEYS. SEL-WIN-WIDTH
> is the width of the live window."
>   (let* ((max-dims (which-key--popup-max-dimensions))
>          (max-lines (car max-dims))
>          (max-width (cdr max-dims))
>          (prefix-desc (key-description prefix-keys))
>          (full-prefix (which-key--full-prefix prefix-desc))
>          (prefix (when (eq which-key-show-prefix 'left)
>                    (+ 2 (which-key--string-width full-prefix))))
>          (prefix-top-bottom (member which-key-show-prefix '(bottom top)))
>          (avl-lines (if prefix-top-bottom (- max-lines 1) max-lines))
>          (min-lines (min avl-lines which-key-min-display-lines))
>          (avl-width (if prefix (- max-width prefix) max-width))
>          (vertical (or (and (eq which-key-popup-type 'side-window)
>                             (member which-key-side-window-location '(left=
 right)))
> 		       (eq which-key-max-display-columns 1)))

Stray tabs to be found here!

>          result)
>     (setq result
>           (which-key--create-pages-1
>            keys avl-lines avl-width min-lines vertical))
>     (when (and result
>                (> (which-key--pages-num-pages result) 0))
>       (setf (which-key--pages-prefix result) prefix-keys)
>       (setf (which-key--pages-prefix-title result)
>             (or prefix-title
>                 (which-key--maybe-get-prefix-title
>                  (key-description prefix-keys))))
>       (when prefix-top-bottom
> 	;; Add back the line earlier reserved for the page information.

Here as well.

>         (setf (which-key--pages-height result) max-lines))
>       (when (and (=3D (which-key--pages-num-pages result) 1)
>                  (> which-key-min-display-lines
>                     (which-key--pages-height result)))
>         ;; result is shorter than requested, so we artificially increase =
the
>         ;; height. See #325. Note this only has an effect if
>         ;; `which-key-allow-imprecise-window-fit' is non-nil.
>         (setf (which-key--pages-height result) which-key-min-display-line=
s))
>       (which-key--debug-message "Frame height: %s
> Minibuffer height: %s
> Max dimensions: (%s,%s)
> Available for bindings: (%s,%s)
> Actual lines: %s" (frame-height) (window-text-height (minibuffer-window))
> max-lines max-width avl-lines avl-width (which-key--pages-height result))
>       result)))
>
> (defun which-key--lighter-status ()
>   "Possibly show number of keys and total in the mode line."
>   (when which-key-show-remaining-keys
>     (let ((n-shown (car (which-key--pages-keys/page which-key--pages-obj)=
))
>           (n-tot (which-key--pages-total-keys which-key--pages-obj)))
>       (setcar (cdr (assq 'which-key-mode minor-mode-alist))
>               (format " WK: %s/%s keys" n-shown n-tot)))))
>
> (defun which-key--lighter-restore ()
>   "Restore the lighter for which-key."
>   (when which-key-show-remaining-keys
>     (setcar (cdr (assq 'which-key-mode minor-mode-alist))
>             which-key-lighter)))
>
> (defun which-key--echo (text)
>   "Echo TEXT to minibuffer without logging."
>   (let (message-log-max)
>     (message "%s" text)))
>
> (defun which-key--next-page-hint (prefix-keys)
>   "Return string for next page hint."
>   (let* ((paging-key (concat prefix-keys " " which-key-paging-key))
>          (paging-key-bound (eq 'which-key-C-h-dispatch
>                                (key-binding (kbd paging-key))))
>          (key (key-description (vector help-char)))
>          (key (if paging-key-bound
>                   (concat key " or " which-key-paging-key)
>                 key)))
>     (when (and which-key-use-C-h-commands
>                (not (equal (vector help-char)
>                            (vconcat (kbd prefix-keys)))))
>       (which-key--propertize (format "[%s paging/help]" key)
>                              'face 'which-key-note-face))))
>
> (eval-and-compile
>   (if (fboundp 'universal-argument--description)
>       (defalias 'which-key--universal-argument--description
>         #'universal-argument--description)
>     (defun which-key--universal-argument--description ()
>       ;; Backport of the definition of universal-argument--description in
>       ;; emacs25 on 2015-12-04
>       (when prefix-arg
>         (concat "C-u"
>                 (pcase prefix-arg
>                   (`(-) " -")
>                   (`(,(and (pred integerp) n))
>                    (let ((str ""))
>                      (while (and (> n 4) (=3D (mod n 4) 0))
>                        (setq str (concat str " C-u"))
>                        (setq n (/ n 4)))
>                      (if (=3D n 4) str (format " %s" prefix-arg))))
>                   (_ (format " %s" prefix-arg))))))))

Is this still necessary?

>
> (defun which-key--full-prefix (prefix-keys &optional -prefix-arg dont-pro=
p-keys)
>   "Return a description of the full key sequence up to now.
> Include prefix arguments."
>   (let* ((left (eq which-key-show-prefix 'left))
>          (prefix-arg (if -prefix-arg -prefix-arg prefix-arg))
>          (str (concat
>                (which-key--universal-argument--description)
>                (when prefix-arg " ")
>                prefix-keys))
>          (dash (if (and (not (string=3D prefix-keys ""))
>                         (null left)) "-" "")))
>     (if (or (eq which-key-show-prefix 'echo) dont-prop-keys)
>         (concat str dash)
>       (concat (which-key--propertize-key str)
>               (which-key--propertize dash 'face 'which-key-key-face)))))
>
> (defun which-key--get-popup-map ()
>   "Generate transient-map for use in the top level binding display."
>   (unless which-key--automatic-display
>     (let ((map (make-sparse-keymap)))
>       (define-key map (kbd which-key-paging-key) #'which-key-C-h-dispatch)
>       (when which-key-use-C-h-commands
>         ;; Show next page even when C-h is pressed
>         (define-key map (vector help-char) #'which-key-C-h-dispatch))
>       map)))
>
> (defun which-key--process-page (pages-obj)
>   "Add information to the basic list of key bindings.
> Include, if applicable, the current prefix, the name of the current
> prefix, and a page count."
>   (let* ((page (car (which-key--pages-pages pages-obj)))
>          (height (which-key--pages-height pages-obj))
>          (n-pages (which-key--pages-num-pages pages-obj))
>          (page-n (car (which-key--pages-page-nums pages-obj)))
>          (prefix-desc (key-description (which-key--pages-prefix pages-obj=
)))
>          (prefix-title (which-key--pages-prefix-title pages-obj))
>          (full-prefix (which-key--full-prefix prefix-desc))
>          (nxt-pg-hint (which-key--next-page-hint prefix-desc))
>          ;; not used in left case
>          (status-line
>           (concat (which-key--propertize prefix-title 'face 'which-key-no=
te-face)
>                   (when (< 1 n-pages)
>                     (which-key--propertize (format " (%s of %s)" page-n n=
-pages)
>                                            'face 'which-key-note-face)))))
>     (pcase which-key-show-prefix
>       (`left

Why the backtick?  Nothing is being destructured here.

>        (let* ((page-cnt (which-key--propertize (format "%s/%s" page-n n-p=
ages)
>                                                'face 'which-key-separator=
-face))
>               (first-col-width (+ 2 (max (which-key--string-width full-pr=
efix)
>                                          (which-key--string-width page-cn=
t))))
>               (prefix (format (concat "%-" (int-to-string first-col-width=
) "s")
>                               full-prefix))
>               (page-cnt (if (> n-pages 1)
>                             (format
>                              (concat "%-" (int-to-string first-col-width)=
 "s")
>                              page-cnt)
>                           (make-string first-col-width 32)))
>               lines first-line new-end)
>          (if (=3D 1 height)
>              (cons (concat prefix page) nil)
>            (setq lines (split-string page "\n")
>                  first-line (concat prefix (car lines) "\n" page-cnt)
>                  new-end (concat "\n" (make-string first-col-width 32)))
>            (cons
>             (concat first-line (mapconcat #'identity (cdr lines) new-end))
>             nil))))
>       (`top
>        (cons
>         (concat (when (or (=3D 0 echo-keystrokes)
>                           (not (eq which-key-side-window-location 'bottom=
)))
>                   (concat full-prefix " "))
>                 status-line " " nxt-pg-hint "\n" page)
>         nil))
>       (`bottom
>        (cons
>         (concat page "\n"
>                 (when (or (=3D 0 echo-keystrokes)
>                           (not (eq which-key-side-window-location 'bottom=
)))
>                   (concat full-prefix " "))
>                 status-line " " nxt-pg-hint)
>         nil))
>       (`echo
>        (cons page
>              (lambda ()
>                (which-key--echo
>                 (concat full-prefix (when prefix-desc " ")
>                         status-line (when status-line " ")
>                         nxt-pg-hint)))))
>       (`mode-line
>        (cons page
>              (lambda ()
>                (with-current-buffer which-key--buffer
>                  (setq-local mode-line-format
>                              (concat " " full-prefix
>                                      " " status-line
>                                      " " nxt-pg-hint))))))
>       (_ (cons page nil)))))
>
> (defun which-key--show-page (&optional n)
>   "Show current page.
> N changes the current page to the Nth page relative to the
> current one."
>   (which-key--init-buffer) ;; in case it was killed
>   (let ((prefix-keys (which-key--current-key-string))
>         golden-ratio-mode)
>     (if (null which-key--pages-obj)
>         (message "%s- which-key can't show keys: There is not \
> enough space based on your settings and frame size." prefix-keys)
>       (when n
>         (setq which-key--pages-obj
>               (which-key--pages-set-current-page which-key--pages-obj n)))
>       (let ((page-echo (which-key--process-page which-key--pages-obj))
>             (height (which-key--pages-height which-key--pages-obj))
>             (width (car (which-key--pages-widths which-key--pages-obj))))
>         (which-key--lighter-status)
>         (if (eq which-key-popup-type 'minibuffer)
>             (which-key--echo (car page-echo))
>           (with-current-buffer which-key--buffer
>             (erase-buffer)
>             (insert (car page-echo))
>             (goto-char (point-min)))
>           (when (cdr page-echo) (funcall (cdr page-echo)))
>           (which-key--show-popup (cons height width)))))
>     ;; used for paging at top-level
>     (if (fboundp 'set-transient-map)
>         (set-transient-map (which-key--get-popup-map))
>       (with-no-warnings
>         (set-temporary-overlay-map (which-key--get-popup-map))))))
>
> ;;; Paging functions
>
> ;;;###autoload
> (defun which-key-reload-key-sequence (&optional key-seq)
>   "Simulate entering the key sequence KEY-SEQ.
> KEY-SEQ should be a list of events as produced by
> `listify-key-sequence'.  If nil, KEY-SEQ defaults to
> `which-key--current-key-list'. Any prefix arguments that were
> used are reapplied to the new key sequence."
>   (let* ((key-seq (or key-seq (which-key--current-key-list)))
>          (next-event (mapcar (lambda (ev) (cons t ev)) key-seq)))
>     (setq prefix-arg current-prefix-arg
>           unread-command-events next-event)))
>
> (defun which-key-turn-page (delta)
>   "Show the next page of keys."
>   (which-key-reload-key-sequence)
>   (if which-key--last-try-2-loc
>       (let ((which-key-side-window-location which-key--last-try-2-loc)
>             (which-key--multiple-locations t))
>         (which-key--show-page delta))
>     (which-key--show-page delta))
>   (which-key--start-paging-timer))
>
> ;;;###autoload
> (defun which-key-show-standard-help (&optional _)
>   "Call the command in `which-key--prefix-help-cmd-backup'.
> Usually this is `describe-prefix-bindings'."
>   (interactive)
>   (let ((which-key-inhibit t)
>         (popup-showing (which-key--popup-showing-p)))
>     (which-key--hide-popup-ignore-command)
>     (cond ((and (eq which-key--prefix-help-cmd-backup
>                     'describe-prefix-bindings)
>                 ;; If the popup is not showing, we call
>                 ;; `describe-prefix-bindings' directly.
>                 popup-showing)
>            ;; This is essentially what `describe-prefix-bindings' does. W=
e can't
>            ;; use this function directly, because the prefix will not be =
correct
>            ;; when we enter using `which-key-C-h-dispatch'.
>            (describe-bindings (kbd (which-key--current-key-string))))
>           ((functionp which-key--prefix-help-cmd-backup)
>            (funcall which-key--prefix-help-cmd-backup)))))
>
> ;;;###autoload
> (defun which-key-show-next-page-no-cycle ()
>   "Show next page of keys or `which-key-show-standard-help'."
>   (interactive)
>   (let ((which-key-inhibit t))
>     (if (which-key--on-last-page)
>         (which-key-show-standard-help)
>       (which-key-turn-page 1))))
>
> ;;;###autoload
> (defun which-key-show-previous-page-no-cycle ()
>   "Show previous page of keys if one exists."
>   (interactive)
>   (let ((which-key-inhibit t))
>     (unless (which-key--on-first-page)
>       (which-key-turn-page -1))))
>
> ;;;###autoload
> (defun which-key-show-next-page-cycle (&optional _)
>   "Show the next page of keys, cycling from end to beginning."
>   (interactive)
>   (let ((which-key-inhibit t))
>     (which-key-turn-page 1)))
>
> ;;;###autoload
> (defun which-key-show-previous-page-cycle (&optional _)
>   "Show the previous page of keys, cycling from beginning to end."
>   (interactive)
>   (let ((which-key-inhibit t))
>     (which-key-turn-page -1)))
>
> ;;;###autoload
> (defun which-key-show-top-level (&optional _)
>   "Show top-level bindings."
>   (interactive)
>   (which-key--create-buffer-and-show nil nil nil "Top-level bindings"))
>
> ;;;###autoload
> (defun which-key-show-major-mode (&optional all)
>   "Show top-level bindings in the map of the current major mode.
> This function will also detect evil bindings made using
> `evil-define-key' in this map. These bindings will depend on the
> current evil state. "
>   (interactive "P")
>   (let ((map-sym (intern (format "%s-map" major-mode))))
>     (if (and (boundp map-sym) (keymapp (symbol-value map-sym)))
>         (which-key--show-keymap
>          "Major-mode bindings"
>          (symbol-value map-sym)
>          (apply-partially #'which-key--map-binding-p (symbol-value map-sy=
m))
>          all)
>       (message "which-key: No map named %s" map-sym))))
>
> ;;;###autoload
> (defun which-key-show-full-major-mode ()
>   "Show all bindings in the map of the current major mode.
> This function will also detect evil bindings made using
> `evil-define-key' in this map. These bindings will depend on the
> current evil state. "
>   (interactive)
>   (which-key-show-major-mode t))
>
> ;;;###autoload
> (defun which-key-dump-bindings (prefix buffer-name)
>   "Dump bindings from PREFIX into buffer named BUFFER-NAME.
> PREFIX should be a string suitable for `kbd'."
>   (interactive "sPrefix: \nB")
>   (let* ((buffer (get-buffer-create buffer-name))
>          (keys (which-key--get-bindings (kbd prefix))))
>     (with-current-buffer buffer
>       (point-max)
>       (save-excursion
>         (dolist (key keys)
>           (insert (apply #'format "%s%s%s\n" key)))))
>     (switch-to-buffer-other-window buffer)))
>
> ;;;###autoload
> (defun which-key-undo-key (&optional _)
>   "Undo last keypress and force which-key update."
>   (interactive)
>   (let* ((key-lst (butlast (which-key--current-key-list)))
>          (which-key-inhibit t))
>     (cond (which-key--prior-show-keymap-args
>            (if (keymapp (cdr (car-safe which-key--prior-show-keymap-args)=
))
>                (let ((args (pop which-key--prior-show-keymap-args)))
>                  (which-key--show-keymap (car args) (cdr args)))
>              (which-key--hide-popup)))
>           (key-lst
>            (which-key-reload-key-sequence key-lst)
>            (which-key--create-buffer-and-show (apply #'vector key-lst)))
>           (t (setq which-key--automatic-display nil)
>              (which-key-show-top-level)))))
> (defalias 'which-key-undo #'which-key-undo-key)
>
> (defun which-key-abort (&optional _)
>   "Abort key sequence."
>   (interactive)
>   (let ((which-key-inhibit t))
>     (which-key--hide-popup-ignore-command)
>     (keyboard-quit)))
>
> (defun which-key-digit-argument (key)
>   "Version of `digit-argument' for use in `which-key-C-h-map'."
>   (interactive)
>   (let ((last-command-event (string-to-char key)))
>     (digit-argument key))
>   (let ((current-prefix-arg prefix-arg))
>     (which-key-reload-key-sequence)))
>
> (defun which-key-toggle-docstrings (&optional _)
>   "Toggle the display of docstrings."
>   (interactive)
>   (unless (eq which-key-show-docstrings 'docstring-only)
>     (setq which-key-show-docstrings (null which-key-show-docstrings)))
>   (which-key-reload-key-sequence)
>   (which-key--create-buffer-and-show (which-key--current-prefix)))
>
> ;;;###autoload
> (defun which-key-C-h-dispatch ()
>   "Dispatch C-h commands by looking up key in `which-key-C-h-map'.
> This command is always accessible (from any prefix) if
> `which-key-use-C-h-commands' is non nil."
>   (interactive)
>   (cond ((and (not (which-key--popup-showing-p))
>               which-key-show-early-on-C-h)
>          (let ((current-prefix
>                 (butlast
>                  (listify-key-sequence
>                   (funcall which-key-this-command-keys-function)))))
>            (which-key-reload-key-sequence current-prefix)
>            (if which-key-idle-secondary-delay
>                (which-key--start-timer which-key-idle-secondary-delay t)
>              (which-key--start-timer 0.05 t))))
>         ((not (which-key--popup-showing-p))
>          (which-key-show-standard-help))
>         (t
>          (if (not (which-key--popup-showing-p))
>              (which-key-show-standard-help)
>            (let* ((prefix-keys (which-key--current-key-string))
>                   (full-prefix (which-key--full-prefix prefix-keys curren=
t-prefix-arg t))
>                   (prompt (concat (when (string-equal prefix-keys "")
>                                     (which-key--propertize
>                                      (concat " "
>                                              (which-key--pages-prefix-tit=
le
>                                               which-key--pages-obj))
>                                      'face 'which-key-note-face))
>                                   full-prefix
>                                   (which-key--propertize
>                                    (substitute-command-keys
>                                     which-key-C-h-map-prompt)
>                                    'face 'which-key-note-face)))
>                   (key (let ((key (read-key prompt)))
>                          (if (numberp key)
>                              (string key)
>                            (vector key))))
>                   (cmd (lookup-key which-key-C-h-map key))
>                   (which-key-inhibit t))
>              (if cmd (funcall cmd key) (which-key-turn-page 0)))))))
>
> ;;; Update
>
> (defun which-key--any-match-p (regexps string)
>   "Non-nil if any of REGEXPS match STRING."
>   (catch 'match
>     (dolist (regexp regexps)
>       (when (string-match-p regexp string)
>         (throw 'match t)))))
>
> (defun which-key--try-2-side-windows
>     (bindings prefix-keys prefix-title loc1 loc2 &rest _ignore)
>   "Try to show BINDINGS (PAGE-N) in LOC1 first.
> Only if no bindings fit fallback to LOC2."
>   (let (pages1)
>     (let ((which-key-side-window-location loc1)
>           (which-key--multiple-locations t))
>       (setq pages1 (which-key--create-pages
>                     bindings prefix-keys prefix-title)))
>     (if pages1
>         (progn
>           (setq which-key--pages-obj pages1)
>           (let ((which-key-side-window-location loc1)
>                 (which-key--multiple-locations t))
>             (which-key--show-page))
>           loc1)
>       (let ((which-key-side-window-location loc2)
>             (which-key--multiple-locations t))
>         (setq which-key--pages-obj
>               (which-key--create-pages bindings prefix-keys prefix-title))
>         (which-key--show-page)
>         loc2))))
>
> (defun which-key--read-keymap ()
>   "Read keymap symbol from minibuffer."
>   (intern
>    (completing-read "Keymap: " obarray
>                     (lambda (m)
>                       (and (boundp m)
>                            (keymapp (symbol-value m))
>                            (not (equal (symbol-value m)
>                                        (make-sparse-keymap)))))
>                     t
>                     (let ((sym (symbol-at-point)))
>                       (and (boundp sym)
>                            (keymapp (symbol-value sym))
>                            (symbol-name sym)))
>                     'which-key-keymap-history)))
>
> ;;;###autoload
> (defun which-key-show-keymap (keymap &optional no-paging)
>   "Show the top-level bindings in KEYMAP using which-key.
> KEYMAP is selected interactively from all available keymaps.
>
> If NO-PAGING is non-nil, which-key will not intercept subsequent
> keypresses for the paging functionality."
>   (interactive (list (which-key--read-keymap)))
>   (which-key--show-keymap (symbol-name keymap)
>                           (symbol-value keymap)
>                           nil nil no-paging))
>
> ;;;###autoload
> (defun which-key-show-full-keymap (keymap)
>   "Show all bindings in KEYMAP using which-key.
> KEYMAP is selected interactively from all available keymaps."
>   (interactive (list (which-key--read-keymap)))
>   (which-key--show-keymap (symbol-name keymap)
>                           (symbol-value keymap)
>                           nil t))
>
> ;;;###autoload
> (defun which-key-show-minor-mode-keymap (&optional all)
>   "Show the top-level bindings in KEYMAP using which-key.
> KEYMAP is selected interactively by mode in
> `minor-mode-map-alist'."
>   (interactive)
>   (let ((mode-sym
>          (intern
>           (completing-read
>            "Minor Mode: "
>            (mapcar #'car
>                    (cl-remove-if-not
>                     (lambda (entry)
>                       (and (symbol-value (car entry))
>                            (not (equal (cdr entry) (make-sparse-keymap)))=
))
>                     minor-mode-map-alist))
>            nil t nil 'which-key-keymap-history))))
>     (which-key--show-keymap (symbol-name mode-sym)
>                             (cdr (assq mode-sym minor-mode-map-alist))
>                             all)))
> ;;;###autoload
> (defun which-key-show-full-minor-mode-keymap ()
>   "Show all bindings in KEYMAP using which-key.
> KEYMAP is selected interactively by mode in
> `minor-mode-map-alist'."
>   (interactive)
>   (which-key-show-minor-mode-keymap t))
>
> (defun which-key--show-keymap
>     (keymap-name keymap &optional prior-args all no-paging filter)
>   (when prior-args (push prior-args which-key--prior-show-keymap-args))
>   (let ((bindings (which-key--get-bindings nil keymap filter all)))
>     (if (null bindings)
>         (message "which-key: No bindings found in %s" keymap-name)
>       (cond ((listp which-key-side-window-location)
>              (setq which-key--last-try-2-loc
>                    (apply #'which-key--try-2-side-windows
>                           bindings nil keymap-name
>                           which-key-side-window-location)))
>             (t (setq which-key--pages-obj
>                      (which-key--create-pages bindings nil keymap-name))
>                (which-key--show-page)))
>       (unless no-paging
>         (let* ((key (read-key))
>                (key-desc (key-description (list key)))
>                (next-def (lookup-key keymap (vector key))))
>           (cond ((and which-key-use-C-h-commands
>                       (numberp key) (=3D key help-char))
>                  (which-key-C-h-dispatch))
>                 ((keymapp next-def)
>                  (which-key--hide-popup-ignore-command)
>                  (which-key--show-keymap
>                   (concat keymap-name " " key-desc)
>                   next-def
>                   (cons keymap-name keymap)))
>                 (t (which-key--hide-popup))))))))
>
> (defun which-key--evil-operator-filter (binding)
>   (let ((def (intern (cdr binding))))
>     (and (functionp def)
>          (not (evil-get-command-property def :suppress-operator)))))
>
> (defun which-key--show-evil-operator-keymap ()
>   (if which-key--inhibit-next-operator-popup
>       (setq which-key--inhibit-next-operator-popup nil)
>     (let ((keymap
>            (make-composed-keymap (list evil-operator-shortcut-map
>                                        evil-operator-state-map
>                                        evil-motion-state-map))))
>       (when (keymapp keymap)
>         (let ((formatted-keys
>                (which-key--get-bindings
>                 nil keymap #'which-key--evil-operator-filter)))
>           (cond ((=3D (length formatted-keys) 0)
>                  (message "which-key: Keymap empty"))
>                 ((listp which-key-side-window-location)
>                  (setq which-key--last-try-2-loc
>                        (apply #'which-key--try-2-side-windows
>                               formatted-keys nil "evil operator/motion ke=
ys"
>                               which-key-side-window-location)))
>                 (t (setq which-key--pages-obj
>                          (which-key--create-pages
>                           formatted-keys
>                           nil "evil operator/motion keys"))
>                    (which-key--show-page)))))
>       (let* ((key (read-key)))

You don't need a let* here.

>         (when (member key '(?f ?F ?t ?T ?`))

Here too, one could use `memq' to be just as explicit as necessary.

>           ;; these keys trigger commands that read the next char manually
>           (setq which-key--inhibit-next-operator-popup t))
>         (cond ((and which-key-use-C-h-commands (numberp key) (=3D key hel=
p-char))
>                (which-key-C-h-dispatch))
>               ((and (numberp key) (=3D key ?\C-\[))
>                (which-key--hide-popup)
>                (keyboard-quit))
>               (t
>                (which-key--hide-popup)
>                (setq unread-command-events (vector key))))))))
>
> (defun which-key--create-buffer-and-show
>     (&optional prefix-keys from-keymap filter prefix-title)
>   "Fill `which-key--buffer' with key descriptions and reformat.
> Finally, show the buffer."
>   (let ((start-time (current-time))
>         (formatted-keys (which-key--get-bindings
>                          prefix-keys from-keymap filter))
>         (prefix-desc (key-description prefix-keys)))
>     (cond ((=3D (length formatted-keys) 0)

See also `null'.

>            (message "%s-  which-key: There are no keys to show" prefix-de=
sc))
>           ((listp which-key-side-window-location)

Or move this up and do a `consp' instead.

>            (setq which-key--last-try-2-loc
>                  (apply #'which-key--try-2-side-windows
>                         formatted-keys prefix-keys prefix-title
>                         which-key-side-window-location)))
>           (t (setq which-key--pages-obj
>                    (which-key--create-pages
>                     formatted-keys prefix-keys prefix-title))
>              (which-key--show-page)))
>     (which-key--debug-message
>      "On prefix \"%s\" which-key took %.0f ms." prefix-desc
>      (* 1000 (float-time (time-since start-time))))))
>
> (defun which-key--update ()
>   "Function run by timer to possibly trigger `which-key--create-buffer-an=
d-show'."
>   (let ((prefix-keys (funcall which-key-this-command-keys-function))
>         delay-time)
>     (cond ((and (> (length prefix-keys) 0)

FWIW there is also `length>', though it won't really make a difference
here, and with length 0 it is basically equivalent to `consp'.

>                 (or (keymapp (key-binding prefix-keys))
>                     ;; Some keymaps are stored here like iso-transl-ctl-x=
-8-map
>                     (keymapp (which-key--safe-lookup-key
>                               key-translation-map prefix-keys))
>                     ;; just in case someone uses one of these
>                     (keymapp (which-key--safe-lookup-key
>                               function-key-map prefix-keys)))
>                 (not which-key-inhibit)
>                 (or (null which-key-allow-regexps)
>                     (which-key--any-match-p
>                      which-key-allow-regexps (key-description prefix-keys=
)))
>                 (or (null which-key-inhibit-regexps)
>                     (not
>                      (which-key--any-match-p
>                       which-key-inhibit-regexps (key-description prefix-k=
eys))))
>                 ;; Do not display the popup if a command is currently bei=
ng
>                 ;; executed
>                 (or (run-hook-with-args-until-success
>                      'which-key-inhibit-display-hook)
>                     (null this-command))
>                 (let ((max-dim (which-key--popup-max-dimensions)))
>                   (> (min (car-safe max-dim) (cdr-safe max-dim)) 0)))
>            (when (and (not (equal prefix-keys (which-key--current-prefix)=
))
>                       (or (null which-key-delay-functions)
>                           (null (setq delay-time
>                                       (run-hook-with-args-until-success
>                                        'which-key-delay-functions
>                                        (key-description prefix-keys)
>                                        (length prefix-keys))))
>                           (sit-for delay-time)))
>              (setq which-key--automatic-display t)
>              (which-key--create-buffer-and-show prefix-keys)
>              (when (and which-key-idle-secondary-delay
>                         (not which-key--secondary-timer-active))
>                (which-key--start-timer which-key-idle-secondary-delay t))=
))
>           ((and which-key-show-transient-maps
>                 ;; Assuming that if this is not true we're in
>                 ;; `which-key-show-top-level', which would then be overwr=
itten.
>                 (> (length prefix-keys) 0)
>                 (keymapp overriding-terminal-local-map)
>                 ;; basic test for it being a hydra
>                 (not (eq (lookup-key overriding-terminal-local-map "\C-u")
>                          'hydra--universal-argument)))
>            (which-key--create-buffer-and-show
>             nil overriding-terminal-local-map))
>           ((and which-key-show-operator-state-maps
>                 (bound-and-true-p evil-state)
>                 (eq evil-state 'operator)
>                 (not (which-key--popup-showing-p)))
>            (which-key--show-evil-operator-keymap))
>           (which-key--automatic-display
>            (which-key--hide-popup)))))
>
> ;;; Timers
>
> (defun which-key--start-timer (&optional delay secondary)
>   "Activate idle timer to trigger `which-key--update'."
>   (which-key--stop-timer)
>   (setq which-key--secondary-timer-active secondary)
>   (setq which-key--timer
>         (run-with-idle-timer (or delay which-key-idle-delay)
>                              t #'which-key--update)))
>
> (defun which-key--stop-timer ()
>   "Deactivate idle timer for `which-key--update'."
>   (when which-key--timer (cancel-timer which-key--timer)))
>
> (defun which-key--start-paging-timer ()
>   "Activate timer to restart which-key after paging."
>   (when which-key--paging-timer (cancel-timer which-key--paging-timer))
>   (which-key--stop-timer)
>   (setq which-key--paging-timer
>         (run-with-idle-timer
>          0.2 t (lambda ()
>                  (when (or (not (member real-last-command
>                                         which-key--paging-functions))
>                            (and (< 0 (length (this-single-command-keys)))
>                                 (not (equal (which-key--current-prefix)
>                                             (funcall which-key-this-comma=
nd-keys-function)))))
>                    (cancel-timer which-key--paging-timer)
>                    (if which-key-idle-secondary-delay
>                        ;; we haven't executed a command yet so the secand=
ary
>                        ;; timer is more relevant here
>                        (which-key--start-timer which-key-idle-secondary-d=
elay t)
>                      (which-key--start-timer)))))))
>
> (provide 'which-key)
> ;;; which-key.el ends here

Again, I hope I didn't repeat myself (setting aside this comment about
myself fearing that I am repeating myself), and I apologise if I'm too
pedantic, it is just interesting how much one can find if you look over
a longer file like this one again.

Also, in some cases, I didn't repeat my comment every time, but it might
be good to check if I didn't miss anything for some of the more general
points.

--=20
	Philip Kaludercic on peregrine




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 1 Mar 2024 23:08:57 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 01 18:08:57 2024
Received: from localhost ([127.0.0.1]:37614 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rgBzt-0003PY-Nv
	for submit <at> debbugs.gnu.org; Fri, 01 Mar 2024 18:08:57 -0500
Received: from out-171.mta0.migadu.com ([91.218.175.171]:55047)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jb@HIDDEN>) id 1rgBzr-0003PG-82
 for 68929 <at> debbugs.gnu.org; Fri, 01 Mar 2024 18:08:56 -0500
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net;
 s=key1; t=1709334501;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to:references:references;
 bh=fO3n93HjU8TTCy16rag1ZtpxTkZwcrBS5d9VfKRufxY=;
 b=K4LgRn6FLUKKhtWp3E2r/Wy9NrD/hJmyRSvX2/V68440gdYF4wdvGgrUMJxf3SFpZQPn3v
 ZIJBowiDH/BbmU27p04f4xYmD9ArWWa1FZ/XpeeOmUjaIG8CvsNGsscRil64H5cztJZer6
 j7IcqKeqS5vEXQXqhAD65PAAkmu74j8msNdqA82OT37SQphDV/tK6FNK46wAVkHbQy1FWj
 NuL9pDldK23GkPdfBBYXucH3+d9a6eZoX5qiLKQCdmhMTamvioJm7l4PGfrVlAt1TLJM7n
 ci6Ra7e7p9cA1jDWNDz2e17TH2a7PHiKUZb6/ToU8/g/nrt7hq+SYEEtGQgQ9g==
From: Jeremy Bryant <jb@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
In-Reply-To: <86h6ijxzjk.fsf@HIDDEN> (Eli Zaretskii's message of "Thu, 08 Feb
 2024 08:03:59 +0200")
References: <871q9rvqbi.fsf@HIDDEN> <87mssc65y8.fsf@HIDDEN>
 <87y1bwrll4.fsf@HIDDEN> <86h6ijxzjk.fsf@HIDDEN>
Date: Fri, 01 Mar 2024 23:08:19 +0000
Message-ID: <87msrh4kkc.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Migadu-Flow: FLOW_OUT
X-Debbugs-Envelope-To: 68929
Cc: philipk@HIDDEN, 68929 <at> debbugs.gnu.org, monnier@HIDDEN,
 justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>

--=-=-=
Content-Type: text/plain

Eli Zaretskii <eliz@HIDDEN> writes:

>> Cc: 68929 <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
>> Date: Wed, 07 Feb 2024 21:48:00 +0000
>> From:  Jeremy Bryant via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN>
>> 
>> 
>> Philip Kaludercic <philipk@HIDDEN> writes:
>> 
>> > My genera feeling is that the code is reinventing the wheel at a number
>> > of places, which might make it more complicated to maintain in the long
>> > term.  Looking for ways to slim down the codebase, perhaps by
>> > deprecating some options, dropping support for third-party packages and
>> > reusing existing functionality seems like something one should look into.
>> 
>> Should these improvements be made before moving which-key to core?
>
> Preferably, yes.

Eli/Philip,

Here is a progress update.

For convenience please find attached a v2 version of which-key with the
improvements (in conjunction with Justin). This includes

* All improvements requested by Eli; docstrings, :verion tags,
etc.. - with the exception of the redesign point for character widths

* The vast majority of improvements requested by Philip; defcustoms
changes, docstrings, sharp-quoted elements, pure function, third party
libs, declare, memq, string-join, null-bindings etc) Missing are some
elements I'm less familiar with, such as design choices related to
deffaces.

These are currently in the form of individual patches in the upstream
git repo (thus attached only for convenience).  Using the 'preserving
history' approach described by Stefan M, this could be moved to core,
thus preserving the commits thus allowing checking of contributor FSF
attribution.


If there are certain elements you feel deserve further work, all
feedback welcome.

WDYT?



--=-=-=
Content-Type: application/emacs-lisp
Content-Disposition: attachment; filename=which-key-v2.el
Content-Transfer-Encoding: quoted-printable

;;; which-key.el --- Display available keybindings in popup  -*- lexical-bi=
nding: t; -*-

;; Copyright (C) 2017-2024  Free Software Foundation, Inc.

;; Author: Justin Burkett <justin@HIDDEN>
;; Maintainer: Justin Burkett <justin@HIDDEN>
;; Version: 3.6.0
;; Keywords:
;; Package-Requires: ((emacs "24.4"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; which-key provides the minor mode which-key-mode for Emacs.  The mode di=
splays
;; the key bindings following your currently entered incomplete command (a
;; prefix) in a popup.  For example, after enabling the minor mode if you e=
nter
;; C-x and wait for the default of 1 second the minibuffer will expand with=
 all
;; of the available key bindings that follow C-x (or as many as space allows
;; given your settings).  This includes prefixes like C-x 8 which are shown=
 in a
;; different face.  Screenshots of what the popup will look like along with
;; information about additional features can be found at
;; https://github.com/justbur/emacs-which-key.
;;

;;; Code:

(require 'cl-lib)
(require 'button)
(require 'regexp-opt)

;; For compiler
(defvar evil-operator-shortcut-map)
(defvar evil-operator-state-map)
(defvar evil-motion-state-map)
(defvar golden-ratio-mode)
(declare-function evil-get-command-property "ext:evil-common.el")

;;; Options

(defgroup which-key nil
  "Customization options for which-key-mode."
  :group 'help
  :prefix "which-key-")

(defcustom which-key-idle-delay 1.0
  "Delay (in seconds) for which-key buffer to popup.
This variable should be set before activating `which-key-mode'.

A value of zero might lead to issues, so a non-zero value is
recommended
(see https://github.com/justbur/emacs-which-key/issues/134)."
  :group 'which-key
  :type 'float
  :version "1.0")

(defcustom which-key-idle-secondary-delay nil
  "Seconds to wait for which-key to pop up after initial display.
This makes it possible to shorten the delay for subsequent popups
in the same key sequence. The default is for this value to be
nil, which disables this behavior."
  :group 'which-key
  :type '(choice float (const :tag "Disabled" nil))
  :version "1.0")

(defcustom which-key-echo-keystrokes (if (and echo-keystrokes
                                              (> (+ echo-keystrokes 0.01)
                                                 which-key-idle-delay))
                                         (/ (float which-key-idle-delay) 4)
                                       echo-keystrokes)
  "Value to use for `echo-keystrokes'.
This only applies if `which-key-popup-type' is minibuffer or
`which-key-show-prefix' is echo.  It needs to be less than
`which-key-idle-delay' or else the keystroke echo will erase the
which-key popup."
  :group 'which-key
  :type 'float
  :version "1.0")

(defcustom which-key-max-description-length 27
  "Truncate the description of keys to this length.
Either nil (no truncation), an integer (truncate after that many
characters), a float (use that fraction of the available width),
or a function, which takes one argument, the available width in
characters, and whose return value has one of the types mentioned
before.  Truncation is done using `which-key-ellipsis'."
  :group 'which-key
  :type '(choice (const :tag "Disable truncation" nil)
		 (integer :tag "Width in characters")
		 (float :tag "Use fraction of available width")
		 function)
  :version "1.0")

(defcustom which-key-min-column-description-width 0
  "Every column should at least have this width."
  :group 'which-key
  :type 'natnum
  :version "1.0")

(defcustom which-key-add-column-padding 0
  "Additional spaces to add to the left of each key column."
  :group 'which-key
  :type 'integer
  :version "1.0")

(defcustom which-key-unicode-correction 3
  "Correction for wide unicode characters.
Since we measure width in terms of the number of characters,
Unicode characters that are wider than ASCII characters throw off
the calculation for available width in the which-key buffer.  This
variable allows you to adjust for the wide unicode characters by
artificially reducing the available width in the buffer.

The default of 3 means allow for the total extra width
contributed by any wide unicode characters to be up to one
additional ASCII character in the which-key buffer.  Increase this
number if you are seeing characters get cutoff on the right side
of the which-key popup."
  :group 'which-key
  :type 'integer
  :version "1.0")

(defcustom which-key-dont-use-unicode nil
  "If non-nil, don't use any unicode characters in default setup.
For affected settings, see `which-key-replacement-alist', `which-key-ellips=
is'
'which-key-separator'."
  :group 'which-key
  :type 'boolean
  :version "1.0")

(defcustom which-key-separator
  (if which-key-dont-use-unicode " : " " =E2=86=92 ")
  "Separator to use between key and description.
Default is \" =E2=86=92 \", unless `which-key-dont-use-unicode' is non
nil, in which case the default is \" : \"."
  :group 'which-key
  :type 'string
  :version "1.0")

(defcustom which-key-ellipsis
  (if which-key-dont-use-unicode ".." "=E2=80=A6")
  "Ellipsis to use when truncating.
Default is \"=E2=80=A6\", unless `which-key-dont-use-unicode' is non nil,
in which case the default is \"..\".  This can also be the empty
string to truncate without using any ellipsis."
  :group 'which-key
  :type 'string
  :version "1.0")

(defcustom which-key-prefix-prefix "+"
  "Prefix string to indicate a key bound to a keymap.
Default is \"+\"."
  :group 'which-key
  :type 'string
  :version "1.0")

(defcustom which-key-compute-remaps nil
  "If non-nil, show remapped commands.
This applies to commands that have been remapped given the
currently active keymaps."
  :group 'which-key
  :type 'boolean
  :version "1.0")

(defcustom which-key-replacement-alist
  (delq nil
        `(((nil . "which-key-show-next-page-no-cycle") . (nil . "wk next pg=
"))
          ,@(unless which-key-dont-use-unicode
              '((("<left>") . ("=E2=86=90"))
                (("<right>") . ("=E2=86=92"))))
          (("<\\([[:alnum:]-]+\\)>") . ("\\1"))))
  "ALIST for manipulating display of binding descriptions.
Each element of the list is a nested cons cell with the format

\(MATCH CONS . REPLACEMENT\).

The MATCH CONS determines when a replacement should occur and
REPLACEMENT determines how the replacement should occur. Each may
have the format \(KEY REGEXP . BINDING REGEXP\). For the
replacement to apply the key binding must match both the KEY
REGEXP and the BINDING REGEXP. A value of nil in either position
can be used to match every possibility. The replacement is
performed by using `replace-regexp-in-string' on the KEY REGEXP
from the MATCH CONS and REPLACEMENT when it is a cons cell, and
then similarly for the BINDING REGEXP. A nil value in the BINDING
REGEXP position cancels the replacement. For example, the entry

\(\(nil . \"Prefix Command\"\) . \(nil . \"prefix\"\)\)

matches any binding with the descriptions \"Prefix Command\" and
replaces the description with \"prefix\", ignoring the
corresponding key.

REPLACEMENT may also be a function taking a cons cell
\(KEY . BINDING\) and producing a new corresponding cons cell.

If REPLACEMENT is anything other than a cons cell \(and non nil\)
the key binding is ignored by which-key.

Finally, you can multiple replacements to occur for a given key
binding by setting `which-key-allow-multiple-replacements' to a
non-nil value."
  :group 'which-key
  :type '(alist :key-type (cons (choice regexp (const nil))
                                (choice regexp (const nil)))
                :value-type (cons (choice string (const nil))
                                  (choice string (const nil))))
  :version "1.0")

(defcustom which-key-allow-multiple-replacements nil
  "Allow a key binding to be modified by multiple elements.
When non-nil, this allows a single key binding to match multiple
patterns in `which-key-replacement-alist'. When nil, only the
first match is used to perform replacements from
`which-key-replacement-alist'."
  :group 'which-key
  :type 'boolean
  :version "1.0")

(defcustom which-key-show-docstrings nil
  "If non-nil, show each command's docstring in the which-key popup.
This will only display the docstring up to the first line
break. If you set this variable to the symbol docstring-only,
then the command's name with be omitted. You probably also want
to adjust `which-key-max-description-length' at the same time if
you use this feature."
  :group 'which-key
  :type '(radio
          (const :tag "Do not show docstrings" nil)
          (const :tag "Add docstring to command names" t)
          (const :tag "Replace command name with docstring" docstring-only))
  :version "1.0")

(defcustom which-key-highlighted-command-list '()
  "Rules used to highlight certain commands.
If the element is a string, assume it is a regexp pattern for
matching command names and use
`which-key-highlighted-command-face' for any matching names. If
the element is a cons cell, it should take the form (regexp .
face to apply)."
  :group 'which-key
  :type  '(repeat (choice string (cons regexp face)))
  :version "1.0")

(defcustom which-key-special-keys '()
  "These keys will automatically be truncated to one character.
They also have `which-key-special-key-face' applied to them. This
is disabled by default. An example configuration is

\(setq which-key-special-keys \\=3D'(\"SPC\" \"TAB\" \"RET\" \"ESC\" \"DEL\=
")\)"
  :group 'which-key
  :type '(repeat string)
  :version "1.0")

(defcustom which-key-buffer-name " *which-key*"
  "Name of which-key buffer."
  :group 'which-key
  :type 'string
  :version "1.0")

(defcustom which-key-show-prefix 'echo
  "Whether to and where to display the current prefix sequence.
Possible choices are echo for echo area (the default), left, top
and nil. Nil turns the feature off."
  :group 'which-key
  :type '(radio (const :tag "Left of the keys" left)
                (const :tag "In the first line" top)
                (const :tag "In the last line" bottom)
                (const :tag "In the echo area" echo)
                (const :tag "In the mode-line" mode-line)
                (const :tag "Hide" nil))
  :version "1.0")

(defcustom which-key-popup-type 'side-window
  "Supported types are minibuffer, side-window, frame, and custom."
  :group 'which-key
  :type '(radio (const :tag "Show in minibuffer" minibuffer)
                (const :tag "Show in side window" side-window)
                (const :tag "Show in popup frame" frame)
                (const :tag "Use your custom display functions" custom))
  :version "1.0")

(defcustom which-key-min-display-lines 1
  "Minimum number of horizontal lines to display in the which-key buffer."
  :group 'which-key
  :type 'integer
  :version "1.0")

(defcustom which-key-max-display-columns nil
  "Maximum number of columns to display in the which-key buffer.
A value of nil means don't impose a maximum."
  :group 'which-key
  :type '(choice integer (const :tag "Unbounded" nil))
  :version "1.0")

(defcustom which-key-side-window-location 'bottom
  "Location of which-key popup when `which-key-popup-type' is side-window.
Should be one of top, bottom, left or right.  You can also specify
a list of two locations, like (right bottom).  In this case, the
first location is tried.  If there is not enough room, the second
location is tried."
  :group 'which-key
  :type '(radio (const right)
                (const bottom)
                (const left)
                (const top)
                (const (right bottom))
                (const (bottom right)))
  :version "1.0")

(defcustom which-key-side-window-slot 0
  "The `slot' to use for `display-buffer-in-side-window'.
This applies when `which-key-popup-type' is `side-window'.
Quoting from the docstring of `display-buffer-in-side-window',

`slot' if non-nil, specifies the window slot where to display
BUFFER.  A value of zero or nil means use the middle slot on the
specified side.  A negative value means use a slot
preceding (that is, above or on the left of) the middle slot.  A
positive value means use a slot following (that is, below or on
the right of) the middle slot.  The default is zero."
  :group 'which-key
  :type 'integer
  :version "1.0")

(defcustom which-key-side-window-max-width 0.333
  "Maximum width of which-key popup when type is side-window.
This variable can also be a number between 0 and 1. In that case,
it denotes a percentage out of the frame's width."
  :group 'which-key
  :type 'float
  :version "1.0")

(defcustom which-key-side-window-max-height 0.25
  "Maximum height of which-key popup when type is side-window.
This variable can also be a number between 0 and 1. In that case, it denotes
a percentage out of the frame's height."
  :group 'which-key
  :type 'float
  :version "1.0")

(defcustom which-key-frame-max-width 60
  "Maximum width of which-key popup when type is frame."
  :group 'which-key
  :type 'integer
  :version "1.0")

(defcustom which-key-frame-max-height 20
  "Maximum height of which-key popup when type is frame."
  :group 'which-key
  :type 'integer
  :version "1.0")

(defcustom which-key-allow-imprecise-window-fit (not (display-graphic-p))
  "Allow which-key to use a simpler method for resizing the popup.
If you are noticing lag when the which-key popup displays turning
this on may help.

See https://github.com/justbur/emacs-which-key/issues/130
and https://github.com/justbur/emacs-which-key/issues/225."
  :group 'which-key
  :type 'boolean
  :version "1.0")

(defcustom which-key-show-remaining-keys nil
  "Show remaining keys in last slot, when keys are hidden."
  :group 'which-key
  :type '(radio (const :tag "Yes" t)
                (const :tag "No" nil))
  :version "1.0")

(defcustom which-key-sort-order 'which-key-key-order
  "Order in which the key bindings are sorted.
If nil, do not resort the output from `describe-buffer-bindings'
which groups by mode. Ordering options
are

1. `which-key-key-order': by key (default)
2. `which-key-key-order-alpha': by key using alphabetical order
3. `which-key-description-order': by description
4. `which-key-prefix-then-key-order': prefix (no prefix first) then key
5. `which-key-local-then-key-order': local binding then key

See the README and the docstrings for those functions for more
information."
  :group 'which-key
  :type '(choice (function-item which-key-key-order)
                 (function-item which-key-key-order-alpha)
                 (function-item which-key-description-order)
                 (function-item which-key-prefix-then-key-order)
                 (function-item which-key-local-then-key-order))
  :version "1.0")

(defcustom which-key-sort-uppercase-first t
  "If non-nil, uppercase comes before lowercase in sorting.
This applies to the function chosen in
`which-key-sort-order'. Otherwise, the order is reversed."
  :group 'which-key
  :type 'boolean
  :version "1.0")

(defcustom which-key-paging-prefixes '()
  "Enable paging for these prefixes."
  :group 'which-key
  :type '(repeat string)
  :version "1.0")

(defcustom which-key-paging-key "<f5>"
  "Key to use for changing pages.
Bound after each of the prefixes in `which-key-paging-prefixes'"
  :group 'which-key
  :type 'string
  :version "1.0")

;; (defcustom which-key-undo-key nil
;;   "Key (string) to use for undoing keypresses. Bound recursively
;; in each of the maps in `which-key-undo-keymaps'."
;;   :group 'which-key
;;   :type 'string)

;; (defcustom which-key-undo-keymaps '()
;;   "Keymaps in which to bind `which-key-undo-key'"
;;   :group 'which-key
;;   :type '(repeat symbol))

(defcustom which-key-use-C-h-commands t
  "Use C-h (`help-char') for paging if non-nil.
Normally `help-char' after a prefix calls
`describe-prefix-bindings'. This changes that command to a
which-key paging command when which-key-mode is active."
  :group 'which-key
  :type 'boolean
  :version "1.0")

(defcustom which-key-show-early-on-C-h nil
  "Allow C-h (`help-char') to trigger which-key popup before timer.
Show the which-key buffer if `help-char' is pressed in the middle
of a prefix before the which-key buffer would normally be
triggered by the time. If combined with the following settings,
which-key will effectively only show when triggered \"manually\"
using C-h.

\(setq `which-key-idle-delay' 10000)
\(setq `which-key-idle-secondary-delay' 0.05)

Note that `which-key-idle-delay' should be set before turning on
`which-key-mode'."
  :group 'which-key
  :type 'boolean
  :version "1.0")

(defcustom which-key-is-verbose nil
  "Whether to warn about potential mistakes in configuration."
  :group 'which-key
  :type 'boolean
  :version "1.0")

(defcustom which-key-preserve-window-configuration nil
  "Save and restore window configuration around which-key popup display.
If non-nil, save window configuration before which-key buffer is
shown and restore it after which-key buffer is hidden. It
prevents which-key from changing window position of visible
buffers.  Only takken into account when popup type is
side-window."
  :group
  'which-key
  :type 'boolean
  :version "1.0")

(defvar which-key-C-h-map-prompt
  (concat " \\<which-key-C-h-map>"
          " \\[which-key-show-next-page-cycle]"
          which-key-separator "next-page,"
          " \\[which-key-show-previous-page-cycle]"
          which-key-separator "previous-page,"
          " \\[which-key-undo-key]"
          which-key-separator "undo-key,"
          " \\[which-key-toggle-docstrings]"
          which-key-separator "toggle-docstrings,"
          " \\[which-key-show-standard-help]"
          which-key-separator "help,"
          " \\[which-key-abort]"
          which-key-separator "abort"
          " 1..9"
          which-key-separator "digit-arg")
  "Prompt to display when invoking `which-key-C-h-map'.
This string is fed into `substitute-command-keys'")

(defvar which-key-C-h-map
  (let ((map (make-sparse-keymap)))
    (dolist (bind `(("\C-a" . which-key-abort)
                    ("a" . which-key-abort)
                    ("\C-d" . which-key-toggle-docstrings)
                    ("d" . which-key-toggle-docstrings)
                    (,(vector help-char) . which-key-show-standard-help)
                    ("h" . which-key-show-standard-help)
                    ("\C-n" . which-key-show-next-page-cycle)
                    ("n" . which-key-show-next-page-cycle)
                    ("\C-p" . which-key-show-previous-page-cycle)
                    ("p" . which-key-show-previous-page-cycle)
                    ("\C-u" . which-key-undo-key)
                    ("u" . which-key-undo-key)
                    ("1" . which-key-digit-argument)
                    ("2" . which-key-digit-argument)
                    ("3" . which-key-digit-argument)
                    ("4" . which-key-digit-argument)
                    ("5" . which-key-digit-argument)
                    ("6" . which-key-digit-argument)
                    ("7" . which-key-digit-argument)
                    ("8" . which-key-digit-argument)
                    ("9" . which-key-digit-argument)))
      (define-key map (car bind) (cdr bind)))
    map)
  "Keymap for C-h commands.")

(defvar which-key--paging-functions
  (list #'which-key-C-h-dispatch
	#'which-key-manual-update
	#'which-key-turn-page
	#'which-key-show-next-page-cycle
	#'which-key-show-next-page-no-cycle
	#'which-key-show-previous-page-cycle
	#'which-key-show-previous-page-no-cycle
	#'which-key-undo-key
	#'which-key-undo))

(defvar which-key-persistent-popup nil
  "Whether or not to disable `which-key--hide-popup'.")

(defcustom which-key-hide-alt-key-translations t
  "Hide key translations using Alt key if non nil.
These translations are not relevant most of the times since a lot
of terminals issue META modifier for the Alt key.

See http://www.gnu.org/software/emacs/manual/html_node/emacs/Modifier-Keys.=
html"
  :group 'which-key
  :type 'boolean
  :version "1.0")

(defcustom which-key-delay-functions nil
  "List of functions that may delay the which-key popup.
A list of functions that may decide whether to delay the
which-key popup based on the current incomplete key
sequence. Each function in the list is run with two arguments,
the current key sequence as produced by `key-description' and the
length of the key sequence. If the popup should be delayed based
on that key sequence, the function should return the delay time
in seconds. Returning nil means no delay. The first function in
this list to return a value is the value that is used.

The delay time is effectively added to the normal
`which-key-idle-delay'."
  :group 'which-key
  :type '(repeat function)
  :version "1.0")

(defcustom which-key-allow-regexps nil
  "A list of regexp strings to use to filter key sequences.
When non-nil, for a key sequence to trigger the which-key popup
it must match one of the regexps in this list.  The format of the
key sequences is what is produced by `key-description'."
  :group 'which-key
  :type '(repeat regexp)
  :version "1.0")

(defcustom which-key-inhibit-regexps nil
  "A list of regexp strings to use to filter key sequences.
When non-nil, for a key sequence to trigger the which-key popup
it cannot match one of the regexps in this list. The format of
the key sequences is what is produced by `key-description'."
  :group 'which-key
  :type '(repeat regexp)
  :version "1.0")

(defcustom which-key-show-transient-maps nil
  "Show keymaps created by `set-transient-map' when applicable.

More specifically, detect when `overriding-terminal-local-map' is
set (this is the keymap used by `set-transient-map') and display
it."
  :group 'which-key
  :type 'boolean
  :version "1.0")

(make-obsolete-variable
 'which-key-enable-extended-define-key
 "which-key-enable-extended-define-key is obsolete and has no effect."
 "2021-06-21")

;; Hooks
(defcustom which-key-init-buffer-hook '()
  "Hook run when which-key buffer is initialized."
  :group 'which-key
  :type 'hook
  :version "1.0")

;;;; Faces

(defgroup which-key-faces nil
  "Faces for which-key-mode"
  :group 'which-key
  :prefix "which-key-")

(defface which-key-key-face
  '((t . (:inherit font-lock-constant-face)))
  "Face for which-key keys"
  :group 'which-key-faces
  :version "1.0")

(defface which-key-separator-face
  '((t . (:inherit font-lock-comment-face)))
  "Face for the separator (default separator is an arrow)"
  :group 'which-key-faces
  :version "1.0")

(defface which-key-note-face
  '((t . (:inherit which-key-separator-face)))
  "Face for notes or hints occasionally provided"
  :group 'which-key-faces
  :version "1.0")

(defface which-key-command-description-face
  '((t . (:inherit font-lock-function-name-face)))
  "Face for the key description when it is a command"
  :group 'which-key-faces
  :version "1.0")

(defface which-key-local-map-description-face
  '((t . (:inherit which-key-command-description-face)))
  "Face for the key description when it is found in `current-local-map'"
  :group 'which-key-faces
  :version "1.0")

(defface which-key-highlighted-command-face
  '((t . (:inherit which-key-command-description-face :underline t)))
  "Default face for the command description when it is a command
and it matches a string in `which-key-highlighted-command-list'."
  :group 'which-key-faces
  :version "1.0")

(defface which-key-group-description-face
  '((t . (:inherit font-lock-keyword-face)))
  "Face for the key description when it is a group or prefix."
  :group 'which-key-faces
  :version "1.0")

(defface which-key-special-key-face
  '((t . (:inherit which-key-key-face :inverse-video t :weight bold)))
  "Face for special keys (SPC, TAB, RET)"
  :group 'which-key-faces
  :version "1.0")

(defface which-key-docstring-face
  '((t . (:inherit which-key-note-face)))
  "Face for docstrings."
  :group 'which-key-faces
  :version "1.0")

;;;; Custom popup

(defcustom which-key-custom-popup-max-dimensions-function nil
  "Set a custom max-dimensions function.
Will be passed the width of the active window and is expected to
return the maximum height in lines and width in characters of the
which-key popup in the form a cons cell (height . width)."
  :group 'which-key
  :type '(choice function (const nil))
  :version "1.0")

(defcustom which-key-custom-hide-popup-function nil
  "Set a custom hide-popup function.
It takes no arguments and the return value is ignored."
  :group 'which-key
  :type '(choice function (const nil))
  :version "1.0")

(defcustom which-key-custom-show-popup-function nil
  "Set a custom show-popup function.
Will be passed the required dimensions in the form (height .
width) in lines and characters respectively.  The return value is
ignored."
  :group 'which-key
  :type '(choice function (const nil))
  :version "1.0")

(defcustom which-key-lighter " WK"
  "Minor mode lighter to use in the mode-line."
  :group 'which-key
  :type 'string
  :version "1.0")

(defvar which-key-inhibit nil
  "Prevent which-key from popping up momentarily.
This can be used by setting this to a non-nil value for the
execution of a command, as in

\(let \(\(which-key-inhibit t\)\)
...\)")

(defcustom which-key-inhibit-display-hook nil
  "Hook run before display of which-key popup.
Each function in the hook is run before displaying the which-key
popup. If any function returns a non-nil value, the popup will
not display."
  :group 'which-key
  :type 'hook
  :version "1.0")

(defvar which-key-keymap-history nil
  "History of keymap selections.
Used in functions like `which-key-show-keymap'.")

;;; Internal Vars

(defvar which-key--buffer nil
  "Holds reference to which-key buffer.")
(defvar which-key--timer nil
  "Holds reference to open window timer.")
(defvar which-key--secondary-timer-active nil
  "Non-nil if the secondary timer is active.")
(defvar which-key--paging-timer nil
  "Holds reference to timer for paging.")
(defvar which-key--frame nil
  "Holds reference to which-key frame.
Used when `which-key-popup-type' is frame.")
(defvar which-key--echo-keystrokes-backup nil
  "Backup the initial value of `echo-keystrokes'.")
(defvar which-key--prefix-help-cmd-backup nil
  "Backup the value of `prefix-help-command'.")
(defvar which-key--last-try-2-loc nil
  "Last location of side-window when two locations used.")
(defvar which-key--automatic-display nil
  "Non-nil if popup was triggered with automatic update.")
(defvar which-key--debug-buffer-name nil
  "If non-nil, use this buffer for debug messages.")
(defvar which-key--multiple-locations nil)
(defvar which-key--inhibit-next-operator-popup nil)
(defvar which-key--prior-show-keymap-args nil)
(defvar which-key--previous-frame-size nil)
(defvar which-key--prefix-title-alist nil)
(defvar which-key--evil-keys-regexp (eval-when-compile
                                      (regexp-opt '("-state"))))
(defvar which-key--ignore-non-evil-keys-regexp
  (eval-when-compile
    (regexp-opt '("mouse-" "wheel-" "remap" "drag-" "scroll-bar"
                  "select-window" "switch-frame" "which-key"))))
(defvar which-key--ignore-keys-regexp
  (regexp-opt '("mouse-" "wheel-" "remap" "drag-" "scroll-bar"
                "select-window" "switch-frame" "-state"
                "which-key")))

(defvar which-key--pages-obj nil)
(cl-defstruct which-key--pages
  pages
  height
  widths
  keys/page
  page-nums
  num-pages
  total-keys
  prefix
  prefix-title)

(defvar which-key--saved-window-configuration nil)

(defun which-key--rotate (list n)
  (let* ((len (length list))
         (n (if (< n 0) (+ len n) n))
         (n (mod n len)))
    (append (last list (- len n)) (butlast list (- len n)))))

(defun which-key--pages-set-current-page (pages-obj n)
  (setf (which-key--pages-pages pages-obj)
        (which-key--rotate (which-key--pages-pages pages-obj) n))
  (setf (which-key--pages-widths pages-obj)
        (which-key--rotate (which-key--pages-widths pages-obj) n))
  (setf (which-key--pages-keys/page pages-obj)
        (which-key--rotate (which-key--pages-keys/page pages-obj) n))
  (setf (which-key--pages-page-nums pages-obj)
        (which-key--rotate (which-key--pages-page-nums pages-obj) n))
  pages-obj)

(defsubst which-key--on-first-page ()
  (=3D (which-key--pages-page-nums which-key--pages-obj) 1))

(defsubst which-key--on-last-page ()
  (=3D (which-key--pages-page-nums which-key--pages-obj)
     (which-key--pages-num-pages which-key--pages-obj)))

(defsubst which-key--current-prefix ()
  (and which-key--pages-obj
       (which-key--pages-prefix which-key--pages-obj)))

(defmacro which-key--debug-message (&rest msg)
  `(when which-key--debug-buffer-name
     (let ((buf (get-buffer-create which-key--debug-buffer-name))
           (fmt-msg (format ,@msg)))
       (with-current-buffer buf
         (goto-char (point-max))
         (insert "\n" fmt-msg "\n")))))

(defsubst which-key--safe-lookup-key (keymap key)
  "Version of `lookup-key' that allows KEYMAP to be nil.
Also convert numeric results of `lookup-key' to nil. KEY is not
checked."
  (when (keymapp keymap)
    (let ((result (lookup-key keymap key)))
      (when (and result (not (numberp result)))
        result))))

(defsubst which-key--safe-lookup-key-description (keymap key)
  "Version of `lookup-key' that allows KEYMAP to be nil.
Also convert numeric results of `lookup-key' to nil. KEY
should be formatted as an input for `kbd'."
  (let ((key (ignore-errors (kbd key))))
    (when (and key (keymapp keymap))
      (let ((result (lookup-key keymap key)))
        (when (and result (not (numberp result)))
          result)))))

;;; Third-party library support

(defun which-key--this-command-keys ()
  "Version of `this-single-command-keys' corrected for key-chords."
  (let ((this-command-keys (this-single-command-keys)))
    (when (and (vectorp this-command-keys)
               (> (length this-command-keys) 0)
               (eq (aref this-command-keys 0) 'key-chord)
               (bound-and-true-p key-chord-mode))
      (setq this-command-keys (this-single-command-raw-keys)))
    this-command-keys))

(defcustom which-key-this-command-keys-function 'which-key--this-command-ke=
ys
  "Function used to retrieve current key sequence.
The purpose of allowing this variable to be customized is to
allow which-key to support packages that insert non-standard
'keys' into the key sequence being read by emacs."
  :group 'which-key
  :type 'function
  :version "1.0")


;;;; Evil

(defvar evil-state nil)

(defcustom which-key-allow-evil-operators (boundp 'evil-this-operator)
  "Allow popup to show for evil operators.
The popup is normally inhibited in the middle of commands, but
setting this to non-nil will override this behavior for evil
operators."
  :group 'which-key
  :type 'boolean
  :version "1.0")

(defcustom which-key-show-operator-state-maps nil
  "Show the keys following an evil command that reads a motion.
These are commands typically mapped to keys such as \"y\", \"d\"
and \"c\" from normal state. This is experimental, because there
might be some valid keys missing and it might be showing some
invalid keys."
  :group 'which-key
  :type 'boolean
  :version "1.0")

(defun which-key-evil-this-operator-p ()
  (and which-key-allow-evil-operators
       (bound-and-true-p evil-this-operator)))

(add-hook 'which-key-inhibit-display-hook
          'which-key-evil-this-operator-p)

;;;; God-mode

(defvar which-key--god-mode-support-enabled nil
  "Support god-mode if non-nil.")

(defvar which-key--god-mode-key-string nil
  "String to use for god-mode support.")

(defun which-key--god-mode-lookup-command-advice (orig-fun arg1 &rest args)
  (setq which-key--god-mode-key-string arg1)
  (unwind-protect
      (apply orig-fun arg1 args)
    (when (bound-and-true-p which-key-mode)
      (which-key--hide-popup))))

(defun which-key--god-mode-this-command-keys ()
  "Version of `this-single-command-keys' corrected for god-mode."
  (let ((this-command-keys (this-single-command-keys)))
    (when (and which-key--god-mode-support-enabled
               (bound-and-true-p god-local-mode)
               (eq this-command 'god-mode-self-insert))
      (setq this-command-keys (when which-key--god-mode-key-string
                                (kbd which-key--god-mode-key-string))))
    this-command-keys))

(defun which-key-god-mode-self-insert-p ()
  (and which-key--god-mode-support-enabled
       (bound-and-true-p god-local-mode)
       (eq this-command 'god-mode-self-insert)))

(defun which-key-enable-god-mode-support (&optional disable)
  "Enable support for god-mode if non-nil.
This is experimental, so you need to explicitly opt-in for
now.  Please report any problems at github.  If DISABLE is non-nil
disable support."
  (interactive "P")
  (setq which-key--god-mode-support-enabled (null disable))
  (if disable
      (progn
        (advice-remove 'god-mode-lookup-command
                       #'which-key--god-mode-lookup-command-advice)
        (setq which-key-this-command-keys-function
              'which-key--this-command-keys)
        (remove-hook 'which-key-inhibit-display-hook
                     'which-key-god-mode-self-insert-p))
    (advice-add 'god-mode-lookup-command :around
                #'which-key--god-mode-lookup-command-advice)
    (setq which-key-this-command-keys-function
          'which-key--god-mode-this-command-keys)
    (add-hook 'which-key-inhibit-display-hook
              'which-key-god-mode-self-insert-p)))

;;; Mode

;;;###autoload
(define-minor-mode which-key-mode
  "Toggle which-key-mode."
  :global t
  :group 'which-key
  :lighter which-key-lighter
  :keymap (let ((map (make-sparse-keymap)))
            (mapc
             (lambda (prefix)
               (define-key map
                 (kbd (concat prefix " " which-key-paging-key))
                 #'which-key-C-h-dispatch))
             which-key-paging-prefixes)
            map)
  (if which-key-mode
      (progn
        (setq which-key--echo-keystrokes-backup echo-keystrokes)
        (when (or (eq which-key-show-prefix 'echo)
                  (eq which-key-popup-type 'minibuffer))
          (which-key--setup-echo-keystrokes))
        (unless (member prefix-help-command which-key--paging-functions)
          (setq which-key--prefix-help-cmd-backup prefix-help-command))
        (when (or which-key-use-C-h-commands
                  which-key-show-early-on-C-h)
          (setq prefix-help-command #'which-key-C-h-dispatch))
        (when which-key-show-remaining-keys
          (add-hook 'pre-command-hook #'which-key--lighter-restore))
        (add-hook 'pre-command-hook #'which-key--hide-popup)
        (add-hook 'window-size-change-functions
                  #'which-key--hide-popup-on-frame-size-change)
        (which-key--start-timer))
    (setq echo-keystrokes which-key--echo-keystrokes-backup)
    (when which-key--prefix-help-cmd-backup
      (setq prefix-help-command which-key--prefix-help-cmd-backup))
    (when which-key-show-remaining-keys
      (remove-hook 'pre-command-hook #'which-key--lighter-restore))
    (remove-hook 'pre-command-hook #'which-key--hide-popup)
    (remove-hook 'window-size-change-functions
                 #'which-key--hide-popup-on-frame-size-change)
    (which-key--stop-timer)))

(defun which-key--init-buffer ()
  "Initialize which-key buffer"
  (unless (buffer-live-p which-key--buffer)
    (setq which-key--buffer (get-buffer-create which-key-buffer-name))
    (with-current-buffer which-key--buffer
      ;; suppress confusing minibuffer message
      (let (message-log-max)
        (toggle-truncate-lines 1)
        (message ""))
      (setq-local cursor-type nil)
      (setq-local cursor-in-non-selected-windows nil)
      (setq-local mode-line-format nil)
      (setq-local header-line-format nil)
      (setq-local word-wrap nil)
      (setq-local show-trailing-whitespace nil)
      (run-hooks 'which-key-init-buffer-hook))))

(defun which-key--setup-echo-keystrokes ()
  "Reduce `echo-keystrokes' if necessary.
It will interfere if set too high."
  (when (and echo-keystrokes
             (> (abs (- echo-keystrokes which-key-echo-keystrokes)) 0.00000=
1))
    (if (> which-key-idle-delay which-key-echo-keystrokes)
        (setq echo-keystrokes which-key-echo-keystrokes)
      (setq which-key-echo-keystrokes (/ (float which-key-idle-delay) 4)
            echo-keystrokes which-key-echo-keystrokes))))

(defun which-key-remove-default-unicode-chars ()
  "Remove default unicode chars from settings.
Use of `which-key-dont-use-unicode' is preferred to this
function, but it's included here in case someone cannot set that
variable early enough in their configuration, if they are using a
starter kit for example."
  (when (string-equal which-key-separator " =E2=86=92 ")
    (setq which-key-separator " : ")))

;;; Default configuration functions for use by users.

;;;###autoload
(defun which-key-setup-side-window-right ()
  "Set up side-window on right."
  (interactive)
  (setq which-key-popup-type 'side-window
        which-key-side-window-location 'right
        which-key-show-prefix 'top))

;;;###autoload
(defun which-key-setup-side-window-right-bottom ()
  "Set up side-window on right if space allows.
Otherwise, use bottom."
  (interactive)
  (setq which-key-popup-type 'side-window
        which-key-side-window-location '(right bottom)
        which-key-show-prefix 'top))

;;;###autoload
(defun which-key-setup-side-window-bottom ()
  "Set up side-window that opens on bottom."
  (interactive)
  (which-key--setup-echo-keystrokes)
  (setq which-key-popup-type 'side-window
        which-key-side-window-location 'bottom
        which-key-show-prefix 'echo))

;;;###autoload
(defun which-key-setup-minibuffer ()
  "Set up minibuffer display.
Do not use this setup if you use the paging commands.  Instead use
`which-key-setup-side-window-bottom', which is nearly identical
but more functional."
  (interactive)
  (which-key--setup-echo-keystrokes)
  (setq which-key-popup-type 'minibuffer
        which-key-show-prefix 'left))

;;; Helper functions to modify replacement lists.

;;;###autoload
(defun which-key-add-keymap-based-replacements (keymap key replacement &res=
t more)
  "Replace the description of KEY using REPLACEMENT in KEYMAP.
KEY should take a format suitable for use in `kbd'. REPLACEMENT
should be a cons cell of the form \(STRING . COMMAND\) for each
REPLACEMENT, where STRING is the replacement string and COMMAND
is a symbol corresponding to the intended command to be
replaced. COMMAND can be nil if the binding corresponds to a key
prefix. An example is

\(which-key-add-keymap-based-replacements global-map
  \"C-x w\" \\=3D'\(\"Save as\" . write-file\)\).

For backwards compatibility, REPLACEMENT can also be a string,
but the above format is preferred, and the option to use a string
for REPLACEMENT will eventually be removed."
  (while key
    (let ((def
           (cond
            ((consp replacement) replacement)
            ((stringp replacement)
             (cons replacement
                   (or (which-key--safe-lookup-key-description keymap key)
                       (make-sparse-keymap))))
            (t
             (user-error "Replacement is neither a cons cell or a string"))=
)))
      (define-key keymap (kbd key) def))
    (setq key (pop more)
          replacement (pop more))))
(put 'which-key-add-keymap-based-replacements 'lisp-indent-function 'defun)

;;;###autoload
(defun which-key-add-key-based-replacements
    (key-sequence replacement &rest more)
  "Replace the description of KEY-SEQUENCE with REPLACEMENT.
KEY-SEQUENCE is a string suitable for use in `kbd'. REPLACEMENT
may either be a string, as in

\(which-key-add-key-based-replacements \"C-x 1\" \"maximize\"\)

a cons of two strings as in

\(which-key-add-key-based-replacements \"C-x 8\"
                                        \\=3D'(\"unicode\" . \"Unicode keys=
\")\)

or a function that takes a \(KEY . BINDING\) cons and returns a
replacement.

In the second case, the second string is used to provide a longer
name for the keys under a prefix.

MORE allows you to specifcy additional KEY REPLACEMENT pairs.  All
replacements are added to `which-key-replacement-alist'."
  ;; TODO: Make interactive
  (while key-sequence
    ;; normalize key sequences before adding
    (let ((key-seq (key-description (kbd key-sequence)))
          (replace (or (and (functionp replacement) replacement)
                       (car-safe replacement)
                       replacement)))
      (push (cons (cons (concat "\\`" (regexp-quote key-seq) "\\'") nil)
                  (if (functionp replace) replace (cons nil replace)))
            which-key-replacement-alist)
      (when (and (not (functionp replacement)) (consp replacement))
        (push (cons key-seq (cdr-safe replacement))
              which-key--prefix-title-alist)))
    (setq key-sequence (pop more) replacement (pop more))))
(put 'which-key-add-key-based-replacements 'lisp-indent-function 'defun)

;;;###autoload
(defun which-key-add-major-mode-key-based-replacements
    (mode key-sequence replacement &rest more)
  "Functions like `which-key-add-key-based-replacements'.
The difference is that MODE specifies the `major-mode' that must
be active for KEY-SEQUENCE and REPLACEMENT (MORE contains
addition KEY-SEQUENCE REPLACEMENT pairs) to apply."
  (declare (indent defun))
  ;; TODO: Make interactive
  (when (not (symbolp mode))
    (error "MODE should be a symbol corresponding to a value of major-mode"=
))
  (let ((mode-alist
         (or (cdr-safe (assq mode which-key-replacement-alist)) (list)))
        (title-mode-alist
         (or (cdr-safe (assq mode which-key--prefix-title-alist)) (list))))
    (while key-sequence
      ;; normalize key sequences before adding
      (let ((key-seq (key-description (kbd key-sequence)))
            (replace (or (and (functionp replacement) replacement)
                         (car-safe replacement)
                         replacement)))
        (push (cons (cons (concat "\\`" (regexp-quote key-seq) "\\'") nil)
                    (if (functionp replace) replace (cons nil replace)))
              mode-alist)
        (when (and (not (functionp replacement)) (consp replacement))
          (push (cons key-seq (cdr-safe replacement))
                title-mode-alist)))
      (setq key-sequence (pop more) replacement (pop more)))
    (if (assq mode which-key-replacement-alist)
        (setcdr (assq mode which-key-replacement-alist) mode-alist)
      (push (cons mode mode-alist) which-key-replacement-alist))
    (if (assq mode which-key--prefix-title-alist)
        (setcdr (assq mode which-key--prefix-title-alist) title-mode-alist)
      (push (cons mode title-mode-alist) which-key--prefix-title-alist))))

(defun which-key-define-key-recursively (map key def &optional at-root)
  "Recursively bind KEY in MAP to DEF on every level of MAP except the firs=
t.
If AT-ROOT is non-nil the binding is also placed at the root of MAP."
  (when at-root (define-key map key def))
  (map-keymap
   (lambda (_ev df)
     (when (keymapp df)
       (which-key-define-key-recursively df key def t)))
   map))

;;; Functions for computing window sizes

(defun which-key--text-width-to-total (text-width)
  "Convert window TEXT-WIDTH to window total-width.
TEXT-WIDTH is the desired text width of the window.  The function
calculates what total width is required for a window in the
selected to have a text-width of TEXT-WIDTH columns.  The
calculation considers possible fringes and scroll bars.  This
function assumes that the desired window has the same character
width as the frame."
  (let ((char-width (frame-char-width)))
    (+ text-width
       (/ (frame-fringe-width) char-width)
       (/ (frame-scroll-bar-width) char-width)
       (if (which-key--char-enlarged-p) 1 0)
       ;; add padding to account for possible wide (unicode) characters
       3)))

(defun which-key--total-width-to-text (total-width)
  "Convert window TOTAL-WIDTH to window text-width.
TOTAL-WIDTH is the desired total width of the window.  The function calcula=
tes
what text width fits such a window.  The calculation considers possible fri=
nges
and scroll bars.  This function assumes that the desired window has the same
character width as the frame."
  (let ((char-width (frame-char-width)))
    (- total-width
       (/ (frame-fringe-width) char-width)
       (/ (frame-scroll-bar-width) char-width)
       (if (which-key--char-enlarged-p) 1 0)
       ;; add padding to account for possible wide (unicode) characters
       3)))

(defun which-key--char-enlarged-p (&optional _frame)
  (> (frame-char-width)
     (/ (float (frame-pixel-width)) (window-total-width (frame-root-window)=
))))

(defun which-key--char-reduced-p (&optional _frame)
  (< (frame-char-width)
     (/ (float (frame-pixel-width)) (window-total-width (frame-root-window)=
))))

(defun which-key--char-exact-p (&optional _frame)
  (=3D (frame-char-width)
     (/ (float (frame-pixel-width)) (window-total-width (frame-root-window)=
))))

(defun which-key--width-or-percentage-to-width (width-or-percentage)
  "Return window total width.
If WIDTH-OR-PERCENTAGE is a whole number, return it unchanged.  Otherwise, =
it
should be a percentage (a number between 0 and 1) out of the frame's width.
More precisely, it should be a percentage out of the frame's root window's
total width."
  (if (wholenump width-or-percentage)
      width-or-percentage
    (round (* width-or-percentage (window-total-width (frame-root-window)))=
)))

(defun which-key--height-or-percentage-to-height (height-or-percentage)
  "Return window total height.
If HEIGHT-OR-PERCENTAGE is a whole number, return it unchanged.  Otherwise,=
 it
should be a percentage (a number between 0 and 1) out of the frame's height.
More precisely, it should be a percentage out of the frame's root window's
total height."
  (if (wholenump height-or-percentage)
      height-or-percentage
    (round (* height-or-percentage (window-total-height (frame-root-window)=
)))))

(defun which-key--frame-size-changed-p ()
  "Non-nil if a change in frame size is detected."
  (let ((new-size (cons (frame-width) (frame-height))))
    (cond ((null which-key--previous-frame-size)
           (setq which-key--previous-frame-size new-size)
           nil)
          ((not (equal which-key--previous-frame-size new-size))
           (setq which-key--previous-frame-size new-size)))))

;;; Show/hide which-key buffer

(defun which-key--hide-popup ()
  "This function is called to hide the which-key buffer."
  (unless (or which-key-persistent-popup
              (member real-this-command which-key--paging-functions))
    (setq which-key--last-try-2-loc nil)
    (setq which-key--pages-obj nil)
    (setq which-key--automatic-display nil)
    (setq which-key--prior-show-keymap-args nil)
    (when (and which-key-idle-secondary-delay which-key--secondary-timer-ac=
tive)
      (which-key--start-timer))
    (which-key--lighter-restore)
    (which-key--hide-popup-ignore-command)))

(defun which-key--hide-popup-ignore-command ()
  "`which-key--hide-popup' without the check of `real-this-command'."
  (cl-case which-key-popup-type
    ;; Not necessary to hide minibuffer
    ;; (minibuffer (which-key--hide-buffer-minibuffer))
    (side-window (which-key--hide-buffer-side-window))
    (frame (which-key--hide-buffer-frame))
    (custom (funcall which-key-custom-hide-popup-function))))

(defun which-key--hide-popup-on-frame-size-change (&optional _)
  "Hide which-key popup if the frame is resized (to trigger a new popup)."
  (when (which-key--frame-size-changed-p)
    (which-key--hide-popup)))

(defun which-key--hide-buffer-side-window ()
  "Hide which-key buffer when side-window popup is used."
  (when (buffer-live-p which-key--buffer)
    ;; in case which-key buffer was shown in an existing window, `quit-wind=
ow'
    ;; will re-show the previous buffer, instead of closing the window
    (quit-windows-on which-key--buffer)
    (when (and which-key-preserve-window-configuration
               which-key--saved-window-configuration)
      (set-window-configuration which-key--saved-window-configuration)
      (setq which-key--saved-window-configuration nil))))

(defun which-key--hide-buffer-frame ()
  "Hide which-key buffer when frame popup is used."
  (when (frame-live-p which-key--frame)
    (delete-frame which-key--frame)))

(defun which-key--popup-showing-p ()
  (and (bufferp which-key--buffer)
       (or (window-live-p (get-buffer-window which-key--buffer))
           (let ((window (get-buffer-window which-key--buffer t)))
             (and (window-live-p window)
                  (frame-visible-p (window-frame window)))))))

(defun which-key--show-popup (act-popup-dim)
  "Show the which-key buffer.
ACT-POPUP-DIM includes the dimensions, (height . width) of the
buffer text to be displayed in the popup.  Return nil if no window
is shown, or if there is no need to start the closing timer."
  (when (and (> (car act-popup-dim) 0)
             (> (cdr act-popup-dim) 0))
    (cl-case which-key-popup-type
      ;; Not called for minibuffer
      ;; (minibuffer (which-key--show-buffer-minibuffer act-popup-dim))
      (side-window (which-key--show-buffer-side-window act-popup-dim))
      (frame (which-key--show-buffer-frame act-popup-dim))
      (custom (funcall which-key-custom-show-popup-function act-popup-dim))=
)))

(defun which-key--fit-buffer-to-window-horizontally
    (&optional window &rest params)
  "Slightly modified version of `fit-buffer-to-window'.
Use &rest params because `fit-buffer-to-window' has a different
call signature in different emacs versions"
  (let ((fit-window-to-buffer-horizontally t)
        (window-min-height 1))
    (apply #'fit-window-to-buffer window params)))

(defun which-key--show-buffer-side-window (act-popup-dim)
  "Show which-key buffer when popup type is side-window."
  (when (and which-key-preserve-window-configuration
             (not which-key--saved-window-configuration))
    (setq which-key--saved-window-configuration (current-window-configurati=
on)))
  (let* ((height (car act-popup-dim))
         (width (cdr act-popup-dim))
         (alist
          (if which-key-allow-imprecise-window-fit
              `((window-width .  ,(which-key--text-width-to-total width))
                (window-height . ,height)
                (side . ,which-key-side-window-location)
                (slot . ,which-key-side-window-slot))
            `((window-width . which-key--fit-buffer-to-window-horizontally)
              (window-height . (lambda (w) (fit-window-to-buffer w nil 1)))
              (side . ,which-key-side-window-location)
              (slot . ,which-key-side-window-slot)))))
    ;; Previously used `display-buffer-in-major-side-window' here, but
    ;; apparently that is meant to be an internal function. See emacs bug #=
24828
    ;; and advice given there.
    (cond
     ((eq which-key--multiple-locations t)
      ;; possibly want to switch sides in this case so we can't reuse the w=
indow
      (delete-windows-on which-key--buffer)
      (display-buffer-in-side-window which-key--buffer alist))
     ((get-buffer-window which-key--buffer)
      (display-buffer-reuse-window which-key--buffer alist))
     (t
      (display-buffer-in-side-window which-key--buffer alist)))))

(defun which-key--show-buffer-frame (act-popup-dim)
  "Show which-key buffer when popup type is frame."
  (let* (;(orig-window (selected-window))
         (frame-height (+ (car act-popup-dim)
                          (if (with-current-buffer which-key--buffer
                                mode-line-format)
                              1
                            0)))
         ;; without adding 2, frame sometimes isn't wide enough for the buf=
fer.
         ;; this is probably because of the fringes. however, setting fring=
es
         ;; sizes to 0 (instead of adding 2) didn't always make the frame w=
ide
         ;; enough. don't know why it is so.
         (frame-width (+ (cdr act-popup-dim) 2))
         (new-window (if (and (frame-live-p which-key--frame)
                              (eq which-key--buffer
                                  (window-buffer
                                   (frame-root-window which-key--frame))))
                         (which-key--show-buffer-reuse-frame
                          frame-height frame-width)
                       (which-key--show-buffer-new-frame
                        frame-height frame-width))))
    (when new-window
      ;; display successful
      (setq which-key--frame (window-frame new-window))
      new-window)))

(defun which-key--show-buffer-new-frame (frame-height frame-width)
  "Helper for `which-key--show-buffer-frame'."
  (let* ((frame-params `((height . ,frame-height)
                         (width . ,frame-width)
                         ;; tell the window manager to respect the given si=
zes
                         (user-size . t)
                         ;; which-key frame doesn't need a minibuffer
                         (minibuffer . nil)
                         (name . "which-key")
                         ;; no need for scroll bars in which-key frame
                         (vertical-scroll-bars . nil)
                         ;; (left-fringe . 0)
                         ;; (right-fringe . 0)
                         ;; (right-divider-width . 0)
                         ;; make sure frame is visible
                         (visibility . t)))
         (alist `((pop-up-frame-parameters . ,frame-params)))
         (orig-frame (selected-frame))
         (new-window (display-buffer-pop-up-frame which-key--buffer alist)))
    (when new-window
      ;; display successful
      (redirect-frame-focus (window-frame new-window) orig-frame)
      new-window)))

(defun which-key--show-buffer-reuse-frame (frame-height frame-width)
  "Helper for `which-key--show-buffer-frame'."
  (let ((window
         (display-buffer-reuse-window
          which-key--buffer `((reusable-frames . ,which-key--frame)))))
    (when window
      ;; display successful
      (set-frame-size (window-frame window) frame-width frame-height)
      window)))

;;; Max dimension of available window functions

(defun which-key--popup-max-dimensions ()
  "Return maximum dimension available for popup.
Dimesion functions should return the maximum possible (height
. width) of the intended popup. SELECTED-WINDOW-WIDTH is the
width of currently active window, not the which-key buffer
window."
  (cl-case which-key-popup-type
    (minibuffer (which-key--minibuffer-max-dimensions))
    (side-window (which-key--side-window-max-dimensions))
    (frame (which-key--frame-max-dimensions))
    (custom (funcall which-key-custom-popup-max-dimensions-function
                     (window-width)))))

(defun which-key--minibuffer-max-dimensions ()
  "Return max-dimensions of minibuffer (height . width).
Measured in lines and characters respectively."
  (cons
   ;; height
   (if (floatp max-mini-window-height)
       (floor (* (frame-text-lines)
                 max-mini-window-height))
     max-mini-window-height)
   ;; width
   (max 0 (- (frame-text-cols) which-key-unicode-correction))))

(defun which-key--side-window-max-dimensions ()
  "Return max-dimensions of the side-window popup.
The return value should be (height . width) in lines and
characters respectively."
  (cons
   ;; height
   (if (member which-key-side-window-location '(left right))
       ;; 1 is a kludge to make sure there is no overlap
       (- (frame-height) (window-text-height (minibuffer-window)) 1)
     ;; (window-mode-line-height which-key--window))
     ;; FIXME: change to something like
     ;; (min which-*-height (calculate-max-height))
     (which-key--height-or-percentage-to-height
      which-key-side-window-max-height))
   ;; width
   (max 0
        (- (if (memq which-key-side-window-location '(left right))
               (which-key--total-width-to-text
                (which-key--width-or-percentage-to-width
                 which-key-side-window-max-width))
             (which-key--total-width-to-text
              (which-key--width-or-percentage-to-width
               1.0)))
           which-key-unicode-correction))))

(defun which-key--frame-max-dimensions ()
  "Return max-dimensions of the frame popup.
The return value should be (height . width) in lines and
characters respectively."
  (cons which-key-frame-max-height which-key-frame-max-width))

;;; Sorting functions

(defun which-key--string< (a b &optional alpha)
  (let ((da (downcase a))
        (db (downcase b)))
    (cond
     ((and alpha (not which-key-sort-uppercase-first))
      (if (string-equal da db)
          (not (string-lessp a b))
        (string-lessp da db)))
     ((and alpha which-key-sort-uppercase-first)
      (if (string-equal da db)
          (string-lessp a b)
        (string-lessp da db)))
     ((not which-key-sort-uppercase-first)
      (let ((aup (not (string-equal da a)))
            (bup (not (string-equal db b))))
        (if (eq aup bup)
            (string-lessp a b)
          bup)))
     (t (string-lessp a b)))))

(defun which-key--key-description< (a b &optional alpha)
  "Key sorting function.
Used for `which-key-key-order' and `which-key-key-order-alpha'."
  (save-match-data
    (let* ((a (which-key--extract-key a))
           (b (which-key--extract-key b))
           (rngrgxp "^\\([^ ]+\\) \\.\\. [^ ]+")
           (a (if (string-match rngrgxp a) (match-string 1 a) a))
           (b (if (string-match rngrgxp b) (match-string 1 b) b))
           (aem? (string-equal a ""))
           (bem? (string-equal b ""))
           (a1? (=3D 1 (length a)))
           (b1? (=3D 1 (length b)))
           (srgxp "^\\(RET\\|SPC\\|TAB\\|DEL\\|LFD\\|ESC\\|NUL\\)")
           (asp? (string-match-p srgxp a))
           (bsp? (string-match-p srgxp b))
           (prrgxp "^\\(M\\|C\\|S\\|A\\|H\\|s\\)-")
           (apr? (string-match-p prrgxp a))
           (bpr? (string-match-p prrgxp b))
           (afn? (string-match-p "<f[0-9]+>" a))
           (bfn? (string-match-p "<f[0-9]+>" b)))
      (cond ((or aem? bem?) (and aem? (not bem?)))
            ((and asp? bsp?)
             (if (string-equal (substring a 0 3) (substring b 0 3))
                 (which-key--key-description<
                  (substring a 3) (substring b 3) alpha)
               (which-key--string< a b alpha)))
            ((or asp? bsp?) asp?)
            ((and a1? b1?) (which-key--string< a b alpha))
            ((or a1? b1?) a1?)
            ((and afn? bfn?)
             (< (string-to-number
                 (replace-regexp-in-string "<f\\([0-9]+\\)>" "\\1" a))
                (string-to-number
                 (replace-regexp-in-string "<f\\([0-9]+\\)>" "\\1" b))))
            ((or afn? bfn?) afn?)
            ((and apr? bpr?)
             (if (string-equal (substring a 0 2) (substring b 0 2))
                 (which-key--key-description<
                  (substring a 2) (substring b 2) alpha)
               (which-key--string< a b alpha)))
            ((or apr? bpr?) apr?)
            (t (which-key--string< a b alpha))))))

(defsubst which-key-key-order-alpha (acons bcons)
  "Order key descriptions A and B.
Order is lexicographic within a \"class\", where the classes and
the ordering of classes are listed below.

special (SPC,TAB,...) < single char < mod (C-,M-,...) < other.
Sorts single characters alphabetically with lowercase coming
before upper."
  (which-key--key-description< (car acons) (car bcons) t))

(defsubst which-key-key-order (acons bcons)
  "Order key descriptions A and B.
Order is lexicographic within a \"class\", where the classes and
the ordering of classes are listed below.

special (SPC,TAB,...) < single char < mod (C-,M-,...) < other."
  (which-key--key-description< (car acons) (car bcons)))

(defsubst which-key-description-order (acons bcons)
  "Order descriptions of A and B.
Uses `string-lessp' after applying lowercase."
  (string-lessp (downcase (cdr acons)) (downcase (cdr bcons))))

(defsubst which-key--group-p (description)
  (or (string-equal description "prefix")
      (string-match-p "^group:" description)
      (keymapp (intern description))))

(defun which-key-prefix-then-key-order (acons bcons)
  "Order prefixes before non-prefixes.
Within these categories order using `which-key-key-order'."
  (let ((apref? (which-key--group-p (cdr acons)))
        (bpref? (which-key--group-p (cdr bcons))))
    (if (not (eq apref? bpref?))
        (and (not apref?) bpref?)
      (which-key-key-order acons bcons))))

(defun which-key-prefix-then-key-order-reverse (acons bcons)
  "Order prefixes before non-prefixes.
Within these categories order using `which-key-key-order'."
  (let ((apref? (which-key--group-p (cdr acons)))
        (bpref? (which-key--group-p (cdr bcons))))
    (if (not (eq apref? bpref?))
        (and apref? (not bpref?))
      (which-key-key-order acons bcons))))

(defun which-key-local-then-key-order (acons bcons)
  "Order local bindings before non-local ones.
Within these categories order using `which-key-key-order'."
  (let ((aloc? (which-key--local-binding-p acons))
        (bloc? (which-key--local-binding-p bcons)))
    (if (not (eq aloc? bloc?))
        (and aloc? (not bloc?))
      (which-key-key-order acons bcons))))

;;; Functions for retrieving and formatting keys

(defsubst which-key--string-width (maybe-string)
  "If MAYBE-STRING is a string use `which-key--string-width' o/w return 0."
  (if (stringp maybe-string) (string-width maybe-string) 0))

(defsubst which-key--butlast-string (str)
  (string-join (butlast (split-string str)) " "))

(defun which-key--match-replacement (key-binding replacement)
  ;; these are mode specific ones to ignore. The mode specific case is
  ;; handled in the selection of alist
  (when (and (consp key-binding) (not (symbolp (car replacement))))
    (let ((key-regexp (caar replacement))
          (binding-regexp (cdar replacement))
          case-fold-search)
      (and (or (null key-regexp)
               (string-match-p key-regexp
                               (car key-binding)))
           (or (null binding-regexp)
               (string-match-p binding-regexp
                               (cdr key-binding)))))))

(defsubst which-key--replace-in-binding (key-binding repl)
  (cond ((or (not (consp repl)) (null (cdr repl)))
         key-binding)
        ((functionp (cdr repl))
         (funcall (cdr repl) key-binding))
        ((consp (cdr repl))
         (cons
          (cond ((and (caar repl) (cadr repl))
                 (replace-regexp-in-string
                  (caar repl) (cadr repl) (car key-binding) t))
                ((cadr repl) (cadr repl))
                (t (car key-binding)))
          (cond ((and (cdar repl) (cddr repl))
                 (replace-regexp-in-string
                  (cdar repl) (cddr repl) (cdr key-binding) t))
                ((cddr repl) (cddr repl))
                (t (cdr key-binding)))))))

(defun which-key--replace-in-repl-list-once (key-binding repls)
  (cl-dolist (repl repls)
    (when (which-key--match-replacement key-binding repl)
      (cl-return `(replaced . ,(which-key--replace-in-binding key-binding r=
epl))))))

(defun which-key--replace-in-repl-list-many (key-binding repls)
  (let (found)
    (dolist (repl repls)
      (when (which-key--match-replacement key-binding repl)
        (setq found 't)
        (setq key-binding (which-key--replace-in-binding key-binding repl))=
))
    (when found `(replaced . ,key-binding))))

(defun which-key--maybe-replace (key-binding)
  "Use `which-key--replacement-alist' to maybe replace KEY-BINDING.
KEY-BINDING is a cons cell of the form \(KEY . BINDING\) each of
which are strings.  KEY is of the form produced by `key-binding'."
  (let* ((replacer (if which-key-allow-multiple-replacements
                       #'which-key--replace-in-repl-list-many
                     #'which-key--replace-in-repl-list-once)))
    (pcase
        (apply replacer
               (list key-binding
                     (cdr-safe (assq major-mode which-key-replacement-alist=
))))
      (`(replaced . ,repl)
       (if which-key-allow-multiple-replacements
           (pcase (apply replacer (list repl which-key-replacement-alist))
             (`(replaced . ,repl) repl)
             ('() repl))
         repl))
      ('()
       (pcase (apply replacer (list key-binding which-key-replacement-alist=
))
         (`(replaced . ,repl) repl)
         ('() key-binding))))))

(defsubst which-key--current-key-list (&optional key-str)
  (append (listify-key-sequence (which-key--current-prefix))
          (when key-str
            (listify-key-sequence (kbd key-str)))))

(defsubst which-key--current-key-string (&optional key-str)
  (key-description (which-key--current-key-list key-str)))

(defun which-key--local-binding-p (keydesc)
  (eq (which-key--safe-lookup-key-description
       (current-local-map)
       (which-key--current-key-string (car keydesc)))
      (intern (cdr keydesc))))

(defun which-key--map-binding-p (map keydesc)
  "Does MAP contain KEYDESC =3D (key . binding)?"
  (or
   (when (bound-and-true-p evil-state)
     (let ((lookup
            (which-key--safe-lookup-key-description
             map
             (which-key--current-key-string
              (format "<%s-state> %s" evil-state (car keydesc))))))
       (or (eq lookup (intern (cdr keydesc)))
           (and (keymapp lookup) (string=3D (cdr keydesc) "Prefix Command")=
))))
   (let ((lookup
          (which-key--safe-lookup-key-description
           map (which-key--current-key-string (car keydesc)))))
     (or (eq lookup (intern (cdr keydesc)))
         (and (keymapp lookup) (string=3D (cdr keydesc) "Prefix Command")))=
)))

(defun which-key--maybe-get-prefix-title (keys)
  "KEYS is a string produced by `key-description'.
A title is possibly returned using
`which-key--prefix-title-alist'.  An empty string is returned if
no title exists."
  (cond
   ((not (string-equal keys ""))
    (let* ((title-res
            (cdr-safe (assoc-string keys which-key--prefix-title-alist)))
           (repl-res
            (cdr-safe (which-key--maybe-replace (cons keys ""))))
           (binding (key-binding (kbd keys)))
           (alternate (when (and binding (symbolp binding))
                        (symbol-name binding))))
      (cond (title-res title-res)
            ((not (string-equal repl-res "")) repl-res)
            ((and (eq which-key-show-prefix 'echo) alternate)
             alternate)
            ((and (member which-key-show-prefix '(bottom top mode-line))
                  (eq which-key-side-window-location 'bottom)
                  echo-keystrokes)
             (if alternate alternate
               (concat "Following " keys)))
            (t ""))))
   (t "")))

(defun which-key--propertize (string &rest properties)
  "Version of `propertize' that checks type of STRING."
  (when (stringp string)
    (apply #'propertize string properties)))

(defun which-key--propertize-key (key)
  "Add a face to KEY.
If KEY contains any \"special keys\" defined in
`which-key-special-keys' then truncate and add the corresponding
`which-key-special-key-face'."
  (let ((key-w-face (which-key--propertize key 'face 'which-key-key-face))
        (regexp (concat "\\("
                        (mapconcat #'identity which-key-special-keys
                                   "\\|")
                        "\\)"))
        case-fold-search)
    (save-match-data
      (if (and which-key-special-keys
               (string-match regexp key))
          (let ((beg (match-beginning 0)) (end (match-end 0)))
            (concat (substring key-w-face 0 beg)
                    (which-key--propertize (substring key-w-face beg (1+ be=
g))
                                           'face 'which-key-special-key-fac=
e)
                    (substring key-w-face end
                               (which-key--string-width key-w-face))))
        key-w-face))))

(defsubst which-key--truncate-description (desc avl-width)
  "Truncate DESC description to `which-key-max-description-length'."
  (let* ((max which-key-max-description-length)
	 (max (cl-etypecase max
		(null nil)
		(integer max)
		(float (truncate (* max avl-width)))
		(function (let ((val (funcall max avl-width)))
			    (if (floatp val) (truncate val) val))))))
    (if (and max (> (length desc) max))
        (let ((dots (and (not (equal which-key-ellipsis ""))
			 (which-key--propertize
			  which-key-ellipsis 'face
			  (get-text-property (1- (length desc)) 'face desc)))))
	  (if dots
              (concat (substring desc 0 (- max (length dots))) dots)
	    (substring desc 0 max)))
      desc)))

(defun which-key--highlight-face (description)
  "Return the highlight face for DESCRIPTION if it has one."
  (let (face)
    (dolist (el which-key-highlighted-command-list)
      (unless face
        (cond ((consp el)
               (when (string-match-p (car el) description)
                 (setq face (cdr el))))
              ((stringp el)
               (when (string-match-p el description)
                 (setq face 'which-key-highlighted-command-face)))
              (t
               (message "which-key: warning: element %s of \
which-key-highlighted-command-list is not a string or a cons
cell" el)))))
    face))

(defun which-key--propertize-description
    (description group local hl-face &optional original-description)
  "Add face to DESCRIPTION.
The face chosen depends on whether the description represents a
group or a command. Also make some minor adjustments to the
description string, like removing a \"group:\" prefix.

ORIGINAL-DESCRIPTION is the description given by
`describe-buffer-bindings'."
  (when description
    (let* ((desc description)
           (desc (if (string-match-p "^group:" desc)
                     (substring desc 6) desc))
           (desc (if group (concat which-key-prefix-prefix desc) desc)))
      (make-text-button
       desc nil
       'face (cond (hl-face hl-face)
                   (group 'which-key-group-description-face)
                   (local 'which-key-local-map-description-face)
                   (t 'which-key-command-description-face))
       'help-echo (cond
                   ((and original-description
                         (fboundp (intern original-description))
                         (documentation (intern original-description))
                         ;; tooltip-mode doesn't exist in emacs-nox
                         (boundp 'tooltip-mode) tooltip-mode)
                    (documentation (intern original-description)))
                   ((and original-description
                         (fboundp (intern original-description))
                         (documentation (intern original-description))
                         (let* ((doc (documentation
                                      (intern original-description)))
                                (str (replace-regexp-in-string "\n" " " doc=
))
                                (max (floor (* (frame-width) 0.8))))
                           (if (> (length str) max)
                               (concat (substring str 0 max) "...")
                             str)))))))))

(defun which-key--extract-key (key-str)
  "Pull the last key (or key range) out of KEY-STR."
  (save-match-data
    (let ((key-range-regexp "\\`.*\\([^ \t]+ \\.\\. [^ \t]+\\)\\'"))
      (if (string-match key-range-regexp key-str)
          (match-string 1 key-str)
        (car (last (split-string key-str " ")))))))

(defun which-key--maybe-add-docstring (current original)
  "Maybe concat a docstring to CURRENT and return result.
Specifically, do this if ORIGINAL is a command with a docstring
and `which-key-show-docstrings' is non-nil.  If
`which-key-show-docstrings' is the symbol docstring-only, just
return the docstring."
  (let* ((orig-sym (intern original))
         (doc (when (commandp orig-sym)
                (documentation orig-sym)))
         (doc (when doc
                (replace-regexp-in-string
                 (concat "^\\(?::"
                         (regexp-opt '("around" "override"
                                       "after" "after-until" "after-while"
                                       "before" "before-until" "before-whil=
e"
                                       "filter-args" "filter-return"))
                         " advice: [^\n]+\n"
                         "\\)+\n")
                 "" doc)))
         (docstring (when doc
                      (which-key--propertize (car (split-string doc "\n"))
                                             'face 'which-key-docstring-fac=
e))))
    (cond ((not (and which-key-show-docstrings docstring))
           current)
          ((eq which-key-show-docstrings 'docstring-only)
           docstring)
          (t
           (format "%s %s" current docstring)))))

(defun which-key--format-and-replace (unformatted &optional preserve-full-k=
ey)
  "Make list of key bindings with separators and descriptions.
Take a list of (key . desc) cons cells in UNFORMATTED, add
faces and perform replacements according to the three replacement
alists. Returns a list (key separator description)."
  (let ((sep-w-face
         (which-key--propertize which-key-separator
                                'face 'which-key-separator-face))
        (local-map (current-local-map))
	(avl-width (cdr (which-key--popup-max-dimensions)))
        new-list)
    (dolist (key-binding unformatted)
      (let* ((keys (car key-binding))
             (orig-desc (cdr key-binding))
             (group (which-key--group-p orig-desc))
             (local (eq (which-key--safe-lookup-key-description
                         local-map keys)
                        (intern orig-desc)))
             (hl-face (which-key--highlight-face orig-desc))
             (key-binding (which-key--maybe-replace key-binding))
             (final-desc (which-key--propertize-description
                          (cdr key-binding) group local hl-face orig-desc)))
        (when final-desc
          (setq final-desc
                (which-key--truncate-description
                 (which-key--maybe-add-docstring final-desc orig-desc)
		 avl-width)))
        (when (consp key-binding)
          (push
           (list (which-key--propertize-key
                  (if preserve-full-key
                      (car key-binding)
                    (which-key--extract-key (car key-binding))))
                 sep-w-face
                 final-desc)
           new-list))))
    (nreverse new-list)))

(defun which-key--compute-binding (binding)
  "Replace BINDING with remapped binding if it exists.
Requires `which-key-compute-remaps' to be non-nil."
  (let (remap)
    (if (and which-key-compute-remaps
             (setq remap (command-remapping binding)))
        (copy-sequence (symbol-name remap))
      (copy-sequence (symbol-name binding)))))

(defun which-key--get-menu-item-binding (def)
  "Retrieve binding for menu-item"
  ;; see `keymap--menu-item-binding'
  (let* ((binding (nth 2 def))
         (plist (nthcdr 3 def))
         (filter (plist-get plist :filter)))
    (if filter (funcall filter binding) binding)))

(defun which-key--get-keymap-bindings-1
    (keymap start &optional prefix filter all ignore-commands)
  "See `which-key--get-keymap-bindings'."
  (let ((bindings start)
        (prefix-map (if prefix (lookup-key keymap prefix) keymap)))
    (when (keymapp prefix-map)
      (map-keymap
       (lambda (ev def)
         (let* ((key (vconcat prefix (list ev)))
                (key-desc (key-description key)))
           (cond
            ((assoc key-desc bindings))
            ((and (listp ignore-commands) (symbolp def) (memq def ignore-co=
mmands)))
            ((or (string-match-p
                  which-key--ignore-non-evil-keys-regexp key-desc)
                 (eq ev 'menu-bar)))
            ((and (keymapp def)
                  (string-match-p which-key--evil-keys-regexp key-desc)))
            ((and (keymapp def)
                  (or all
                      ;; event 27 is escape, so this will pick up meta
                      ;; bindings and hopefully not too much more
                      (and (numberp ev) (=3D ev 27))))
             (setq bindings
                   (which-key--get-keymap-bindings-1
                    keymap bindings key nil all ignore-commands)))
            (def
             (let* ((def (if (eq 'menu-item (car-safe def))
                             (which-key--get-menu-item-binding def)
                           def))
                    (binding
                     (cons key-desc
                           (cond
                            ((symbolp def) (which-key--compute-binding def))
                            ((keymapp def) "prefix")
                            ((eq 'lambda (car-safe def)) "lambda")
                            ((eq 'closure (car-safe def)) "closure")
                            ((stringp def) def)
                            ((vectorp def) (key-description def))
                            ((and (consp def)
                                  ;; looking for (STRING . DEFN)
                                  (stringp (car def)))
                             (concat (when (keymapp (cdr-safe def))
                                       "group:")
                                     (car def)))
                            (t "unknown")))))
               (when (or (null filter)
                         (and (functionp filter)
                              (funcall filter binding)))
                 (push binding bindings)))))))
       prefix-map))
    bindings))

(defun which-key--get-keymap-bindings
    (keymap &optional start prefix filter all evil)
  "Retrieve top-level bindings from KEYMAP.
PREFIX limits bindings to those starting with this key
sequence.  START is a list of existing bindings to add to.  If ALL
is non-nil, recursively retrieve all bindings below PREFIX. If
EVIL is non-nil, extract active evil bidings."
  (let ((bindings start)
        (ignore '(self-insert-command ignore ignore-event company-ignore))
        (evil-map
         (when (and evil (bound-and-true-p evil-local-mode))
           (lookup-key keymap (kbd (format "<%s-state>" evil-state))))))
    (when (keymapp evil-map)
      (setq bindings (which-key--get-keymap-bindings-1
                      evil-map bindings prefix filter all ignore)))
    (which-key--get-keymap-bindings-1
     keymap bindings prefix filter all ignore)))

(defun which-key--get-current-bindings (&optional prefix filter)
  "Generate a list of current active bindings."
  (let (bindings)
    (dolist (map (current-active-maps t) bindings)
      (when (cdr map)
        (setq bindings
              (which-key--get-keymap-bindings
               map bindings prefix filter))))))

(defun which-key--get-bindings (&optional prefix keymap filter recursive)
  "Collect key bindings.
If KEYMAP is nil, collect from current buffer using the current
key sequence as a prefix. Otherwise, collect from KEYMAP. FILTER
is a function to use to filter the bindings. If RECURSIVE is
non-nil, then bindings are collected recursively for all prefixes."
  (let* ((unformatted
          (cond ((keymapp keymap)
                 (which-key--get-keymap-bindings
                  keymap nil prefix filter recursive))
                (keymap
                 (error "%s is not a keymap" keymap))
                (t
                 (which-key--get-current-bindings prefix filter)))))
    (when which-key-sort-order
      (setq unformatted
            (sort unformatted which-key-sort-order)))
    (which-key--format-and-replace unformatted recursive)))

;;; Functions for laying out which-key buffer pages

(defun which-key--normalize-columns (columns)
  "Pad COLUMNS to the same length using empty strings."
  (let ((max-len (cl-reduce (lambda (a x) (max a (length x))) columns
                            :initial-value 0)))
    (mapcar
     (lambda (c)
       (if (< (length c) max-len)
           (append c (make-list (- max-len (length c)) ""))
         c))
     columns)))

(defsubst which-key--join-columns (columns)
  "Transpose columns into rows, concat rows into lines and rows into page."
  (let* ((padded (which-key--normalize-columns (nreverse columns)))
         (rows (apply #'cl-mapcar #'list padded)))
    (mapconcat (lambda (row) (mapconcat #'identity row " ")) rows "\n")))

(defsubst which-key--max-len (keys index &optional initial-value)
  "Find the max length of the INDEX element in each of KEYS."
  (cl-reduce
   (lambda (x y) (max x (which-key--string-width (nth index y))))
   keys :initial-value (if initial-value initial-value 0)))

(defun which-key--pad-column (col-keys avl-width)
  "Pad cells of COL-KEYS to AVL-WIDTH.
Take a column of (key separator description) COL-KEYS,
calculate the max width in the column and pad all cells out to
that width."
  (let* ((col-key-width  (+ which-key-add-column-padding
                            (which-key--max-len col-keys 0)))
         (col-sep-width  (which-key--max-len col-keys 1))
	 (avl-width      (- avl-width col-key-width col-sep-width))
         (col-desc-width (min avl-width
			      (which-key--max-len
                               col-keys 2
			       which-key-min-column-description-width)))
         (col-width      (+ col-key-width col-sep-width col-desc-width))
	 (col-format     (concat "%" (int-to-string col-key-width)
                                 "s%s%-" (int-to-string col-desc-width) "s"=
)))
    (cons col-width
          (mapcar (lambda (k) (apply #'format col-format k))
		  col-keys))))

(defun which-key--partition-list (n list)
  "Partition LIST into N-sized sublists."
  (let (res)
    (while list
      (setq res (cons (cl-subseq list 0 (min n (length list))) res)
            list (nthcdr n list)))
    (nreverse res)))

(defun which-key--list-to-pages (keys avl-lines avl-width)
  "Convert list of KEYS to columns based on dimensions AVL-LINES and AVL-WI=
DTH.
Returns a `which-key--pages' object that holds the page strings,
as well as metadata."
  (let ((cols-w-widths (mapcar (lambda (c) (which-key--pad-column c avl-wid=
th))
			       (which-key--partition-list avl-lines keys)))
        (page-width 0) (n-pages 0) (n-keys 0) (n-columns 0)
        page-cols pages page-widths keys/page col)
    (if (> (apply #'max (mapcar #'car cols-w-widths)) avl-width)
        ;; give up if no columns fit
        nil
      (while cols-w-widths
        ;; start new page
        (cl-incf n-pages)
        (setq col (pop cols-w-widths))
        (setq page-cols (list (cdr col)))
        (setq page-width (car col))
        (setq n-keys (length (cdr col)))
        (setq n-columns 1)
        ;; add additional columns as long as they fit
        (while (and cols-w-widths
                    (or (null which-key-max-display-columns)
                        (< n-columns which-key-max-display-columns))
                    (<=3D (+ page-width 1 (caar cols-w-widths)) avl-width))
          (setq col (pop cols-w-widths))
          (push (cdr col) page-cols)
          (cl-incf page-width (1+ (car col)))
          (cl-incf n-keys (length (cdr col)))
          (cl-incf n-columns))
        (push (which-key--join-columns page-cols) pages)
        (push n-keys keys/page)
        (push page-width page-widths))
      (make-which-key--pages
       :pages (nreverse pages)
       :height (if (> n-pages 1) avl-lines (min avl-lines n-keys))
       :widths (nreverse page-widths)
       :keys/page (reverse keys/page)
       :page-nums (number-sequence 1 n-pages)
       :num-pages n-pages
       :total-keys (apply #'+ keys/page)))))

(defun which-key--create-pages-1
    (keys available-lines available-width &optional min-lines vertical)
  "Create page strings using `which-key--list-to-pages'.
Will try to find the best number of rows and columns using the
given dimensions and the length and widths of ITEMS. Use VERTICAL
if the ITEMS are laid out vertically and the number of columns
should be minimized."
  (let ((result (which-key--list-to-pages
                 keys available-lines available-width))
        (min-lines (or min-lines 0))
        found prev-result)
    (if (or (null result)
            vertical
            (> (which-key--pages-num-pages result) 1)
            (=3D 1 available-lines))
        result
      ;; simple search for a fitting page
      (while (and (> available-lines min-lines)
                  (not found))
        (setq available-lines (- available-lines 1)
              prev-result result
              result (which-key--list-to-pages
                      keys available-lines available-width)
              found (> (which-key--pages-num-pages result) 1)))
      (if found prev-result result))))

(defun which-key--create-pages (keys &optional prefix-keys prefix-title)
  "Create page strings using `which-key--list-to-pages'.
Will try to find the best number of rows and columns using the
given dimensions and the length and wdiths of KEYS. SEL-WIN-WIDTH
is the width of the live window."
  (let* ((max-dims (which-key--popup-max-dimensions))
         (max-lines (car max-dims))
         (max-width (cdr max-dims))
         (prefix-desc (key-description prefix-keys))
         (full-prefix (which-key--full-prefix prefix-desc))
         (prefix (when (eq which-key-show-prefix 'left)
                   (+ 2 (which-key--string-width full-prefix))))
         (prefix-top-bottom (member which-key-show-prefix '(bottom top)))
         (avl-lines (if prefix-top-bottom (- max-lines 1) max-lines))
         (min-lines (min avl-lines which-key-min-display-lines))
         (avl-width (if prefix (- max-width prefix) max-width))
         (vertical (or (and (eq which-key-popup-type 'side-window)
                            (member which-key-side-window-location '(left r=
ight)))
		       (eq which-key-max-display-columns 1)))
         result)
    (setq result
          (which-key--create-pages-1
           keys avl-lines avl-width min-lines vertical))
    (when (and result
               (> (which-key--pages-num-pages result) 0))
      (setf (which-key--pages-prefix result) prefix-keys)
      (setf (which-key--pages-prefix-title result)
            (or prefix-title
                (which-key--maybe-get-prefix-title
                 (key-description prefix-keys))))
      (when prefix-top-bottom
	;; Add back the line earlier reserved for the page information.
        (setf (which-key--pages-height result) max-lines))
      (when (and (=3D (which-key--pages-num-pages result) 1)
                 (> which-key-min-display-lines
                    (which-key--pages-height result)))
        ;; result is shorter than requested, so we artificially increase the
        ;; height. See #325. Note this only has an effect if
        ;; `which-key-allow-imprecise-window-fit' is non-nil.
        (setf (which-key--pages-height result) which-key-min-display-lines))
      (which-key--debug-message "Frame height: %s
Minibuffer height: %s
Max dimensions: (%s,%s)
Available for bindings: (%s,%s)
Actual lines: %s" (frame-height) (window-text-height (minibuffer-window))
max-lines max-width avl-lines avl-width (which-key--pages-height result))
      result)))

(defun which-key--lighter-status ()
  "Possibly show number of keys and total in the mode line."
  (when which-key-show-remaining-keys
    (let ((n-shown (car (which-key--pages-keys/page which-key--pages-obj)))
          (n-tot (which-key--pages-total-keys which-key--pages-obj)))
      (setcar (cdr (assq 'which-key-mode minor-mode-alist))
              (format " WK: %s/%s keys" n-shown n-tot)))))

(defun which-key--lighter-restore ()
  "Restore the lighter for which-key."
  (when which-key-show-remaining-keys
    (setcar (cdr (assq 'which-key-mode minor-mode-alist))
            which-key-lighter)))

(defun which-key--echo (text)
  "Echo TEXT to minibuffer without logging."
  (let (message-log-max)
    (message "%s" text)))

(defun which-key--next-page-hint (prefix-keys)
  "Return string for next page hint."
  (let* ((paging-key (concat prefix-keys " " which-key-paging-key))
         (paging-key-bound (eq 'which-key-C-h-dispatch
                               (key-binding (kbd paging-key))))
         (key (key-description (vector help-char)))
         (key (if paging-key-bound
                  (concat key " or " which-key-paging-key)
                key)))
    (when (and which-key-use-C-h-commands
               (not (equal (vector help-char)
                           (vconcat (kbd prefix-keys)))))
      (which-key--propertize (format "[%s paging/help]" key)
                             'face 'which-key-note-face))))

(eval-and-compile
  (if (fboundp 'universal-argument--description)
      (defalias 'which-key--universal-argument--description
        #'universal-argument--description)
    (defun which-key--universal-argument--description ()
      ;; Backport of the definition of universal-argument--description in
      ;; emacs25 on 2015-12-04
      (when prefix-arg
        (concat "C-u"
                (pcase prefix-arg
                  (`(-) " -")
                  (`(,(and (pred integerp) n))
                   (let ((str ""))
                     (while (and (> n 4) (=3D (mod n 4) 0))
                       (setq str (concat str " C-u"))
                       (setq n (/ n 4)))
                     (if (=3D n 4) str (format " %s" prefix-arg))))
                  (_ (format " %s" prefix-arg))))))))

(defun which-key--full-prefix (prefix-keys &optional -prefix-arg dont-prop-=
keys)
  "Return a description of the full key sequence up to now.
Include prefix arguments."
  (let* ((left (eq which-key-show-prefix 'left))
         (prefix-arg (if -prefix-arg -prefix-arg prefix-arg))
         (str (concat
               (which-key--universal-argument--description)
               (when prefix-arg " ")
               prefix-keys))
         (dash (if (and (not (string=3D prefix-keys ""))
                        (null left)) "-" "")))
    (if (or (eq which-key-show-prefix 'echo) dont-prop-keys)
        (concat str dash)
      (concat (which-key--propertize-key str)
              (which-key--propertize dash 'face 'which-key-key-face)))))

(defun which-key--get-popup-map ()
  "Generate transient-map for use in the top level binding display."
  (unless which-key--automatic-display
    (let ((map (make-sparse-keymap)))
      (define-key map (kbd which-key-paging-key) #'which-key-C-h-dispatch)
      (when which-key-use-C-h-commands
        ;; Show next page even when C-h is pressed
        (define-key map (vector help-char) #'which-key-C-h-dispatch))
      map)))

(defun which-key--process-page (pages-obj)
  "Add information to the basic list of key bindings.
Include, if applicable, the current prefix, the name of the current
prefix, and a page count."
  (let* ((page (car (which-key--pages-pages pages-obj)))
         (height (which-key--pages-height pages-obj))
         (n-pages (which-key--pages-num-pages pages-obj))
         (page-n (car (which-key--pages-page-nums pages-obj)))
         (prefix-desc (key-description (which-key--pages-prefix pages-obj)))
         (prefix-title (which-key--pages-prefix-title pages-obj))
         (full-prefix (which-key--full-prefix prefix-desc))
         (nxt-pg-hint (which-key--next-page-hint prefix-desc))
         ;; not used in left case
         (status-line
          (concat (which-key--propertize prefix-title 'face 'which-key-note=
-face)
                  (when (< 1 n-pages)
                    (which-key--propertize (format " (%s of %s)" page-n n-p=
ages)
                                           'face 'which-key-note-face)))))
    (pcase which-key-show-prefix
      (`left
       (let* ((page-cnt (which-key--propertize (format "%s/%s" page-n n-pag=
es)
                                               'face 'which-key-separator-f=
ace))
              (first-col-width (+ 2 (max (which-key--string-width full-pref=
ix)
                                         (which-key--string-width page-cnt)=
)))
              (prefix (format (concat "%-" (int-to-string first-col-width) =
"s")
                              full-prefix))
              (page-cnt (if (> n-pages 1)
                            (format
                             (concat "%-" (int-to-string first-col-width) "=
s")
                             page-cnt)
                          (make-string first-col-width 32)))
              lines first-line new-end)
         (if (=3D 1 height)
             (cons (concat prefix page) nil)
           (setq lines (split-string page "\n")
                 first-line (concat prefix (car lines) "\n" page-cnt)
                 new-end (concat "\n" (make-string first-col-width 32)))
           (cons
            (concat first-line (mapconcat #'identity (cdr lines) new-end))
            nil))))
      (`top
       (cons
        (concat (when (or (=3D 0 echo-keystrokes)
                          (not (eq which-key-side-window-location 'bottom)))
                  (concat full-prefix " "))
                status-line " " nxt-pg-hint "\n" page)
        nil))
      (`bottom
       (cons
        (concat page "\n"
                (when (or (=3D 0 echo-keystrokes)
                          (not (eq which-key-side-window-location 'bottom)))
                  (concat full-prefix " "))
                status-line " " nxt-pg-hint)
        nil))
      (`echo
       (cons page
             (lambda ()
               (which-key--echo
                (concat full-prefix (when prefix-desc " ")
                        status-line (when status-line " ")
                        nxt-pg-hint)))))
      (`mode-line
       (cons page
             (lambda ()
               (with-current-buffer which-key--buffer
                 (setq-local mode-line-format
                             (concat " " full-prefix
                                     " " status-line
                                     " " nxt-pg-hint))))))
      (_ (cons page nil)))))

(defun which-key--show-page (&optional n)
  "Show current page.
N changes the current page to the Nth page relative to the
current one."
  (which-key--init-buffer) ;; in case it was killed
  (let ((prefix-keys (which-key--current-key-string))
        golden-ratio-mode)
    (if (null which-key--pages-obj)
        (message "%s- which-key can't show keys: There is not \
enough space based on your settings and frame size." prefix-keys)
      (when n
        (setq which-key--pages-obj
              (which-key--pages-set-current-page which-key--pages-obj n)))
      (let ((page-echo (which-key--process-page which-key--pages-obj))
            (height (which-key--pages-height which-key--pages-obj))
            (width (car (which-key--pages-widths which-key--pages-obj))))
        (which-key--lighter-status)
        (if (eq which-key-popup-type 'minibuffer)
            (which-key--echo (car page-echo))
          (with-current-buffer which-key--buffer
            (erase-buffer)
            (insert (car page-echo))
            (goto-char (point-min)))
          (when (cdr page-echo) (funcall (cdr page-echo)))
          (which-key--show-popup (cons height width)))))
    ;; used for paging at top-level
    (if (fboundp 'set-transient-map)
        (set-transient-map (which-key--get-popup-map))
      (with-no-warnings
        (set-temporary-overlay-map (which-key--get-popup-map))))))

;;; Paging functions

;;;###autoload
(defun which-key-reload-key-sequence (&optional key-seq)
  "Simulate entering the key sequence KEY-SEQ.
KEY-SEQ should be a list of events as produced by
`listify-key-sequence'.  If nil, KEY-SEQ defaults to
`which-key--current-key-list'. Any prefix arguments that were
used are reapplied to the new key sequence."
  (let* ((key-seq (or key-seq (which-key--current-key-list)))
         (next-event (mapcar (lambda (ev) (cons t ev)) key-seq)))
    (setq prefix-arg current-prefix-arg
          unread-command-events next-event)))

(defun which-key-turn-page (delta)
  "Show the next page of keys."
  (which-key-reload-key-sequence)
  (if which-key--last-try-2-loc
      (let ((which-key-side-window-location which-key--last-try-2-loc)
            (which-key--multiple-locations t))
        (which-key--show-page delta))
    (which-key--show-page delta))
  (which-key--start-paging-timer))

;;;###autoload
(defun which-key-show-standard-help (&optional _)
  "Call the command in `which-key--prefix-help-cmd-backup'.
Usually this is `describe-prefix-bindings'."
  (interactive)
  (let ((which-key-inhibit t)
        (popup-showing (which-key--popup-showing-p)))
    (which-key--hide-popup-ignore-command)
    (cond ((and (eq which-key--prefix-help-cmd-backup
                    'describe-prefix-bindings)
                ;; If the popup is not showing, we call
                ;; `describe-prefix-bindings' directly.
                popup-showing)
           ;; This is essentially what `describe-prefix-bindings' does. We =
can't
           ;; use this function directly, because the prefix will not be co=
rrect
           ;; when we enter using `which-key-C-h-dispatch'.
           (describe-bindings (kbd (which-key--current-key-string))))
          ((functionp which-key--prefix-help-cmd-backup)
           (funcall which-key--prefix-help-cmd-backup)))))

;;;###autoload
(defun which-key-show-next-page-no-cycle ()
  "Show next page of keys or `which-key-show-standard-help'."
  (interactive)
  (let ((which-key-inhibit t))
    (if (which-key--on-last-page)
        (which-key-show-standard-help)
      (which-key-turn-page 1))))

;;;###autoload
(defun which-key-show-previous-page-no-cycle ()
  "Show previous page of keys if one exists."
  (interactive)
  (let ((which-key-inhibit t))
    (unless (which-key--on-first-page)
      (which-key-turn-page -1))))

;;;###autoload
(defun which-key-show-next-page-cycle (&optional _)
  "Show the next page of keys, cycling from end to beginning."
  (interactive)
  (let ((which-key-inhibit t))
    (which-key-turn-page 1)))

;;;###autoload
(defun which-key-show-previous-page-cycle (&optional _)
  "Show the previous page of keys, cycling from beginning to end."
  (interactive)
  (let ((which-key-inhibit t))
    (which-key-turn-page -1)))

;;;###autoload
(defun which-key-show-top-level (&optional _)
  "Show top-level bindings."
  (interactive)
  (which-key--create-buffer-and-show nil nil nil "Top-level bindings"))

;;;###autoload
(defun which-key-show-major-mode (&optional all)
  "Show top-level bindings in the map of the current major mode.
This function will also detect evil bindings made using
`evil-define-key' in this map. These bindings will depend on the
current evil state. "
  (interactive "P")
  (let ((map-sym (intern (format "%s-map" major-mode))))
    (if (and (boundp map-sym) (keymapp (symbol-value map-sym)))
        (which-key--show-keymap
         "Major-mode bindings"
         (symbol-value map-sym)
         (apply-partially #'which-key--map-binding-p (symbol-value map-sym))
         all)
      (message "which-key: No map named %s" map-sym))))

;;;###autoload
(defun which-key-show-full-major-mode ()
  "Show all bindings in the map of the current major mode.
This function will also detect evil bindings made using
`evil-define-key' in this map. These bindings will depend on the
current evil state. "
  (interactive)
  (which-key-show-major-mode t))

;;;###autoload
(defun which-key-dump-bindings (prefix buffer-name)
  "Dump bindings from PREFIX into buffer named BUFFER-NAME.
PREFIX should be a string suitable for `kbd'."
  (interactive "sPrefix: \nB")
  (let* ((buffer (get-buffer-create buffer-name))
         (keys (which-key--get-bindings (kbd prefix))))
    (with-current-buffer buffer
      (point-max)
      (save-excursion
        (dolist (key keys)
          (insert (apply #'format "%s%s%s\n" key)))))
    (switch-to-buffer-other-window buffer)))

;;;###autoload
(defun which-key-undo-key (&optional _)
  "Undo last keypress and force which-key update."
  (interactive)
  (let* ((key-lst (butlast (which-key--current-key-list)))
         (which-key-inhibit t))
    (cond (which-key--prior-show-keymap-args
           (if (keymapp (cdr (car-safe which-key--prior-show-keymap-args)))
               (let ((args (pop which-key--prior-show-keymap-args)))
                 (which-key--show-keymap (car args) (cdr args)))
             (which-key--hide-popup)))
          (key-lst
           (which-key-reload-key-sequence key-lst)
           (which-key--create-buffer-and-show (apply #'vector key-lst)))
          (t (setq which-key--automatic-display nil)
             (which-key-show-top-level)))))
(defalias 'which-key-undo #'which-key-undo-key)

(defun which-key-abort (&optional _)
  "Abort key sequence."
  (interactive)
  (let ((which-key-inhibit t))
    (which-key--hide-popup-ignore-command)
    (keyboard-quit)))

(defun which-key-digit-argument (key)
  "Version of `digit-argument' for use in `which-key-C-h-map'."
  (interactive)
  (let ((last-command-event (string-to-char key)))
    (digit-argument key))
  (let ((current-prefix-arg prefix-arg))
    (which-key-reload-key-sequence)))

(defun which-key-toggle-docstrings (&optional _)
  "Toggle the display of docstrings."
  (interactive)
  (unless (eq which-key-show-docstrings 'docstring-only)
    (setq which-key-show-docstrings (null which-key-show-docstrings)))
  (which-key-reload-key-sequence)
  (which-key--create-buffer-and-show (which-key--current-prefix)))

;;;###autoload
(defun which-key-C-h-dispatch ()
  "Dispatch C-h commands by looking up key in `which-key-C-h-map'.
This command is always accessible (from any prefix) if
`which-key-use-C-h-commands' is non nil."
  (interactive)
  (cond ((and (not (which-key--popup-showing-p))
              which-key-show-early-on-C-h)
         (let ((current-prefix
                (butlast
                 (listify-key-sequence
                  (funcall which-key-this-command-keys-function)))))
           (which-key-reload-key-sequence current-prefix)
           (if which-key-idle-secondary-delay
               (which-key--start-timer which-key-idle-secondary-delay t)
             (which-key--start-timer 0.05 t))))
        ((not (which-key--popup-showing-p))
         (which-key-show-standard-help))
        (t
         (if (not (which-key--popup-showing-p))
             (which-key-show-standard-help)
           (let* ((prefix-keys (which-key--current-key-string))
                  (full-prefix (which-key--full-prefix prefix-keys current-=
prefix-arg t))
                  (prompt (concat (when (string-equal prefix-keys "")
                                    (which-key--propertize
                                     (concat " "
                                             (which-key--pages-prefix-title
                                              which-key--pages-obj))
                                     'face 'which-key-note-face))
                                  full-prefix
                                  (which-key--propertize
                                   (substitute-command-keys
                                    which-key-C-h-map-prompt)
                                   'face 'which-key-note-face)))
                  (key (let ((key (read-key prompt)))
                         (if (numberp key)
                             (string key)
                           (vector key))))
                  (cmd (lookup-key which-key-C-h-map key))
                  (which-key-inhibit t))
             (if cmd (funcall cmd key) (which-key-turn-page 0)))))))

;;; Update

(defun which-key--any-match-p (regexps string)
  "Non-nil if any of REGEXPS match STRING."
  (catch 'match
    (dolist (regexp regexps)
      (when (string-match-p regexp string)
        (throw 'match t)))))

(defun which-key--try-2-side-windows
    (bindings prefix-keys prefix-title loc1 loc2 &rest _ignore)
  "Try to show BINDINGS (PAGE-N) in LOC1 first.
Only if no bindings fit fallback to LOC2."
  (let (pages1)
    (let ((which-key-side-window-location loc1)
          (which-key--multiple-locations t))
      (setq pages1 (which-key--create-pages
                    bindings prefix-keys prefix-title)))
    (if pages1
        (progn
          (setq which-key--pages-obj pages1)
          (let ((which-key-side-window-location loc1)
                (which-key--multiple-locations t))
            (which-key--show-page))
          loc1)
      (let ((which-key-side-window-location loc2)
            (which-key--multiple-locations t))
        (setq which-key--pages-obj
              (which-key--create-pages bindings prefix-keys prefix-title))
        (which-key--show-page)
        loc2))))

(defun which-key--read-keymap ()
  "Read keymap symbol from minibuffer."
  (intern
   (completing-read "Keymap: " obarray
                    (lambda (m)
                      (and (boundp m)
                           (keymapp (symbol-value m))
                           (not (equal (symbol-value m)
                                       (make-sparse-keymap)))))
                    t
                    (let ((sym (symbol-at-point)))
                      (and (boundp sym)
                           (keymapp (symbol-value sym))
                           (symbol-name sym)))
                    'which-key-keymap-history)))

;;;###autoload
(defun which-key-show-keymap (keymap &optional no-paging)
  "Show the top-level bindings in KEYMAP using which-key.
KEYMAP is selected interactively from all available keymaps.

If NO-PAGING is non-nil, which-key will not intercept subsequent
keypresses for the paging functionality."
  (interactive (list (which-key--read-keymap)))
  (which-key--show-keymap (symbol-name keymap)
                          (symbol-value keymap)
                          nil nil no-paging))

;;;###autoload
(defun which-key-show-full-keymap (keymap)
  "Show all bindings in KEYMAP using which-key.
KEYMAP is selected interactively from all available keymaps."
  (interactive (list (which-key--read-keymap)))
  (which-key--show-keymap (symbol-name keymap)
                          (symbol-value keymap)
                          nil t))

;;;###autoload
(defun which-key-show-minor-mode-keymap (&optional all)
  "Show the top-level bindings in KEYMAP using which-key.
KEYMAP is selected interactively by mode in
`minor-mode-map-alist'."
  (interactive)
  (let ((mode-sym
         (intern
          (completing-read
           "Minor Mode: "
           (mapcar #'car
                   (cl-remove-if-not
                    (lambda (entry)
                      (and (symbol-value (car entry))
                           (not (equal (cdr entry) (make-sparse-keymap)))))
                    minor-mode-map-alist))
           nil t nil 'which-key-keymap-history))))
    (which-key--show-keymap (symbol-name mode-sym)
                            (cdr (assq mode-sym minor-mode-map-alist))
                            all)))
;;;###autoload
(defun which-key-show-full-minor-mode-keymap ()
  "Show all bindings in KEYMAP using which-key.
KEYMAP is selected interactively by mode in
`minor-mode-map-alist'."
  (interactive)
  (which-key-show-minor-mode-keymap t))

(defun which-key--show-keymap
    (keymap-name keymap &optional prior-args all no-paging filter)
  (when prior-args (push prior-args which-key--prior-show-keymap-args))
  (let ((bindings (which-key--get-bindings nil keymap filter all)))
    (if (null bindings)
        (message "which-key: No bindings found in %s" keymap-name)
      (cond ((listp which-key-side-window-location)
             (setq which-key--last-try-2-loc
                   (apply #'which-key--try-2-side-windows
                          bindings nil keymap-name
                          which-key-side-window-location)))
            (t (setq which-key--pages-obj
                     (which-key--create-pages bindings nil keymap-name))
               (which-key--show-page)))
      (unless no-paging
        (let* ((key (read-key))
               (key-desc (key-description (list key)))
               (next-def (lookup-key keymap (vector key))))
          (cond ((and which-key-use-C-h-commands
                      (numberp key) (=3D key help-char))
                 (which-key-C-h-dispatch))
                ((keymapp next-def)
                 (which-key--hide-popup-ignore-command)
                 (which-key--show-keymap
                  (concat keymap-name " " key-desc)
                  next-def
                  (cons keymap-name keymap)))
                (t (which-key--hide-popup))))))))

(defun which-key--evil-operator-filter (binding)
  (let ((def (intern (cdr binding))))
    (and (functionp def)
         (not (evil-get-command-property def :suppress-operator)))))

(defun which-key--show-evil-operator-keymap ()
  (if which-key--inhibit-next-operator-popup
      (setq which-key--inhibit-next-operator-popup nil)
    (let ((keymap
           (make-composed-keymap (list evil-operator-shortcut-map
                                       evil-operator-state-map
                                       evil-motion-state-map))))
      (when (keymapp keymap)
        (let ((formatted-keys
               (which-key--get-bindings
                nil keymap #'which-key--evil-operator-filter)))
          (cond ((=3D (length formatted-keys) 0)
                 (message "which-key: Keymap empty"))
                ((listp which-key-side-window-location)
                 (setq which-key--last-try-2-loc
                       (apply #'which-key--try-2-side-windows
                              formatted-keys nil "evil operator/motion keys"
                              which-key-side-window-location)))
                (t (setq which-key--pages-obj
                         (which-key--create-pages
                          formatted-keys
                          nil "evil operator/motion keys"))
                   (which-key--show-page)))))
      (let* ((key (read-key)))
        (when (member key '(?f ?F ?t ?T ?`))
          ;; these keys trigger commands that read the next char manually
          (setq which-key--inhibit-next-operator-popup t))
        (cond ((and which-key-use-C-h-commands (numberp key) (=3D key help-=
char))
               (which-key-C-h-dispatch))
              ((and (numberp key) (=3D key ?\C-\[))
               (which-key--hide-popup)
               (keyboard-quit))
              (t
               (which-key--hide-popup)
               (setq unread-command-events (vector key))))))))

(defun which-key--create-buffer-and-show
    (&optional prefix-keys from-keymap filter prefix-title)
  "Fill `which-key--buffer' with key descriptions and reformat.
Finally, show the buffer."
  (let ((start-time (current-time))
        (formatted-keys (which-key--get-bindings
                         prefix-keys from-keymap filter))
        (prefix-desc (key-description prefix-keys)))
    (cond ((=3D (length formatted-keys) 0)
           (message "%s-  which-key: There are no keys to show" prefix-desc=
))
          ((listp which-key-side-window-location)
           (setq which-key--last-try-2-loc
                 (apply #'which-key--try-2-side-windows
                        formatted-keys prefix-keys prefix-title
                        which-key-side-window-location)))
          (t (setq which-key--pages-obj
                   (which-key--create-pages
                    formatted-keys prefix-keys prefix-title))
             (which-key--show-page)))
    (which-key--debug-message
     "On prefix \"%s\" which-key took %.0f ms." prefix-desc
     (* 1000 (float-time (time-since start-time))))))

(defun which-key--update ()
  "Function run by timer to possibly trigger `which-key--create-buffer-and-=
show'."
  (let ((prefix-keys (funcall which-key-this-command-keys-function))
        delay-time)
    (cond ((and (> (length prefix-keys) 0)
                (or (keymapp (key-binding prefix-keys))
                    ;; Some keymaps are stored here like iso-transl-ctl-x-8=
-map
                    (keymapp (which-key--safe-lookup-key
                              key-translation-map prefix-keys))
                    ;; just in case someone uses one of these
                    (keymapp (which-key--safe-lookup-key
                              function-key-map prefix-keys)))
                (not which-key-inhibit)
                (or (null which-key-allow-regexps)
                    (which-key--any-match-p
                     which-key-allow-regexps (key-description prefix-keys)))
                (or (null which-key-inhibit-regexps)
                    (not
                     (which-key--any-match-p
                      which-key-inhibit-regexps (key-description prefix-key=
s))))
                ;; Do not display the popup if a command is currently being
                ;; executed
                (or (run-hook-with-args-until-success
                     'which-key-inhibit-display-hook)
                    (null this-command))
                (let ((max-dim (which-key--popup-max-dimensions)))
                  (> (min (car-safe max-dim) (cdr-safe max-dim)) 0)))
           (when (and (not (equal prefix-keys (which-key--current-prefix)))
                      (or (null which-key-delay-functions)
                          (null (setq delay-time
                                      (run-hook-with-args-until-success
                                       'which-key-delay-functions
                                       (key-description prefix-keys)
                                       (length prefix-keys))))
                          (sit-for delay-time)))
             (setq which-key--automatic-display t)
             (which-key--create-buffer-and-show prefix-keys)
             (when (and which-key-idle-secondary-delay
                        (not which-key--secondary-timer-active))
               (which-key--start-timer which-key-idle-secondary-delay t))))
          ((and which-key-show-transient-maps
                ;; Assuming that if this is not true we're in
                ;; `which-key-show-top-level', which would then be overwrit=
ten.
                (> (length prefix-keys) 0)
                (keymapp overriding-terminal-local-map)
                ;; basic test for it being a hydra
                (not (eq (lookup-key overriding-terminal-local-map "\C-u")
                         'hydra--universal-argument)))
           (which-key--create-buffer-and-show
            nil overriding-terminal-local-map))
          ((and which-key-show-operator-state-maps
                (bound-and-true-p evil-state)
                (eq evil-state 'operator)
                (not (which-key--popup-showing-p)))
           (which-key--show-evil-operator-keymap))
          (which-key--automatic-display
           (which-key--hide-popup)))))

;;; Timers

(defun which-key--start-timer (&optional delay secondary)
  "Activate idle timer to trigger `which-key--update'."
  (which-key--stop-timer)
  (setq which-key--secondary-timer-active secondary)
  (setq which-key--timer
        (run-with-idle-timer (or delay which-key-idle-delay)
                             t #'which-key--update)))

(defun which-key--stop-timer ()
  "Deactivate idle timer for `which-key--update'."
  (when which-key--timer (cancel-timer which-key--timer)))

(defun which-key--start-paging-timer ()
  "Activate timer to restart which-key after paging."
  (when which-key--paging-timer (cancel-timer which-key--paging-timer))
  (which-key--stop-timer)
  (setq which-key--paging-timer
        (run-with-idle-timer
         0.2 t (lambda ()
                 (when (or (not (member real-last-command
                                        which-key--paging-functions))
                           (and (< 0 (length (this-single-command-keys)))
                                (not (equal (which-key--current-prefix)
                                            (funcall which-key-this-command=
-keys-function)))))
                   (cancel-timer which-key--paging-timer)
                   (if which-key-idle-secondary-delay
                       ;; we haven't executed a command yet so the secandary
                       ;; timer is more relevant here
                       (which-key--start-timer which-key-idle-secondary-del=
ay t)
                     (which-key--start-timer)))))))

(provide 'which-key)
;;; which-key.el ends here

--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 23 Feb 2024 23:25:24 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Feb 23 18:25:24 2024
Received: from localhost ([127.0.0.1]:53242 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rdeuw-0001hx-60
	for submit <at> debbugs.gnu.org; Fri, 23 Feb 2024 18:25:23 -0500
Received: from out-177.mta1.migadu.com ([95.215.58.177]:18209)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jb@HIDDEN>) id 1rdeiJ-000150-Sa
 for 68929 <at> debbugs.gnu.org; Fri, 23 Feb 2024 18:12:21 -0500
References: <871q9rvqbi.fsf@HIDDEN> <87mssc65y8.fsf@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net;
 s=key1; t=1708729909;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=SbDQHUH05lh/+I9pcIu4yEK8LwcAfwzA+2w4w3SSgTw=;
 b=ogMj2zuOSAg7C/gL31o7u0ZnXBdKwr4Bm2vEbTUI6QrtoLqD+w4ACFk+c6UKsJhlOI9Xs9
 cBv1ZOGeWM9DaGTRynUv3CTXEOeFrGGOzNtzp+i3sLds6UbzvAD5myefHYwXHMjSrM+7Yf
 vp+hQvsw+t5IKgASJlQWgy4pgUl2CbAZwINLip4SFcuygjMt3XChKODwB+S1KZ2LqrxGKE
 XLO3mnS2NHKBhH/hhygeIVNx6NpY21D47ag7xk99vXjAbYIgd82M9+kiQRxqwDEES62UE5
 z6Y6TnaASP0e7VRESZJpg7U+0CKq9qY9QIXYyTIjnMYRQs5s+oRWrvMVKzxgtQ==
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
From: Jeremy Bryant <jb@HIDDEN>
To: Philip Kaludercic <philipk@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
Date: Fri, 23 Feb 2024 23:07:24 +0000
In-reply-to: <87mssc65y8.fsf@HIDDEN>
Message-ID: <875xyeojwu.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Migadu-Flow: FLOW_OUT
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 68929
Cc: 68929 <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)


Philip,

Going through your suggestions, progressing upstream.

Philip Kaludercic <philipk@HIDDEN> writes:
>> +(defvar which-key--ignore-keys-regexp
>> +  (eval-when-compile
>> +    (regexp-opt '("mouse-" "wheel-" "remap" "drag-" "scroll-bar"
>> +                  "select-window" "switch-frame" "-state"
>> +                  "which-key"))))
>
> regexp-opt is marked as pure, you don't need the eval-when-compile here.
>

Please clarify your request?

It would seem The manual has a similar example to the original code.=20=20
(elisp) Eval During Compile

     If you have a constant that needs some calculation to produce,
     =E2=80=98eval-when-compile=E2=80=99 can do that at compile-time.  For =
example,

          (defvar my-regexp
            (eval-when-compile (regexp-opt '("aaa" "aba" "abb"))))

What am I missing?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929-done <at> debbugs.gnu.org:


Received: (at 68929-done) by debbugs.gnu.org; 17 Feb 2024 16:59:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Feb 17 11:59:32 2024
Received: from localhost ([127.0.0.1]:33690 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rbO2G-0005kH-5g
	for submit <at> debbugs.gnu.org; Sat, 17 Feb 2024 11:59:32 -0500
Received: from eggs.gnu.org ([209.51.188.92]:33514)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1rbO2D-0005k2-8K
 for 68929-done <at> debbugs.gnu.org; Sat, 17 Feb 2024 11:59:30 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1rbO1i-0004nu-55; Sat, 17 Feb 2024 11:58:59 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=X/D0G3puKQ0p0x6q6k4KyKoynTp7+cjU919458Y/7Ow=; b=GJ5YaNg4jEs2
 SS1gwMLLFOVteDiR2rC5JeZ60BYgYvrdqZgC0X+8xwtOjckR1Rd8Q9IOjBpHCr6Hp4Uamb020p/+K
 p6bhOumbw4nUQbDI8eYCi8MBcy3YYAHjnCnqDONMavy7KBnk34xy1sTx2VtK9yFKyBFJlMkdpWGFO
 nK2MHQGw50x2xSt7D+5yCkhwVN/bskUlXK+dYUQRrWYE5RB7PjOTpt5qzXOpfh3KNjmjOvjXl7VLO
 clBXpTDNy3svXKa7g4npwWR8q7Cy95dwsdfV3fjgtoj3jBJ/9wCjo60XcL2aDuE0f1gE4aTH5HDb0
 rHzyNh/8ryHffbpaTSptaA==;
Date: Sat, 17 Feb 2024 18:58:55 +0200
Message-Id: <868r3jt4c0.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
In-Reply-To: <87le7joy9l.fsf@HIDDEN> (message from Jeremy Bryant on
 Sat, 17 Feb 2024 13:10:51 +0000)
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
 <CAF8XuLgkTgHwZ12pY3s4e3j_evzAzfoCRtUutrmuPuHbN_8Rvg@HIDDEN>
 <87ttmkrlc5.fsf@HIDDEN> <86fry3xzae.fsf@HIDDEN>
 <87zfwar3qd.fsf@HIDDEN> <87wmraptwj.fsf@HIDDEN>
 <86r0hew2pc.fsf@HIDDEN> <87le7joy9l.fsf@HIDDEN>
X-Spam-Score: -4.2 (----)
X-Debbugs-Envelope-To: 68929-done
Cc: 68929-done <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -5.2 (-----)

> From: Jeremy Bryant <jb@HIDDEN>
> Cc: 68929 <at> debbugs.gnu.org, justin@HIDDEN, monnier@HIDDEN
> Date: Sat, 17 Feb 2024 13:10:51 +0000
> 
> Eli Zaretskii <eliz@HIDDEN> writes:
> 
> > LGTM, thanks.  Some minor comments below.
> 
> Revised patch attached.

Thanks.  (The argument of @anchor should be in braces; I fixed that.)

Installed on master, and closing the bug.




Notification sent to Jeremy Bryant <jb@HIDDEN>:
bug acknowledged by developer. Full text available.
Reply sent to Eli Zaretskii <eliz@HIDDEN>:
You have taken responsibility. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 17 Feb 2024 16:24:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Feb 17 11:24:32 2024
Received: from localhost ([127.0.0.1]:33667 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rbNUN-0004o3-PJ
	for submit <at> debbugs.gnu.org; Sat, 17 Feb 2024 11:24:32 -0500
Received: from out-172.mta1.migadu.com ([95.215.58.172]:42426)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jb@HIDDEN>) id 1rbNUL-0004nv-PM
 for 68929 <at> debbugs.gnu.org; Sat, 17 Feb 2024 11:24:30 -0500
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
 <CAF8XuLgkTgHwZ12pY3s4e3j_evzAzfoCRtUutrmuPuHbN_8Rvg@HIDDEN>
 <87ttmkrlc5.fsf@HIDDEN> <86fry3xzae.fsf@HIDDEN>
 <87zfwar3qd.fsf@HIDDEN> <87wmraptwj.fsf@HIDDEN>
 <86r0hew2pc.fsf@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net;
 s=key1; t=1708187018;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to:references:references;
 bh=mz16aDXwJRhybSHQyLgc28YAvkeei7ghgzJenl18a9w=;
 b=RIwXaCashWZsspoNHvAfZ9zJm/aQKKxVUyBavnChO9jLd+xoUznXeXKVXtkazmxdn1K/Gf
 LKV4XLTbuxqjlVrqnrCBIyvLzVvrNgknjFydEJNyM04QT0tKKFKQf6+491zdoEfZ/9KELL
 uFfYRTZXFaNgy793KIs8LEfBFiNUsntB5Riv+1kaefGQTonZqstdPhDRaDfyJHW4MwyQoT
 x0lkfdfikAbqPiExvAPXgFValDP2cAiyR63MsPJNe5UV/O8c0h8MtWAbhiiWCxyjBDPxpE
 T0R9gVO0aRqEkZT4mM4I/cq9QkUv+lJq6jT8AI0hAVBfdNbOlTQg+kwWWnWdNw==
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
From: Jeremy Bryant <jb@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
Date: Sat, 17 Feb 2024 13:10:51 +0000
In-reply-to: <86r0hew2pc.fsf@HIDDEN>
Message-ID: <87le7joy9l.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Migadu-Flow: FLOW_OUT
X-Spam-Score: -0.3 (/)
X-Debbugs-Envelope-To: 68929
Cc: 68929 <at> debbugs.gnu.org, justin@HIDDEN, monnier@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.3 (-)

--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
 filename=0003-v2-Add-manual-entries-for-which-key.patch

From eae203569f73081e82035990a5a5ac1e0beb9083 Mon Sep 17 00:00:00 2001
From: Jeremy Bryant <jb@HIDDEN>
Date: Sun, 11 Feb 2024 21:26:41 +0000
Subject: [PATCH 3/3] Add manual entries for which-key

* doc/emacs/display.texi (Display Custom):  Briefly introduce which-key.
* doc/emacs/help.texi (Key Help):  Briefly mention which-key.
---
 doc/emacs/display.texi | 3 ++-
 doc/emacs/help.texi    | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index d2557d6148e..bda57d2b30e 100644
--- a/doc/emacs/display.texi
+++ b/doc/emacs/display.texi
@@ -2215,7 +2215,8 @@ Display Custom
 default), the multi-character key sequence echo shown according to
 @code{echo-keystrokes} will include a short help text about keys which
 will invoke @code{describe-prefix-bindings} (@pxref{Misc Help}) to show
-the list of commands for the prefix you already typed.
+the list of commands for the prefix you already typed.  For a related
+help facility, see @ref{which-key}.
 
 @cindex mouse pointer
 @cindex hourglass pointer display
diff --git a/doc/emacs/help.texi b/doc/emacs/help.texi
index 99a4173ac29..1a76e663657 100644
--- a/doc/emacs/help.texi
+++ b/doc/emacs/help.texi
@@ -260,6 +260,11 @@ Key Help
 @code{widget-describe} commands, that should be run with point over
 the button.
 
+@anchor which-key
+@kbd{M-x which-key} is a global minor mode which helps in discovering
+ keymaps.  It displays keybindings following your currently entered
+ incomplete command (prefix), in a popup.
+
 @node Name Help
 @section Help by Command or Variable Name
 
-- 
2.42.0


--=-=-=
Content-Type: text/plain


Eli Zaretskii <eliz@HIDDEN> writes:

> LGTM, thanks.  Some minor comments below.

Revised patch attached.

>> * doc/emacs/display.texi (Display Custom):  brief mention
>> * doc/emacs/help.texi (Key Help):  reference node above
>
> The descriptions of the changes in these entries should be complete
> sentences: begin with a capital letter and end with a period.

Corrected in patch.
Thank you for explaining, I now realise this was in CONTRIBUTE.

>
>> --- a/doc/emacs/display.texi
>> +++ b/doc/emacs/display.texi
>> @@ -2215,7 +2215,8 @@ Display Custom
>>  default), the multi-character key sequence echo shown according to
>>  @code{echo-keystrokes} will include a short help text about keys which
>>  will invoke @code{describe-prefix-bindings} (@pxref{Misc Help}) to show
>> -the list of commands for the prefix you already typed.
>> +the list of commands for the prefix you already typed.  For a related
>> +help facility (@pxref{which-key}).
>
> The parentheses here don't look right.  It is better to say
>
>   For a related help facility, see @ref{which-key}.
>
>> +@node which-key
>
> It is better to use
>
>   @anchor which-key
>
> Then you don't need the @subsection at all.
>
>> + @command{M-x which-key} is a global minor mode which helps in
>
> @command is for shell commands.  Here you show something the user
> types, so the right markup is @kbd.

Corrected in patch.
Thanks, I have learnt more TeXinfo with this.

--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 15 Feb 2024 08:29:35 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 15 03:29:35 2024
Received: from localhost ([127.0.0.1]:53939 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1raX7e-0000Og-Ib
	for submit <at> debbugs.gnu.org; Thu, 15 Feb 2024 03:29:35 -0500
Received: from eggs.gnu.org ([209.51.188.92]:39038)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1raX7b-0000OT-KA
 for 68929 <at> debbugs.gnu.org; Thu, 15 Feb 2024 03:29:32 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1raX7C-00050v-Qx; Thu, 15 Feb 2024 03:29:06 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=MkUFEq8I9T1srNZJMmNz5vmTdCXbY6GhXXnH2o+Qz+8=; b=aGP0aV6pLWVF
 M2ARpR5i38S2q5946benKGa7qRDv93HE7xZiPtxxB5u5bsU6imJlu5t3AihE9h0DWdRWvhgwyI9AJ
 ds58u//Ql/IwOXtMt/Fed18qLRgJodbluIdSW8t9Y1cqA195wYcM2eoF85kDSZzclcL9iN4vNZe7O
 amvnUkrMlTLriX5oXuUxnwK6YqY5NiaG0nb6Ttz9ItAcBDwMZaUH9Eli1EtXBiC1tBZeyst9fGgyO
 9CEv8cEWZDgTHQWRm+AfuViBuw4W5u4jRUanj0ly86xPnswj3maaP++0JXaL/EgNOd/P1LwPQWbku
 +j3AMpiiL4z2FyBKZOLxIA==;
Date: Thu, 15 Feb 2024 10:29:03 +0200
Message-Id: <86r0hew2pc.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
In-Reply-To: <87wmraptwj.fsf@HIDDEN> (message from Jeremy Bryant on
 Sun, 11 Feb 2024 21:32:44 +0000)
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
 <CAF8XuLgkTgHwZ12pY3s4e3j_evzAzfoCRtUutrmuPuHbN_8Rvg@HIDDEN>
 <87ttmkrlc5.fsf@HIDDEN> <86fry3xzae.fsf@HIDDEN>
 <87zfwar3qd.fsf@HIDDEN> <87wmraptwj.fsf@HIDDEN>
X-Spam-Score: -4.2 (----)
X-Debbugs-Envelope-To: 68929
Cc: 68929 <at> debbugs.gnu.org, justin@HIDDEN, monnier@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -5.2 (-----)

> From: Jeremy Bryant <jb@HIDDEN>
> Cc: Eli Zaretskii <eliz@HIDDEN>, 68929 <at> debbugs.gnu.org, justin@HIDDEN,
>  monnier@HIDDEN, bug-gnu-emacs@HIDDEN
> Date: Sun, 11 Feb 2024 21:32:44 +0000
> 
> > Eli Zaretskii <eliz@HIDDEN> writes:
> >
> >> Will the section be very long?  How long?
> >>
> >> If it's not very long, I think the right place is in "Key Help",
> >> perhaps as a separate subsection below it.  Also, I think which-key
> >> should be briefly mentioned in "Display Custom", where echo-keystrokes
> >> is described.
> >>
> >> If the section about which-key you envision is supposed to be long and
> >> detailed, perhaps it would be better to have a separate manual with
> >> all that stuff, whereas the Emacs user manual should have only a short
> >> description of the main features, and a cross-reference to the
> >> separate manual.
> >
> > I would propose to make a new section short enough to belong in the main
> > Emacs manual, as which-key's "keymay discovery" perspective should be
> > easier to find.
> >
> > I can volunteer to write a draft and confer with Justin, the actual
> > author, for completeness.
> 
> Attached are a proposed patch for the Emacs manual, intentionally very
> short.
> Feedback welcome on any aspects.

LGTM, thanks.  Some minor comments below.

> * doc/emacs/display.texi (Display Custom):  brief mention
> * doc/emacs/help.texi (Key Help):  reference node above

The descriptions of the changes in these entries should be complete
sentences: begin with a capital letter and end with a period.

> --- a/doc/emacs/display.texi
> +++ b/doc/emacs/display.texi
> @@ -2215,7 +2215,8 @@ Display Custom
>  default), the multi-character key sequence echo shown according to
>  @code{echo-keystrokes} will include a short help text about keys which
>  will invoke @code{describe-prefix-bindings} (@pxref{Misc Help}) to show
> -the list of commands for the prefix you already typed.
> +the list of commands for the prefix you already typed.  For a related
> +help facility (@pxref{which-key}).

The parentheses here don't look right.  It is better to say

  For a related help facility, see @ref{which-key}.

> +@node which-key

It is better to use

  @anchor which-key

Then you don't need the @subsection at all.

> + @command{M-x which-key} is a global minor mode which helps in

@command is for shell commands.  Here you show something the user
types, so the right markup is @kbd.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 11 Feb 2024 21:55:28 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 11 16:55:27 2024
Received: from localhost ([127.0.0.1]:51530 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rZHnK-0004m5-Be
	for submit <at> debbugs.gnu.org; Sun, 11 Feb 2024 16:55:27 -0500
Received: from out-184.mta1.migadu.com ([2001:41d0:203:375::b8]:27955)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jb@HIDDEN>) id 1rZHTK-0003mL-1X
 for 68929 <at> debbugs.gnu.org; Sun, 11 Feb 2024 16:34:47 -0500
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
 <CAF8XuLgkTgHwZ12pY3s4e3j_evzAzfoCRtUutrmuPuHbN_8Rvg@HIDDEN>
 <87ttmkrlc5.fsf@HIDDEN> <86fry3xzae.fsf@HIDDEN>
 <87zfwar3qd.fsf@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net;
 s=key1; t=1707687267;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to:references:references;
 bh=HcmA3GRJvrlN88MAVkrvh7OI2ebcF+9F1394/bdhlgk=;
 b=IDuzH4Uasbq5XdjlEpqES7FpJozBN85EtK8DXdkR2i+pxvxd+L1kB+aa3XPBnRqAwclu1p
 9l7b8xjg50dmAioWO95UOeMYcV2O6DInRrU282Q371cNlANhJ2tYNPc6nGLnBx7B/7l+r4
 KR6bZ9v41X0LlrN+7pxSVBlTa7uBES+/Jyd7ZQCbtRRrkxzrA7K9vuPaUFggDOSTWPrd0D
 V7HzLyJvg5T4hfo/IfqvvRp6gFSEQBxIdeE2OxGxzRFCPtmRHCl2S6aXfbhQINHGJyDlj8
 b8DPWWx2g4mQzT3ZFywE8fdrc7ESVZw2nq43BoNxnCIMxWAbd7a7XXtA20B4dw==
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
From: Jeremy Bryant <jb@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
Date: Sun, 11 Feb 2024 21:32:44 +0000
In-reply-to: <87zfwar3qd.fsf@HIDDEN>
Message-ID: <87wmraptwj.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Migadu-Flow: FLOW_OUT
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 68929
Cc: Eli Zaretskii <eliz@HIDDEN>, 68929 <at> debbugs.gnu.org, bug-gnu-emacs@HIDDEN,
 justin@HIDDEN, monnier@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain


> Eli Zaretskii <eliz@HIDDEN> writes:
>
>> Will the section be very long?  How long?
>>
>> If it's not very long, I think the right place is in "Key Help",
>> perhaps as a separate subsection below it.  Also, I think which-key
>> should be briefly mentioned in "Display Custom", where echo-keystrokes
>> is described.
>>
>> If the section about which-key you envision is supposed to be long and
>> detailed, perhaps it would be better to have a separate manual with
>> all that stuff, whereas the Emacs user manual should have only a short
>> description of the main features, and a cross-reference to the
>> separate manual.
>
> I would propose to make a new section short enough to belong in the main
> Emacs manual, as which-key's "keymay discovery" perspective should be
> easier to find.
>
> I can volunteer to write a draft and confer with Justin, the actual
> author, for completeness.

Attached are a proposed patch for the Emacs manual, intentionally very
short.
Feedback welcome on any aspects.


--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
 filename=0002-Add-manual-entries-for-which-key.patch

From c8264398374ad6eae380ea46428092efa0ba02fc Mon Sep 17 00:00:00 2001
From: Jeremy Bryant <jb@HIDDEN>
Date: Sun, 11 Feb 2024 21:26:41 +0000
Subject: [PATCH 2/2] Add manual entries for which-key

* doc/emacs/display.texi (Display Custom):  brief mention
* doc/emacs/help.texi (Key Help):  reference node above
---
 doc/emacs/display.texi | 3 ++-
 doc/emacs/help.texi    | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index d2557d6148e..754f9b6d048 100644
--- a/doc/emacs/display.texi
+++ b/doc/emacs/display.texi
@@ -2215,7 +2215,8 @@ Display Custom
 default), the multi-character key sequence echo shown according to
 @code{echo-keystrokes} will include a short help text about keys which
 will invoke @code{describe-prefix-bindings} (@pxref{Misc Help}) to show
-the list of commands for the prefix you already typed.
+the list of commands for the prefix you already typed.  For a related
+help facility (@pxref{which-key}).
 
 @cindex mouse pointer
 @cindex hourglass pointer display
diff --git a/doc/emacs/help.texi b/doc/emacs/help.texi
index 99a4173ac29..25bb3ccc08a 100644
--- a/doc/emacs/help.texi
+++ b/doc/emacs/help.texi
@@ -260,6 +260,12 @@ Key Help
 @code{widget-describe} commands, that should be run with point over
 the button.
 
+@node which-key
+@subsection which-key
+ @command{M-x which-key} is a global minor mode which helps in
+ discovering keymaps.  It displays keybindings following your currently
+ entered incomplete command (prefix), in a popup.
+
 @node Name Help
 @section Help by Command or Variable Name
 
-- 
2.42.0


--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 11 Feb 2024 21:55:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 11 16:55:29 2024
Received: from localhost ([127.0.0.1]:51532 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rZHnL-0004mG-Vj
	for submit <at> debbugs.gnu.org; Sun, 11 Feb 2024 16:55:29 -0500
Received: from lists.gnu.org ([2001:470:142::17]:39988)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jb@HIDDEN>) id 1rZHTU-0003me-L4
 for submit <at> debbugs.gnu.org; Sun, 11 Feb 2024 16:34:57 -0500
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 <jb@HIDDEN>)
 id 1rZHT8-0008Vl-Q5
 for bug-gnu-emacs@HIDDEN; Sun, 11 Feb 2024 16:34:34 -0500
Received: from out-189.mta1.migadu.com ([2001:41d0:203:375::bd])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <jb@HIDDEN>)
 id 1rZHT6-0000l1-Na
 for bug-gnu-emacs@HIDDEN; Sun, 11 Feb 2024 16:34:34 -0500
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
 <CAF8XuLgkTgHwZ12pY3s4e3j_evzAzfoCRtUutrmuPuHbN_8Rvg@HIDDEN>
 <87ttmkrlc5.fsf@HIDDEN> <86fry3xzae.fsf@HIDDEN>
 <87zfwar3qd.fsf@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net;
 s=key1; t=1707687267;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to:references:references;
 bh=HcmA3GRJvrlN88MAVkrvh7OI2ebcF+9F1394/bdhlgk=;
 b=IDuzH4Uasbq5XdjlEpqES7FpJozBN85EtK8DXdkR2i+pxvxd+L1kB+aa3XPBnRqAwclu1p
 9l7b8xjg50dmAioWO95UOeMYcV2O6DInRrU282Q371cNlANhJ2tYNPc6nGLnBx7B/7l+r4
 KR6bZ9v41X0LlrN+7pxSVBlTa7uBES+/Jyd7ZQCbtRRrkxzrA7K9vuPaUFggDOSTWPrd0D
 V7HzLyJvg5T4hfo/IfqvvRp6gFSEQBxIdeE2OxGxzRFCPtmRHCl2S6aXfbhQINHGJyDlj8
 b8DPWWx2g4mQzT3ZFywE8fdrc7ESVZw2nq43BoNxnCIMxWAbd7a7XXtA20B4dw==
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
From: Jeremy Bryant <jb@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
Date: Sun, 11 Feb 2024 21:32:44 +0000
In-reply-to: <87zfwar3qd.fsf@HIDDEN>
Message-ID: <87wmraptwj.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Migadu-Flow: FLOW_OUT
Received-SPF: pass client-ip=2001:41d0:203:375::bd;
 envelope-from=jb@HIDDEN; helo=out-189.mta1.migadu.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.9 (/)
X-Debbugs-Envelope-To: submit
Cc: Eli Zaretskii <eliz@HIDDEN>, 68929 <at> debbugs.gnu.org, bug-gnu-emacs@HIDDEN,
 justin@HIDDEN, monnier@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.1 (/)

--=-=-=
Content-Type: text/plain


> Eli Zaretskii <eliz@HIDDEN> writes:
>
>> Will the section be very long?  How long?
>>
>> If it's not very long, I think the right place is in "Key Help",
>> perhaps as a separate subsection below it.  Also, I think which-key
>> should be briefly mentioned in "Display Custom", where echo-keystrokes
>> is described.
>>
>> If the section about which-key you envision is supposed to be long and
>> detailed, perhaps it would be better to have a separate manual with
>> all that stuff, whereas the Emacs user manual should have only a short
>> description of the main features, and a cross-reference to the
>> separate manual.
>
> I would propose to make a new section short enough to belong in the main
> Emacs manual, as which-key's "keymay discovery" perspective should be
> easier to find.
>
> I can volunteer to write a draft and confer with Justin, the actual
> author, for completeness.

Attached are a proposed patch for the Emacs manual, intentionally very
short.
Feedback welcome on any aspects.


--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
 filename=0002-Add-manual-entries-for-which-key.patch

From c8264398374ad6eae380ea46428092efa0ba02fc Mon Sep 17 00:00:00 2001
From: Jeremy Bryant <jb@HIDDEN>
Date: Sun, 11 Feb 2024 21:26:41 +0000
Subject: [PATCH 2/2] Add manual entries for which-key

* doc/emacs/display.texi (Display Custom):  brief mention
* doc/emacs/help.texi (Key Help):  reference node above
---
 doc/emacs/display.texi | 3 ++-
 doc/emacs/help.texi    | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index d2557d6148e..754f9b6d048 100644
--- a/doc/emacs/display.texi
+++ b/doc/emacs/display.texi
@@ -2215,7 +2215,8 @@ Display Custom
 default), the multi-character key sequence echo shown according to
 @code{echo-keystrokes} will include a short help text about keys which
 will invoke @code{describe-prefix-bindings} (@pxref{Misc Help}) to show
-the list of commands for the prefix you already typed.
+the list of commands for the prefix you already typed.  For a related
+help facility (@pxref{which-key}).
 
 @cindex mouse pointer
 @cindex hourglass pointer display
diff --git a/doc/emacs/help.texi b/doc/emacs/help.texi
index 99a4173ac29..25bb3ccc08a 100644
--- a/doc/emacs/help.texi
+++ b/doc/emacs/help.texi
@@ -260,6 +260,12 @@ Key Help
 @code{widget-describe} commands, that should be run with point over
 the button.
 
+@node which-key
+@subsection which-key
+ @command{M-x which-key} is a global minor mode which helps in
+ discovering keymaps.  It displays keybindings following your currently
+ entered incomplete command (prefix), in a popup.
+
 @node Name Help
 @section Help by Command or Variable Name
 
-- 
2.42.0


--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 9 Feb 2024 06:51:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Feb 09 01:51:32 2024
Received: from localhost ([127.0.0.1]:39606 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rYKjT-00066y-Tb
	for submit <at> debbugs.gnu.org; Fri, 09 Feb 2024 01:51:32 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:47090)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1rYKjS-00066c-J6
 for 68929 <at> debbugs.gnu.org; Fri, 09 Feb 2024 01:51:31 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1rYKj8-0004QT-27; Fri, 09 Feb 2024 01:51:10 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=+QJfX/S+az/RWTe7sGNaeHjZnKKhPUi/qTtkcblkijw=; b=l6KhWQRBblcp
 B6Exo/a+mCCphQaOk8Lda3EIyOW5zdRLOuy8g1GVYeRjwFQYdIn2SvFQ2TMXtubjkGdXmTxzLHo9K
 KC0OAQ6MBXJuzTh9DuhX0yD9Zvk0Nhp7t+PWrnjcCI4CQHNXbGYXCfT/4gSWub1ZFEwp6pzKwHQPx
 9P5+hPExBVbuR5JEGe0dYghF7d1C21y/G4PxDVpFCBKF9OoJo+8GoQsleaFaHsd0bCuyLQwTYUC7L
 GiajTWU/RShwes6XEAm8K4fI07rcoyZH4mp2iAOYK1G0l10Vom9MLY7AtJoVAu22Uwd6tHX+by+9L
 doLPAjmpZYBDQ/ulLr0n+g==;
Date: Fri, 09 Feb 2024 08:51:05 +0200
Message-Id: <864jeiw2p2.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
In-Reply-To: <87v86yr3jj.fsf@HIDDEN> (message from Jeremy Bryant on
 Thu, 08 Feb 2024 22:27:58 +0000)
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
 <87plx8rkps.fsf@HIDDEN> <86cyt7xyy7.fsf@HIDDEN>
 <87v86yr3jj.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68929
Cc: 68929 <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Jeremy Bryant <jb@HIDDEN>
> Cc: 68929 <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
> Date: Thu, 08 Feb 2024 22:27:58 +0000
> 
> Defcustom is covered below
> "
> New defcustom's should always have a ':version' tag stating the first
> Emacs version in which they will appear.  Likewise with defcustom's
> whose value is changed -- update their ':version' tag.
> "
> 
> Is defface conceptually close enough not to warrant an extra para?

No, it's an omission, now fixed.

Thanks.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 8 Feb 2024 22:32:14 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 08 17:32:14 2024
Received: from localhost ([127.0.0.1]:36557 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rYCwI-0008MD-5T
	for submit <at> debbugs.gnu.org; Thu, 08 Feb 2024 17:32:14 -0500
Received: from out-182.mta0.migadu.com ([2001:41d0:1004:224b::b6]:52242)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jb@HIDDEN>) id 1rYCwG-0008Lb-1S
 for 68929 <at> debbugs.gnu.org; Thu, 08 Feb 2024 17:32:12 -0500
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
 <87plx8rkps.fsf@HIDDEN> <86cyt7xyy7.fsf@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net;
 s=key1; t=1707431510;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to:references:references;
 bh=QR3O0meFo+zOJLh5/pzDFtdJ4k4WKETZjAlI4yRfQcM=;
 b=linqFtxLid8mbK7U6TP7yMG9VarBOH7URkCeuw7T7uJyr2oACWBPaoxg6AvrouZ08+J2GD
 ZpyhVXZyzTFZurMS2vaQsGmIB0L8wNzxCpG8yqzU6UYMyKb+2r+NKyU/8HO4oM6Aoln5C2
 AcNd62QK0ERgVxnPH2K2ruXvOeWnr/k9k1GA8BpN0AgECvYmPsH1H6ivl7OcwX2iRAxLMu
 a1AfP5ChL2Q+t9pbZ6b4p2+1wediYYjJRRDroyqzhdXcuMmpLGUUOLtgKgv6eB6CJ9gbpR
 xRSKSqZeTi/CJblWNY9OtBsjcMkoi1stvjv+riWrvfCRKYBIBbrOHqiSz1qduw==
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
From: Jeremy Bryant <jb@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
Date: Thu, 08 Feb 2024 22:27:58 +0000
In-reply-to: <86cyt7xyy7.fsf@HIDDEN>
Message-ID: <87v86yr3jj.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Migadu-Flow: FLOW_OUT
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 68929
Cc: 68929 <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)


Eli Zaretskii <eliz@HIDDEN> writes:

>> From: Jeremy Bryant <jb@HIDDEN>
>> Cc: 68929 <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
>> Date: Wed, 07 Feb 2024 22:01:05 +0000
>> 
>> 
>> Eli Zaretskii <eliz@HIDDEN> writes:
>> > Two spaces between sentences in comments and doc strings, here and
>> > elsewhere.
>> 
>> OK.  Related point - This is not in the Elisp manual "Tips for
>> documentation strings", is it worth a patch for this?
>
> That section is not specific to the Emacs development.  Our
> conventions, which are specific to the Emacs development project, are
> in CONTRIBUTE.

I stand corrected, indeed, I was looking in the wrong place.


>> > Please add a :version tag to all defcustom's and defface's.
>> 
>> I cannot locate this in the elisp manual, Appendix D "Tips and
>> conventions", or in the defcustom and defface sections, should this be
>> documented and how?
>
> It's already documented in CONTRIBUTE.  Again, other Lisp programs out
> there are free not to follow these guidelines (and, in fact, :version
> might not have any useful effect in 3rd party packages), it is our own
> convention whose purpose is to help "M-x customize-changed" do its job
> well.

Understood.

Defcustom is covered below
"
New defcustom's should always have a ':version' tag stating the first
Emacs version in which they will appear.  Likewise with defcustom's
whose value is changed -- update their ':version' tag.
"

Is defface conceptually close enough not to warrant an extra para?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 8 Feb 2024 22:28:05 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 08 17:28:05 2024
Received: from localhost ([127.0.0.1]:36238 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rYCsF-00084z-Qn
	for submit <at> debbugs.gnu.org; Thu, 08 Feb 2024 17:28:05 -0500
Received: from out-179.mta1.migadu.com ([95.215.58.179]:48157)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jb@HIDDEN>) id 1rYCsD-00083x-2b
 for 68929 <at> debbugs.gnu.org; Thu, 08 Feb 2024 17:28:02 -0500
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
 <CAF8XuLgkTgHwZ12pY3s4e3j_evzAzfoCRtUutrmuPuHbN_8Rvg@HIDDEN>
 <87ttmkrlc5.fsf@HIDDEN> <86fry3xzae.fsf@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net;
 s=key1; t=1707431265;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to:references:references;
 bh=g1rO8cUU0UY3xKgKAX3MjCikNM7i14q7jNZTDr01HhQ=;
 b=CN03dVHb1n8DsefiK1JNsTXFSJBTV0ZG5pIfFdM0nPFnxGUBSrGbqPdvwNteyUYfj1C8f2
 zY8bYsWOfdrtDoLVyqAC4T2F5EOqYTm5hx2yN5GsbFgIv9vxwWmP3qiyhV4rKOpZkC0Lr7
 ZkA/s5o40tHZCFUlzImr66HJeZ2uWfKOZYgxF186Tz5dpbHIV+IN2T9gnMFed2VFKDaQYy
 VESleOgobUOUzoGhvvYfNU2wx2cMH9/mIDJS8EEERerDvYZRiZ3I6OsKfwcBRiq7gpb7OY
 9dEiEHiUavBYaCoZZi9v8reHV3SRig+Y2Cv42WCYRs4MvDoQ7+u+7motZaINyQ==
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
From: Jeremy Bryant <jb@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
Date: Thu, 08 Feb 2024 22:25:39 +0000
In-reply-to: <86fry3xzae.fsf@HIDDEN>
Message-ID: <87zfwar3qd.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Migadu-Flow: FLOW_OUT
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 68929
Cc: 68929 <at> debbugs.gnu.org, justin@HIDDEN, monnier@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)


Eli Zaretskii <eliz@HIDDEN> writes:

>> From: Jeremy Bryant <jb@HIDDEN>
>> Cc: Eli Zaretskii <eliz@HIDDEN>, 68929 <at> debbugs.gnu.org,
>>  monnier@HIDDEN
>> Date: Wed, 07 Feb 2024 21:53:55 +0000
>> 
>> Is there a natural place in the Emacs manual (Perhaps "Other Help
>> Commands"?) to add a new section on M-x which-key? WDYT?
>
> Will the section be very long?  How long?
>
> If it's not very long, I think the right place is in "Key Help",
> perhaps as a separate subsection below it.  Also, I think which-key
> should be briefly mentioned in "Display Custom", where echo-keystrokes
> is described.
>
> If the section about which-key you envision is supposed to be long and
> detailed, perhaps it would be better to have a separate manual with
> all that stuff, whereas the Emacs user manual should have only a short
> description of the main features, and a cross-reference to the
> separate manual.

I would propose to make a new section short enough to belong in the main
Emacs manual, as which-key's "keymay discovery" perspective should be
easier to find.

I can volunteer to write a draft and confer with Justin, the actual
author, for completeness.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 8 Feb 2024 16:54:52 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 08 11:54:52 2024
Received: from localhost ([127.0.0.1]:33519 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rY7fo-0006Aq-7Q
	for submit <at> debbugs.gnu.org; Thu, 08 Feb 2024 11:54:52 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:40704)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1rY7fm-0006Ae-KD
 for 68929 <at> debbugs.gnu.org; Thu, 08 Feb 2024 11:54:51 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1rY7fP-00016a-MN; Thu, 08 Feb 2024 11:54:27 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=sNQ/1FF9fdX+OFa7IqGKNYZ+UufCePnqN32+Vp2g+eY=; b=QIL/2MtKp8Et
 V0/tIN+ALK8P8C1FbFNtjpmp9rJ63uZhmuwriPIMvk+R9Wi0BMCTjg3HGIABI8E8ZqZ8OA4g0v19z
 TAavtCMhfaZxq8eS2N32ajCmOycxz+lCRKMTAzD1V9EaRlJHPrxTd4b9oSqhYEn3n+7v5wF08RD9n
 NllXTICvhoFiSZUaovlqIt8G5vS2Vx3ENv3e2VtxxUPaz8cr6MtTluIF48o+Hzje7OEX9NYeZqezW
 Cx3MUJ4Lwm+2OvFgFq9jMlC44H5KH/ddGPT57jJ3FZtycNe3+kNWv3uZLm1njow3OSHYG2/kZAGRK
 CgO7DDF+WFYH5Someu1tuQ==;
Date: Thu, 08 Feb 2024 18:54:24 +0200
Message-Id: <86h6iix5fj.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
In-Reply-To: <jwvcyt7ose1.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Thu, 08 Feb 2024 11:10:44 -0500)
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
 <87plx8rkps.fsf@HIDDEN> <86cyt7xyy7.fsf@HIDDEN>
 <CAF8XuLjwPL+JLxc+ebUYSoqzL74UTEw6nyusugFttPUtiXreiA@HIDDEN>
 <jwvcyt7ose1.fsf-monnier+emacs@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68929
Cc: jb@HIDDEN, 68929 <at> debbugs.gnu.org, justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Stefan Monnier <monnier@HIDDEN>
> Cc: Eli Zaretskii <eliz@HIDDEN>,  Jeremy Bryant <jb@HIDDEN>,
>   68929 <at> debbugs.gnu.org
> Date: Thu, 08 Feb 2024 11:10:44 -0500
> 
> > 4. I never really liked the timer mechanism either, but I didn't find
> > an alternative to detecting when emacs was in the middle of reading a
> > key sequence. I like the idea of which-key as simply being a different
> > describe-prefix-bindings function, but my sense is that novices
> > appreciate the automatic popup. I'm wondering if anyone has any other
> > ideas. In principle, one could have a hook that emacs uses to notify
> > which-key that emacs is waiting on a key sequence, but maybe that is
> > overkill.
> 
> I don't have a strong opinion about the use of a timer.
> But maybe we could hook into the `echo-keystrokes` mechanism (and thus
> reuse its timer, which also defaults to 1s).

Yes, that'd be the first possibility I'd recommend to explore.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 8 Feb 2024 16:11:09 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 08 11:11:09 2024
Received: from localhost ([127.0.0.1]:33460 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rY6zU-00050j-Rz
	for submit <at> debbugs.gnu.org; Thu, 08 Feb 2024 11:11:09 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:11398)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@HIDDEN>) id 1rY6zT-00050X-9k
 for 68929 <at> debbugs.gnu.org; Thu, 08 Feb 2024 11:11:07 -0500
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id C8C3F10009E;
 Thu,  8 Feb 2024 11:10:46 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1707408645;
 bh=S4czLC5j8UhjLXxZ+60CIIzTtokCWOJSPO6O89MNSSg=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=Jn+uznqh71iBoQKlAzgYYDsgmHLh6oQIQMY+5Wnp87ilKnxzreX4An8QWYtl+QjRS
 uaepsMrZbqMb2WDUsSP5eNBbdqvr5VNz/451CSXBz9MlC+2B33+3WiVVaAeUnlq5Ze
 r8QdWJKCLmGvi2sui8i36V+01XaDBpclO8Y0ySYjOUjpnTNtg0eO5KqsdCm1YxZq4s
 f6esgqP0XhAlZ8fcV5Jn51+ERsatUZ9NDeHwN5Z5qhJppV6SLy7IYCgUWAIoC3L+8D
 XAeFSsHslBiIVx1PkuH+XWo7WiKYJm5EdiCoe43n7c8Sl/f95Oe82Tx5EU9El7hkro
 gq3/c20FEBiWg==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id CF3CA10001D;
 Thu,  8 Feb 2024 11:10:45 -0500 (EST)
Received: from pastel (unknown [104.247.238.113])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A1A9312032C;
 Thu,  8 Feb 2024 11:10:45 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Justin Burkett <justin@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
In-Reply-To: <CAF8XuLjwPL+JLxc+ebUYSoqzL74UTEw6nyusugFttPUtiXreiA@HIDDEN>
 (Justin Burkett's message of "Thu, 8 Feb 2024 10:42:15 -0500")
Message-ID: <jwvcyt7ose1.fsf-monnier+emacs@HIDDEN>
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
 <87plx8rkps.fsf@HIDDEN> <86cyt7xyy7.fsf@HIDDEN>
 <CAF8XuLjwPL+JLxc+ebUYSoqzL74UTEw6nyusugFttPUtiXreiA@HIDDEN>
Date: Thu, 08 Feb 2024 11:10:44 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain T_SCC_BODY_TEXT_LINE    -0.01 -
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68929
Cc: Eli Zaretskii <eliz@HIDDEN>, 68929 <at> debbugs.gnu.org,
 Jeremy Bryant <jb@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> 1. I think replacing third-party support with hooks that will allow
> whatever package to insert code where needed is a good idea, although
> some of these packages (like evil) have some pretty idiosyncratic
> needs if I remember correctly.

Indeed, resolving such issues can be non-trivial (especially when they
require synchronization with other packages).

Often we end up doing it in two steps: first introduce the hook (making
sure that it is flexible enough that it can cover our needs and those
of other packages), then later remove the ad-hoc third-party support.

> 3. There were some oddities that we ran into early on around computing
> the width of unicode characters that I did not fully understand, which
> is why there are some clunky options for those. The main issue was
> some characters came out wider than anticipated, breaking the width
> calculations for the table shown by which-key. I would be happy to
> improve those with guidance.

For monospace fonts, `string-width` *should* give you the information
you need.

> 4. I never really liked the timer mechanism either, but I didn't find
> an alternative to detecting when emacs was in the middle of reading a
> key sequence. I like the idea of which-key as simply being a different
> describe-prefix-bindings function, but my sense is that novices
> appreciate the automatic popup. I'm wondering if anyone has any other
> ideas. In principle, one could have a hook that emacs uses to notify
> which-key that emacs is waiting on a key sequence, but maybe that is
> overkill.

I don't have a strong opinion about the use of a timer.
But maybe we could hook into the `echo-keystrokes` mechanism (and thus
reuse its timer, which also defaults to 1s).


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 8 Feb 2024 15:42:51 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 08 10:42:51 2024
Received: from localhost ([127.0.0.1]:33449 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rY6Y6-0004AT-NT
	for submit <at> debbugs.gnu.org; Thu, 08 Feb 2024 10:42:51 -0500
Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]:43332)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <justin@HIDDEN>) id 1rY6Y3-0004AE-Cq
 for 68929 <at> debbugs.gnu.org; Thu, 08 Feb 2024 10:42:49 -0500
Received: by mail-ej1-x62a.google.com with SMTP id
 a640c23a62f3a-a388c5542e9so191966366b.1
 for <68929 <at> debbugs.gnu.org>; Thu, 08 Feb 2024 07:42:32 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=burkett-cc.20230601.gappssmtp.com; s=20230601; t=1707406947; x=1708011747;
 darn=debbugs.gnu.org; 
 h=content-transfer-encoding:cc:to:subject:message-id:date:from
 :in-reply-to:references:mime-version:from:to:cc:subject:date
 :message-id:reply-to;
 bh=MXdtm8cK03RNYP4EzBR/rBknorG7XugP9W/ELYMJBUE=;
 b=H1ETM2ZKIS7blcGjaOCkc4jMzKdn6Bpg7RQL9U7ScdJlOYLwnOI7CuR4C0Tjxiqew6
 XYDw6OXxdxC1VWCanFsI36FCUebYO5Ab3qddva6g+gncZ3c9ubZhw9U8yb4fSbOGdT2h
 5rK54CEy0XEk/myH9qKHMJFH0Ifq9b9+3/5e0KO+Vi0+z+MpECKBw0nKlyioOs4/3vuB
 IZiVy1a3GkhexA47FR9LvgNep+awkYzDCA5aLVE4pLoGQAS0n3QVfZ5K0tvNfKN6TAD4
 XbmzQ3z4tpbtNJb00sf0xcPzfIQZIJuhpAN9tjFL3YGPK+uR1Ln5Efb/A33wOooTWTFd
 iXxw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1707406947; x=1708011747;
 h=content-transfer-encoding:cc:to:subject:message-id:date:from
 :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=MXdtm8cK03RNYP4EzBR/rBknorG7XugP9W/ELYMJBUE=;
 b=jsBPhudKoJkhKYVj2FdtGM1zHj0J6oD3bM6IdHsSUpqCvbatk2IAcdrQCZf2ubd3VS
 lvkSO9PEk7dDJ5k2WTHgs4UYw6NySg29ALcjycSuAjw7G5IbqoM6aVDpR9QC8pYM8SdE
 NztlDFbJ9qyMw1E9y6hvfUhPdutaGCM2cWop5caBMFr88Q+j05VaD0sLiuISbJvTBkfb
 rJ09ao/b3NzP9vN8cv2P94FYRHyXkLCptcW0kiIE5pBPWhplRRKtuWtvaayd5EvmNpmH
 aWYrZMBl766gEH1dRGoJ0/Z1p01gOndpZe6PzcPZLMaAv7QKn8Y4OizLQGaHjIBGXc+r
 oPGg==
X-Forwarded-Encrypted: i=1;
 AJvYcCVSKjnCrOCZ1QNMnczil5vnF5dBXNx9AaPZCG/vBVM+eQxEnsZp1wAbUaTyQAldWQ1RAs6GkV78pxJhMiWLDxYBLFY3XYI=
X-Gm-Message-State: AOJu0YxnTeeRILBdGWOQYUTirmHM1Hf5qpC6ZwKd2rGuYWpLDqTz2heH
 0tk6lDGfcwEmL4GPx4x6D5SGbvhTZhrVBcYkGbdqxr8tpsNNX6QUPCVObGHboMDbw95Va1eZZPS
 1SYXOa2YPZ/6JEJb4maSWMiKphpJlEZWGUvQnlQ==
X-Google-Smtp-Source: AGHT+IERqGaP6oe3TQq159P4r84WD7KOtjApw/iPfS7ZdyyccgzyJ+657J9xMZOJUXNvG2y+gRNJ6HFpyTa2GpqmEGE=
X-Received: by 2002:a17:907:648:b0:a3b:ca3a:128c with SMTP id
 wq8-20020a170907064800b00a3bca3a128cmr459603ejb.22.1707406946863; Thu, 08 Feb
 2024 07:42:26 -0800 (PST)
MIME-Version: 1.0
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
 <87plx8rkps.fsf@HIDDEN> <86cyt7xyy7.fsf@HIDDEN>
In-Reply-To: <86cyt7xyy7.fsf@HIDDEN>
From: Justin Burkett <justin@HIDDEN>
Date: Thu, 8 Feb 2024 10:42:15 -0500
Message-ID: <CAF8XuLjwPL+JLxc+ebUYSoqzL74UTEw6nyusugFttPUtiXreiA@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
To: Eli Zaretskii <eliz@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 68929
Cc: Jeremy Bryant <jb@HIDDEN>, 68929 <at> debbugs.gnu.org,
 monnier@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi all,

I appreciate the feedback. I have no doubt there are improvements to
be made. To the extent that I reinvented the wheel, it was because I
wasn't aware that particular wheel existed at the time. When I get
time, I will work on the things that have been mentioned here. I do
have a few questions and comments:

1. I think replacing third-party support with hooks that will allow
whatever package to insert code where needed is a good idea, although
some of these packages (like evil) have some pretty idiosyncratic
needs if I remember correctly.

2. I would like to depend as much as possible on built-in functions,
but I am probably unaware of all of the possibilities here, so any
suggestions would be appreciated. There might also be libraries in
emacs that have been written/improved since I wrote many of these
functions.

3. There were some oddities that we ran into early on around computing
the width of unicode characters that I did not fully understand, which
is why there are some clunky options for those. The main issue was
some characters came out wider than anticipated, breaking the width
calculations for the table shown by which-key. I would be happy to
improve those with guidance.

4. I never really liked the timer mechanism either, but I didn't find
an alternative to detecting when emacs was in the middle of reading a
key sequence. I like the idea of which-key as simply being a different
describe-prefix-bindings function, but my sense is that novices
appreciate the automatic popup. I'm wondering if anyone has any other
ideas. In principle, one could have a hook that emacs uses to notify
which-key that emacs is waiting on a key sequence, but maybe that is
overkill.

Thanks,
Justin

On Thu, Feb 8, 2024 at 1:16=E2=80=AFAM Eli Zaretskii <eliz@HIDDEN> wrote:
>
> > From: Jeremy Bryant <jb@HIDDEN>
> > Cc: 68929 <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
> > Date: Wed, 07 Feb 2024 22:01:05 +0000
> >
> >
> > Eli Zaretskii <eliz@HIDDEN> writes:
> > > Two spaces between sentences in comments and doc strings, here and
> > > elsewhere.
> >
> > OK.  Related point - This is not in the Elisp manual "Tips for
> > documentation strings", is it worth a patch for this?
>
> That section is not specific to the Emacs development.  Our
> conventions, which are specific to the Emacs development project, are
> in CONTRIBUTE.
>
> > > Please add a :version tag to all defcustom's and defface's.
> >
> > I cannot locate this in the elisp manual, Appendix D "Tips and
> > conventions", or in the defcustom and defface sections, should this be
> > documented and how?
>
> It's already documented in CONTRIBUTE.  Again, other Lisp programs out
> there are free not to follow these guidelines (and, in fact, :version
> might not have any useful effect in 3rd party packages), it is our own
> convention whose purpose is to help "M-x customize-changed" do its job
> well.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 8 Feb 2024 06:17:14 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 08 01:17:13 2024
Received: from localhost ([127.0.0.1]:58839 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rXxij-0000Tb-IV
	for submit <at> debbugs.gnu.org; Thu, 08 Feb 2024 01:17:13 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:59468)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1rXxih-0000TN-BU
 for 68929 <at> debbugs.gnu.org; Thu, 08 Feb 2024 01:17:12 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1rXxiM-0001jE-Fh; Thu, 08 Feb 2024 01:16:50 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=ZcXfqqoG3CMSYscFahyQeL6T5zCH74gAVpq38enteks=; b=rlJjxvMxKQyG
 RV8pX04k0YZkbTmxb9w54h1Stg4HS+AvHa7VSZG/Q3D+mFafAu7nYiEPwlqgjsPIjeH7MakTkA4zf
 KoqrhRQQjZCfN4jeDCCApMcWpI4HAbauOI83/kv0Us3D7h51BAGj4CMLIX4hEZxlFp4bptUv+7EdD
 MVkw5nrXqbgNjW7tqx1QxtfeqqHeRdhMfaclobX6Jl28Me/Cyowxq+ykptsMlQrHsl4djn6Held5/
 ErpX6fIqrzpsLWWluOSa126GDc8gX8JB0k9suc95kyrkayvxHN1Y7qG3GG5Z3JKymeObBydH9J72B
 QfxFWW/Sunw//m1uLoJt4w==;
Date: Thu, 08 Feb 2024 08:16:48 +0200
Message-Id: <86cyt7xyy7.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
In-Reply-To: <87plx8rkps.fsf@HIDDEN> (message from Jeremy Bryant on
 Wed, 07 Feb 2024 22:01:05 +0000)
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
 <87plx8rkps.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68929
Cc: 68929 <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Jeremy Bryant <jb@HIDDEN>
> Cc: 68929 <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
> Date: Wed, 07 Feb 2024 22:01:05 +0000
> 
> 
> Eli Zaretskii <eliz@HIDDEN> writes:
> > Two spaces between sentences in comments and doc strings, here and
> > elsewhere.
> 
> OK.  Related point - This is not in the Elisp manual "Tips for
> documentation strings", is it worth a patch for this?

That section is not specific to the Emacs development.  Our
conventions, which are specific to the Emacs development project, are
in CONTRIBUTE.

> > Please add a :version tag to all defcustom's and defface's.
> 
> I cannot locate this in the elisp manual, Appendix D "Tips and
> conventions", or in the defcustom and defface sections, should this be
> documented and how?

It's already documented in CONTRIBUTE.  Again, other Lisp programs out
there are free not to follow these guidelines (and, in fact, :version
might not have any useful effect in 3rd party packages), it is our own
convention whose purpose is to help "M-x customize-changed" do its job
well.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 8 Feb 2024 06:09:53 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 08 01:09:53 2024
Received: from localhost ([127.0.0.1]:58829 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rXxbd-0000Em-8h
	for submit <at> debbugs.gnu.org; Thu, 08 Feb 2024 01:09:53 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:43262)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1rXxbb-0000Ea-D2
 for 68929 <at> debbugs.gnu.org; Thu, 08 Feb 2024 01:09:51 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1rXxbH-0000RH-RP; Thu, 08 Feb 2024 01:09:31 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=Zzr6zvaPF6TTfoalOJZ0WsU1avwLJHhkviz+8+vXq/Y=; b=ReT1CfhvOreJ
 UcFgsm/h1wQ+6EF6UIm1l6dfdQjo7uVpAQQ5TgpH1IT6Ll3wjnCvix+0DaTh0B19+AToBM9n+SFMB
 1v/pKV6wU+6/K2dsPfwHbS6fZ3l89OiK41O/tEJ9/Nuw1UD4F+Ee9t3R/VAg7hlJlUcqSaBYTrto6
 WHsanqDIUJWeYdlewomAa0JIJFvg6/v5EkqoHC489yBKHVJp58c30XJVNQhbYJTrD7IlHVjrwOa11
 7R1ShHdZOd95OhVBjWN2l1AocLbZ8tRj01T73nPxYQNKQIBfNh/ezwZRAkzDFV7zysxBg5d3eMH3X
 4nju/dbcmGL73dWaTOXUCw==;
Date: Thu, 08 Feb 2024 08:09:29 +0200
Message-Id: <86fry3xzae.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
In-Reply-To: <87ttmkrlc5.fsf@HIDDEN> (message from Jeremy Bryant on
 Wed, 07 Feb 2024 21:53:55 +0000)
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
 <CAF8XuLgkTgHwZ12pY3s4e3j_evzAzfoCRtUutrmuPuHbN_8Rvg@HIDDEN>
 <87ttmkrlc5.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68929
Cc: 68929 <at> debbugs.gnu.org, justin@HIDDEN, monnier@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Jeremy Bryant <jb@HIDDEN>
> Cc: Eli Zaretskii <eliz@HIDDEN>, 68929 <at> debbugs.gnu.org,
>  monnier@HIDDEN
> Date: Wed, 07 Feb 2024 21:53:55 +0000
> 
> Is there a natural place in the Emacs manual (Perhaps "Other Help
> Commands"?) to add a new section on M-x which-key? WDYT?

Will the section be very long?  How long?

If it's not very long, I think the right place is in "Key Help",
perhaps as a separate subsection below it.  Also, I think which-key
should be briefly mentioned in "Display Custom", where echo-keystrokes
is described.

If the section about which-key you envision is supposed to be long and
detailed, perhaps it would be better to have a separate manual with
all that stuff, whereas the Emacs user manual should have only a short
description of the main features, and a cross-reference to the
separate manual.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 8 Feb 2024 06:04:27 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 08 01:04:27 2024
Received: from localhost ([127.0.0.1]:58820 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rXxWN-0008R6-3C
	for submit <at> debbugs.gnu.org; Thu, 08 Feb 2024 01:04:27 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:57758)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1rXxWL-0008Qs-2R
 for 68929 <at> debbugs.gnu.org; Thu, 08 Feb 2024 01:04:26 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1rXxW0-0007jL-8Q; Thu, 08 Feb 2024 01:04:04 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=SIgXPSdWG1206wsFJHvqx6ltRaxFCnLdsCpJ4pfUNGY=; b=DIHyknZqu3sf
 QB//JY6DAWZ5D8XfXRBYf/a6N1OSrq4EINh/OtYr5rEIn/GMwWpP8MxlXylI8ADxyphS7XZSIwBVt
 Yma6Lwsihxyc+1lLpzDhh0yOjOuUYQvXCYG81ePD+upljfbow2ZDXTqFohzOuORmZQd4r4WfBw6Cw
 D5KPM3PDws/DF9meQJiCD2dDpnyQtec+QbOSIcR1s0n2kDd9PbIdixM/RLAFgv8tZXuMN3m49Xod5
 o48u7qLTAzSlxYOeLbOcrfKQfTACp5E3bx8ZyD+kjbLJ4rmNemBPQk5B+cx2CvpJSdtas67Ye/yR6
 IDvlyWEiEkDls9sHb4EOPQ==;
Date: Thu, 08 Feb 2024 08:03:59 +0200
Message-Id: <86h6ijxzjk.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
In-Reply-To: <87y1bwrll4.fsf@HIDDEN> (bug-gnu-emacs@HIDDEN)
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
References: <871q9rvqbi.fsf@HIDDEN> <87mssc65y8.fsf@HIDDEN>
 <87y1bwrll4.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68929
Cc: philipk@HIDDEN, 68929 <at> debbugs.gnu.org, monnier@HIDDEN,
 justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> Cc: 68929 <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
> Date: Wed, 07 Feb 2024 21:48:00 +0000
> From:  Jeremy Bryant via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN>
> 
> 
> Philip Kaludercic <philipk@HIDDEN> writes:
> 
> > My genera feeling is that the code is reinventing the wheel at a number
> > of places, which might make it more complicated to maintain in the long
> > term.  Looking for ways to slim down the codebase, perhaps by
> > deprecating some options, dropping support for third-party packages and
> > reusing existing functionality seems like something one should look into.
> 
> Should these improvements be made before moving which-key to core?

Preferably, yes.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 7 Feb 2024 22:09:01 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 07 17:09:01 2024
Received: from localhost ([127.0.0.1]:58104 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rXq6H-0003Dp-A4
	for submit <at> debbugs.gnu.org; Wed, 07 Feb 2024 17:09:01 -0500
Received: from out-183.mta0.migadu.com ([91.218.175.183]:11259)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jb@HIDDEN>) id 1rXq6E-0003DX-PP
 for 68929 <at> debbugs.gnu.org; Wed, 07 Feb 2024 17:08:59 -0500
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net;
 s=key1; t=1707343718;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to:references:references;
 bh=75JzED/MNcor9Vb3KQAhuCJwyg/oeOjNmfccOBY+G70=;
 b=cZL/l/Rm9iugHI4oEZUpwQOwoTZ2W24IhQRHt63rDwZkIO0VCBNPvHCOJK+DjSW4hpzw5j
 khTjA/2LCziR0KK2x+YeuBsY4lBz30lr1HZ2CoKR2oFGQD87D+2hJ3s6l+y4UHgMbVFZRT
 iA4ZNzgftYDFFHHaBkZRDU9sZsXLXx4gXLjjXyKHUNm0xKwJHB3ee6TuKLTQPWmlySUzXx
 +h8E/zucPDn0xB7m21daLlZuYCge48LiAOmF5tejqNYngPpSShdjuvwQyTBC1ejJVpFViO
 QAQMBHSOYO5D7ktsQIqEPUYf4RC50HqJa4OsnSl+zZVERKAQdCgpt83mkdTE+Q==
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
From: Jeremy Bryant <jb@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
Date: Wed, 07 Feb 2024 22:01:05 +0000
In-reply-to: <86wmrj148c.fsf@HIDDEN>
Message-ID: <87plx8rkps.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Migadu-Flow: FLOW_OUT
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 68929
Cc: 68929 <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)


Eli Zaretskii <eliz@HIDDEN> writes:
> Two spaces between sentences in comments and doc strings, here and
> elsewhere.

OK.  Related point - This is not in the Elisp manual "Tips for
documentation strings", is it worth a patch for this?

(although this is flagged by M-x checkdoc)

>
> Please add a :version tag to all defcustom's and defface's.

I cannot locate this in the elisp manual, Appendix D "Tips and
conventions", or in the defcustom and defface sections, should this be
documented and how?





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 7 Feb 2024 21:55:26 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 07 16:55:26 2024
Received: from localhost ([127.0.0.1]:58084 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rXpt7-0002sX-Sc
	for submit <at> debbugs.gnu.org; Wed, 07 Feb 2024 16:55:26 -0500
Received: from out-184.mta1.migadu.com ([95.215.58.184]:14541)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jb@HIDDEN>) id 1rXpt6-0002sP-3v
 for 68929 <at> debbugs.gnu.org; Wed, 07 Feb 2024 16:55:25 -0500
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
 <CAF8XuLgkTgHwZ12pY3s4e3j_evzAzfoCRtUutrmuPuHbN_8Rvg@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net;
 s=key1; t=1707342908;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=4RPbJqTcO/vFb+TC+ft1TPKSJjJFSRh3SchjX5Z44lw=;
 b=n/NXND1sXs0W6IPSQbZwo/akQ+4UoWH0bpy0oglNJv3cScYmwMLVP8smL5Xfm2OpgwXKOS
 31y+ksOAco/WvPJGadiU8mZ6kzt7bHq7pBo8e8Kw/bj1s1gk6amKrVwFrQs+KPXqgEz8/u
 6rxJitW2VbunAU/8Q7cD8DsxhG0apmiQ0Vq06ARkdFOCnk/hyCR9PHZJvvLW8GPK1mo+Ji
 ru+rGtyOo6/mnL0s7O80A2QVmI/iTo9UFhf9rGveHsetpY8EIV/HbUBRu5Ogf/9DLkR4up
 ne7DAmV2z4nAaLLFTtbxKZbshYjET5SqQJ+xAFFWR/wscbB8mV+toNV3oZ4jMQ==
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
From: Jeremy Bryant <jb@HIDDEN>
To: Justin Burkett <justin@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
Date: Wed, 07 Feb 2024 21:53:55 +0000
In-reply-to: <CAF8XuLgkTgHwZ12pY3s4e3j_evzAzfoCRtUutrmuPuHbN_8Rvg@HIDDEN>
Message-ID: <87ttmkrlc5.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Migadu-Flow: FLOW_OUT
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 68929
Cc: Eli Zaretskii <eliz@HIDDEN>, 68929 <at> debbugs.gnu.org,
 monnier@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)


Justin Burkett <justin@HIDDEN> writes:

> Thanks for the comments. I'll work on these.
>
> On Mon, Feb 5, 2024 at 7:32=E2=80=AFAM Eli Zaretskii <eliz@HIDDEN> wrote:
>>
>> > Date: Sun, 04 Feb 2024 22:02:50 +0000
>> > From:  Jeremy Bryant via "Bug reports for GNU Emacs,
>> >  the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN>
>> >
>> > This patch brings the latest version of which-key from GNU ELPA into
>> > Emacs core
>> >
>> > If suitable I will then work on the updates to user-facing aspects suc=
h as
>> > manual and NEWS.

Is there a natural place in the Emacs manual (Perhaps "Other Help
Commands"?) to add a new section on M-x which-key? WDYT?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 7 Feb 2024 21:50:09 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 07 16:50:09 2024
Received: from localhost ([127.0.0.1]:58079 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rXpo1-0002lN-5g
	for submit <at> debbugs.gnu.org; Wed, 07 Feb 2024 16:50:09 -0500
Received: from out-183.mta0.migadu.com ([91.218.175.183]:46870)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jb@HIDDEN>) id 1rXpny-0002kn-4h
 for 68929 <at> debbugs.gnu.org; Wed, 07 Feb 2024 16:50:07 -0500
References: <871q9rvqbi.fsf@HIDDEN> <87mssc65y8.fsf@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net;
 s=key1; t=1707342585;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to:references:references;
 bh=jzLn1b3hDUZmXUYqgQxjiKkCZWgt1YjCmbAGFOVyAh4=;
 b=g2UXW1xnWqhQen95XD7Bjcb0XsaqjjpbkunWKTxuVEK9zHEH44X3+yQ41IsKWb1RyS6Vp3
 Z16QKxGf2nf7jumoAjgFl96qlK+zWghqlxk9XQT7AsezAFzfivqihw9V+9qXYlmMgVZEpp
 xlvM9Fsyxbk1wHamkEK5MLRdGebaqmEUcqLU1lL9L12HjGgNEMsR6GxqLHTDaJOggtv2Q0
 1+93FYKUrytJPWmJCDLB4QW00TuNNuqMcKkl2ovpULyGrKJMqbUjkDfc4y5cf/a2JJNWk6
 9JA8mh6BV+d4OP8RnSFfo2MPnxQSaER736T0M8rP60PO8JEXSC1FRGFgT4XOLA==
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
From: Jeremy Bryant <jb@HIDDEN>
To: Philip Kaludercic <philipk@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
Date: Wed, 07 Feb 2024 21:48:00 +0000
In-reply-to: <87mssc65y8.fsf@HIDDEN>
Message-ID: <87y1bwrll4.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Migadu-Flow: FLOW_OUT
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 68929
Cc: 68929 <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)


Philip Kaludercic <philipk@HIDDEN> writes:

> My genera feeling is that the code is reinventing the wheel at a number
> of places, which might make it more complicated to maintain in the long
> term.  Looking for ways to slim down the codebase, perhaps by
> deprecating some options, dropping support for third-party packages and
> reusing existing functionality seems like something one should look into.

Should these improvements be made before moving which-key to core?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 7 Feb 2024 08:21:11 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 07 03:21:11 2024
Received: from localhost ([127.0.0.1]:55659 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rXdB9-0000NK-97
	for submit <at> debbugs.gnu.org; Wed, 07 Feb 2024 03:21:11 -0500
Received: from mout02.posteo.de ([185.67.36.66]:36863)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <philipk@HIDDEN>) id 1rXdB6-0000Ma-VW
 for 68929 <at> debbugs.gnu.org; Wed, 07 Feb 2024 03:21:09 -0500
Received: from submission (posteo.de [185.67.36.169]) 
 by mout02.posteo.de (Postfix) with ESMTPS id 50725240104
 for <68929 <at> debbugs.gnu.org>; Wed,  7 Feb 2024 09:20:49 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1707294049; bh=zylwJfdZPlx2pdq7gF89K1kAAD9qfAMMHZONeFrHDBI=;
 h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version:
 Content-Type:Content-Transfer-Encoding:From;
 b=jMVjyoWOftKkBXsiTJThVOtT9nmCHzOcgdoHZjZYHBBXPvhh+kF67zIeoWI6QbjXN
 +2Hgk7h0BoLDmM2OBE6G7EoLpgO0P5NzNoNxD9oosH/1Qvbn9sV0axZKVm72OVpZwz
 7clQnfVSfZz976ho9WYqcCXfy6E0v+gtb9qGeBQa2G0PtP4xOJi3C8tyR0eCovIq9Y
 Hkbe2xGe4cCuluR6Ck/oElz6v6AFhH4Ks7iGP9dk4h6LS5jxmLotGenxhWr6rlWbEr
 3a94/Bf2TGuePwbD9Zy3p1KR41+K+qTcYdt31y+f/Qcj18CUEUKpUMssHSyracpK7w
 zuKdBzOSbJmdg==
Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4TVCjq6njDz6tw3;
 Wed,  7 Feb 2024 09:20:47 +0100 (CET)
From: Philip Kaludercic <philipk@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
In-Reply-To: <871q9rvqbi.fsf@HIDDEN> (Jeremy Bryant's message of
 "Sun, 04 Feb 2024 22:02:50 +0000")
References: <871q9rvqbi.fsf@HIDDEN>
Autocrypt: addr=philipk@HIDDEN; keydata=
 mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo
 aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0
 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI
 BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0
 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB
 BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE
 Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK
 NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof
 z4oM
OpenPGP: id=7126E1DE2F0CE35C770BED01F2C3CC513DB89F66;
 url="https://keys.openpgp.org/vks/v1/by-fingerprint/7126E1DE2F0CE35C770BED01F2C3CC513DB89F66";
 preference=signencrypt
Date: Wed, 07 Feb 2024 08:20:47 +0000
Message-ID: <87mssc65y8.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Debbugs-Envelope-To: 68929
Cc: 68929 <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>

Jeremy Bryant <jb@HIDDEN> writes:

> Tags: patch
>
> This patch brings the latest version of which-key from GNU ELPA into
> Emacs core
>
> If suitable I will then work on the updates to user-facing aspects such as
> manual and NEWS.
>
>>From 1a3207344a18b6743772927b6f8f709b05246a51 Mon Sep 17 00:00:00 2001
> From: Jeremy Bryant <jb@HIDDEN>
> Date: Sun, 4 Feb 2024 21:56:16 +0000
> Subject: [PATCH] * lisp/which-key.el:  Display available keybindings in p=
opup
>
> Copy feature which-key from GNU ELPA
> ---
>  lisp/which-key.el | 2753 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 2753 insertions(+)
>  create mode 100644 lisp/which-key.el
>
> diff --git a/lisp/which-key.el b/lisp/which-key.el
> new file mode 100644
> index 00000000000..d68942cf8b1
> --- /dev/null
> +++ b/lisp/which-key.el
> @@ -0,0 +1,2753 @@
> +;;; which-key.el --- Display available keybindings in popup  -*- lexical=
-binding: t; -*-
> +
> +;; Copyright (C) 2017-2021  Free Software Foundation, Inc.
> +
> +;; Author: Justin Burkett <justin@HIDDEN>
> +;; Maintainer: Justin Burkett <justin@HIDDEN>
> +;; URL: https://github.com/justbur/emacs-which-key

IIUC the plan is to maintain the package in emacs.git, right?  Shouldn't
this line then be removed?

> +;; Version: 3.6.0
> +;; Keywords:
> +;; Package-Requires: ((emacs "24.4"))
> +
> +;; This program is free software; you can redistribute it and/or modify
> +;; it under the terms of the GNU General Public License as published by
> +;; the Free Software Foundation, either version 3 of the License, or
> +;; (at your option) any later version.
> +
> +;; This program is distributed in the hope that it will be useful,
> +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
> +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +;; GNU General Public License for more details.
> +
> +;; You should have received a copy of the GNU General Public License
> +;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +;;; Commentary:
> +
> +;; which-key provides the minor mode which-key-mode for Emacs. The mode =
displays
> +;; the key bindings following your currently entered incomplete command =
(a
> +;; prefix) in a popup. For example, after enabling the minor mode if you=
 enter
> +;; C-x and wait for the default of 1 second the minibuffer will expand w=
ith all
> +;; of the available key bindings that follow C-x (or as many as space al=
lows
> +;; given your settings). This includes prefixes like C-x 8 which are sho=
wn in a
> +;; different face. Screenshots of what the popup will look like along wi=
th
> +;; information about additional features can be found at
> +;; https://github.com/justbur/emacs-which-key.
> +;;
> +
> +;;; Code:
> +
> +(require 'cl-lib)
> +(require 'button)
> +(require 'regexp-opt)
> +
> +;; For compiler
> +(defvar evil-operator-shortcut-map)
> +(defvar evil-operator-state-map)
> +(defvar evil-motion-state-map)
> +(defvar golden-ratio-mode)
> +(declare-function evil-get-command-property "ext:evil-common.el")
> +
> +;;; Options
> +
> +(defgroup which-key nil
> +  "Customization options for which-key-mode"
> +  :group 'help
> +  :prefix "which-key-")
> +
> +(defcustom which-key-idle-delay 1.0
> +  "Delay (in seconds) for which-key buffer to popup.
> +This variable should be set before activating `which-key-mode'.
> +
> +A value of zero might lead to issues, so a non-zero value is
> +recommended
> +(see https://github.com/justbur/emacs-which-key/issues/134)."
> +  :group 'which-key

By default :group falls back to the last defgroup, so you don't need to
specify them every time.

> +  :type 'float)
> +
> +(defcustom which-key-idle-secondary-delay nil
> +  "Once the which-key buffer shows once for a key sequence reduce
> +the idle time to this amount (in seconds). This makes it possible
> +to shorten the delay for subsequent popups in the same key
> +sequence. The default is for this value to be nil, which disables
> +this behavior."
> +  :group 'which-key
> +  :type '(choice float (const :tag "Disabled" nil)))
> +
> +(defcustom which-key-echo-keystrokes (if (and echo-keystrokes
> +                                              (> (+ echo-keystrokes 0.01)
> +                                                 which-key-idle-delay))
> +                                         (/ (float which-key-idle-delay)=
 4)
> +                                       echo-keystrokes)
> +  "Value to use for `echo-keystrokes'.
> +This only applies if `which-key-popup-type' is minibuffer or
> +`which-key-show-prefix' is echo. It needs to be less than
> +`which-key-idle-delay' or else the keystroke echo will erase the
> +which-key popup."
> +  :group 'which-key
> +  :type 'float)
> +
> +(defcustom which-key-max-description-length 27
> +  "Truncate the description of keys to this length.
> +Either nil (no truncation), an integer (truncate after that many
> +characters), a float (use that fraction of the available width),
> +or a function, which takes one argument, the available width in
> +characters, and whose return value has one of the types mentioned
> +before.  Truncation is done using `which-key-ellipsis'."
> +  :group 'which-key
> +  :type '(choice (const :tag "Disable truncation" nil)
> +		 (integer :tag "Width in characters")
> +		 (float :tag "Use fraction of available width")
> +		 function))
> +
> +(defcustom which-key-min-column-description-width 0
> +  "Every column should at least have this width."
> +  :group 'which-key
> +  :type 'integer)

Perhasps natnum would be a more specific type here.

> +
> +(defcustom which-key-add-column-padding 0
> +  "Additional padding (number of spaces) to add to the left of
> +each key column."
> +  :group 'which-key
> +  :type 'integer)
> +
> +(defcustom which-key-unicode-correction 3
> +  "Correction for wide unicode characters.
> +Since we measure width in terms of the number of characters,
> +Unicode characters that are wider than ASCII characters throw off
> +the calculation for available width in the which-key buffer.  This
> +variable allows you to adjust for the wide unicode characters by
> +artificially reducing the available width in the buffer.
> +
> +The default of 3 means allow for the total extra width
> +contributed by any wide unicode characters to be up to one
> +additional ASCII character in the which-key buffer.  Increase this
> +number if you are seeing characters get cutoff on the right side
> +of the which-key popup."
> +  :group 'which-key
> +  :type 'integer)
> +
> +(defcustom which-key-dont-use-unicode nil

Could we set this to t?  That would seem to be more consistent with the
regular appearance of Emacs OOTB.

> +  "If non-nil, don't use any unicode characters in default setup."
> +  :group 'which-key
> +  :type 'boolean)
> +
> +(defcustom which-key-separator
> +  (if which-key-dont-use-unicode " : " " =E2=86=92 ")
> +  "Separator to use between key and description. Default is \" =E2=86=92
> +\", unless `which-key-dont-use-unicode' is non nil, in which case
> +the default is \" : \"."
> +  :group 'which-key
> +  :type 'string)
> +
> +(defcustom which-key-ellipsis
> +  (if which-key-dont-use-unicode ".." "=E2=80=A6")
> +  "Ellipsis to use when truncating.
> +Default is \"=E2=80=A6\", unless `which-key-dont-use-unicode' is non nil,
> +in which case the default is \"..\".  This can also be the empty
> +string to truncate without using any ellipsis."
> +  :group 'which-key
> +  :type 'string)
> +
> +(defcustom which-key-prefix-prefix "+"
> +  "String to insert in front of prefix commands (i.e., commands
> +that represent a sub-map). Default is \"+\"."
> +  :group 'which-key
> +  :type 'string)
> +
> +(defcustom which-key-compute-remaps nil
> +  "If non-nil, show remapped command if a command has been
> +remapped given the currently active keymaps."
> +  :group 'which-key
> +  :type 'boolean)
> +
> +(defcustom which-key-replacement-alist
> +  (delq nil
> +        `(((nil . "which-key-show-next-page-no-cycle") . (nil . "wk next=
 pg"))
> +          ,@(unless which-key-dont-use-unicode
> +              '((("<left>") . ("=E2=86=90"))
> +                (("<right>") . ("=E2=86=92"))))
> +          (("<\\([[:alnum:]-]+\\)>") . ("\\1"))))
> +  "Association list to determine how to manipulate descriptions
> +of key bindings in the which-key popup. Each element of the list
> +is a nested cons cell with the format
> +
> +\(MATCH CONS . REPLACEMENT\).
> +
> +The MATCH CONS determines when a replacement should occur and
> +REPLACEMENT determines how the replacement should occur. Each may
> +have the format \(KEY REGEXP . BINDING REGEXP\). For the
> +replacement to apply the key binding must match both the KEY
> +REGEXP and the BINDING REGEXP. A value of nil in either position
> +can be used to match every possibility. The replacement is
> +performed by using `replace-regexp-in-string' on the KEY REGEXP
> +from the MATCH CONS and REPLACEMENT when it is a cons cell, and
> +then similarly for the BINDING REGEXP. A nil value in the BINDING
> +REGEXP position cancels the replacement. For example, the entry
> +
> +\(\(nil . \"Prefix Command\"\) . \(nil . \"prefix\"\)\)
> +
> +matches any binding with the descriptions \"Prefix Command\" and
> +replaces the description with \"prefix\", ignoring the
> +corresponding key.
> +
> +REPLACEMENT may also be a function taking a cons cell
> +\(KEY . BINDING\) and producing a new corresponding cons cell.
> +
> +If REPLACEMENT is anything other than a cons cell \(and non nil\)
> +the key binding is ignored by which-key.
> +
> +Finally, you can multiple replacements to occur for a given key
> +binding by setting `which-key-allow-multiple-replacements' to a
> +non-nil value."
> +  :group 'which-key
> +  :type '(alist :key-type (cons (choice regexp (const nil))
> +                                (choice regexp (const nil)))
> +                :value-type (cons (choice string (const nil))
> +                                  (choice string (const nil)))))
> +
> +(defcustom which-key-allow-multiple-replacements nil
> +  "Allow a key binding to match and be modified by multiple
> +elements in `which-key-replacement-alist' if non-nil. When nil,
> +only the first match is used to perform replacements from
> +`which-key-replacement-alist'."
> +  :group 'which-key
> +  :type 'boolean)
> +
> +(defcustom which-key-show-docstrings nil
> +  "If non-nil, show each command's docstring next to the command
> +in the which-key buffer. This will only display the docstring up
> +to the first line break. If you set this variable to the symbol
> +docstring-only, then the command's name with be omitted. You
> +probably also want to adjust `which-key-max-description-length'
> +at the same time if you use this feature."
> +  :group 'which-key
> +  :type '(radio
> +          (const :tag "Do not show docstrings" nil)
> +          (const :tag "Add docstring to command names" t)
> +          (const :tag "Replace command name with docstring" docstring-on=
ly)))
> +
> +(defcustom which-key-highlighted-command-list '()
> +  "A list of strings and/or cons cells used to highlight certain
> +commands. If the element is a string, assume it is a regexp
> +pattern for matching command names and use
> +`which-key-highlighted-command-face' for any matching names. If
> +the element is a cons cell, it should take the form (regexp .
> +face to apply)."
> +  :group 'which-key
> +  :type  '(repeat (choice string (cons regexp face))))
> +
> +(defcustom which-key-special-keys '()
> +  "These keys will automatically be truncated to one character
> +and have `which-key-special-key-face' applied to them. This is
> +disabled by default. Try this to see the effect.
> +
> +\(setq which-key-special-keys \\=3D'(\"SPC\" \"TAB\" \"RET\" \"ESC\" \"D=
EL\")\)"
> +  :group 'which-key
> +  :type '(repeat string))

Perhaps '(repeat key) here?

> +
> +(defcustom which-key-buffer-name " *which-key*"
> +  "Name of which-key buffer."
> +  :group 'which-key
> +  :type 'string)
> +
> +(defcustom which-key-show-prefix 'echo
> +  "Whether to and where to display the current prefix sequence
> +Possible choices are echo for echo area (the default), left, top
> +and nil. Nil turns the feature off."
> +  :group 'which-key
> +  :type '(radio (const :tag "Left of the keys" left)
> +                (const :tag "In the first line" top)
> +                (const :tag "In the last line" bottom)
> +                (const :tag "In the echo area" echo)
> +                (const :tag "In the mode-line" mode-line)
> +                (const :tag "Hide" nil)))
> +
> +(defcustom which-key-popup-type 'side-window
> +  "Supported types are minibuffer, side-window, frame, and custom"
> +  :group 'which-key
> +  :type '(radio (const :tag "Show in minibuffer" minibuffer)
> +                (const :tag "Show in side window" side-window)
> +                (const :tag "Show in popup frame" frame)
> +                (const :tag "Use your custom display functions" custom)))
> +
> +(defcustom which-key-min-display-lines 1
> +  "Minimum number of horizontal lines to display in the which-key buffer"
> +  :group 'which-key
> +  :type 'integer)
> +
> +(defcustom which-key-max-display-columns nil
> +  "Maximum number of columns to display in the which-key buffer
> +nil means don't impose a maximum."
> +  :group 'which-key
> +  :type '(choice integer (const :tag "Unbounded" nil)))
> +
> +(defcustom which-key-side-window-location 'bottom
> +  "Location of which-key popup when `which-key-popup-type' is side-windo=
w.
> +Should be one of top, bottom, left or right. You can also specify
> +a list of two locations, like (right bottom). In this case, the
> +first location is tried. If there is not enough room, the second
> +location is tried."
> +  :group 'which-key
> +  :type '(radio (const right)
> +                (const bottom)
> +                (const left)
> +                (const top)
> +                (const (right bottom))
> +                (const (bottom right))))
> +
> +(defcustom which-key-side-window-slot 0
> +  "The `slot' to use for `display-buffer-in-side-window' when
> +`which-key-popup-type' is `side-window'.  Quoting from the
> +docstring of `display-buffer-in-side-window',
> +
> +`slot' if non-nil, specifies the window slot where to display
> +BUFFER.  A value of zero or nil means use the middle slot on the
> +specified side.  A negative value means use a slot
> +preceding (that is, above or on the left of) the middle slot.  A
> +positive value means use a slot following (that is, below or on
> +the right of) the middle slot.  The default is zero."
> +  :group 'which-key
> +  :type 'integer)
> +
> +(defcustom which-key-side-window-max-width 0.333
> +  "Maximum width of which-key popup when type is side-window
> +This variable can also be a number between 0 and 1. In that case,
> +it denotes a percentage out of the frame's width."
> +  :group 'which-key
> +  :type 'float)
> +
> +(defcustom which-key-side-window-max-height 0.25
> +  "Maximum height of which-key popup when type is side-window
> +This variable can also be a number between 0 and 1. In that case, it den=
otes
> +a percentage out of the frame's height."
> +  :group 'which-key
> +  :type 'float)
> +
> +(defcustom which-key-frame-max-width 60
> +  "Maximum width of which-key popup when type is frame."
> +  :group 'which-key
> +  :type 'integer)
> +
> +(defcustom which-key-frame-max-height 20
> +  "Maximum height of which-key popup when type is frame."
> +  :group 'which-key
> +  :type 'integer)
> +
> +(defcustom which-key-allow-imprecise-window-fit (not (display-graphic-p))
> +  "If non-nil allow which-key to use a less intensive method of
> +fitting the popup window to the buffer. If you are noticing lag
> +when the which-key popup displays turning this on may help.
> +
> +See https://github.com/justbur/emacs-which-key/issues/130
> +and https://github.com/justbur/emacs-which-key/issues/225."
> +  :group 'which-key
> +  :type 'boolean)
> +
> +(defcustom which-key-show-remaining-keys nil
> +  "Show remaining keys in last slot, when keys are hidden."
> +  :group 'which-key
> +  :type '(radio (const :tag "Yes" t)
> +                (const :tag "No" nil)))
> +
> +(defcustom which-key-sort-order 'which-key-key-order
> +  "If nil, do not resort the output from
> +`describe-buffer-bindings' which groups by mode. Ordering options
> +are
> +
> +1. `which-key-key-order': by key (default)
> +2. `which-key-key-order-alpha': by key using alphabetical order
> +3. `which-key-description-order': by description
> +4. `which-key-prefix-then-key-order': prefix (no prefix first) then key
> +5. `which-key-local-then-key-order': local binding then key
> +
> +See the README and the docstrings for those functions for more
> +information."
> +  :group 'which-key
> +  :type '(choice (function-item which-key-key-order)
> +                 (function-item which-key-key-order-alpha)
> +                 (function-item which-key-description-order)
> +                 (function-item which-key-prefix-then-key-order)
> +                 (function-item which-key-local-then-key-order)))
> +
> +(defcustom which-key-sort-uppercase-first t
> +  "If non-nil, uppercase comes before lowercase in sorting
> +function chosen in `which-key-sort-order'. Otherwise, the order
> +is reversed."
> +  :group 'which-key
> +  :type 'boolean)
> +
> +(defcustom which-key-paging-prefixes '()
> +  "Enable paging for these prefixes."
> +  :group 'which-key
> +  :type '(repeat string))
> +
> +(defcustom which-key-paging-key "<f5>"
> +  "Key to use for changing pages. Bound after each of the
> +prefixes in `which-key-paging-prefixes'"
> +  :group 'which-key
> +  :type 'string)

Can you set this to key and replace the default value with (kbd "<f5>")?

Also, do we really want to use f5 for this?  Also, also why is this
configured in a user option, not part of a map?

> +
> +;; (defcustom which-key-undo-key nil
> +;;   "Key (string) to use for undoing keypresses. Bound recursively
> +;; in each of the maps in `which-key-undo-keymaps'."
> +;;   :group 'which-key
> +;;   :type 'string)
> +
> +;; (defcustom which-key-undo-keymaps '()
> +;;   "Keymaps in which to bind `which-key-undo-key'"
> +;;   :group 'which-key
> +;;   :type '(repeat symbol))

Comments are not for code, please remove these.

> +(defcustom which-key-use-C-h-commands t
> +  "Use C-h (or whatever `help-char' is set to) for paging if
> +non-nil. Normally C-h after a prefix calls

Rephrase this to avoid the line break.  I think that checkdoc should
warn you about issues like these.

> +`describe-prefix-bindings'. This changes that command to a
> +which-key paging command when which-key-mode is active."
> +  :group 'which-key
> +  :type 'boolean)
> +
> +(defcustom which-key-show-early-on-C-h nil
> +  "Show the which-key buffer before if C-h (or whatever
> +`help-char' is set to) is pressed in the middle of a prefix
> +before the which-key buffer would normally be triggered through
> +the idle delay. If combined with the following settings,
> +which-key will effectively only show when triggered \"manually\"
> +using C-h.
> +
> +\(setq `which-key-idle-delay' 10000)
> +\(setq `which-key-idle-secondary-delay' 0.05)
> +
> +Note that `which-key-idle-delay' should be set before turning on
> +`which-key-mode'. "
> +  :group 'which-key
> +  :type 'boolean)
> +
> +(defcustom which-key-is-verbose nil
> +  "Whether to warn about potential mistakes in configuration."
> +  :group 'which-key
> +  :type 'boolean)
> +
> +(defcustom which-key-preserve-window-configuration nil
> +  "If non-nil, save window configuration before which-key buffer is shown
> +and restore it after which-key buffer is hidden. It prevents which-key f=
rom
> +changing window position of visible buffers.
> +Only takken into account when popup type is side-window."
> +  :group
> +  'which-key
> +  :type 'boolean)
> +
> +(defvar which-key-C-h-map-prompt
> +  (concat " \\<which-key-C-h-map>"
> +          " \\[which-key-show-next-page-cycle]"
> +          which-key-separator "next-page,"
> +          " \\[which-key-show-previous-page-cycle]"
> +          which-key-separator "previous-page,"
> +          " \\[which-key-undo-key]"
> +          which-key-separator "undo-key,"
> +          " \\[which-key-toggle-docstrings]"
> +          which-key-separator "toggle-docstrings,"
> +          " \\[which-key-show-standard-help]"
> +          which-key-separator "help,"
> +          " \\[which-key-abort]"
> +          which-key-separator "abort"
> +          " 1..9"
> +          which-key-separator "digit-arg")
> +  "Prompt to display when invoking `which-key-C-h-map'. This string
> +is fed into `substitute-command-keys'")
> +
> +(defvar which-key-C-h-map
> +  (let ((map (make-sparse-keymap)))
> +    (dolist (bind `(("\C-a" . which-key-abort)

You should be able to use defvar-keymap here.  That might be closer to
what you are looking for with the dolist here.

> +                    ("a" . which-key-abort)
> +                    ("\C-d" . which-key-toggle-docstrings)
> +                    ("d" . which-key-toggle-docstrings)
> +                    (,(vector help-char) . which-key-show-standard-help)
> +                    ("h" . which-key-show-standard-help)
> +                    ("\C-n" . which-key-show-next-page-cycle)
> +                    ("n" . which-key-show-next-page-cycle)
> +                    ("\C-p" . which-key-show-previous-page-cycle)
> +                    ("p" . which-key-show-previous-page-cycle)
> +                    ("\C-u" . which-key-undo-key)
> +                    ("u" . which-key-undo-key)
> +                    ("1" . which-key-digit-argument)
> +                    ("2" . which-key-digit-argument)
> +                    ("3" . which-key-digit-argument)
> +                    ("4" . which-key-digit-argument)
> +                    ("5" . which-key-digit-argument)
> +                    ("6" . which-key-digit-argument)
> +                    ("7" . which-key-digit-argument)
> +                    ("8" . which-key-digit-argument)
> +                    ("9" . which-key-digit-argument)))
> +      (define-key map (car bind) (cdr bind)))
> +    map)
> +  "Keymap for C-h commands.")
> +
> +(defvar which-key--paging-functions '(which-key-C-h-dispatch

In your place, I'd not use a quoted list here but (list ...) where each
element is sharp-quoted so that the byte-compiler can check if the
functions exist.

> +                                      which-key-manual-update
> +                                      which-key-turn-page
> +                                      which-key-show-next-page-cycle
> +                                      which-key-show-next-page-no-cycle
> +                                      which-key-show-previous-page-cycle
> +                                      which-key-show-previous-page-no-cy=
cle
> +                                      which-key-undo-key
> +                                      which-key-undo))
> +
> +(defvar which-key-persistent-popup nil
> +  "Whether or not to disable `which-key--hide-popup'.")
> +
> +(defcustom which-key-hide-alt-key-translations t
> +  "Hide key translations using Alt key if non nil.
> +These translations are not relevant most of the times since a lot
> +of terminals issue META modifier for the Alt key.
> +
> +See http://www.gnu.org/software/emacs/manual/html_node/emacs/Modifier-Ke=
ys.html"
> +  :group 'which-key
> +  :type 'boolean)
> +
> +(defcustom which-key-delay-functions nil
> +  "A list of functions that may decide whether to delay the
> +which-key popup based on the current incomplete key
> +sequence. Each function in the list is run with two arguments,
> +the current key sequence as produced by `key-description' and the
> +length of the key sequence. If the popup should be delayed based
> +on that key sequence, the function should return the delay time
> +in seconds. Returning nil means no delay. The first function in
> +this list to return a value is the value that is used.
> +
> +The delay time is effectively added to the normal
> +`which-key-idle-delay'."
> +  :group 'which-key
> +  :type '(repeat function))
> +
> +(defcustom which-key-allow-regexps nil
> +  "A list of regexp strings to use to filter key sequences.
> +When non-nil, for a key sequence to trigger the which-key popup
> +it must match one of the regexps in this list. The format of the
> +key sequences is what is produced by `key-description'."
> +  :group 'which-key
> +  :type '(repeat regexp))
> +
> +(defcustom which-key-inhibit-regexps nil
> +  "Similar to `which-key-allow-regexps', a list of regexp strings
> +to use to filter key sequences. When non-nil, for a key sequence
> +to trigger the which-key popup it cannot match one of the regexps
> +in this list. The format of the key sequences is what is produced
> +by `key-description'."
> +  :group 'which-key
> +  :type '(repeat regexp))
> +
> +(defcustom which-key-show-transient-maps nil
> +  "Show keymaps created by `set-transient-map' when applicable.
> +
> +More specifically, detect when `overriding-terminal-local-map' is
> +set (this is the keymap used by `set-transient-map') and display
> +it."
> +  :group 'which-key
> +  :type 'boolean)
> +
> +(make-obsolete-variable
> + 'which-key-enable-extended-define-key
> + "which-key-enable-extended-define-key is obsolete and has no effect."
> + "2021-06-21")
> +
> +;; Hooks
> +(defcustom which-key-init-buffer-hook '()
> +  "Hook run when which-key buffer is initialized."
> +  :group 'which-key
> +  :type 'hook)
> +
> +;;;; Faces
> +
> +(defgroup which-key-faces nil
> +  "Faces for which-key-mode"
> +  :group 'which-key
> +  :prefix "which-key-")
> +
> +(defface which-key-key-face
> +  '((t . (:inherit font-lock-constant-face)))

Shouldn't this inherit from `help-key-binding'?

> +  "Face for which-key keys"
> +  :group 'which-key-faces)
> +
> +(defface which-key-separator-face
> +  '((t . (:inherit font-lock-comment-face)))

Why comment face?  What is the semantic intention here?  I guess the
same question applies below as well, these mappings seem arbitrary.

> +  "Face for the separator (default separator is an arrow)"
> +  :group 'which-key-faces)
> +
> +(defface which-key-note-face
> +  '((t . (:inherit which-key-separator-face)))
> +  "Face for notes or hints occasionally provided"
> +  :group 'which-key-faces)
> +
> +(defface which-key-command-description-face
> +  '((t . (:inherit font-lock-function-name-face)))
> +  "Face for the key description when it is a command"
> +  :group 'which-key-faces)
> +
> +(defface which-key-local-map-description-face
> +  '((t . (:inherit which-key-command-description-face)))
> +  "Face for the key description when it is found in `current-local-map'"
> +  :group 'which-key-faces)
> +
> +(defface which-key-highlighted-command-face
> +  '((t . (:inherit which-key-command-description-face :underline t)))
> +  "Default face for the command description when it is a command
> +and it matches a string in `which-key-highlighted-command-list'."
> +  :group 'which-key-faces)
> +
> +(defface which-key-group-description-face
> +  '((t . (:inherit font-lock-keyword-face)))
> +  "Face for the key description when it is a group or prefix"
> +  :group 'which-key-faces)
> +
> +(defface which-key-special-key-face
> +  '((t . (:inherit which-key-key-face :inverse-video t :weight bold)))
> +  "Face for special keys (SPC, TAB, RET)"
> +  :group 'which-key-faces)
> +
> +(defface which-key-docstring-face
> +  '((t . (:inherit which-key-note-face)))
> +  "Face for docstrings"
> +  :group 'which-key-faces)
> +
> +;;;; Custom popup
> +
> +(defcustom which-key-custom-popup-max-dimensions-function nil
> +  "Variable to hold a custom max-dimensions function.
> +Will be passed the width of the active window and is expected to
> +return the maximum height in lines and width in characters of the
> +which-key popup in the form a cons cell (height . width)."
> +  :group 'which-key
> +  :type '(choice function (const nil)))
> +
> +(defcustom which-key-custom-hide-popup-function nil
> +  "Variable to hold a custom hide-popup function.
> +It takes no arguments and the return value is ignored."
> +  :group 'which-key
> +  :type '(choice function (const nil)))
> +
> +(defcustom which-key-custom-show-popup-function nil
> +  "Variable to hold a custom show-popup function.
> +Will be passed the required dimensions in the form (height .
> +width) in lines and characters respectively.  The return value is
> +ignored."
> +  :group 'which-key
> +  :type '(choice function (const nil)))
> +
> +(defcustom which-key-lighter " WK"
> +  "Minor mode lighter to use in the mode-line."
> +  :group 'which-key
> +  :type 'string)
> +
> +(defvar which-key-inhibit nil
> +  "Prevent which-key from popping up momentarily by setting this
> +to a non-nil value for the execution of a command. Like this
> +
> +\(let \(\(which-key-inhibit t\)\)
> +...\)")
> +
> +(defvar which-key-keymap-history nil
> +  "History of keymap selections in functions like
> +`which-key-show-keymap'.")
> +
> +;;; Internal Vars
> +
> +(defvar which-key--buffer nil
> +  "Internal: Holds reference to which-key buffer.")
> +(defvar which-key--timer nil
> +  "Internal: Holds reference to open window timer.")
> +(defvar which-key--secondary-timer-active nil
> +  "Internal: Non-nil if the secondary timer is active.")
> +(defvar which-key--paging-timer nil
> +  "Internal: Holds reference to timer for paging.")
> +(defvar which-key--frame nil
> +  "Internal: Holds reference to which-key frame.
> +Used when `which-key-popup-type' is frame.")
> +(defvar which-key--echo-keystrokes-backup nil
> +  "Internal: Backup the initial value of `echo-keystrokes'.")
> +(defvar which-key--prefix-help-cmd-backup nil
> +  "Internal: Backup the value of `prefix-help-command'.")
> +(defvar which-key--last-try-2-loc nil
> +  "Internal: Last location of side-window when two locations
> +used.")
> +(defvar which-key--automatic-display nil
> +  "Internal: Non-nil if popup was triggered with automatic
> +update.")
> +(defvar which-key--debug-buffer-name nil
> +  "If non-nil, use this buffer for debug messages.")
> +(defvar which-key--multiple-locations nil)
> +(defvar which-key--inhibit-next-operator-popup nil)
> +(defvar which-key--prior-show-keymap-args nil)
> +(defvar which-key--previous-frame-size nil)
> +(defvar which-key--prefix-title-alist nil)
> +(defvar which-key--evil-keys-regexp (eval-when-compile
> +                                      (regexp-opt '("-state"))))
> +(defvar which-key--ignore-non-evil-keys-regexp
> +  (eval-when-compile
> +    (regexp-opt '("mouse-" "wheel-" "remap" "drag-" "scroll-bar"
> +                  "select-window" "switch-frame" "which-key"))))
> +(defvar which-key--ignore-keys-regexp
> +  (eval-when-compile
> +    (regexp-opt '("mouse-" "wheel-" "remap" "drag-" "scroll-bar"
> +                  "select-window" "switch-frame" "-state"
> +                  "which-key"))))

regexp-opt is marked as pure, you don't need the eval-when-compile here.

> +
> +(defvar which-key--pages-obj nil)
> +(cl-defstruct which-key--pages
> +  pages
> +  height
> +  widths
> +  keys/page
> +  page-nums
> +  num-pages
> +  total-keys
> +  prefix
> +  prefix-title)
> +
> +(defvar which-key--saved-window-configuration nil)
> +
> +(defun which-key--rotate (list n)
> +  (let* ((len (length list))
> +         (n (if (< n 0) (+ len n) n))
> +         (n (mod n len)))
> +    (append (last list (- len n)) (butlast list (- len n)))))
> +
> +(defun which-key--pages-set-current-page (pages-obj n)
> +  (setf (which-key--pages-pages pages-obj)
> +        (which-key--rotate (which-key--pages-pages pages-obj) n))
> +  (setf (which-key--pages-widths pages-obj)
> +        (which-key--rotate (which-key--pages-widths pages-obj) n))
> +  (setf (which-key--pages-keys/page pages-obj)
> +        (which-key--rotate (which-key--pages-keys/page pages-obj) n))
> +  (setf (which-key--pages-page-nums pages-obj)
> +        (which-key--rotate (which-key--pages-page-nums pages-obj) n))
> +  pages-obj)
> +
> +(defsubst which-key--on-first-page ()
> +  (=3D (which-key--pages-page-nums which-key--pages-obj) 1))
> +
> +(defsubst which-key--on-last-page ()
> +  (=3D (which-key--pages-page-nums which-key--pages-obj)
> +     (which-key--pages-num-pages which-key--pages-obj)))
> +
> +(defsubst which-key--current-prefix ()
> +  (and which-key--pages-obj
> +       (which-key--pages-prefix which-key--pages-obj)))
> +
> +(defmacro which-key--debug-message (&rest msg)
> +  `(when which-key--debug-buffer-name
> +     (let ((buf (get-buffer-create which-key--debug-buffer-name))
> +           (fmt-msg (format ,@msg)))
> +       (with-current-buffer buf
> +         (goto-char (point-max))
> +         (insert "\n" fmt-msg "\n")))))
> +
> +(defsubst which-key--safe-lookup-key (keymap key)
> +  "Version of `lookup-key' that allows KEYMAP to be nil.
> +Also convert numeric results of `lookup-key' to nil. KEY is not
> +checked."
> +  (when (keymapp keymap)
> +    (let ((result (lookup-key keymap key)))
> +      (when (and result (not (numberp result)))
> +        result))))
> +
> +(defsubst which-key--safe-lookup-key-description (keymap key)
> +  "Version of `lookup-key' that allows KEYMAP to be nil.
> +Also convert numeric results of `lookup-key' to nil. KEY
> +should be formatted as an input for `kbd'."
> +  (let ((key (ignore-errors (kbd key))))

???

> +    (when (and key (keymapp keymap))
> +      (let ((result (lookup-key keymap key)))
> +        (when (and result (not (numberp result)))
> +          result)))))
> +
> +;;; Third-party library support

Should this be kept?  Or can the other libraries take over this code?

> +;;;; Evil
> +
> +(defvar evil-state nil)
> +
> +(defcustom which-key-allow-evil-operators (boundp 'evil-this-operator)
> +  "Allow popup to show for evil operators.
> +The popup is normally inhibited in the middle of commands, but
> +setting this to non-nil will override this behavior for evil
> +operators."
> +  :group 'which-key
> +  :type 'boolean)
> +
> +(defcustom which-key-show-operator-state-maps nil
> +  "Experimental: Try to show the right keys following an evil
> +command that reads a motion, such as \"y\", \"d\" and \"c\" from
> +normal state. This is experimental, because there might be some
> +valid keys missing and it might be showing some invalid keys."
> +  :group 'which-key
> +  :type 'boolean)
> +
> +;;;; God-mode
> +
> +(defvar which-key--god-mode-support-enabled nil
> +  "Support god-mode if non-nil. This is experimental,
> +so you need to explicitly opt-in for now. Please report any
> +problems at github.")
> +
> +(defvar which-key--god-mode-key-string nil
> +  "Holds key string to use for god-mode support.")
> +
> +(defun which-key--god-mode-lookup-command-advice (orig-fun arg1 &rest ar=
gs)
> +  (setq which-key--god-mode-key-string arg1)
> +  (unwind-protect
> +      (apply orig-fun arg1 args)
> +    (when (bound-and-true-p which-key-mode)
> +      (which-key--hide-popup))))
> +
> +(defun which-key-enable-god-mode-support (&optional disable)
> +  "Enable support for god-mode if non-nil.
> +This is experimental, so you need to explicitly opt-in for
> +now. Please report any problems at github. If DISABLE is non-nil
> +disable support."
> +  (interactive "P")
> +  (setq which-key--god-mode-support-enabled (null disable))
> +  (if disable
> +      (advice-remove 'god-mode-lookup-command
> +                     #'which-key--god-mode-lookup-command-advice)
> +    (advice-add 'god-mode-lookup-command :around
> +                #'which-key--god-mode-lookup-command-advice)))
> +
> +;;; Mode
> +
> +;;;###autoload
> +(define-minor-mode which-key-mode
> +  "Toggle which-key-mode."
> +  :global t
> +  :group 'which-key
> +  :lighter which-key-lighter
> +  :keymap (let ((map (make-sparse-keymap)))
> +            (mapc
> +             (lambda (prefix)
> +               (define-key map
> +                 (kbd (concat prefix " " which-key-paging-key))
> +                 #'which-key-C-h-dispatch))
> +             which-key-paging-prefixes)
> +            map)
> +  (if which-key-mode
> +      (progn
> +        (setq which-key--echo-keystrokes-backup echo-keystrokes)
> +        (when (or (eq which-key-show-prefix 'echo)
> +                  (eq which-key-popup-type 'minibuffer))
> +          (which-key--setup-echo-keystrokes))
> +        (unless (member prefix-help-command which-key--paging-functions)
> +          (setq which-key--prefix-help-cmd-backup prefix-help-command))
> +        (when (or which-key-use-C-h-commands
> +                  which-key-show-early-on-C-h)
> +          (setq prefix-help-command #'which-key-C-h-dispatch))
> +        (when which-key-show-remaining-keys
> +          (add-hook 'pre-command-hook #'which-key--lighter-restore))
> +        (add-hook 'pre-command-hook #'which-key--hide-popup)
> +        (add-hook 'window-size-change-functions
> +                  #'which-key--hide-popup-on-frame-size-change)
> +        (which-key--start-timer))
> +    (setq echo-keystrokes which-key--echo-keystrokes-backup)
> +    (when which-key--prefix-help-cmd-backup
> +      (setq prefix-help-command which-key--prefix-help-cmd-backup))
> +    (when which-key-show-remaining-keys
> +      (remove-hook 'pre-command-hook #'which-key--lighter-restore))
> +    (remove-hook 'pre-command-hook #'which-key--hide-popup)
> +    (remove-hook 'window-size-change-functions
> +                 #'which-key--hide-popup-on-frame-size-change)
> +    (which-key--stop-timer)))
> +
> +(defun which-key--init-buffer ()
> +  "Initialize which-key buffer"
> +  (unless (buffer-live-p which-key--buffer)
> +    (setq which-key--buffer (get-buffer-create which-key-buffer-name))
> +    (with-current-buffer which-key--buffer
> +      ;; suppress confusing minibuffer message
> +      (let (message-log-max)
> +        (toggle-truncate-lines 1)
> +        (message ""))
> +      (setq-local cursor-type nil)
> +      (setq-local cursor-in-non-selected-windows nil)
> +      (setq-local mode-line-format nil)
> +      (setq-local header-line-format nil)
> +      (setq-local word-wrap nil)
> +      (setq-local show-trailing-whitespace nil)
> +      (run-hooks 'which-key-init-buffer-hook))))
> +
> +(defun which-key--setup-echo-keystrokes ()
> +  "Reduce `echo-keystrokes' if necessary (it will interfere if
> +it's set too high)."
> +  (when (and echo-keystrokes
> +             (> (abs (- echo-keystrokes which-key-echo-keystrokes)) 0.00=
0001))
> +    (if (> which-key-idle-delay which-key-echo-keystrokes)
> +        (setq echo-keystrokes which-key-echo-keystrokes)
> +      (setq which-key-echo-keystrokes (/ (float which-key-idle-delay) 4)
> +            echo-keystrokes which-key-echo-keystrokes))))
> +
> +(defun which-key-remove-default-unicode-chars ()
> +  "Use of `which-key-dont-use-unicode' is preferred to this
> +function, but it's included here in case someone cannot set that
> +variable early enough in their configuration, if they are using a
> +starter kit for example."
> +  (when (string-equal which-key-separator " =E2=86=92 ")
> +    (setq which-key-separator " : ")))
> +
> +;;; Default configuration functions for use by users.
> +
> +;;;###autoload
> +(defun which-key-setup-side-window-right ()
> +  "Apply suggested settings for side-window that opens on right."
> +  (interactive)
> +  (setq which-key-popup-type 'side-window
> +        which-key-side-window-location 'right
> +        which-key-show-prefix 'top))
> +
> +;;;###autoload
> +(defun which-key-setup-side-window-right-bottom ()
> +  "Apply suggested settings for side-window that opens on right
> +if there is space and the bottom otherwise."
> +  (interactive)
> +  (setq which-key-popup-type 'side-window
> +        which-key-side-window-location '(right bottom)
> +        which-key-show-prefix 'top))
> +
> +;;;###autoload
> +(defun which-key-setup-side-window-bottom ()
> +  "Apply suggested settings for side-window that opens on bottom."
> +  (interactive)
> +  (which-key--setup-echo-keystrokes)
> +  (setq which-key-popup-type 'side-window
> +        which-key-side-window-location 'bottom
> +        which-key-show-prefix 'echo))
> +
> +;;;###autoload
> +(defun which-key-setup-minibuffer ()
> +  "Apply suggested settings for minibuffer.
> +Do not use this setup if you use the paging commands. Instead use
> +`which-key-setup-side-window-bottom', which is nearly identical
> +but more functional."
> +  (interactive)
> +  (which-key--setup-echo-keystrokes)
> +  (setq which-key-popup-type 'minibuffer
> +        which-key-show-prefix 'left))
> +
> +;;; Helper functions to modify replacement lists.
> +
> +;;;###autoload
> +(defun which-key-add-keymap-based-replacements (keymap key replacement &=
rest more)
> +  "Replace the description of KEY using REPLACEMENT in KEYMAP.
> +KEY should take a format suitable for use in `kbd'. REPLACEMENT
> +should be a cons cell of the form \(STRING . COMMAND\) for each
> +REPLACEMENT, where STRING is the replacement string and COMMAND
> +is a symbol corresponding to the intended command to be
> +replaced. COMMAND can be nil if the binding corresponds to a key
> +prefix. An example is
> +
> +\(which-key-add-keymap-based-replacements global-map
> +  \"C-x w\" \\=3D'\(\"Save as\" . write-file\)\).
> +
> +For backwards compatibility, REPLACEMENT can also be a string,
> +but the above format is preferred, and the option to use a string
> +for REPLACEMENT will eventually be removed."
> +  (while key
> +    (let ((def
> +           (cond
> +            ((consp replacement) replacement)
> +            ((stringp replacement)
> +             (cons replacement
> +                   (or (which-key--safe-lookup-key-description keymap ke=
y)
> +                       (make-sparse-keymap))))
> +            (t
> +             (user-error "replacement is neither a cons cell or a string=
")))))
> +      (define-key keymap (kbd key) def))
> +    (setq key (pop more)
> +          replacement (pop more))))
> +(put 'which-key-add-keymap-based-replacements 'lisp-indent-function 'def=
un)

You can also set this using a declare form at the beginning of the above
defun's body.

> +
> +;;;###autoload
> +(defun which-key-add-key-based-replacements
> +    (key-sequence replacement &rest more)
> +  "Replace the description of KEY-SEQUENCE with REPLACEMENT.
> +KEY-SEQUENCE is a string suitable for use in `kbd'. REPLACEMENT
> +may either be a string, as in
> +
> +\(which-key-add-key-based-replacements \"C-x 1\" \"maximize\"\)
> +
> +a cons of two strings as in
> +
> +\(which-key-add-key-based-replacements \"C-x 8\"
> +                                        \\=3D'(\"unicode\" . \"Unicode k=
eys\")\)
> +
> +or a function that takes a \(KEY . BINDING\) cons and returns a
> +replacement.
> +
> +In the second case, the second string is used to provide a longer
> +name for the keys under a prefix.
> +
> +MORE allows you to specifcy additional KEY REPLACEMENT pairs.  All
> +replacements are added to `which-key-replacement-alist'."
> +  ;; TODO: Make interactive
> +  (while key-sequence
> +    ;; normalize key sequences before adding
> +    (let ((key-seq (key-description (kbd key-sequence)))
> +          (replace (or (and (functionp replacement) replacement)
> +                       (car-safe replacement)
> +                       replacement)))
> +      (push (cons (cons (concat "\\`" (regexp-quote key-seq) "\\'") nil)
> +                  (if (functionp replace) replace (cons nil replace)))
> +            which-key-replacement-alist)
> +      (when (and (not (functionp replacement)) (consp replacement))
> +        (push (cons key-seq (cdr-safe replacement))
> +              which-key--prefix-title-alist)))
> +    (setq key-sequence (pop more) replacement (pop more))))
> +(put 'which-key-add-key-based-replacements 'lisp-indent-function 'defun)
> +
> +;;;###autoload
> +(defun which-key-add-major-mode-key-based-replacements
> +    (mode key-sequence replacement &rest more)
> +  "Functions like `which-key-add-key-based-replacements'.
> +The difference is that MODE specifies the `major-mode' that must
> +be active for KEY-SEQUENCE and REPLACEMENT (MORE contains
> +addition KEY-SEQUENCE REPLACEMENT pairs) to apply."
> +  ;; TODO: Make interactive
> +  (when (not (symbolp mode))
> +    (error "MODE should be a symbol corresponding to a value of major-mo=
de"))
> +  (let ((mode-alist
> +         (or (cdr-safe (assq mode which-key-replacement-alist)) (list)))
> +        (title-mode-alist
> +         (or (cdr-safe (assq mode which-key--prefix-title-alist)) (list)=
)))
> +    (while key-sequence
> +      ;; normalize key sequences before adding
> +      (let ((key-seq (key-description (kbd key-sequence)))
> +            (replace (or (and (functionp replacement) replacement)
> +                         (car-safe replacement)
> +                         replacement)))
> +        (push (cons (cons (concat "\\`" (regexp-quote key-seq) "\\'") ni=
l)
> +                    (if (functionp replace) replace (cons nil replace)))
> +              mode-alist)
> +        (when (and (not (functionp replacement)) (consp replacement))
> +          (push (cons key-seq (cdr-safe replacement))
> +                title-mode-alist)))
> +      (setq key-sequence (pop more) replacement (pop more)))
> +    (if (assq mode which-key-replacement-alist)
> +        (setcdr (assq mode which-key-replacement-alist) mode-alist)
> +      (push (cons mode mode-alist) which-key-replacement-alist))
> +    (if (assq mode which-key--prefix-title-alist)
> +        (setcdr (assq mode which-key--prefix-title-alist) title-mode-ali=
st)
> +      (push (cons mode title-mode-alist) which-key--prefix-title-alist))=
))
> +(put 'which-key-add-major-mode-key-based-replacements
> +     'lisp-indent-function 'defun)
> +
> +(defun which-key-define-key-recursively (map key def &optional at-root)
> +  "Recursively bind KEY in MAP to DEF on every level of MAP except the f=
irst.
> +If AT-ROOT is non-nil the binding is also placed at the root of MAP."
> +  (when at-root (define-key map key def))
> +  (map-keymap
> +   (lambda (_ev df)
> +     (when (keymapp df)
> +       (which-key-define-key-recursively df key def t)))
> +   map))
> +
> +;;; Functions for computing window sizes
> +
> +(defun which-key--text-width-to-total (text-width)
> +  "Convert window text-width to window total-width.
> +TEXT-WIDTH is the desired text width of the window.  The function
> +calculates what total width is required for a window in the
> +selected to have a text-width of TEXT-WIDTH columns.  The
> +calculation considers possible fringes and scroll bars.  This
> +function assumes that the desired window has the same character
> +width as the frame."
> +  (let ((char-width (frame-char-width)))
> +    (+ text-width
> +       (/ (frame-fringe-width) char-width)
> +       (/ (frame-scroll-bar-width) char-width)
> +       (if (which-key--char-enlarged-p) 1 0)
> +       ;; add padding to account for possible wide (unicode) characters
> +       3)))
> +
> +(defun which-key--total-width-to-text (total-width)
> +  "Convert window total-width to window text-width.
> +TOTAL-WIDTH is the desired total width of the window.  The function calc=
ulates
> +what text width fits such a window.  The calculation considers possible =
fringes
> +and scroll bars.  This function assumes that the desired window has the =
same
> +character width as the frame."
> +  (let ((char-width (frame-char-width)))
> +    (- total-width
> +       (/ (frame-fringe-width) char-width)
> +       (/ (frame-scroll-bar-width) char-width)
> +       (if (which-key--char-enlarged-p) 1 0)
> +       ;; add padding to account for possible wide (unicode) characters
> +       3)))
> +
> +(defun which-key--char-enlarged-p (&optional _frame)
> +  (> (frame-char-width)
> +     (/ (float (frame-pixel-width)) (window-total-width (frame-root-wind=
ow)))))
> +
> +(defun which-key--char-reduced-p (&optional _frame)
> +  (< (frame-char-width)
> +     (/ (float (frame-pixel-width)) (window-total-width (frame-root-wind=
ow)))))
> +
> +(defun which-key--char-exact-p (&optional _frame)
> +  (=3D (frame-char-width)
> +     (/ (float (frame-pixel-width)) (window-total-width (frame-root-wind=
ow)))))
> +
> +(defun which-key--width-or-percentage-to-width (width-or-percentage)
> +  "Return window total width.
> +If WIDTH-OR-PERCENTAGE is a whole number, return it unchanged.  Otherwis=
e, it
> +should be a percentage (a number between 0 and 1) out of the frame's wid=
th.
> +More precisely, it should be a percentage out of the frame's root window=
's
> +total width."
> +  (if (wholenump width-or-percentage)
> +      width-or-percentage
> +    (round (* width-or-percentage (window-total-width (frame-root-window=
))))))
> +
> +(defun which-key--height-or-percentage-to-height (height-or-percentage)
> +  "Return window total height.
> +If HEIGHT-OR-PERCENTAGE is a whole number, return it unchanged.  Otherwi=
se, it
> +should be a percentage (a number between 0 and 1) out of the frame's hei=
ght.
> +More precisely, it should be a percentage out of the frame's root window=
's
> +total height."
> +  (if (wholenump height-or-percentage)
> +      height-or-percentage
> +    (round (* height-or-percentage (window-total-height (frame-root-wind=
ow))))))
> +
> +(defun which-key--frame-size-changed-p ()
> +  "Non-nil if a change in frame size is detected."
> +  (let ((new-size (cons (frame-width) (frame-height))))
> +    (cond ((null which-key--previous-frame-size)
> +           (setq which-key--previous-frame-size new-size)
> +           nil)
> +          ((not (equal which-key--previous-frame-size new-size))
> +           (setq which-key--previous-frame-size new-size)))))
> +
> +;;; Show/hide which-key buffer
> +
> +(defun which-key--hide-popup ()
> +  "This function is called to hide the which-key buffer."
> +  (unless (or which-key-persistent-popup
> +              (member real-this-command which-key--paging-functions))
> +    (setq which-key--last-try-2-loc nil)
> +    (setq which-key--pages-obj nil)
> +    (setq which-key--automatic-display nil)
> +    (setq which-key--prior-show-keymap-args nil)
> +    (when (and which-key-idle-secondary-delay which-key--secondary-timer=
-active)
> +      (which-key--start-timer))
> +    (which-key--lighter-restore)
> +    (which-key--hide-popup-ignore-command)))
> +
> +(defun which-key--hide-popup-ignore-command ()
> +  "Version of `which-key--hide-popup' without the check of
> +`real-this-command'."
> +  (cl-case which-key-popup-type
> +    ;; Not necessary to hide minibuffer
> +    ;; (minibuffer (which-key--hide-buffer-minibuffer))
> +    (side-window (which-key--hide-buffer-side-window))
> +    (frame (which-key--hide-buffer-frame))
> +    (custom (funcall which-key-custom-hide-popup-function))))
> +
> +(defun which-key--hide-popup-on-frame-size-change (&optional _)
> +  "Hide which-key popup if the frame is resized (to trigger a new popup)=
."
> +  (when (which-key--frame-size-changed-p)
> +    (which-key--hide-popup)))
> +
> +(defun which-key--hide-buffer-side-window ()
> +  "Hide which-key buffer when side-window popup is used."
> +  (when (buffer-live-p which-key--buffer)
> +    ;; in case which-key buffer was shown in an existing window, `quit-w=
indow'
> +    ;; will re-show the previous buffer, instead of closing the window
> +    (quit-windows-on which-key--buffer)
> +    (when (and which-key-preserve-window-configuration
> +               which-key--saved-window-configuration)
> +      (set-window-configuration which-key--saved-window-configuration)
> +      (setq which-key--saved-window-configuration nil))))
> +
> +(defun which-key--hide-buffer-frame ()
> +  "Hide which-key buffer when frame popup is used."
> +  (when (frame-live-p which-key--frame)
> +    (delete-frame which-key--frame)))
> +
> +(defun which-key--popup-showing-p ()
> +  (and (bufferp which-key--buffer)
> +       (or (window-live-p (get-buffer-window which-key--buffer))
> +           (let ((window (get-buffer-window which-key--buffer t)))
> +             (and (window-live-p window)
> +                  (frame-visible-p (window-frame window)))))))
> +
> +(defun which-key--show-popup (act-popup-dim)
> +  "Show the which-key buffer.
> +ACT-POPUP-DIM includes the dimensions, (height . width) of the
> +buffer text to be displayed in the popup.  Return nil if no window
> +is shown, or if there is no need to start the closing timer."
> +  (when (and (> (car act-popup-dim) 0)
> +             (> (cdr act-popup-dim) 0))
> +    (cl-case which-key-popup-type
> +      ;; Not called for minibuffer
> +      ;; (minibuffer (which-key--show-buffer-minibuffer act-popup-dim))
> +      (side-window (which-key--show-buffer-side-window act-popup-dim))
> +      (frame (which-key--show-buffer-frame act-popup-dim))
> +      (custom (funcall which-key-custom-show-popup-function act-popup-di=
m)))))
> +
> +(defun which-key--fit-buffer-to-window-horizontally
> +    (&optional window &rest params)
> +  "Slightly modified version of `fit-buffer-to-window'.
> +Use &rest params because `fit-buffer-to-window' has a different
> +call signature in different emacs versions"
> +  (let ((fit-window-to-buffer-horizontally t)
> +        (window-min-height 1))
> +    (apply #'fit-window-to-buffer window params)))
> +
> +(defun which-key--show-buffer-side-window (act-popup-dim)
> +  "Show which-key buffer when popup type is side-window."
> +  (when (and which-key-preserve-window-configuration
> +             (not which-key--saved-window-configuration))
> +    (setq which-key--saved-window-configuration (current-window-configur=
ation)))
> +  (let* ((height (car act-popup-dim))
> +         (width (cdr act-popup-dim))
> +         (alist
> +          (if which-key-allow-imprecise-window-fit
> +              `((window-width .  ,(which-key--text-width-to-total width))
> +                (window-height . ,height)
> +                (side . ,which-key-side-window-location)
> +                (slot . ,which-key-side-window-slot))
> +            `((window-width . which-key--fit-buffer-to-window-horizontal=
ly)
> +              (window-height . (lambda (w) (fit-window-to-buffer w nil 1=
)))
> +              (side . ,which-key-side-window-location)
> +              (slot . ,which-key-side-window-slot)))))
> +    ;; Previously used `display-buffer-in-major-side-window' here, but
> +    ;; apparently that is meant to be an internal function. See emacs bu=
g #24828
> +    ;; and advice given there.
> +    (cond
> +     ((eq which-key--multiple-locations t)
> +      ;; possibly want to switch sides in this case so we can't reuse th=
e window
> +      (delete-windows-on which-key--buffer)
> +      (display-buffer-in-side-window which-key--buffer alist))
> +     ((get-buffer-window which-key--buffer)
> +      (display-buffer-reuse-window which-key--buffer alist))
> +     (t
> +      (display-buffer-in-side-window which-key--buffer alist)))))
> +
> +(defun which-key--show-buffer-frame (act-popup-dim)
> +  "Show which-key buffer when popup type is frame."
> +  (let* (;(orig-window (selected-window))
> +         (frame-height (+ (car act-popup-dim)
> +                          (if (with-current-buffer which-key--buffer
> +                                mode-line-format)
> +                              1
> +                            0)))
> +         ;; without adding 2, frame sometimes isn't wide enough for the =
buffer.
> +         ;; this is probably because of the fringes. however, setting fr=
inges
> +         ;; sizes to 0 (instead of adding 2) didn't always make the fram=
e wide
> +         ;; enough. don't know why it is so.
> +         (frame-width (+ (cdr act-popup-dim) 2))
> +         (new-window (if (and (frame-live-p which-key--frame)
> +                              (eq which-key--buffer
> +                                  (window-buffer
> +                                   (frame-root-window which-key--frame))=
))
> +                         (which-key--show-buffer-reuse-frame
> +                          frame-height frame-width)
> +                       (which-key--show-buffer-new-frame
> +                        frame-height frame-width))))
> +    (when new-window
> +      ;; display successful
> +      (setq which-key--frame (window-frame new-window))
> +      new-window)))
> +
> +(defun which-key--show-buffer-new-frame (frame-height frame-width)
> +  "Helper for `which-key--show-buffer-frame'."
> +  (let* ((frame-params `((height . ,frame-height)
> +                         (width . ,frame-width)
> +                         ;; tell the window manager to respect the given=
 sizes
> +                         (user-size . t)
> +                         ;; which-key frame doesn't need a minibuffer
> +                         (minibuffer . nil)
> +                         (name . "which-key")
> +                         ;; no need for scroll bars in which-key frame
> +                         (vertical-scroll-bars . nil)
> +                         ;; (left-fringe . 0)
> +                         ;; (right-fringe . 0)
> +                         ;; (right-divider-width . 0)
> +                         ;; make sure frame is visible
> +                         (visibility . t)))
> +         (alist `((pop-up-frame-parameters . ,frame-params)))
> +         (orig-frame (selected-frame))
> +         (new-window (display-buffer-pop-up-frame which-key--buffer alis=
t)))
> +    (when new-window
> +      ;; display successful
> +      (redirect-frame-focus (window-frame new-window) orig-frame)
> +      new-window)))
> +
> +(defun which-key--show-buffer-reuse-frame (frame-height frame-width)
> +  "Helper for `which-key--show-buffer-frame'."
> +  (let ((window
> +         (display-buffer-reuse-window
> +          which-key--buffer `((reusable-frames . ,which-key--frame)))))
> +    (when window
> +      ;; display successful
> +      (set-frame-size (window-frame window) frame-width frame-height)
> +      window)))
> +
> +;;; Max dimension of available window functions
> +
> +(defun which-key--popup-max-dimensions ()
> +  "Dimesion functions should return the maximum possible (height
> +. width) of the intended popup. SELECTED-WINDOW-WIDTH is the
> +width of currently active window, not the which-key buffer
> +window."
> +  (cl-case which-key-popup-type
> +    (minibuffer (which-key--minibuffer-max-dimensions))
> +    (side-window (which-key--side-window-max-dimensions))
> +    (frame (which-key--frame-max-dimensions))
> +    (custom (funcall which-key-custom-popup-max-dimensions-function
> +                     (window-width)))))
> +
> +(defun which-key--minibuffer-max-dimensions ()
> +  "Return max-dimensions of minibuffer (height . width).
> +Measured in lines and characters respectively."
> +  (cons
> +   ;; height
> +   (if (floatp max-mini-window-height)
> +       (floor (* (frame-text-lines)
> +                 max-mini-window-height))
> +     max-mini-window-height)
> +   ;; width
> +   (max 0 (- (frame-text-cols) which-key-unicode-correction))))
> +
> +(defun which-key--side-window-max-dimensions ()
> +  "Return max-dimensions of the side-window popup (height .
> +width) in lines and characters respectively."
> +  (cons
> +   ;; height
> +   (if (member which-key-side-window-location '(left right))
> +       ;; 1 is a kludge to make sure there is no overlap
> +       (- (frame-height) (window-text-height (minibuffer-window)) 1)
> +     ;; (window-mode-line-height which-key--window))
> +     ;; FIXME: change to something like
> +     ;; (min which-*-height (calculate-max-height))
> +     (which-key--height-or-percentage-to-height
> +      which-key-side-window-max-height))
> +   ;; width
> +   (max 0
> +        (- (if (member which-key-side-window-location '(left right))

Could be a memq here.

> +               (which-key--total-width-to-text
> +                (which-key--width-or-percentage-to-width
> +                 which-key-side-window-max-width))
> +             (which-key--total-width-to-text
> +              (which-key--width-or-percentage-to-width
> +               1.0)))
> +           which-key-unicode-correction))))
> +
> +(defun which-key--frame-max-dimensions ()
> +  "Return max-dimensions of the frame popup (height .
> +width) in lines and characters respectively."
> +  (cons which-key-frame-max-height which-key-frame-max-width))
> +
> +;;; Sorting functions
> +
> +(defun which-key--string< (a b &optional alpha)
> +  (let ((da (downcase a))
> +        (db (downcase b)))

Perhaps you could also use `string-equal-ignore-case' below.

> +    (cond
> +     ((and alpha (not which-key-sort-uppercase-first))
> +      (if (string-equal da db)
> +          (not (string-lessp a b))
> +        (string-lessp da db)))
> +     ((and alpha which-key-sort-uppercase-first)
> +      (if (string-equal da db)
> +          (string-lessp a b)
> +        (string-lessp da db)))
> +     ((not which-key-sort-uppercase-first)
> +      (let ((aup (not (string-equal da a)))
> +            (bup (not (string-equal db b))))
> +        (if (eq aup bup)
> +            (string-lessp a b)
> +          bup)))
> +     (t (string-lessp a b)))))
> +
> +(defun which-key--key-description< (a b &optional alpha)
> +  "Sorting function used for `which-key-key-order' and
> +`which-key-key-order-alpha'."
> +  (save-match-data
> +    (let* ((a (which-key--extract-key a))
> +           (b (which-key--extract-key b))
> +           (rngrgxp "^\\([^ ]+\\) \\.\\. [^ ]+")
> +           (a (if (string-match rngrgxp a) (match-string 1 a) a))
> +           (b (if (string-match rngrgxp b) (match-string 1 b) b))
> +           (aem? (string-equal a ""))
> +           (bem? (string-equal b ""))
> +           (a1? (=3D 1 (length a)))
> +           (b1? (=3D 1 (length b)))
> +           (srgxp "^\\(RET\\|SPC\\|TAB\\|DEL\\|LFD\\|ESC\\|NUL\\)")
> +           (asp? (string-match-p srgxp a))
> +           (bsp? (string-match-p srgxp b))
> +           (prrgxp "^\\(M\\|C\\|S\\|A\\|H\\|s\\)-")
> +           (apr? (string-match-p prrgxp a))
> +           (bpr? (string-match-p prrgxp b))
> +           (afn? (string-match-p "<f[0-9]+>" a))
> +           (bfn? (string-match-p "<f[0-9]+>" b)))
> +      (cond ((or aem? bem?) (and aem? (not bem?)))
> +            ((and asp? bsp?)
> +             (if (string-equal (substring a 0 3) (substring b 0 3))
> +                 (which-key--key-description<
> +                  (substring a 3) (substring b 3) alpha)
> +               (which-key--string< a b alpha)))
> +            ((or asp? bsp?) asp?)
> +            ((and a1? b1?) (which-key--string< a b alpha))
> +            ((or a1? b1?) a1?)
> +            ((and afn? bfn?)
> +             (< (string-to-number
> +                 (replace-regexp-in-string "<f\\([0-9]+\\)>" "\\1" a))
> +                (string-to-number
> +                 (replace-regexp-in-string "<f\\([0-9]+\\)>" "\\1" b))))
> +            ((or afn? bfn?) afn?)
> +            ((and apr? bpr?)
> +             (if (string-equal (substring a 0 2) (substring b 0 2))
> +                 (which-key--key-description<
> +                  (substring a 2) (substring b 2) alpha)
> +               (which-key--string< a b alpha)))
> +            ((or apr? bpr?) apr?)
> +            (t (which-key--string< a b alpha))))))
> +
> +(defsubst which-key-key-order-alpha (acons bcons)
> +  "Order key descriptions A and B.
> +Order is lexicographic within a \"class\", where the classes and
> +the ordering of classes are listed below.
> +
> +special (SPC,TAB,...) < single char < mod (C-,M-,...) < other.
> +Sorts single characters alphabetically with lowercase coming
> +before upper."
> +  (which-key--key-description< (car acons) (car bcons) t))
> +
> +(defsubst which-key-key-order (acons bcons)
> +  "Order key descriptions A and B.
> +Order is lexicographic within a \"class\", where the classes and
> +the ordering of classes are listed below.
> +
> +special (SPC,TAB,...) < single char < mod (C-,M-,...) < other."
> +  (which-key--key-description< (car acons) (car bcons)))
> +
> +(defsubst which-key-description-order (acons bcons)
> +  "Order descriptions of A and B.
> +Uses `string-lessp' after applying lowercase."
> +  (string-lessp (downcase (cdr acons)) (downcase (cdr bcons))))
> +
> +(defsubst which-key--group-p (description)
> +  (or (string-equal description "prefix")
> +      (string-match-p "^group:" description)
> +      (keymapp (intern description))))
> +
> +(defun which-key-prefix-then-key-order (acons bcons)
> +  "Order first by whether A and/or B is a prefix with no prefix
> +coming before a prefix. Within these categories order using
> +`which-key-key-order'."
> +  (let ((apref? (which-key--group-p (cdr acons)))
> +        (bpref? (which-key--group-p (cdr bcons))))
> +    (if (not (eq apref? bpref?))
> +        (and (not apref?) bpref?)
> +      (which-key-key-order acons bcons))))
> +
> +(defun which-key-prefix-then-key-order-reverse (acons bcons)
> +  "Order first by whether A and/or B is a prefix with prefix
> +coming before a prefix. Within these categories order using
> +`which-key-key-order'."
> +  (let ((apref? (which-key--group-p (cdr acons)))
> +        (bpref? (which-key--group-p (cdr bcons))))
> +    (if (not (eq apref? bpref?))
> +        (and apref? (not bpref?))
> +      (which-key-key-order acons bcons))))
> +
> +(defun which-key-local-then-key-order (acons bcons)
> +  "Order first by whether A and/or B is a local binding with
> +local bindings coming first. Within these categories order using
> +`which-key-key-order'."
> +  (let ((aloc? (which-key--local-binding-p acons))
> +        (bloc? (which-key--local-binding-p bcons)))
> +    (if (not (eq aloc? bloc?))
> +        (and aloc? (not bloc?))
> +      (which-key-key-order acons bcons))))
> +
> +;;; Functions for retrieving and formatting keys
> +
> +(defsubst which-key--string-width (maybe-string)
> +  "If MAYBE-STRING is a string use `which-key--string-width' o/w return =
0."
> +  (if (stringp maybe-string) (string-width maybe-string) 0))
> +
> +(defsubst which-key--butlast-string (str)
> +  (mapconcat #'identity (butlast (split-string str)) " "))

Or string-join.

> +
> +(defun which-key--match-replacement (key-binding replacement)
> +  ;; these are mode specific ones to ignore. The mode specific case is
> +  ;; handled in the selection of alist
> +  (when (and (consp key-binding) (not (symbolp (car replacement))))
> +    (let ((key-regexp (caar replacement))
> +          (binding-regexp (cdar replacement))
> +          case-fold-search)
> +      (and (or (null key-regexp)
> +               (string-match-p key-regexp
> +                               (car key-binding)))
> +           (or (null binding-regexp)
> +               (string-match-p binding-regexp
> +                               (cdr key-binding)))))))
> +
> +(defsubst which-key--replace-in-binding (key-binding repl)
> +  (cond ((or (not (consp repl)) (null (cdr repl)))
> +         key-binding)
> +        ((functionp (cdr repl))
> +         (funcall (cdr repl) key-binding))
> +        ((consp (cdr repl))
> +         (cons
> +          (cond ((and (caar repl) (cadr repl))
> +                 (replace-regexp-in-string
> +                  (caar repl) (cadr repl) (car key-binding) t))
> +                ((cadr repl) (cadr repl))
> +                (t (car key-binding)))
> +          (cond ((and (cdar repl) (cddr repl))
> +                 (replace-regexp-in-string
> +                  (cdar repl) (cddr repl) (cdr key-binding) t))
> +                ((cddr repl) (cddr repl))
> +                (t (cdr key-binding)))))))
> +
> +(defun which-key--replace-in-repl-list-once (key-binding repls)
> +  (cl-dolist (repl repls)
> +    (when (which-key--match-replacement key-binding repl)
> +      (cl-return `(replaced . ,(which-key--replace-in-binding key-bindin=
g repl))))))
> +
> +(defun which-key--replace-in-repl-list-many (key-binding repls)
> +  (let (found)
> +    (dolist (repl repls)
> +      (when (which-key--match-replacement key-binding repl)
> +        (setq found 't)
> +        (setq key-binding (which-key--replace-in-binding key-binding rep=
l))))
> +    (when found `(replaced . ,key-binding))))

I think a throw-catch construct would be preferable.

> +
> +(defun which-key--maybe-replace (key-binding)
> +  "Use `which-key--replacement-alist' to maybe replace KEY-BINDING.
> +KEY-BINDING is a cons cell of the form \(KEY . BINDING\) each of
> +which are strings. KEY is of the form produced by `key-binding'."
> +  (let* ((replacer (if which-key-allow-multiple-replacements
> +                       #'which-key--replace-in-repl-list-many
> +                     #'which-key--replace-in-repl-list-once)))
> +    (pcase
> +        (apply replacer
> +               (list key-binding
> +                     (cdr-safe (assq major-mode which-key-replacement-al=
ist))))
> +      (`(replaced . ,repl)
> +       (if which-key-allow-multiple-replacements
> +           (pcase (apply replacer (list repl which-key-replacement-alist=
))
> +             (`(replaced . ,repl) repl)
> +             ('() repl))
> +         repl))
> +      ('()
> +       (pcase (apply replacer (list key-binding which-key-replacement-al=
ist))
> +         (`(replaced . ,repl) repl)
> +         ('() key-binding))))))
> +
> +(defsubst which-key--current-key-list (&optional key-str)
> +  (append (listify-key-sequence (which-key--current-prefix))
> +          (when key-str
> +            (listify-key-sequence (kbd key-str)))))
> +
> +(defsubst which-key--current-key-string (&optional key-str)
> +  (key-description (which-key--current-key-list key-str)))
> +
> +(defun which-key--local-binding-p (keydesc)
> +  (eq (which-key--safe-lookup-key-description
> +       (current-local-map)
> +       (which-key--current-key-string (car keydesc)))
> +      (intern (cdr keydesc))))
> +
> +(defun which-key--map-binding-p (map keydesc)
> +  "Does MAP contain KEYDESC =3D (key . binding)?"
> +  (or
> +   (when (bound-and-true-p evil-state)
> +     (let ((lookup
> +            (which-key--safe-lookup-key-description
> +             map
> +             (which-key--current-key-string
> +              (format "<%s-state> %s" evil-state (car keydesc))))))
> +       (or (eq lookup (intern (cdr keydesc)))
> +           (and (keymapp lookup) (string=3D (cdr keydesc) "Prefix Comman=
d")))))
> +   (let ((lookup
> +          (which-key--safe-lookup-key-description
> +           map (which-key--current-key-string (car keydesc)))))
> +     (or (eq lookup (intern (cdr keydesc)))
> +         (and (keymapp lookup) (string=3D (cdr keydesc) "Prefix Command"=
))))))
> +
> +(defun which-key--maybe-get-prefix-title (keys)
> +  "KEYS is a string produced by `key-description'.
> +A title is possibly returned using
> +`which-key--prefix-title-alist'.  An empty string is returned if
> +no title exists."
> +  (cond
> +   ((not (string-equal keys ""))
> +    (let* ((title-res
> +            (cdr-safe (assoc-string keys which-key--prefix-title-alist)))
> +           (repl-res
> +            (cdr-safe (which-key--maybe-replace (cons keys ""))))
> +           (binding (key-binding (kbd keys)))
> +           (alternate (when (and binding (symbolp binding))
> +                        (symbol-name binding))))
> +      (cond (title-res title-res)
> +            ((not (string-equal repl-res "")) repl-res)
> +            ((and (eq which-key-show-prefix 'echo) alternate)
> +             alternate)
> +            ((and (member which-key-show-prefix '(bottom top mode-line))
> +                  (eq which-key-side-window-location 'bottom)
> +                  echo-keystrokes)
> +             (if alternate alternate
> +               (concat "Following " keys)))
> +            (t ""))))
> +   (t "")))
> +
> +(defun which-key--propertize (string &rest properties)
> +  "Version of `propertize' that checks type of STRING."
> +  (when (stringp string)
> +    (apply #'propertize string properties)))

What is the point of this?  This seems to be the kind of thing that
would let bugs slide through silently.

> +
> +(defun which-key--propertize-key (key)
> +  "Add a face to KEY.
> +If KEY contains any \"special keys\" defined in
> +`which-key-special-keys' then truncate and add the corresponding
> +`which-key-special-key-face'."
> +  (let ((key-w-face (which-key--propertize key 'face 'which-key-key-face=
))
> +        (regexp (concat "\\("
> +                        (mapconcat #'identity which-key-special-keys
> +                                   "\\|")
> +                        "\\)"))
> +        case-fold-search)
> +    (save-match-data
> +      (if (and which-key-special-keys
> +               (string-match regexp key))
> +          (let ((beg (match-beginning 0)) (end (match-end 0)))
> +            (concat (substring key-w-face 0 beg)
> +                    (which-key--propertize (substring key-w-face beg (1+=
 beg))
> +                                           'face 'which-key-special-key-=
face)
> +                    (substring key-w-face end
> +                               (which-key--string-width key-w-face))))
> +        key-w-face))))
> +
> +(defsubst which-key--truncate-description (desc avl-width)
> +  "Truncate DESC description to `which-key-max-description-length'."
> +  (let* ((max which-key-max-description-length)
> +	 (max (cl-etypecase max
> +		(null nil)
> +		(integer max)
> +		(float (truncate (* max avl-width)))
> +		(function (let ((val (funcall max avl-width)))
> +			    (if (floatp val) (truncate val) val))))))
> +    (if (and max (> (length desc) max))
> +        (let ((dots (and (not (equal which-key-ellipsis ""))
> +			 (which-key--propertize
> +			  which-key-ellipsis 'face
> +			  (get-text-property (1- (length desc)) 'face desc)))))
> +	  (if dots
> +              (concat (substring desc 0 (- max (length dots))) dots)
> +	    (substring desc 0 max)))
> +      desc)))
> +
> +(defun which-key--highlight-face (description)
> +  "Return the highlight face for DESCRIPTION if it has one."
> +  (let (face)
> +    (dolist (el which-key-highlighted-command-list)
> +      (unless face
> +        (cond ((consp el)
> +               (when (string-match-p (car el) description)
> +                 (setq face (cdr el))))
> +              ((stringp el)
> +               (when (string-match-p el description)
> +                 (setq face 'which-key-highlighted-command-face)))
> +              (t
> +               (message "which-key: warning: element %s of \
> +which-key-highlighted-command-list is not a string or a cons
> +cell" el)))))
> +    face))
> +
> +(defun which-key--propertize-description
> +    (description group local hl-face &optional original-description)
> +  "Add face to DESCRIPTION where the face chosen depends on
> +whether the description represents a group or a command. Also
> +make some minor adjustments to the description string, like
> +removing a \"group:\" prefix.
> +
> +ORIGINAL-DESCRIPTION is the description given by
> +`describe-buffer-bindings'."
> +  (when description
> +    (let* ((desc description)
> +           (desc (if (string-match-p "^group:" desc)
> +                     (substring desc 6) desc))
> +           (desc (if group (concat which-key-prefix-prefix desc) desc)))
> +      (make-text-button
> +       desc nil
> +       'face (cond (hl-face hl-face)
> +                   (group 'which-key-group-description-face)
> +                   (local 'which-key-local-map-description-face)
> +                   (t 'which-key-command-description-face))
> +       'help-echo (cond
> +                   ((and original-description
> +                         (fboundp (intern original-description))
> +                         (documentation (intern original-description))
> +                         ;; tooltip-mode doesn't exist in emacs-nox
> +                         (boundp 'tooltip-mode) tooltip-mode)
> +                    (documentation (intern original-description)))
> +                   ((and original-description
> +                         (fboundp (intern original-description))
> +                         (documentation (intern original-description))
> +                         (let* ((doc (documentation
> +                                      (intern original-description)))
> +                                (str (replace-regexp-in-string "\n" " " =
doc))
> +                                (max (floor (* (frame-width) 0.8))))
> +                           (if (> (length str) max)
> +                               (concat (substring str 0 max) "...")
> +                             str)))))))))
> +
> +(defun which-key--extract-key (key-str)
> +  "Pull the last key (or key range) out of KEY-STR."
> +  (save-match-data
> +    (let ((key-range-regexp "\\`.*\\([^ \t]+ \\.\\. [^ \t]+\\)\\'"))
> +      (if (string-match key-range-regexp key-str)
> +          (match-string 1 key-str)
> +        (car (last (split-string key-str " ")))))))
> +
> +(defun which-key--maybe-add-docstring (current original)
> +  "Maybe concat a docstring to CURRENT and return result.
> +Specifically, do this if ORIGINAL is a command with a docstring
> +and `which-key-show-docstrings' is non-nil. If
> +`which-key-show-docstrings' is the symbol docstring-only, just
> +return the docstring."
> +  (let* ((orig-sym (intern original))
> +         (doc (when (commandp orig-sym)
> +                (documentation orig-sym)))
> +         (doc (when doc
> +                (replace-regexp-in-string
> +                 (concat "^\\(?::"
> +                         (regexp-opt '("around" "override"
> +                                       "after" "after-until" "after-whil=
e"
> +                                       "before" "before-until" "before-w=
hile"
> +                                       "filter-args" "filter-return"))
> +                         " advice: [^\n]+\n"
> +                         "\\)+\n")
> +                 "" doc)))
> +         (docstring (when doc
> +                      (which-key--propertize (car (split-string doc "\n"=
))
> +                                             'face 'which-key-docstring-=
face))))
> +    (cond ((not (and which-key-show-docstrings docstring))
> +           current)
> +          ((eq which-key-show-docstrings 'docstring-only)
> +           docstring)
> +          (t
> +           (format "%s %s" current docstring)))))
> +
> +(defun which-key--format-and-replace (unformatted &optional preserve-ful=
l-key)
> +  "Take a list of (key . desc) cons cells in UNFORMATTED, add
> +faces and perform replacements according to the three replacement
> +alists. Returns a list (key separator description)."
> +  (let ((sep-w-face
> +         (which-key--propertize which-key-separator
> +                                'face 'which-key-separator-face))
> +        (local-map (current-local-map))
> +	(avl-width (cdr (which-key--popup-max-dimensions)))
> +        new-list)
> +    (dolist (key-binding unformatted)
> +      (let* ((keys (car key-binding))
> +             (orig-desc (cdr key-binding))
> +             (group (which-key--group-p orig-desc))
> +             (local (eq (which-key--safe-lookup-key-description
> +                         local-map keys)
> +                        (intern orig-desc)))
> +             (hl-face (which-key--highlight-face orig-desc))
> +             (key-binding (which-key--maybe-replace key-binding))
> +             (final-desc (which-key--propertize-description
> +                          (cdr key-binding) group local hl-face orig-des=
c)))
> +        (when final-desc
> +          (setq final-desc
> +                (which-key--truncate-description
> +                 (which-key--maybe-add-docstring final-desc orig-desc)
> +		 avl-width)))
> +        (when (consp key-binding)
> +          (push
> +           (list (which-key--propertize-key
> +                  (if preserve-full-key
> +                      (car key-binding)
> +                    (which-key--extract-key (car key-binding))))
> +                 sep-w-face
> +                 final-desc)
> +           new-list))))
> +    (nreverse new-list)))
> +
> +(defun which-key--compute-binding (binding)
> +  "Replace BINDING with remapped binding if it exists.
> +
> +Requires `which-key-compute-remaps' to be non-nil"
> +  (let (remap)
> +    (if (and which-key-compute-remaps
> +             (setq remap (command-remapping binding)))
> +        (copy-sequence (symbol-name remap))
> +      (copy-sequence (symbol-name binding)))))
> +
> +(defun which-key--get-menu-item-binding (def)
> +  "Retrieve binding for menu-item"
> +  ;; see `keymap--menu-item-binding'
> +  (let* ((binding (nth 2 def))
> +         (plist (nthcdr 3 def))
> +         (filter (plist-get plist :filter)))
> +    (if filter (funcall filter binding) binding)))
> +
> +(defun which-key--get-keymap-bindings-1
> +    (keymap start &optional prefix filter all ignore-commands)
> +  "See `which-key--get-keymap-bindings'."
> +  (let ((bindings start)
> +        (prefix-map (if prefix (lookup-key keymap prefix) keymap)))
> +    (when (keymapp prefix-map)
> +      (map-keymap
> +       (lambda (ev def)
> +         (let* ((key (vconcat prefix (list ev)))
> +                (key-desc (key-description key)))
> +           (cond
> +            ((assoc key-desc bindings))
> +            ((and (listp ignore-commands) (symbolp def) (memq def ignore=
-commands)))
> +            ((or (string-match-p
> +                  which-key--ignore-non-evil-keys-regexp key-desc)
> +                 (eq ev 'menu-bar)))
> +            ((and (keymapp def)
> +                  (string-match-p which-key--evil-keys-regexp key-desc)))
> +            ((and (keymapp def)
> +                  (or all
> +                      ;; event 27 is escape, so this will pick up meta
> +                      ;; bindings and hopefully not too much more
> +                      (and (numberp ev) (=3D ev 27))))
> +             (setq bindings
> +                   (which-key--get-keymap-bindings-1
> +                    keymap bindings key nil all ignore-commands)))
> +            (def
> +             (let* ((def (if (eq 'menu-item (car-safe def))
> +                             (which-key--get-menu-item-binding def)
> +                           def))
> +                    (binding
> +                     (cons key-desc
> +                           (cond
> +                            ((symbolp def) (which-key--compute-binding d=
ef))
> +                            ((keymapp def) "prefix")
> +                            ((eq 'lambda (car-safe def)) "lambda")
> +                            ((eq 'closure (car-safe def)) "closure")
> +                            ((stringp def) def)
> +                            ((vectorp def) (key-description def))
> +                            ((and (consp def)
> +                                  ;; looking for (STRING . DEFN)
> +                                  (stringp (car def)))
> +                             (concat (when (keymapp (cdr-safe def))
> +                                       "group:")
> +                                     (car def)))
> +                            (t "unknown")))))
> +               (when (or (null filter)
> +                         (and (functionp filter)
> +                              (funcall filter binding)))
> +                 (push binding bindings)))))))
> +       prefix-map))
> +    bindings))
> +
> +(defun which-key--get-keymap-bindings
> +    (keymap &optional start prefix filter all evil)
> +  "Retrieve top-level bindings from KEYMAP.
> +PREFIX limits bindings to those starting with this key
> +sequence. START is a list of existing bindings to add to.  If ALL
> +is non-nil, recursively retrieve all bindings below PREFIX. If
> +EVIL is non-nil, extract active evil bidings."
> +  (let ((bindings start)
> +        (ignore '(self-insert-command ignore ignore-event company-ignore=
))
> +        (evil-map
> +         (when (and evil (bound-and-true-p evil-local-mode))
> +           (lookup-key keymap (kbd (format "<%s-state>" evil-state))))))
> +    (when (keymapp evil-map)
> +      (setq bindings (which-key--get-keymap-bindings-1
> +                      evil-map bindings prefix filter all ignore)))
> +    (which-key--get-keymap-bindings-1
> +     keymap bindings prefix filter all ignore)))
> +
> +(defun which-key--get-current-bindings (&optional prefix filter)
> +  "Generate a list of current active bindings."
> +  (let (bindings)
> +    (dolist (map (current-active-maps t) bindings)
> +      (when (cdr map)
> +        (setq bindings
> +              (which-key--get-keymap-bindings
> +               map bindings prefix filter))))))
> +
> +(defun which-key--get-bindings (&optional prefix keymap filter recursive)
> +  "Collect key bindings.
> +If KEYMAP is nil, collect from current buffer using the current
> +key sequence as a prefix. Otherwise, collect from KEYMAP. FILTER
> +is a function to use to filter the bindings. If RECURSIVE is
> +non-nil, then bindings are collected recursively for all prefixes."
> +  (let* ((unformatted
> +          (cond ((keymapp keymap)
> +                 (which-key--get-keymap-bindings
> +                  keymap nil prefix filter recursive))
> +                (keymap
> +                 (error "%s is not a keymap" keymap))
> +                (t
> +                 (which-key--get-current-bindings prefix filter)))))
> +    (when which-key-sort-order
> +      (setq unformatted
> +            (sort unformatted which-key-sort-order)))
> +    (which-key--format-and-replace unformatted recursive)))
> +
> +;;; Functions for laying out which-key buffer pages
> +
> +(defun which-key--normalize-columns (columns)
> +  "Pad COLUMNS to the same length using empty strings."
> +  (let ((max-len (cl-reduce (lambda (a x) (max a (length x))) columns
> +                            :initial-value 0)))
> +    (mapcar
> +     (lambda (c)
> +       (if (< (length c) max-len)

Using (length< c max-len) avoids traversing the entire list, but it
probably doesn't matter because of the length in the next line.

> +           (append c (make-list (- max-len (length c)) ""))
> +         c))
> +     columns)))
> +
> +(defsubst which-key--join-columns (columns)
> +  "Transpose columns into rows, concat rows into lines and rows into pag=
e."
> +  (let* ((padded (which-key--normalize-columns (nreverse columns)))
> +         (rows (apply #'cl-mapcar #'list padded)))
> +    (mapconcat (lambda (row) (mapconcat #'identity row " ")) rows "\n")))
> +
> +(defsubst which-key--max-len (keys index &optional initial-value)
> +  "Internal function for finding the max length of the INDEX
> +element in each list element of KEYS."
> +  (cl-reduce
> +   (lambda (x y) (max x (which-key--string-width (nth index y))))
> +   keys :initial-value (if initial-value initial-value 0)))
> +
> +(defun which-key--pad-column (col-keys avl-width)
> +  "Take a column of (key separator description) COL-KEYS,
> +calculate the max width in the column and pad all cells out to
> +that width."
> +  (let* ((col-key-width  (+ which-key-add-column-padding
> +                            (which-key--max-len col-keys 0)))
> +         (col-sep-width  (which-key--max-len col-keys 1))
> +	 (avl-width      (- avl-width col-key-width col-sep-width))
> +         (col-desc-width (min avl-width
> +			      (which-key--max-len
> +                               col-keys 2
> +			       which-key-min-column-description-width)))
> +         (col-width      (+ col-key-width col-sep-width col-desc-width))
> +	 (col-format     (concat "%" (int-to-string col-key-width)
> +                                 "s%s%-" (int-to-string col-desc-width) =
"s")))
> +    (cons col-width
> +          (mapcar (lambda (k) (apply #'format col-format k))
> +		  col-keys))))
> +
> +(defun which-key--partition-list (n list)
> +  "Partition LIST into N-sized sublists."
> +  (let (res)
> +    (while list
> +      (setq res (cons (cl-subseq list 0 (min n (length list))) res)
> +            list (nthcdr n list)))
> +    (nreverse res)))
> +
> +(defun which-key--list-to-pages (keys avl-lines avl-width)
> +  "Convert list of KEYS to columns based on dimensions AVL-LINES and AVL=
-WIDTH.
> +Returns a `which-key--pages' object that holds the page strings,
> +as well as metadata."
> +  (let ((cols-w-widths (mapcar (lambda (c) (which-key--pad-column c avl-=
width))
> +			       (which-key--partition-list avl-lines keys)))
> +        (page-width 0) (n-pages 0) (n-keys 0) (n-columns 0)
> +        page-cols pages page-widths keys/page col)
> +    (if (> (apply #'max (mapcar #'car cols-w-widths)) avl-width)

It probably won't cause any issues, but

  (cl-reduce #'max cols-w-widths :key #'car)

shouldn't run into issues with the maximum number of arguments you can
apply to a function.  Also saves you from consing a list.

> +        ;; give up if no columns fit
> +        nil
> +      (while cols-w-widths
> +        ;; start new page
> +        (cl-incf n-pages)
> +        (setq col (pop cols-w-widths))
> +        (setq page-cols (list (cdr col)))
> +        (setq page-width (car col))
> +        (setq n-keys (length (cdr col)))
> +        (setq n-columns 1)
> +        ;; add additional columns as long as they fit
> +        (while (and cols-w-widths
> +                    (or (null which-key-max-display-columns)
> +                        (< n-columns which-key-max-display-columns))
> +                    (<=3D (+ page-width 1 (caar cols-w-widths)) avl-widt=
h))
> +          (setq col (pop cols-w-widths))
> +          (push (cdr col) page-cols)
> +          (cl-incf page-width (1+ (car col)))
> +          (cl-incf n-keys (length (cdr col)))
> +          (cl-incf n-columns))
> +        (push (which-key--join-columns page-cols) pages)
> +        (push n-keys keys/page)
> +        (push page-width page-widths))
> +      (make-which-key--pages
> +       :pages (nreverse pages)
> +       :height (if (> n-pages 1) avl-lines (min avl-lines n-keys))
> +       :widths (nreverse page-widths)
> +       :keys/page (reverse keys/page)
> +       :page-nums (number-sequence 1 n-pages)
> +       :num-pages n-pages
> +       :total-keys (apply #'+ keys/page)))))
> +
> +(defun which-key--create-pages-1
> +    (keys available-lines available-width &optional min-lines vertical)
> +  "Create page strings using `which-key--list-to-pages'.
> +Will try to find the best number of rows and columns using the
> +given dimensions and the length and widths of ITEMS. Use VERTICAL
> +if the ITEMS are laid out vertically and the number of columns
> +should be minimized."
> +  (let ((result (which-key--list-to-pages
> +                 keys available-lines available-width))
> +        (min-lines (or min-lines 0))
> +        found prev-result)
> +    (if (or (null result)
> +            vertical
> +            (> (which-key--pages-num-pages result) 1)
> +            (=3D 1 available-lines))
> +        result
> +      ;; simple search for a fitting page
> +      (while (and (> available-lines min-lines)
> +                  (not found))
> +        (setq available-lines (- available-lines 1)
> +              prev-result result
> +              result (which-key--list-to-pages
> +                      keys available-lines available-width)
> +              found (> (which-key--pages-num-pages result) 1)))
> +      (if found prev-result result))))
> +
> +(defun which-key--create-pages (keys &optional prefix-keys prefix-title)
> +  "Create page strings using `which-key--list-to-pages'.
> +Will try to find the best number of rows and columns using the
> +given dimensions and the length and wdiths of KEYS. SEL-WIN-WIDTH
> +is the width of the live window."
> +  (let* ((max-dims (which-key--popup-max-dimensions))
> +         (max-lines (car max-dims))
> +         (max-width (cdr max-dims))
> +         (prefix-desc (key-description prefix-keys))
> +         (full-prefix (which-key--full-prefix prefix-desc))
> +         (prefix (when (eq which-key-show-prefix 'left)
> +                   (+ 2 (which-key--string-width full-prefix))))
> +         (prefix-top-bottom (member which-key-show-prefix '(bottom top)))
> +         (avl-lines (if prefix-top-bottom (- max-lines 1) max-lines))
> +         (min-lines (min avl-lines which-key-min-display-lines))
> +         (avl-width (if prefix (- max-width prefix) max-width))
> +         (vertical (or (and (eq which-key-popup-type 'side-window)
> +                            (member which-key-side-window-location '(lef=
t right)))
> +		       (eq which-key-max-display-columns 1)))
> +         result)
> +    (setq result
> +          (which-key--create-pages-1
> +           keys avl-lines avl-width min-lines vertical))
> +    (when (and result
> +               (> (which-key--pages-num-pages result) 0))
> +      (setf (which-key--pages-prefix result) prefix-keys)
> +      (setf (which-key--pages-prefix-title result)
> +            (or prefix-title
> +                (which-key--maybe-get-prefix-title
> +                 (key-description prefix-keys))))
> +      (when prefix-top-bottom
> +	;; Add back the line earlier reserved for the page information.
> +        (setf (which-key--pages-height result) max-lines))
> +      (when (and (=3D (which-key--pages-num-pages result) 1)
> +                 (> which-key-min-display-lines
> +                    (which-key--pages-height result)))
> +        ;; result is shorter than requested, so we artificially increase=
 the
> +        ;; height. See #325. Note this only has an effect if
> +        ;; `which-key-allow-imprecise-window-fit' is non-nil.
> +        (setf (which-key--pages-height result) which-key-min-display-lin=
es))
> +      (which-key--debug-message "Frame height: %s
> +Minibuffer height: %s
> +Max dimensions: (%s,%s)
> +Available for bindings: (%s,%s)
> +Actual lines: %s" (frame-height) (window-text-height (minibuffer-window))
> +max-lines max-width avl-lines avl-width (which-key--pages-height result))
> +      result)))
> +
> +(defun which-key--lighter-status ()
> +  "Possibly show number of keys and total in the mode line."
> +  (when which-key-show-remaining-keys
> +    (let ((n-shown (car (which-key--pages-keys/page which-key--pages-obj=
)))
> +          (n-tot (which-key--pages-total-keys which-key--pages-obj)))
> +      (setcar (cdr (assq 'which-key-mode minor-mode-alist))
> +              (format " WK: %s/%s keys" n-shown n-tot)))))
> +
> +(defun which-key--lighter-restore ()
> +  "Restore the lighter for which-key."
> +  (when which-key-show-remaining-keys
> +    (setcar (cdr (assq 'which-key-mode minor-mode-alist))
> +            which-key-lighter)))
> +
> +(defun which-key--echo (text)
> +  "Echo TEXT to minibuffer without logging."
> +  (let (message-log-max)
> +    (message "%s" text)))
> +
> +(defun which-key--next-page-hint (prefix-keys)
> +  "Return string for next page hint."
> +  (let* ((paging-key (concat prefix-keys " " which-key-paging-key))
> +         (paging-key-bound (eq 'which-key-C-h-dispatch
> +                               (key-binding (kbd paging-key))))
> +         (key (key-description (vector help-char)))
> +         (key (if paging-key-bound
> +                  (concat key " or " which-key-paging-key)
> +                key)))
> +    (when (and which-key-use-C-h-commands
> +               (not (equal (vector help-char)
> +                           (vconcat (kbd prefix-keys)))))
> +      (which-key--propertize (format "[%s paging/help]" key)
> +                             'face 'which-key-note-face))))
> +
> +(eval-and-compile
> +  (if (fboundp 'universal-argument--description)
> +      (defalias 'which-key--universal-argument--description
> +        #'universal-argument--description)
> +    (defun which-key--universal-argument--description ()
> +      ;; Backport of the definition of universal-argument--description in
> +      ;; emacs25 on 2015-12-04
> +      (when prefix-arg
> +        (concat "C-u"
> +                (pcase prefix-arg
> +                  (`(-) " -")
> +                  (`(,(and (pred integerp) n))
> +                   (let ((str ""))
> +                     (while (and (> n 4) (=3D (mod n 4) 0))
> +                       (setq str (concat str " C-u"))
> +                       (setq n (/ n 4)))
> +                     (if (=3D n 4) str (format " %s" prefix-arg))))
> +                  (_ (format " %s" prefix-arg))))))))
> +
> +(defun which-key--full-prefix (prefix-keys &optional -prefix-arg dont-pr=
op-keys)
> +  "Return a description of the full key sequence up to now,
> +including prefix arguments."
> +  (let* ((left (eq which-key-show-prefix 'left))
> +         (prefix-arg (if -prefix-arg -prefix-arg prefix-arg))
> +         (str (concat
> +               (which-key--universal-argument--description)
> +               (when prefix-arg " ")
> +               prefix-keys))
> +         (dash (if (and (not (string=3D prefix-keys ""))
> +                        (null left)) "-" "")))
> +    (if (or (eq which-key-show-prefix 'echo) dont-prop-keys)
> +        (concat str dash)
> +      (concat (which-key--propertize-key str)
> +              (which-key--propertize dash 'face 'which-key-key-face)))))
> +
> +(defun which-key--get-popup-map ()
> +  "Generate transient-map for use in the top level binding display."
> +  (unless which-key--automatic-display
> +    (let ((map (make-sparse-keymap)))
> +      (define-key map (kbd which-key-paging-key) #'which-key-C-h-dispatc=
h)
> +      (when which-key-use-C-h-commands
> +        ;; Show next page even when C-h is pressed
> +        (define-key map (vector help-char) #'which-key-C-h-dispatch))
> +      map)))
> +
> +(defun which-key--process-page (pages-obj)
> +  "Add information to the basic list of key bindings, including
> +if applicable the current prefix, the name of the current prefix,
> +and a page count."
> +  (let* ((page (car (which-key--pages-pages pages-obj)))
> +         (height (which-key--pages-height pages-obj))
> +         (n-pages (which-key--pages-num-pages pages-obj))
> +         (page-n (car (which-key--pages-page-nums pages-obj)))
> +         (prefix-desc (key-description (which-key--pages-prefix pages-ob=
j)))
> +         (prefix-title (which-key--pages-prefix-title pages-obj))
> +         (full-prefix (which-key--full-prefix prefix-desc))
> +         (nxt-pg-hint (which-key--next-page-hint prefix-desc))
> +         ;; not used in left case
> +         (status-line
> +          (concat (which-key--propertize prefix-title 'face 'which-key-n=
ote-face)
> +                  (when (< 1 n-pages)
> +                    (which-key--propertize (format " (%s of %s)" page-n =
n-pages)
> +                                           'face 'which-key-note-face)))=
))
> +    (pcase which-key-show-prefix
> +      (`left

There is no need for a backtick here.

> +       (let* ((page-cnt (which-key--propertize (format "%s/%s" page-n n-=
pages)
> +                                               'face 'which-key-separato=
r-face))
> +              (first-col-width (+ 2 (max (which-key--string-width full-p=
refix)
> +                                         (which-key--string-width page-c=
nt))))
> +              (prefix (format (concat "%-" (int-to-string first-col-widt=
h) "s")
> +                              full-prefix))
> +              (page-cnt (if (> n-pages 1)
> +                            (format
> +                             (concat "%-" (int-to-string first-col-width=
) "s")
> +                             page-cnt)
> +                          (make-string first-col-width 32)))
> +              lines first-line new-end)
> +         (if (=3D 1 height)
> +             (cons (concat prefix page) nil)
> +           (setq lines (split-string page "\n")
> +                 first-line (concat prefix (car lines) "\n" page-cnt)
> +                 new-end (concat "\n" (make-string first-col-width 32)))
> +           (cons
> +            (concat first-line (mapconcat #'identity (cdr lines) new-end=
))
> +            nil))))
> +      (`top
> +       (cons
> +        (concat (when (or (=3D 0 echo-keystrokes)
> +                          (not (eq which-key-side-window-location 'botto=
m)))
> +                  (concat full-prefix " "))
> +                status-line " " nxt-pg-hint "\n" page)
> +        nil))
> +      (`bottom
> +       (cons
> +        (concat page "\n"
> +                (when (or (=3D 0 echo-keystrokes)
> +                          (not (eq which-key-side-window-location 'botto=
m)))
> +                  (concat full-prefix " "))
> +                status-line " " nxt-pg-hint)
> +        nil))
> +      (`echo
> +       (cons page
> +             (lambda ()
> +               (which-key--echo
> +                (concat full-prefix (when prefix-desc " ")
> +                        status-line (when status-line " ")
> +                        nxt-pg-hint)))))
> +      (`mode-line
> +       (cons page
> +             (lambda ()
> +               (with-current-buffer which-key--buffer
> +                 (setq-local mode-line-format
> +                             (concat " " full-prefix
> +                                     " " status-line
> +                                     " " nxt-pg-hint))))))
> +      (_ (cons page nil)))))
> +
> +(defun which-key--show-page (&optional n)
> +  "Show current page.
> +N changes the current page to the Nth page relative to the
> +current one."
> +  (which-key--init-buffer) ;; in case it was killed
> +  (let ((prefix-keys (which-key--current-key-string))
> +        golden-ratio-mode)

What is this?

> +    (if (null which-key--pages-obj)
> +        (message "%s- which-key can't show keys: There is not \
> +enough space based on your settings and frame size." prefix-keys)
> +      (when n
> +        (setq which-key--pages-obj
> +              (which-key--pages-set-current-page which-key--pages-obj n)=
))
> +      (let ((page-echo (which-key--process-page which-key--pages-obj))
> +            (height (which-key--pages-height which-key--pages-obj))
> +            (width (car (which-key--pages-widths which-key--pages-obj))))
> +        (which-key--lighter-status)
> +        (if (eq which-key-popup-type 'minibuffer)
> +            (which-key--echo (car page-echo))
> +          (with-current-buffer which-key--buffer
> +            (erase-buffer)
> +            (insert (car page-echo))
> +            (goto-char (point-min)))
> +          (when (cdr page-echo) (funcall (cdr page-echo)))
> +          (which-key--show-popup (cons height width)))))
> +    ;; used for paging at top-level
> +    (if (fboundp 'set-transient-map)
> +        (set-transient-map (which-key--get-popup-map))
> +      (with-no-warnings

If you disable warnings, you should explain why you are doing that.

> +        (set-temporary-overlay-map (which-key--get-popup-map))))))
> +
> +;;; Paging functions
> +
> +;;;###autoload
> +(defun which-key-reload-key-sequence (&optional key-seq)
> +  "Simulate entering the key sequence KEY-SEQ.
> +KEY-SEQ should be a list of events as produced by
> +`listify-key-sequence'. If nil, KEY-SEQ defaults to
> +`which-key--current-key-list'. Any prefix arguments that were
> +used are reapplied to the new key sequence."
> +  (let* ((key-seq (or key-seq (which-key--current-key-list)))
> +         (next-event (mapcar (lambda (ev) (cons t ev)) key-seq)))
> +    (setq prefix-arg current-prefix-arg
> +          unread-command-events next-event)))
> +
> +(defun which-key-turn-page (delta)
> +  "Show the next page of keys."
> +  (which-key-reload-key-sequence)
> +  (if which-key--last-try-2-loc
> +      (let ((which-key-side-window-location which-key--last-try-2-loc)
> +            (which-key--multiple-locations t))
> +        (which-key--show-page delta))
> +    (which-key--show-page delta))
> +  (which-key--start-paging-timer))
> +
> +;;;###autoload
> +(defun which-key-show-standard-help (&optional _)
> +  "Call the command in `which-key--prefix-help-cmd-backup'.
> +Usually this is `describe-prefix-bindings'."
> +  (interactive)
> +  (let ((which-key-inhibit t)
> +        (popup-showing (which-key--popup-showing-p)))
> +    (which-key--hide-popup-ignore-command)
> +    (cond ((and (eq which-key--prefix-help-cmd-backup
> +                    'describe-prefix-bindings)
> +                ;; If the popup is not showing, we call
> +                ;; `describe-prefix-bindings' directly.
> +                popup-showing)
> +           ;; This is essentially what `describe-prefix-bindings' does. =
We can't
> +           ;; use this function directly, because the prefix will not be=
 correct
> +           ;; when we enter using `which-key-C-h-dispatch'.
> +           (describe-bindings (kbd (which-key--current-key-string))))
> +          ((functionp which-key--prefix-help-cmd-backup)
> +           (funcall which-key--prefix-help-cmd-backup)))))
> +
> +;;;###autoload
> +(defun which-key-show-next-page-no-cycle ()
> +  "Show next page of keys unless on the last page, in which case
> +call `which-key-show-standard-help'."
> +  (interactive)
> +  (let ((which-key-inhibit t))
> +    (if (which-key--on-last-page)
> +        (which-key-show-standard-help)
> +      (which-key-turn-page 1))))
> +
> +;;;###autoload
> +(defun which-key-show-previous-page-no-cycle ()
> +  "Show previous page of keys unless on the first page, in which
> +case do nothing."
> +  (interactive)
> +  (let ((which-key-inhibit t))
> +    (unless (which-key--on-first-page)
> +      (which-key-turn-page -1))))
> +
> +;;;###autoload
> +(defun which-key-show-next-page-cycle (&optional _)
> +  "Show the next page of keys, cycling from end to beginning
> +after last page."
> +  (interactive)
> +  (let ((which-key-inhibit t))
> +    (which-key-turn-page 1)))
> +
> +;;;###autoload
> +(defun which-key-show-previous-page-cycle (&optional _)
> +  "Show the previous page of keys, cycling from beginning to end
> +after first page."
> +  (interactive)
> +  (let ((which-key-inhibit t))
> +    (which-key-turn-page -1)))
> +
> +;;;###autoload
> +(defun which-key-show-top-level (&optional _)
> +  "Show top-level bindings."
> +  (interactive)
> +  (which-key--create-buffer-and-show nil nil nil "Top-level bindings"))
> +
> +;;;###autoload
> +(defun which-key-show-major-mode (&optional all)
> +  "Show top-level bindings in the map of the current major mode.
> +
> +This function will also detect evil bindings made using
> +`evil-define-key' in this map. These bindings will depend on the
> +current evil state. "
> +  (interactive "P")
> +  (let ((map-sym (intern (format "%s-map" major-mode))))
> +    (if (and (boundp map-sym) (keymapp (symbol-value map-sym)))
> +        (which-key--show-keymap
> +         "Major-mode bindings"
> +         (symbol-value map-sym)
> +         (apply-partially #'which-key--map-binding-p (symbol-value map-s=
ym))
> +         all)
> +      (message "which-key: No map named %s" map-sym))))
> +
> +;;;###autoload
> +(defun which-key-show-full-major-mode ()
> +  "Show all bindings in the map of the current major mode.
> +
> +This function will also detect evil bindings made using
> +`evil-define-key' in this map. These bindings will depend on the
> +current evil state. "
> +  (interactive)
> +  (which-key-show-major-mode t))
> +
> +;;;###autoload
> +(defun which-key-dump-bindings (prefix buffer-name)
> +  "Dump bindings from PREFIX into buffer named BUFFER-NAME.
> +
> +PREFIX should be a string suitable for `kbd'."
> +  (interactive "sPrefix: \nB")
> +  (let* ((buffer (get-buffer-create buffer-name))
> +         (keys (which-key--get-bindings (kbd prefix))))
> +    (with-current-buffer buffer
> +      (point-max)
> +      (save-excursion
> +        (dolist (key keys)
> +          (insert (apply #'format "%s%s%s\n" key)))))
> +    (switch-to-buffer-other-window buffer)))
> +
> +;;;###autoload
> +(defun which-key-undo-key (&optional _)
> +  "Undo last keypress and force which-key update."
> +  (interactive)
> +  (let* ((key-lst (butlast (which-key--current-key-list)))
> +         (which-key-inhibit t))
> +    (cond (which-key--prior-show-keymap-args
> +           (if (keymapp (cdr (car-safe which-key--prior-show-keymap-args=
)))
> +               (let ((args (pop which-key--prior-show-keymap-args)))
> +                 (which-key--show-keymap (car args) (cdr args)))
> +             (which-key--hide-popup)))
> +          (key-lst
> +           (which-key-reload-key-sequence key-lst)
> +           (which-key--create-buffer-and-show (apply #'vector key-lst)))
> +          (t (setq which-key--automatic-display nil)
> +             (which-key-show-top-level)))))
> +(defalias 'which-key-undo #'which-key-undo-key)
> +
> +(defun which-key-abort (&optional _)
> +  "Abort key sequence."
> +  (interactive)
> +  (let ((which-key-inhibit t))
> +    (which-key--hide-popup-ignore-command)
> +    (keyboard-quit)))
> +
> +(defun which-key-digit-argument (key)
> +  "Version of `digit-argument' for use in `which-key-C-h-map'."
> +  (interactive)
> +  (let ((last-command-event (string-to-char key)))
> +    (digit-argument key))
> +  (let ((current-prefix-arg prefix-arg))
> +    (which-key-reload-key-sequence)))
> +
> +(defun which-key-toggle-docstrings (&optional _)
> +  "Toggle the display of docstrings."
> +  (interactive)
> +  (unless (eq which-key-show-docstrings 'docstring-only)
> +    (setq which-key-show-docstrings (null which-key-show-docstrings)))
> +  (which-key-reload-key-sequence)
> +  (which-key--create-buffer-and-show (which-key--current-prefix)))
> +
> +;;;###autoload
> +(defun which-key-C-h-dispatch ()
> +  "Dispatch C-h commands by looking up key in
> +`which-key-C-h-map'. This command is always accessible (from any
> +prefix) if `which-key-use-C-h-commands' is non nil."
> +  (interactive)
> +  (cond ((and (not (which-key--popup-showing-p))
> +              which-key-show-early-on-C-h)
> +         (let ((current-prefix
> +                (butlast
> +                 (listify-key-sequence (which-key--this-command-keys)))))
> +           (which-key-reload-key-sequence current-prefix)
> +           (if which-key-idle-secondary-delay
> +               (which-key--start-timer which-key-idle-secondary-delay t)
> +             (which-key--start-timer 0.05 t))))
> +        ((not (which-key--popup-showing-p))
> +         (which-key-show-standard-help))
> +        (t
> +         (if (not (which-key--popup-showing-p))
> +             (which-key-show-standard-help)
> +           (let* ((prefix-keys (which-key--current-key-string))
> +                  (full-prefix (which-key--full-prefix prefix-keys curre=
nt-prefix-arg t))
> +                  (prompt (concat (when (string-equal prefix-keys "")
> +                                    (which-key--propertize
> +                                     (concat " "
> +                                             (which-key--pages-prefix-ti=
tle
> +                                              which-key--pages-obj))
> +                                     'face 'which-key-note-face))
> +                                  full-prefix
> +                                  (which-key--propertize
> +                                   (substitute-command-keys
> +                                    which-key-C-h-map-prompt)
> +                                   'face 'which-key-note-face)))
> +                  (key (let ((key (read-key prompt)))
> +                         (if (numberp key)
> +                             (string key)
> +                           (vector key))))
> +                  (cmd (lookup-key which-key-C-h-map key))
> +                  (which-key-inhibit t))
> +             (if cmd (funcall cmd key) (which-key-turn-page 0)))))))
> +
> +;;; Update
> +
> +(defun which-key--any-match-p (regexps string)
> +  "Non-nil if any of REGEXPS match STRING."
> +  (catch 'match
> +    (dolist (regexp regexps)
> +      (when (string-match-p regexp string)
> +        (throw 'match t)))))

You should be able to check this with a

  (string-match-p
   (string-join regexps "\\|")
   string)

> +
> +(defun which-key--try-2-side-windows
> +    (bindings prefix-keys prefix-title loc1 loc2 &rest _ignore)
> +  "Try to show BINDINGS (PAGE-N) in LOC1 first.
> +
> +Only if no bindings fit fallback to LOC2."
> +  (let (pages1)
> +    (let ((which-key-side-window-location loc1)
> +          (which-key--multiple-locations t))
> +      (setq pages1 (which-key--create-pages
> +                    bindings prefix-keys prefix-title)))
> +    (if pages1
> +        (progn
> +          (setq which-key--pages-obj pages1)
> +          (let ((which-key-side-window-location loc1)
> +                (which-key--multiple-locations t))
> +            (which-key--show-page))
> +          loc1)
> +      (let ((which-key-side-window-location loc2)
> +            (which-key--multiple-locations t))
> +        (setq which-key--pages-obj
> +              (which-key--create-pages bindings prefix-keys prefix-title=
))
> +        (which-key--show-page)
> +        loc2))))
> +
> +(defun which-key--read-keymap ()
> +  "Read keymap symbol from minibuffer."
> +  (intern
> +   (completing-read "Keymap: " obarray
> +                    (lambda (m)
> +                      (and (boundp m)
> +                           (keymapp (symbol-value m))
> +                           (not (equal (symbol-value m)
> +                                       (make-sparse-keymap)))))
> +                    t
> +                    (let ((sym (symbol-at-point)))
> +                      (and (boundp sym)
> +                           (keymapp (symbol-value sym))
> +                           (symbol-name sym)))
> +                    'which-key-keymap-history)))
> +
> +;;;###autoload
> +(defun which-key-show-keymap (keymap &optional no-paging)
> +  "Show the top-level bindings in KEYMAP using which-key.
> +KEYMAP is selected interactively from all available keymaps.
> +
> +If NO-PAGING is non-nil, which-key will not intercept subsequent
> +keypresses for the paging functionality."
> +  (interactive (list (which-key--read-keymap)))
> +  (which-key--show-keymap (symbol-name keymap)
> +                          (symbol-value keymap)
> +                          nil nil no-paging))
> +
> +;;;###autoload
> +(defun which-key-show-full-keymap (keymap)
> +  "Show all bindings in KEYMAP using which-key.
> +KEYMAP is selected interactively from all available keymaps."
> +  (interactive (list (which-key--read-keymap)))
> +  (which-key--show-keymap (symbol-name keymap)
> +                          (symbol-value keymap)
> +                          nil t))
> +
> +;;;###autoload
> +(defun which-key-show-minor-mode-keymap (&optional all)
> +  "Show the top-level bindings in KEYMAP using which-key.
> +KEYMAP is selected interactively by mode in
> +`minor-mode-map-alist'."
> +  (interactive)
> +  (let ((mode-sym
> +         (intern
> +          (completing-read
> +           "Minor Mode: "
> +           (mapcar #'car
> +                   (cl-remove-if-not
> +                    (lambda (entry)
> +                      (and (symbol-value (car entry))
> +                           (not (equal (cdr entry) (make-sparse-keymap))=
)))
> +                    minor-mode-map-alist))
> +           nil t nil 'which-key-keymap-history))))
> +    (which-key--show-keymap (symbol-name mode-sym)
> +                            (cdr (assq mode-sym minor-mode-map-alist))
> +                            all)))
> +;;;###autoload
> +(defun which-key-show-full-minor-mode-keymap ()
> +  "Show all bindings in KEYMAP using which-key.
> +KEYMAP is selected interactively by mode in
> +`minor-mode-map-alist'."
> +  (interactive)
> +  (which-key-show-minor-mode-keymap t))
> +
> +(defun which-key--show-keymap
> +    (keymap-name keymap &optional prior-args all no-paging filter)
> +  (when prior-args (push prior-args which-key--prior-show-keymap-args))
> +  (let ((bindings (which-key--get-bindings nil keymap filter all)))
> +    (if (=3D (length bindings) 0)

Prefer (null bindings).

> +        (message "which-key: No bindings found in %s" keymap-name)
> +      (cond ((listp which-key-side-window-location)
> +             (setq which-key--last-try-2-loc
> +                   (apply #'which-key--try-2-side-windows
> +                          bindings nil keymap-name
> +                          which-key-side-window-location)))
> +            (t (setq which-key--pages-obj
> +                     (which-key--create-pages bindings nil keymap-name))
> +               (which-key--show-page)))
> +      (unless no-paging
> +        (let* ((key (read-key))
> +               (key-desc (key-description (list key)))
> +               (next-def (lookup-key keymap (vector key))))
> +          (cond ((and which-key-use-C-h-commands
> +                      (numberp key) (=3D key help-char))
> +                 (which-key-C-h-dispatch))
> +                ((keymapp next-def)
> +                 (which-key--hide-popup-ignore-command)
> +                 (which-key--show-keymap
> +                  (concat keymap-name " " key-desc)
> +                  next-def
> +                  (cons keymap-name keymap)))
> +                (t (which-key--hide-popup))))))))
> +
> +(defun which-key--evil-operator-filter (binding)
> +  (let ((def (intern (cdr binding))))
> +    (and (functionp def)
> +         (not (evil-get-command-property def :suppress-operator)))))
> +
> +(defun which-key--show-evil-operator-keymap ()
> +  (if which-key--inhibit-next-operator-popup
> +      (setq which-key--inhibit-next-operator-popup nil)
> +    (let ((keymap
> +           (make-composed-keymap (list evil-operator-shortcut-map
> +                                       evil-operator-state-map
> +                                       evil-motion-state-map))))
> +      (when (keymapp keymap)
> +        (let ((formatted-keys
> +               (which-key--get-bindings
> +                nil keymap #'which-key--evil-operator-filter)))
> +          (cond ((=3D (length formatted-keys) 0)
> +                 (message "which-key: Keymap empty"))
> +                ((listp which-key-side-window-location)
> +                 (setq which-key--last-try-2-loc
> +                       (apply #'which-key--try-2-side-windows
> +                              formatted-keys nil "evil operator/motion k=
eys"
> +                              which-key-side-window-location)))
> +                (t (setq which-key--pages-obj
> +                         (which-key--create-pages
> +                          formatted-keys
> +                          nil "evil operator/motion keys"))
> +                   (which-key--show-page)))))
> +      (let* ((key (read-key)))
> +        (when (member key '(?f ?F ?t ?T ?`))
> +          ;; these keys trigger commands that read the next char manually
> +          (setq which-key--inhibit-next-operator-popup t))
> +        (cond ((and which-key-use-C-h-commands (numberp key) (=3D key he=
lp-char))
> +               (which-key-C-h-dispatch))
> +              ((and (numberp key) (=3D key ?\C-\[))
> +               (which-key--hide-popup)
> +               (keyboard-quit))
> +              (t
> +               (which-key--hide-popup)
> +               (setq unread-command-events (vector key))))))))
> +
> +(defun which-key--create-buffer-and-show
> +    (&optional prefix-keys from-keymap filter prefix-title)
> +  "Fill `which-key--buffer' with key descriptions and reformat.
> +Finally, show the buffer."
> +  (let ((start-time (current-time))
> +        (formatted-keys (which-key--get-bindings
> +                         prefix-keys from-keymap filter))
> +        (prefix-desc (key-description prefix-keys)))
> +    (cond ((=3D (length formatted-keys) 0)
> +           (message "%s-  which-key: There are no keys to show" prefix-d=
esc))
> +          ((listp which-key-side-window-location)
> +           (setq which-key--last-try-2-loc
> +                 (apply #'which-key--try-2-side-windows
> +                        formatted-keys prefix-keys prefix-title
> +                        which-key-side-window-location)))
> +          (t (setq which-key--pages-obj
> +                   (which-key--create-pages
> +                    formatted-keys prefix-keys prefix-title))
> +             (which-key--show-page)))
> +    (which-key--debug-message
> +     "On prefix \"%s\" which-key took %.0f ms." prefix-desc
> +     (* 1000 (float-time (time-since start-time))))))
> +
> +(defun which-key--this-command-keys ()
> +  "Version of `this-single-command-keys' corrected for key-chords and go=
d-mode."
> +  (let ((this-command-keys (this-single-command-keys)))
> +    (when (and (vectorp this-command-keys)
> +               (> (length this-command-keys) 0)
> +               (eq (aref this-command-keys 0) 'key-chord)
> +               (bound-and-true-p key-chord-mode))
> +      (setq this-command-keys (this-single-command-raw-keys)))
> +    (when (and which-key--god-mode-support-enabled
> +               (bound-and-true-p god-local-mode)
> +               (eq this-command 'god-mode-self-insert))
> +      (setq this-command-keys (when which-key--god-mode-key-string
> +                                (kbd which-key--god-mode-key-string))))
> +    this-command-keys))
> +
> +(defun which-key--update ()
> +  "Function run by timer to possibly trigger
> +`which-key--create-buffer-and-show'."
> +  (let ((prefix-keys (which-key--this-command-keys))
> +        delay-time)
> +    (cond ((and (> (length prefix-keys) 0)
> +                (or (keymapp (key-binding prefix-keys))
> +                    ;; Some keymaps are stored here like iso-transl-ctl-=
x-8-map
> +                    (keymapp (which-key--safe-lookup-key
> +                              key-translation-map prefix-keys))
> +                    ;; just in case someone uses one of these
> +                    (keymapp (which-key--safe-lookup-key
> +                              function-key-map prefix-keys)))
> +                (not which-key-inhibit)
> +                (or (null which-key-allow-regexps)
> +                    (which-key--any-match-p
> +                     which-key-allow-regexps (key-description prefix-key=
s)))
> +                (or (null which-key-inhibit-regexps)
> +                    (not
> +                     (which-key--any-match-p
> +                      which-key-inhibit-regexps (key-description prefix-=
keys))))
> +                ;; Do not display the popup if a command is currently be=
ing
> +                ;; executed
> +                (or (and which-key-allow-evil-operators
> +                         (bound-and-true-p evil-this-operator))
> +                    (and which-key--god-mode-support-enabled
> +                         (bound-and-true-p god-local-mode)
> +                         (eq this-command 'god-mode-self-insert))
> +                    (null this-command))
> +                (let ((max-dim (which-key--popup-max-dimensions)))
> +                  (> (min (car-safe max-dim) (cdr-safe max-dim)) 0)))
> +           (when (and (not (equal prefix-keys (which-key--current-prefix=
)))
> +                      (or (null which-key-delay-functions)
> +                          (null (setq delay-time
> +                                      (run-hook-with-args-until-success
> +                                       'which-key-delay-functions
> +                                       (key-description prefix-keys)
> +                                       (length prefix-keys))))
> +                          (sit-for delay-time)))
> +             (setq which-key--automatic-display t)
> +             (which-key--create-buffer-and-show prefix-keys)
> +             (when (and which-key-idle-secondary-delay
> +                        (not which-key--secondary-timer-active))
> +               (which-key--start-timer which-key-idle-secondary-delay t)=
)))
> +          ((and which-key-show-transient-maps
> +                ;; Assuming that if this is not true we're in
> +                ;; `which-key-show-top-level', which would then be overw=
ritten.
> +                (> (length prefix-keys) 0)
> +                (keymapp overriding-terminal-local-map)
> +                ;; basic test for it being a hydra
> +                (not (eq (lookup-key overriding-terminal-local-map "\C-u=
")
> +                         'hydra--universal-argument)))
> +           (which-key--create-buffer-and-show
> +            nil overriding-terminal-local-map))
> +          ((and which-key-show-operator-state-maps
> +                (bound-and-true-p evil-state)
> +                (eq evil-state 'operator)
> +                (not (which-key--popup-showing-p)))
> +           (which-key--show-evil-operator-keymap))
> +          (which-key--automatic-display
> +           (which-key--hide-popup)))))
> +
> +;;; Timers
> +
> +(defun which-key--start-timer (&optional delay secondary)
> +  "Activate idle timer to trigger `which-key--update'."
> +  (which-key--stop-timer)
> +  (setq which-key--secondary-timer-active secondary)
> +  (setq which-key--timer
> +        (run-with-idle-timer (or delay which-key-idle-delay)
> +                             t #'which-key--update)))
> +
> +(defun which-key--stop-timer ()
> +  "Deactivate idle timer for `which-key--update'."
> +  (when which-key--timer (cancel-timer which-key--timer)))
> +
> +(defun which-key--start-paging-timer ()
> +  "Activate timer to restart which-key after paging."
> +  (when which-key--paging-timer (cancel-timer which-key--paging-timer))
> +  (which-key--stop-timer)
> +  (setq which-key--paging-timer
> +        (run-with-idle-timer
> +         0.2 t (lambda ()
> +                 (when (or (not (member real-last-command
> +                                        which-key--paging-functions))
> +                           (and (< 0 (length (this-single-command-keys)))
> +                                (not (equal (which-key--current-prefix)
> +                                            (which-key--this-command-key=
s)))))
> +                   (cancel-timer which-key--paging-timer)
> +                   (if which-key-idle-secondary-delay
> +                       ;; we haven't executed a command yet so the secan=
dary
> +                       ;; timer is more relevant here
> +                       (which-key--start-timer which-key-idle-secondary-=
delay t)
> +                     (which-key--start-timer)))))))
> +
> +(provide 'which-key)
> +;;; which-key.el ends here

My genera feeling is that the code is reinventing the wheel at a number
of places, which might make it more complicated to maintain in the long
term.  Looking for ways to slim down the codebase, perhaps by
deprecating some options, dropping support for third-party packages and
reusing existing functionality seems like something one should look into.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 6 Feb 2024 02:51:42 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Feb 05 21:51:42 2024
Received: from localhost ([127.0.0.1]:52965 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rXBYi-00042x-Ib
	for submit <at> debbugs.gnu.org; Mon, 05 Feb 2024 21:51:42 -0500
Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]:60608)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <justin@HIDDEN>) id 1rXBYc-00042e-FJ
 for 68929 <at> debbugs.gnu.org; Mon, 05 Feb 2024 21:51:38 -0500
Received: by mail-ed1-x532.google.com with SMTP id
 4fb4d7f45d1cf-5608f7fd83cso1041959a12.0
 for <68929 <at> debbugs.gnu.org>; Mon, 05 Feb 2024 18:51:21 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=burkett-cc.20230601.gappssmtp.com; s=20230601; t=1707187876; x=1707792676;
 darn=debbugs.gnu.org; 
 h=content-transfer-encoding:cc:to:subject:message-id:date:from
 :in-reply-to:references:mime-version:from:to:cc:subject:date
 :message-id:reply-to;
 bh=TVxfcz8Rr0nJWgCO3ERIgDL+F9/M72H+bSmgpseBhBY=;
 b=fbHoJQH8LB/Zm9YtMixbjRdsW1dcK555W+jNwKpeau93dzYunIkYmIU2BjHDvbfJfZ
 2lTVzY8B9dEyi3aqYGYrD/9nnzeJHTs9TfOsFLmDUTZiBzy1IJhAlHjihO6/cNSlgbnd
 MdE15pPdGkSsH+m/X7XedlxQz7zbEHQp/zS9asZeUgn7tjz4sVNfIrUb2YtrgATMNU+f
 7zWKBLytKiGG+JSN6GdSAC9ZTjkqATpIaJRjIkT95IlEIaidxyD+IsXOQmCdezChsa4S
 oegWlL2SEYrpfesVRXCvm0JvbwQoL3wMowHTqmYxz3IL5KgDXTUXQM+gP3tJR4TnTxQH
 YLzQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1707187876; x=1707792676;
 h=content-transfer-encoding:cc:to:subject:message-id:date:from
 :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=TVxfcz8Rr0nJWgCO3ERIgDL+F9/M72H+bSmgpseBhBY=;
 b=jWzoDV2RtVJlL1JCPzg/je2dFk31uGChJPyVLJd5/ALsDGVQfBNW0TPBi4G1O/4k3Z
 GobMrJA9KsPnu5iaSfstcQuz6jQn9SSjF6XMWWaJO5t95YoojuezTa21FAYwu8xhGa/m
 nE8OyYiN88g4xBhHjE9U1uoOOmiZndkOAto9jfK5muJ7Dx1bxadav1E+iZ2/D5iMYkqP
 8LeVuAZ8KAxTAyVbZx/YNRfuKJsDxAymMNsj3ixWrpWVhh6OphF+5LxKx4TRcy++yLz8
 dIajMvjCgvS7gTWlbLS8vkYXhdfyXgCNV0pjkf6hYYyDk+uviskZsXYu2FCUMiYOkKAV
 dXQw==
X-Gm-Message-State: AOJu0YxKif1VIF5yZSnUUm6WRJK+YNMEITnmpK0gnw1s+0znFgMJ8yla
 JNnLn+gJTZnlpkY7wVWVy59KXPzXVInsEpteqzAcn95x6vFwGDAY1mDOahsG8rvkoUyhgw2l2EL
 PqOiQkjiGXlx5iXRiFUed+g0+VnoQqqaLxSY9bQ==
X-Google-Smtp-Source: AGHT+IFmTi1uNovEV0T+SliVVdY4ePK5yDpR3gnzEtHnKaZqx+bJNwPLjM9sxA8MGrrVWYnNTvIRYwL38kfrguWTwJ0=
X-Received: by 2002:aa7:da50:0:b0:55f:a7d6:fd6a with SMTP id
 w16-20020aa7da50000000b0055fa7d6fd6amr567796eds.5.1707187875705; Mon, 05 Feb
 2024 18:51:15 -0800 (PST)
MIME-Version: 1.0
References: <871q9rvqbi.fsf@HIDDEN> <86wmrj148c.fsf@HIDDEN>
In-Reply-To: <86wmrj148c.fsf@HIDDEN>
From: Justin Burkett <justin@HIDDEN>
Date: Mon, 5 Feb 2024 21:51:04 -0500
Message-ID: <CAF8XuLgkTgHwZ12pY3s4e3j_evzAzfoCRtUutrmuPuHbN_8Rvg@HIDDEN>
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
To: Eli Zaretskii <eliz@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 68929
Cc: Jeremy Bryant <jb@HIDDEN>, 68929 <at> debbugs.gnu.org,
 monnier@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Thanks for the comments. I'll work on these.

On Mon, Feb 5, 2024 at 7:32=E2=80=AFAM Eli Zaretskii <eliz@HIDDEN> wrote:
>
> > Date: Sun, 04 Feb 2024 22:02:50 +0000
> > From:  Jeremy Bryant via "Bug reports for GNU Emacs,
> >  the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN>
> >
> > This patch brings the latest version of which-key from GNU ELPA into
> > Emacs core
> >
> > If suitable I will then work on the updates to user-facing aspects such=
 as
> > manual and NEWS.
>
> This "needs work"...  Based on a very superficial reading of this huge
> file:
>
> > +;; which-key provides the minor mode which-key-mode for Emacs. The mod=
e displays
>                                                                 ^^
> Two spaces between sentences in comments and doc strings, here and
> elsewhere.
>
> > +(defcustom which-key-idle-delay 1.0
> > +  "Delay (in seconds) for which-key buffer to popup.
> > +This variable should be set before activating `which-key-mode'.
> > +
> > +A value of zero might lead to issues, so a non-zero value is
> > +recommended
> > +(see https://github.com/justbur/emacs-which-key/issues/134)."
> > +  :group 'which-key
> > +  :type 'float)
>
> Please add a :version tag to all defcustom's and defface's.
>
>
> > +(defcustom which-key-idle-secondary-delay nil
> > +  "Once the which-key buffer shows once for a key sequence reduce
> > +the idle time to this amount (in seconds). This makes it possible
>
> The first sentence of a doc string should be a single complete
> sentence.  In this case I suggest
>
>   Number of seconds to reduce idle-timer delay after showing which-key on=
ce.
>
> > +(defcustom which-key-min-column-description-width 0
> > +  "Every column should at least have this width."
>
> This needs details, otherwise it's mot very useful.
>
> > +(defcustom which-key-unicode-correction 3
> > +  "Correction for wide unicode characters.
> > +Since we measure width in terms of the number of characters,
> > +Unicode characters that are wider than ASCII characters throw off
> > +the calculation for available width in the which-key buffer.  This
> > +variable allows you to adjust for the wide unicode characters by
> > +artificially reducing the available width in the buffer.
> > +
> > +The default of 3 means allow for the total extra width
> > +contributed by any wide unicode characters to be up to one
> > +additional ASCII character in the which-key buffer.  Increase this
> > +number if you are seeing characters get cutoff on the right side
> > +of the which-key popup."
>
> This seems to be a sub-optimal way of accounting for character widths.
> We have better ways, e.g., char-width, string-pixel-width etc.
>
> > +(defcustom which-key-dont-use-unicode nil
> > +  "If non-nil, don't use any unicode characters in default setup."
>
> This should mention the settings affected by it.
>
> Please go through all the doc strings and make sure they are
> sufficiently self-explanatory.
>
> Thanks.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at 68929 <at> debbugs.gnu.org:


Received: (at 68929) by debbugs.gnu.org; 5 Feb 2024 12:32:49 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Feb 05 07:32:49 2024
Received: from localhost ([127.0.0.1]:50697 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rWy9Z-0000H4-5r
	for submit <at> debbugs.gnu.org; Mon, 05 Feb 2024 07:32:49 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:45834)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1rWy9T-0000Gm-Vj
 for 68929 <at> debbugs.gnu.org; Mon, 05 Feb 2024 07:32:48 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1rWy9B-0005Rt-3i; Mon, 05 Feb 2024 07:32:25 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=Cdo2KRx9zIV8lwPGFfvvMDrLH0tElUgdWkF1aVH+Q1c=; b=Lv8oe3DBWabD
 +ik8aORtGs9cY0uZ3IyUZ0SDojh1V7q8L3M+h/+r3emh13LvIM6ajaIfBxiHoh2vLodJnEMaqcLmS
 QY9kNKRJIKz4Rv0B5ewNKLf1UcZOujN4X3ATSzZsJBn9YwFw651Q9FO7aEchTtaGanZBGmzwr3n9h
 HOshWHrF4Z+ibwv0gvOhJ/fcj6Jl3uMT/gcGktSh0gv+tlwh2RPycpnQ0ei7euGi8VZNMxc8LInP8
 iYUqO+Fe4GjtISLO69cOKBLrFmLpEUEeXZe/UGtTuDJ6ClzFDDgiUlc4Sb7A5vBpvcM3IvOYesZBh
 5uAwnd6CGb096YOhpc8IyQ==;
Date: Mon, 05 Feb 2024 14:32:19 +0200
Message-Id: <86wmrj148c.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Jeremy Bryant <jb@HIDDEN>
In-Reply-To: <871q9rvqbi.fsf@HIDDEN> (bug-gnu-emacs@HIDDEN)
Subject: Re: bug#68929: [PATCH] Copy which-key from GNU ELPA into core
References: <871q9rvqbi.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 68929
Cc: 68929 <at> debbugs.gnu.org, monnier@HIDDEN, justin@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> Date: Sun, 04 Feb 2024 22:02:50 +0000
> From:  Jeremy Bryant via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN>
> 
> This patch brings the latest version of which-key from GNU ELPA into
> Emacs core
> 
> If suitable I will then work on the updates to user-facing aspects such as
> manual and NEWS.

This "needs work"...  Based on a very superficial reading of this huge
file:

> +;; which-key provides the minor mode which-key-mode for Emacs. The mode displays
                                                                ^^
Two spaces between sentences in comments and doc strings, here and
elsewhere.

> +(defcustom which-key-idle-delay 1.0
> +  "Delay (in seconds) for which-key buffer to popup.
> +This variable should be set before activating `which-key-mode'.
> +
> +A value of zero might lead to issues, so a non-zero value is
> +recommended
> +(see https://github.com/justbur/emacs-which-key/issues/134)."
> +  :group 'which-key
> +  :type 'float)

Please add a :version tag to all defcustom's and defface's.


> +(defcustom which-key-idle-secondary-delay nil
> +  "Once the which-key buffer shows once for a key sequence reduce
> +the idle time to this amount (in seconds). This makes it possible

The first sentence of a doc string should be a single complete
sentence.  In this case I suggest

  Number of seconds to reduce idle-timer delay after showing which-key once.

> +(defcustom which-key-min-column-description-width 0
> +  "Every column should at least have this width."

This needs details, otherwise it's mot very useful.

> +(defcustom which-key-unicode-correction 3
> +  "Correction for wide unicode characters.
> +Since we measure width in terms of the number of characters,
> +Unicode characters that are wider than ASCII characters throw off
> +the calculation for available width in the which-key buffer.  This
> +variable allows you to adjust for the wide unicode characters by
> +artificially reducing the available width in the buffer.
> +
> +The default of 3 means allow for the total extra width
> +contributed by any wide unicode characters to be up to one
> +additional ASCII character in the which-key buffer.  Increase this
> +number if you are seeing characters get cutoff on the right side
> +of the which-key popup."

This seems to be a sub-optimal way of accounting for character widths.
We have better ways, e.g., char-width, string-pixel-width etc.

> +(defcustom which-key-dont-use-unicode nil
> +  "If non-nil, don't use any unicode characters in default setup."

This should mention the settings affected by it.

Please go through all the doc strings and make sure they are
sufficiently self-explanatory.

Thanks.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 5 Feb 2024 03:10:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 04 22:10:32 2024
Received: from localhost ([127.0.0.1]:50333 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rWpNP-0007Vn-LT
	for submit <at> debbugs.gnu.org; Sun, 04 Feb 2024 22:10:31 -0500
Received: from lists.gnu.org ([2001:470:142::17]:48176)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@HIDDEN>) id 1rWpNN-0007VZ-0X
 for submit <at> debbugs.gnu.org; Sun, 04 Feb 2024 22:10:29 -0500
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 <monnier@HIDDEN>)
 id 1rWpN5-00051i-Ap
 for bug-gnu-emacs@HIDDEN; Sun, 04 Feb 2024 22:10:11 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <monnier@HIDDEN>)
 id 1rWpN3-0008Vh-SX
 for bug-gnu-emacs@HIDDEN; Sun, 04 Feb 2024 22:10:11 -0500
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id E20CD441F20;
 Sun,  4 Feb 2024 22:10:08 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1707102607;
 bh=nGBEfsNb+JqC7TzmqxX8FAiDhnnjS0qOekebrTFgbiU=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=Oj95IE1NWnYjH3N5r+iwsQNrzApj9BQ1h7nc9A7TcC9cz5/d11yMhm3IORdwNPCy7
 oEEddNdc+bnmUGUFhhtuyeLPp5JfMRsox7f5z7kOJaoBtOqZlZoHsuUIoBuPyZw1gb
 a6YnWLpkZh8Wzk2o2si8uTutzqeH+BF8tQw6YJGgyQa+p7817TQpmxWAimUuo8sOHs
 CwL+H3IB0aL412iKw9/hKTs5cudQ+PZPSkHlkH+GOB9xqh9I3d5dUjjLEaQyydwoK3
 QEHitMNgz2xkGQbx8KbVVqotioZEkqUr+ChVcB5PKGyrxYXO61bKLpwVdVjlFkRIIb
 LXGIEKQgNJ3qg==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 8558A441C58;
 Sun,  4 Feb 2024 22:10:07 -0500 (EST)
Received: from pastel (69-165-153-17.dsl.teksavvy.com [69.165.153.17])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 5D6081202A0;
 Sun,  4 Feb 2024 22:10:07 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Justin Burkett <justin@HIDDEN>
Subject: Re: [PATCH] Copy which-key from GNU ELPA into core
In-Reply-To: <CAF8XuLg1n0RxKD4VtSPS1qWY-+KgF3z=MoPNvzHoA3kw6EhK=A@HIDDEN>
 (Justin Burkett's message of "Sun, 4 Feb 2024 21:15:19 -0500")
Message-ID: <jwvttmnzk71.fsf-monnier+emacs@HIDDEN>
References: <871q9rvqbi.fsf@HIDDEN>
 <CAF8XuLg1n0RxKD4VtSPS1qWY-+KgF3z=MoPNvzHoA3kw6EhK=A@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
Date: Sun, 04 Feb 2024 22:10:06 -0500
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.595 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DCC_CHECK                 1.1 Detected as bulk mail by DCC (dcc-servers.net)
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
 FSL_BULK_SIG            1.036 Bulk signature with no Unsubscribe
 T_SCC_BODY_TEXT_LINE    -0.01 -
X-SPAM-LEVEL: 
Received-SPF: pass client-ip=132.204.25.50;
 envelope-from=monnier@HIDDEN; helo=mailscanner.iro.umontreal.ca
X-Spam_score_int: -42
X-Spam_score: -4.3
X-Spam_bar: ----
X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3,
 SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
 T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: submit
Cc: Jeremy Bryant <jb@HIDDEN>, bug-gnu-emacs@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

> I can take care of this tomorrow, but otherwise feel free to make the move
> yourselves.

BTW, rather than adding a file, another way to add it to `emacs.git` is
by `git merge --allow-unrelated-histories`.
If you wan to do that, you'll want to first create a new commit which
moves the files to their "final" destination, like:

    git rm .gitignore .github Makefile LICENSE.md ...
    git mv which-key.el lisp/which-key.el
    git mv which-key-tests.el test/lisp/which-key-tests.el
    [ not sure what you plan to do with the README.org and image files. ]
    git commit -m 'Move files in preparation for merge into emacs.git'

and then you can `git merge` that new commit into Emacs, preserving
the history.


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 5 Feb 2024 03:09:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 04 22:09:32 2024
Received: from localhost ([127.0.0.1]:50328 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rWpMS-0007U3-8Q
	for submit <at> debbugs.gnu.org; Sun, 04 Feb 2024 22:09:32 -0500
Received: from lists.gnu.org ([2001:470:142::17]:50126)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@HIDDEN>) id 1rWpMM-0007Tn-T2
 for submit <at> debbugs.gnu.org; Sun, 04 Feb 2024 22:09:30 -0500
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 <monnier@HIDDEN>)
 id 1rWpM4-0004up-Vt
 for bug-gnu-emacs@HIDDEN; Sun, 04 Feb 2024 22:09:09 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <monnier@HIDDEN>)
 id 1rWpM3-00089V-15
 for bug-gnu-emacs@HIDDEN; Sun, 04 Feb 2024 22:09:08 -0500
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id C88D0100390;
 Sun,  4 Feb 2024 22:09:04 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1707102541;
 bh=nGBEfsNb+JqC7TzmqxX8FAiDhnnjS0qOekebrTFgbiU=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=eP2JSO+xCGtQQ3odUwvjnnzLuNj9UoPZLvPzeRF09QBl5z2Zk+2SgDYWfsvfzpG70
 Mo2fNa4xxjpn2KIgQil+wr/7gDWqj7xYe5DYMVg/Da/tjejcLmsFKsk+dF6AYcEpwC
 C9TOG5Dj1NByH4mDPEnGgHPVVPbWNGpooJklH2XnfKMXRL2sYduCAusoCXFhYfsJwh
 cYdANKxmjzgZfBiPnc0clBnKV1+zlaMe6qbzqnRqwAlVliB7n7aKHBSBqtGM2NpOIA
 nXqXdS2dUNpOlqjH3unq/+4TSoFQM91xDN4N0H9WSoAS4LB+AMZ/k++Wxp/qPO3P3Q
 T/BsEPILxcDlA==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 2BC08100301;
 Sun,  4 Feb 2024 22:09:01 -0500 (EST)
Received: from pastel (69-165-153-17.dsl.teksavvy.com [69.165.153.17])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id E3C4E12030A;
 Sun,  4 Feb 2024 22:09:00 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: Justin Burkett <justin@HIDDEN>
Subject: Re: [PATCH] Copy which-key from GNU ELPA into core
In-Reply-To: <CAF8XuLg1n0RxKD4VtSPS1qWY-+KgF3z=MoPNvzHoA3kw6EhK=A@HIDDEN>
 (Justin Burkett's message of "Sun, 4 Feb 2024 21:15:19 -0500")
Message-ID: <jwvttmnzk71.fsf-monnier+emacs@HIDDEN>
References: <871q9rvqbi.fsf@HIDDEN>
 <CAF8XuLg1n0RxKD4VtSPS1qWY-+KgF3z=MoPNvzHoA3kw6EhK=A@HIDDEN>
Date: Sun, 04 Feb 2024 22:08:59 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.299 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain T_SCC_BODY_TEXT_LINE    -0.01 -
X-SPAM-LEVEL: 
Received-SPF: pass client-ip=132.204.25.50;
 envelope-from=monnier@HIDDEN; helo=mailscanner.iro.umontreal.ca
X-Spam_score_int: -42
X-Spam_score: -4.3
X-Spam_bar: ----
X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3,
 SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
 T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: submit
Cc: Jeremy Bryant <jb@HIDDEN>, bug-gnu-emacs@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

> I can take care of this tomorrow, but otherwise feel free to make the move
> yourselves.

BTW, rather than adding a file, another way to add it to `emacs.git` is
by `git merge --allow-unrelated-histories`.
If you wan to do that, you'll want to first create a new commit which
moves the files to their "final" destination, like:

    git rm .gitignore .github Makefile LICENSE.md ...
    git mv which-key.el lisp/which-key.el
    git mv which-key-tests.el test/lisp/which-key-tests.el
    [ not sure what you plan to do with the README.org and image files. ]
    git commit -m 'Move files in preparation for merge into emacs.git'

and then you can `git merge` that new commit into Emacs, preserving
the history.


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 5 Feb 2024 02:15:58 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 04 21:15:58 2024
Received: from localhost ([127.0.0.1]:50314 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rWoWc-00065L-51
	for submit <at> debbugs.gnu.org; Sun, 04 Feb 2024 21:15:58 -0500
Received: from lists.gnu.org ([2001:470:142::17]:60972)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <justin@HIDDEN>) id 1rWoWY-000656-GA
 for submit <at> debbugs.gnu.org; Sun, 04 Feb 2024 21:15:56 -0500
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 <justin@HIDDEN>) id 1rWoWF-0006xo-AF
 for bug-gnu-emacs@HIDDEN; Sun, 04 Feb 2024 21:15:36 -0500
Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <justin@HIDDEN>) id 1rWoWC-0008Ci-Oq
 for bug-gnu-emacs@HIDDEN; Sun, 04 Feb 2024 21:15:34 -0500
Received: by mail-ed1-x534.google.com with SMTP id
 4fb4d7f45d1cf-55f279dca99so5572622a12.3
 for <bug-gnu-emacs@HIDDEN>; Sun, 04 Feb 2024 18:15:31 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=burkett-cc.20230601.gappssmtp.com; s=20230601; t=1707099330; x=1707704130;
 darn=gnu.org; 
 h=cc:to:subject:message-id:date:from:in-reply-to:references
 :mime-version:from:to:cc:subject:date:message-id:reply-to;
 bh=2OpqcqOkVHIUuqdxw7yTDlq2PiVfnPp5wcds7D+LEes=;
 b=HTd/+aF4RuJ8qLDrddzoQJUMy1My2npYtZdAJaud++SToCWCBFHXZi+HPK/xXOx4Ts
 9lIN41+NS7iSTYkUKzEuKq1xt+rLp7L/3C+qm/mt+v8laynOQaRmqs4Yr+SoSX/3x+6c
 7OSoZT79k+d8ShQVGhMr7L6qdAeD/iNeUE2oakJR3lW3oCHwpfujKiOKBCYyAi1y1jTn
 Et/uNwIZfTivaqlRqhkq/0a15VTHwg2+w27LDpNdFpH5L6EisJXSZi+AJpGCcmPRlLWr
 iPrmi6ct9oBZllHrO7CFwW/ILxAdAgBy/oYRgaaFsXZF3NipwoT24zP8XFof1VOUrFgU
 qpvA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1707099330; x=1707704130;
 h=cc:to:subject:message-id:date:from:in-reply-to:references
 :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=2OpqcqOkVHIUuqdxw7yTDlq2PiVfnPp5wcds7D+LEes=;
 b=Zo/80jRVz9OFqKOi0FRM7VES1W+Q5TDQXH813m1Wk6zD20dLzbq1LiDqCSWyND+ePl
 Y8Dsrbe/1hD77ZSnWM1eLU+GwmPmo1jScOIQJ/Eo0C96jNQP+akrC31EG91Ju9Oqr1yy
 lXsbOzEjg6hqwGgpKR71Uz8fNXTRbjfgLiq0xstX2REFlkvAvAOK39UQLtiB2XsAV1Lf
 c7SykHkPPerExvPVXuOqrchSI27H3uZKz7imbybqeXCV7B8sPh4Llj5xuzOSJ8SZV9z8
 +YkWwXINWsfaJH4IgkKrUnp91T4u67lXDw82p+dexGrj0siKbFjM/18QnWLAYDPTkpjr
 tnDw==
X-Forwarded-Encrypted: i=0;
 AJvYcCUUQGw/D4YoqVjqRyFR+QL7q3r0oh0vjNlASVTAMBDPvMxw8bzTWlR/JjGzUUhe9VMlaFvmWIAYUldLku9pNXfRzKaLh8M=
X-Gm-Message-State: AOJu0Yx8o4BjO6ECT0YWqHMeoib5tepU5ZyMlVw4JOzbPZnCWj01worN
 6KfCt9mK/zCiiofCIbxlgfBVgO+KuTnDHwk/rueRhB1yL4j4DbinRCBI3KhyMR6D1gOW1q7J78W
 f6KGFfnmCdl1SfDtkQiUojm19dCVnR6mYzAuuug==
X-Google-Smtp-Source: AGHT+IG3hXc1l4QR8VMJU19oxGf1cidgsdERQsdXp+vJXCdoydCdg0fI7EeDvvod0jfOkjTVl3cpy+zGx+M9tvBL+qg=
X-Received: by 2002:a05:6402:3588:b0:560:5e66:6952 with SMTP id
 y8-20020a056402358800b005605e666952mr1240002edc.42.1707099330355; Sun, 04 Feb
 2024 18:15:30 -0800 (PST)
MIME-Version: 1.0
References: <871q9rvqbi.fsf@HIDDEN>
In-Reply-To: <871q9rvqbi.fsf@HIDDEN>
From: Justin Burkett <justin@HIDDEN>
Date: Sun, 4 Feb 2024 21:15:19 -0500
Message-ID: <CAF8XuLg1n0RxKD4VtSPS1qWY-+KgF3z=MoPNvzHoA3kw6EhK=A@HIDDEN>
Subject: Re: [PATCH] Copy which-key from GNU ELPA into core
To: Jeremy Bryant <jb@HIDDEN>
Content-Type: multipart/alternative; boundary="0000000000002eb35506109909a1"
Received-SPF: none client-ip=2a00:1450:4864:20::534;
 envelope-from=justin@HIDDEN; helo=mail-ed1-x534.google.com
X-Spam_score_int: -18
X-Spam_score: -1.9
X-Spam_bar: -
X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001,
 SPF_HELO_NONE=0.001, SPF_NONE=0.001,
 T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: submit
Cc: bug-gnu-emacs@HIDDEN, Stefan Monnier <monnier@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--0000000000002eb35506109909a1
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

I can take care of this tomorrow, but otherwise feel free to make the move
yourselves.

Justin

On Sun, Feb 4, 2024 at 5:04=E2=80=AFPM Jeremy Bryant <jb@HIDDEN> =
wrote:

> Tags: patch
>
> This patch brings the latest version of which-key from GNU ELPA into
> Emacs core
>
> If suitable I will then work on the updates to user-facing aspects such a=
s
> manual and NEWS.
>
>

--0000000000002eb35506109909a1
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">I can take care of this tomorrow, but otherwise feel free=
 to make the move yourselves.=C2=A0</div><div dir=3D"auto"><br></div><div d=
ir=3D"auto">Justin</div><div><br><div class=3D"gmail_quote"><div dir=3D"ltr=
" class=3D"gmail_attr">On Sun, Feb 4, 2024 at 5:04=E2=80=AFPM Jeremy Bryant=
 &lt;<a href=3D"mailto:jb@HIDDEN">jb@HIDDEN</a>&gt; wro=
te:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;b=
order-left:1px #ccc solid;padding-left:1ex">Tags: patch<br>
<br>
This patch brings the latest version of which-key from GNU ELPA into<br>
Emacs core<br>
<br>
If suitable I will then work on the updates to user-facing aspects such as<=
br>
manual and NEWS.<br>
<br>
</blockquote></div></div>

--0000000000002eb35506109909a1--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 4 Feb 2024 22:05:33 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 04 17:05:33 2024
Received: from localhost ([127.0.0.1]:50119 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rWkcG-0008GP-T4
	for submit <at> debbugs.gnu.org; Sun, 04 Feb 2024 17:05:32 -0500
Received: from lists.gnu.org ([2001:470:142::17]:47264)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jb@HIDDEN>) id 1rWkcF-0008G4-6H
 for submit <at> debbugs.gnu.org; Sun, 04 Feb 2024 17:05:31 -0500
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 <jb@HIDDEN>)
 id 1rWkbt-0002Pu-4K
 for bug-gnu-emacs@HIDDEN; Sun, 04 Feb 2024 17:05:09 -0500
Received: from out-174.mta0.migadu.com ([2001:41d0:1004:224b::ae])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <jb@HIDDEN>)
 id 1rWkbk-0006sT-1e
 for bug-gnu-emacs@HIDDEN; Sun, 04 Feb 2024 17:05:07 -0500
X-Report-Abuse: Please report any abuse attempt to abuse@HIDDEN and
 include these headers.
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net;
 s=key1; t=1707084295;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:mime-version:mime-version:content-type:content-type;
 bh=9NjavrmSUQpC5RKwUMLX5vnDUk7J197d8H0x7xZ7kpE=;
 b=I1nr8o1BTBxa3eW1dzMwKqtpaRnr3acNUmf9VoqCe/e3Dk7YzgyHi7MeNxb78NCrKgIJ7Q
 MQrzDLgWfItomEl+NJ7L+EOh9ACqBGjMMHL3qXiOYHfwYcyVG/08PqvzZft/qKfEcPG6AO
 2Vqx459zvDbtvOZ9cm65/NdZGgsgOL/gPIqGW81erWusZHasXxmtH6F/jVwIqVRfoh2fhA
 GbnWG33HfsilfxraTqy9CrZBpziIQGHskW2+AhiQ55nytPPlS7vywG9FDRqhDiuP1KRLl9
 Hr2uIm/FTXUwwQcM749pRTPaR5b8f9/JK4DCH9HNiZ43pnCYjeffkHwhDbchNg==
From: Jeremy Bryant <jb@HIDDEN>
To: bug-gnu-emacs@HIDDEN, Stefan Monnier <monnier@HIDDEN>, Justin
 Burkett <justin@HIDDEN>
Subject: [PATCH] Copy which-key from GNU ELPA into core
Date: Sun, 04 Feb 2024 22:02:50 +0000
Message-ID: <871q9rvqbi.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Migadu-Flow: FLOW_OUT
Received-SPF: pass client-ip=2001:41d0:1004:224b::ae;
 envelope-from=jb@HIDDEN; helo=out-174.mta0.migadu.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>

--=-=-=
Content-Type: text/plain

Tags: patch

This patch brings the latest version of which-key from GNU ELPA into
Emacs core

If suitable I will then work on the updates to user-facing aspects such as
manual and NEWS.


--=-=-=
Content-Type: text/patch; charset=utf-8
Content-Disposition: attachment;
 filename=0001-lisp-which-key.el-Display-available-keybindings-in-p.patch
Content-Transfer-Encoding: quoted-printable

From 1a3207344a18b6743772927b6f8f709b05246a51 Mon Sep 17 00:00:00 2001
From: Jeremy Bryant <jb@HIDDEN>
Date: Sun, 4 Feb 2024 21:56:16 +0000
Subject: [PATCH] * lisp/which-key.el:  Display available keybindings in pop=
up

Copy feature which-key from GNU ELPA
---
 lisp/which-key.el | 2753 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 2753 insertions(+)
 create mode 100644 lisp/which-key.el

diff --git a/lisp/which-key.el b/lisp/which-key.el
new file mode 100644
index 00000000000..d68942cf8b1
--- /dev/null
+++ b/lisp/which-key.el
@@ -0,0 +1,2753 @@
+;;; which-key.el --- Display available keybindings in popup  -*- lexical-b=
inding: t; -*-
+
+;; Copyright (C) 2017-2021  Free Software Foundation, Inc.
+
+;; Author: Justin Burkett <justin@HIDDEN>
+;; Maintainer: Justin Burkett <justin@HIDDEN>
+;; URL: https://github.com/justbur/emacs-which-key
+;; Version: 3.6.0
+;; Keywords:
+;; Package-Requires: ((emacs "24.4"))
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; which-key provides the minor mode which-key-mode for Emacs. The mode di=
splays
+;; the key bindings following your currently entered incomplete command (a
+;; prefix) in a popup. For example, after enabling the minor mode if you e=
nter
+;; C-x and wait for the default of 1 second the minibuffer will expand wit=
h all
+;; of the available key bindings that follow C-x (or as many as space allo=
ws
+;; given your settings). This includes prefixes like C-x 8 which are shown=
 in a
+;; different face. Screenshots of what the popup will look like along with
+;; information about additional features can be found at
+;; https://github.com/justbur/emacs-which-key.
+;;
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'button)
+(require 'regexp-opt)
+
+;; For compiler
+(defvar evil-operator-shortcut-map)
+(defvar evil-operator-state-map)
+(defvar evil-motion-state-map)
+(defvar golden-ratio-mode)
+(declare-function evil-get-command-property "ext:evil-common.el")
+
+;;; Options
+
+(defgroup which-key nil
+  "Customization options for which-key-mode"
+  :group 'help
+  :prefix "which-key-")
+
+(defcustom which-key-idle-delay 1.0
+  "Delay (in seconds) for which-key buffer to popup.
+This variable should be set before activating `which-key-mode'.
+
+A value of zero might lead to issues, so a non-zero value is
+recommended
+(see https://github.com/justbur/emacs-which-key/issues/134)."
+  :group 'which-key
+  :type 'float)
+
+(defcustom which-key-idle-secondary-delay nil
+  "Once the which-key buffer shows once for a key sequence reduce
+the idle time to this amount (in seconds). This makes it possible
+to shorten the delay for subsequent popups in the same key
+sequence. The default is for this value to be nil, which disables
+this behavior."
+  :group 'which-key
+  :type '(choice float (const :tag "Disabled" nil)))
+
+(defcustom which-key-echo-keystrokes (if (and echo-keystrokes
+                                              (> (+ echo-keystrokes 0.01)
+                                                 which-key-idle-delay))
+                                         (/ (float which-key-idle-delay) 4)
+                                       echo-keystrokes)
+  "Value to use for `echo-keystrokes'.
+This only applies if `which-key-popup-type' is minibuffer or
+`which-key-show-prefix' is echo. It needs to be less than
+`which-key-idle-delay' or else the keystroke echo will erase the
+which-key popup."
+  :group 'which-key
+  :type 'float)
+
+(defcustom which-key-max-description-length 27
+  "Truncate the description of keys to this length.
+Either nil (no truncation), an integer (truncate after that many
+characters), a float (use that fraction of the available width),
+or a function, which takes one argument, the available width in
+characters, and whose return value has one of the types mentioned
+before.  Truncation is done using `which-key-ellipsis'."
+  :group 'which-key
+  :type '(choice (const :tag "Disable truncation" nil)
+		 (integer :tag "Width in characters")
+		 (float :tag "Use fraction of available width")
+		 function))
+
+(defcustom which-key-min-column-description-width 0
+  "Every column should at least have this width."
+  :group 'which-key
+  :type 'integer)
+
+(defcustom which-key-add-column-padding 0
+  "Additional padding (number of spaces) to add to the left of
+each key column."
+  :group 'which-key
+  :type 'integer)
+
+(defcustom which-key-unicode-correction 3
+  "Correction for wide unicode characters.
+Since we measure width in terms of the number of characters,
+Unicode characters that are wider than ASCII characters throw off
+the calculation for available width in the which-key buffer.  This
+variable allows you to adjust for the wide unicode characters by
+artificially reducing the available width in the buffer.
+
+The default of 3 means allow for the total extra width
+contributed by any wide unicode characters to be up to one
+additional ASCII character in the which-key buffer.  Increase this
+number if you are seeing characters get cutoff on the right side
+of the which-key popup."
+  :group 'which-key
+  :type 'integer)
+
+(defcustom which-key-dont-use-unicode nil
+  "If non-nil, don't use any unicode characters in default setup."
+  :group 'which-key
+  :type 'boolean)
+
+(defcustom which-key-separator
+  (if which-key-dont-use-unicode " : " " =E2=86=92 ")
+  "Separator to use between key and description. Default is \" =E2=86=92
+\", unless `which-key-dont-use-unicode' is non nil, in which case
+the default is \" : \"."
+  :group 'which-key
+  :type 'string)
+
+(defcustom which-key-ellipsis
+  (if which-key-dont-use-unicode ".." "=E2=80=A6")
+  "Ellipsis to use when truncating.
+Default is \"=E2=80=A6\", unless `which-key-dont-use-unicode' is non nil,
+in which case the default is \"..\".  This can also be the empty
+string to truncate without using any ellipsis."
+  :group 'which-key
+  :type 'string)
+
+(defcustom which-key-prefix-prefix "+"
+  "String to insert in front of prefix commands (i.e., commands
+that represent a sub-map). Default is \"+\"."
+  :group 'which-key
+  :type 'string)
+
+(defcustom which-key-compute-remaps nil
+  "If non-nil, show remapped command if a command has been
+remapped given the currently active keymaps."
+  :group 'which-key
+  :type 'boolean)
+
+(defcustom which-key-replacement-alist
+  (delq nil
+        `(((nil . "which-key-show-next-page-no-cycle") . (nil . "wk next p=
g"))
+          ,@(unless which-key-dont-use-unicode
+              '((("<left>") . ("=E2=86=90"))
+                (("<right>") . ("=E2=86=92"))))
+          (("<\\([[:alnum:]-]+\\)>") . ("\\1"))))
+  "Association list to determine how to manipulate descriptions
+of key bindings in the which-key popup. Each element of the list
+is a nested cons cell with the format
+
+\(MATCH CONS . REPLACEMENT\).
+
+The MATCH CONS determines when a replacement should occur and
+REPLACEMENT determines how the replacement should occur. Each may
+have the format \(KEY REGEXP . BINDING REGEXP\). For the
+replacement to apply the key binding must match both the KEY
+REGEXP and the BINDING REGEXP. A value of nil in either position
+can be used to match every possibility. The replacement is
+performed by using `replace-regexp-in-string' on the KEY REGEXP
+from the MATCH CONS and REPLACEMENT when it is a cons cell, and
+then similarly for the BINDING REGEXP. A nil value in the BINDING
+REGEXP position cancels the replacement. For example, the entry
+
+\(\(nil . \"Prefix Command\"\) . \(nil . \"prefix\"\)\)
+
+matches any binding with the descriptions \"Prefix Command\" and
+replaces the description with \"prefix\", ignoring the
+corresponding key.
+
+REPLACEMENT may also be a function taking a cons cell
+\(KEY . BINDING\) and producing a new corresponding cons cell.
+
+If REPLACEMENT is anything other than a cons cell \(and non nil\)
+the key binding is ignored by which-key.
+
+Finally, you can multiple replacements to occur for a given key
+binding by setting `which-key-allow-multiple-replacements' to a
+non-nil value."
+  :group 'which-key
+  :type '(alist :key-type (cons (choice regexp (const nil))
+                                (choice regexp (const nil)))
+                :value-type (cons (choice string (const nil))
+                                  (choice string (const nil)))))
+
+(defcustom which-key-allow-multiple-replacements nil
+  "Allow a key binding to match and be modified by multiple
+elements in `which-key-replacement-alist' if non-nil. When nil,
+only the first match is used to perform replacements from
+`which-key-replacement-alist'."
+  :group 'which-key
+  :type 'boolean)
+
+(defcustom which-key-show-docstrings nil
+  "If non-nil, show each command's docstring next to the command
+in the which-key buffer. This will only display the docstring up
+to the first line break. If you set this variable to the symbol
+docstring-only, then the command's name with be omitted. You
+probably also want to adjust `which-key-max-description-length'
+at the same time if you use this feature."
+  :group 'which-key
+  :type '(radio
+          (const :tag "Do not show docstrings" nil)
+          (const :tag "Add docstring to command names" t)
+          (const :tag "Replace command name with docstring" docstring-only=
)))
+
+(defcustom which-key-highlighted-command-list '()
+  "A list of strings and/or cons cells used to highlight certain
+commands. If the element is a string, assume it is a regexp
+pattern for matching command names and use
+`which-key-highlighted-command-face' for any matching names. If
+the element is a cons cell, it should take the form (regexp .
+face to apply)."
+  :group 'which-key
+  :type  '(repeat (choice string (cons regexp face))))
+
+(defcustom which-key-special-keys '()
+  "These keys will automatically be truncated to one character
+and have `which-key-special-key-face' applied to them. This is
+disabled by default. Try this to see the effect.
+
+\(setq which-key-special-keys \\=3D'(\"SPC\" \"TAB\" \"RET\" \"ESC\" \"DEL=
\")\)"
+  :group 'which-key
+  :type '(repeat string))
+
+(defcustom which-key-buffer-name " *which-key*"
+  "Name of which-key buffer."
+  :group 'which-key
+  :type 'string)
+
+(defcustom which-key-show-prefix 'echo
+  "Whether to and where to display the current prefix sequence
+Possible choices are echo for echo area (the default), left, top
+and nil. Nil turns the feature off."
+  :group 'which-key
+  :type '(radio (const :tag "Left of the keys" left)
+                (const :tag "In the first line" top)
+                (const :tag "In the last line" bottom)
+                (const :tag "In the echo area" echo)
+                (const :tag "In the mode-line" mode-line)
+                (const :tag "Hide" nil)))
+
+(defcustom which-key-popup-type 'side-window
+  "Supported types are minibuffer, side-window, frame, and custom"
+  :group 'which-key
+  :type '(radio (const :tag "Show in minibuffer" minibuffer)
+                (const :tag "Show in side window" side-window)
+                (const :tag "Show in popup frame" frame)
+                (const :tag "Use your custom display functions" custom)))
+
+(defcustom which-key-min-display-lines 1
+  "Minimum number of horizontal lines to display in the which-key buffer"
+  :group 'which-key
+  :type 'integer)
+
+(defcustom which-key-max-display-columns nil
+  "Maximum number of columns to display in the which-key buffer
+nil means don't impose a maximum."
+  :group 'which-key
+  :type '(choice integer (const :tag "Unbounded" nil)))
+
+(defcustom which-key-side-window-location 'bottom
+  "Location of which-key popup when `which-key-popup-type' is side-window.
+Should be one of top, bottom, left or right. You can also specify
+a list of two locations, like (right bottom). In this case, the
+first location is tried. If there is not enough room, the second
+location is tried."
+  :group 'which-key
+  :type '(radio (const right)
+                (const bottom)
+                (const left)
+                (const top)
+                (const (right bottom))
+                (const (bottom right))))
+
+(defcustom which-key-side-window-slot 0
+  "The `slot' to use for `display-buffer-in-side-window' when
+`which-key-popup-type' is `side-window'.  Quoting from the
+docstring of `display-buffer-in-side-window',
+
+`slot' if non-nil, specifies the window slot where to display
+BUFFER.  A value of zero or nil means use the middle slot on the
+specified side.  A negative value means use a slot
+preceding (that is, above or on the left of) the middle slot.  A
+positive value means use a slot following (that is, below or on
+the right of) the middle slot.  The default is zero."
+  :group 'which-key
+  :type 'integer)
+
+(defcustom which-key-side-window-max-width 0.333
+  "Maximum width of which-key popup when type is side-window
+This variable can also be a number between 0 and 1. In that case,
+it denotes a percentage out of the frame's width."
+  :group 'which-key
+  :type 'float)
+
+(defcustom which-key-side-window-max-height 0.25
+  "Maximum height of which-key popup when type is side-window
+This variable can also be a number between 0 and 1. In that case, it denot=
es
+a percentage out of the frame's height."
+  :group 'which-key
+  :type 'float)
+
+(defcustom which-key-frame-max-width 60
+  "Maximum width of which-key popup when type is frame."
+  :group 'which-key
+  :type 'integer)
+
+(defcustom which-key-frame-max-height 20
+  "Maximum height of which-key popup when type is frame."
+  :group 'which-key
+  :type 'integer)
+
+(defcustom which-key-allow-imprecise-window-fit (not (display-graphic-p))
+  "If non-nil allow which-key to use a less intensive method of
+fitting the popup window to the buffer. If you are noticing lag
+when the which-key popup displays turning this on may help.
+
+See https://github.com/justbur/emacs-which-key/issues/130
+and https://github.com/justbur/emacs-which-key/issues/225."
+  :group 'which-key
+  :type 'boolean)
+
+(defcustom which-key-show-remaining-keys nil
+  "Show remaining keys in last slot, when keys are hidden."
+  :group 'which-key
+  :type '(radio (const :tag "Yes" t)
+                (const :tag "No" nil)))
+
+(defcustom which-key-sort-order 'which-key-key-order
+  "If nil, do not resort the output from
+`describe-buffer-bindings' which groups by mode. Ordering options
+are
+
+1. `which-key-key-order': by key (default)
+2. `which-key-key-order-alpha': by key using alphabetical order
+3. `which-key-description-order': by description
+4. `which-key-prefix-then-key-order': prefix (no prefix first) then key
+5. `which-key-local-then-key-order': local binding then key
+
+See the README and the docstrings for those functions for more
+information."
+  :group 'which-key
+  :type '(choice (function-item which-key-key-order)
+                 (function-item which-key-key-order-alpha)
+                 (function-item which-key-description-order)
+                 (function-item which-key-prefix-then-key-order)
+                 (function-item which-key-local-then-key-order)))
+
+(defcustom which-key-sort-uppercase-first t
+  "If non-nil, uppercase comes before lowercase in sorting
+function chosen in `which-key-sort-order'. Otherwise, the order
+is reversed."
+  :group 'which-key
+  :type 'boolean)
+
+(defcustom which-key-paging-prefixes '()
+  "Enable paging for these prefixes."
+  :group 'which-key
+  :type '(repeat string))
+
+(defcustom which-key-paging-key "<f5>"
+  "Key to use for changing pages. Bound after each of the
+prefixes in `which-key-paging-prefixes'"
+  :group 'which-key
+  :type 'string)
+
+;; (defcustom which-key-undo-key nil
+;;   "Key (string) to use for undoing keypresses. Bound recursively
+;; in each of the maps in `which-key-undo-keymaps'."
+;;   :group 'which-key
+;;   :type 'string)
+
+;; (defcustom which-key-undo-keymaps '()
+;;   "Keymaps in which to bind `which-key-undo-key'"
+;;   :group 'which-key
+;;   :type '(repeat symbol))
+
+(defcustom which-key-use-C-h-commands t
+  "Use C-h (or whatever `help-char' is set to) for paging if
+non-nil. Normally C-h after a prefix calls
+`describe-prefix-bindings'. This changes that command to a
+which-key paging command when which-key-mode is active."
+  :group 'which-key
+  :type 'boolean)
+
+(defcustom which-key-show-early-on-C-h nil
+  "Show the which-key buffer before if C-h (or whatever
+`help-char' is set to) is pressed in the middle of a prefix
+before the which-key buffer would normally be triggered through
+the idle delay. If combined with the following settings,
+which-key will effectively only show when triggered \"manually\"
+using C-h.
+
+\(setq `which-key-idle-delay' 10000)
+\(setq `which-key-idle-secondary-delay' 0.05)
+
+Note that `which-key-idle-delay' should be set before turning on
+`which-key-mode'. "
+  :group 'which-key
+  :type 'boolean)
+
+(defcustom which-key-is-verbose nil
+  "Whether to warn about potential mistakes in configuration."
+  :group 'which-key
+  :type 'boolean)
+
+(defcustom which-key-preserve-window-configuration nil
+  "If non-nil, save window configuration before which-key buffer is shown
+and restore it after which-key buffer is hidden. It prevents which-key from
+changing window position of visible buffers.
+Only takken into account when popup type is side-window."
+  :group
+  'which-key
+  :type 'boolean)
+
+(defvar which-key-C-h-map-prompt
+  (concat " \\<which-key-C-h-map>"
+          " \\[which-key-show-next-page-cycle]"
+          which-key-separator "next-page,"
+          " \\[which-key-show-previous-page-cycle]"
+          which-key-separator "previous-page,"
+          " \\[which-key-undo-key]"
+          which-key-separator "undo-key,"
+          " \\[which-key-toggle-docstrings]"
+          which-key-separator "toggle-docstrings,"
+          " \\[which-key-show-standard-help]"
+          which-key-separator "help,"
+          " \\[which-key-abort]"
+          which-key-separator "abort"
+          " 1..9"
+          which-key-separator "digit-arg")
+  "Prompt to display when invoking `which-key-C-h-map'. This string
+is fed into `substitute-command-keys'")
+
+(defvar which-key-C-h-map
+  (let ((map (make-sparse-keymap)))
+    (dolist (bind `(("\C-a" . which-key-abort)
+                    ("a" . which-key-abort)
+                    ("\C-d" . which-key-toggle-docstrings)
+                    ("d" . which-key-toggle-docstrings)
+                    (,(vector help-char) . which-key-show-standard-help)
+                    ("h" . which-key-show-standard-help)
+                    ("\C-n" . which-key-show-next-page-cycle)
+                    ("n" . which-key-show-next-page-cycle)
+                    ("\C-p" . which-key-show-previous-page-cycle)
+                    ("p" . which-key-show-previous-page-cycle)
+                    ("\C-u" . which-key-undo-key)
+                    ("u" . which-key-undo-key)
+                    ("1" . which-key-digit-argument)
+                    ("2" . which-key-digit-argument)
+                    ("3" . which-key-digit-argument)
+                    ("4" . which-key-digit-argument)
+                    ("5" . which-key-digit-argument)
+                    ("6" . which-key-digit-argument)
+                    ("7" . which-key-digit-argument)
+                    ("8" . which-key-digit-argument)
+                    ("9" . which-key-digit-argument)))
+      (define-key map (car bind) (cdr bind)))
+    map)
+  "Keymap for C-h commands.")
+
+(defvar which-key--paging-functions '(which-key-C-h-dispatch
+                                      which-key-manual-update
+                                      which-key-turn-page
+                                      which-key-show-next-page-cycle
+                                      which-key-show-next-page-no-cycle
+                                      which-key-show-previous-page-cycle
+                                      which-key-show-previous-page-no-cycle
+                                      which-key-undo-key
+                                      which-key-undo))
+
+(defvar which-key-persistent-popup nil
+  "Whether or not to disable `which-key--hide-popup'.")
+
+(defcustom which-key-hide-alt-key-translations t
+  "Hide key translations using Alt key if non nil.
+These translations are not relevant most of the times since a lot
+of terminals issue META modifier for the Alt key.
+
+See http://www.gnu.org/software/emacs/manual/html_node/emacs/Modifier-Keys=
.html"
+  :group 'which-key
+  :type 'boolean)
+
+(defcustom which-key-delay-functions nil
+  "A list of functions that may decide whether to delay the
+which-key popup based on the current incomplete key
+sequence. Each function in the list is run with two arguments,
+the current key sequence as produced by `key-description' and the
+length of the key sequence. If the popup should be delayed based
+on that key sequence, the function should return the delay time
+in seconds. Returning nil means no delay. The first function in
+this list to return a value is the value that is used.
+
+The delay time is effectively added to the normal
+`which-key-idle-delay'."
+  :group 'which-key
+  :type '(repeat function))
+
+(defcustom which-key-allow-regexps nil
+  "A list of regexp strings to use to filter key sequences.
+When non-nil, for a key sequence to trigger the which-key popup
+it must match one of the regexps in this list. The format of the
+key sequences is what is produced by `key-description'."
+  :group 'which-key
+  :type '(repeat regexp))
+
+(defcustom which-key-inhibit-regexps nil
+  "Similar to `which-key-allow-regexps', a list of regexp strings
+to use to filter key sequences. When non-nil, for a key sequence
+to trigger the which-key popup it cannot match one of the regexps
+in this list. The format of the key sequences is what is produced
+by `key-description'."
+  :group 'which-key
+  :type '(repeat regexp))
+
+(defcustom which-key-show-transient-maps nil
+  "Show keymaps created by `set-transient-map' when applicable.
+
+More specifically, detect when `overriding-terminal-local-map' is
+set (this is the keymap used by `set-transient-map') and display
+it."
+  :group 'which-key
+  :type 'boolean)
+
+(make-obsolete-variable
+ 'which-key-enable-extended-define-key
+ "which-key-enable-extended-define-key is obsolete and has no effect."
+ "2021-06-21")
+
+;; Hooks
+(defcustom which-key-init-buffer-hook '()
+  "Hook run when which-key buffer is initialized."
+  :group 'which-key
+  :type 'hook)
+
+;;;; Faces
+
+(defgroup which-key-faces nil
+  "Faces for which-key-mode"
+  :group 'which-key
+  :prefix "which-key-")
+
+(defface which-key-key-face
+  '((t . (:inherit font-lock-constant-face)))
+  "Face for which-key keys"
+  :group 'which-key-faces)
+
+(defface which-key-separator-face
+  '((t . (:inherit font-lock-comment-face)))
+  "Face for the separator (default separator is an arrow)"
+  :group 'which-key-faces)
+
+(defface which-key-note-face
+  '((t . (:inherit which-key-separator-face)))
+  "Face for notes or hints occasionally provided"
+  :group 'which-key-faces)
+
+(defface which-key-command-description-face
+  '((t . (:inherit font-lock-function-name-face)))
+  "Face for the key description when it is a command"
+  :group 'which-key-faces)
+
+(defface which-key-local-map-description-face
+  '((t . (:inherit which-key-command-description-face)))
+  "Face for the key description when it is found in `current-local-map'"
+  :group 'which-key-faces)
+
+(defface which-key-highlighted-command-face
+  '((t . (:inherit which-key-command-description-face :underline t)))
+  "Default face for the command description when it is a command
+and it matches a string in `which-key-highlighted-command-list'."
+  :group 'which-key-faces)
+
+(defface which-key-group-description-face
+  '((t . (:inherit font-lock-keyword-face)))
+  "Face for the key description when it is a group or prefix"
+  :group 'which-key-faces)
+
+(defface which-key-special-key-face
+  '((t . (:inherit which-key-key-face :inverse-video t :weight bold)))
+  "Face for special keys (SPC, TAB, RET)"
+  :group 'which-key-faces)
+
+(defface which-key-docstring-face
+  '((t . (:inherit which-key-note-face)))
+  "Face for docstrings"
+  :group 'which-key-faces)
+
+;;;; Custom popup
+
+(defcustom which-key-custom-popup-max-dimensions-function nil
+  "Variable to hold a custom max-dimensions function.
+Will be passed the width of the active window and is expected to
+return the maximum height in lines and width in characters of the
+which-key popup in the form a cons cell (height . width)."
+  :group 'which-key
+  :type '(choice function (const nil)))
+
+(defcustom which-key-custom-hide-popup-function nil
+  "Variable to hold a custom hide-popup function.
+It takes no arguments and the return value is ignored."
+  :group 'which-key
+  :type '(choice function (const nil)))
+
+(defcustom which-key-custom-show-popup-function nil
+  "Variable to hold a custom show-popup function.
+Will be passed the required dimensions in the form (height .
+width) in lines and characters respectively.  The return value is
+ignored."
+  :group 'which-key
+  :type '(choice function (const nil)))
+
+(defcustom which-key-lighter " WK"
+  "Minor mode lighter to use in the mode-line."
+  :group 'which-key
+  :type 'string)
+
+(defvar which-key-inhibit nil
+  "Prevent which-key from popping up momentarily by setting this
+to a non-nil value for the execution of a command. Like this
+
+\(let \(\(which-key-inhibit t\)\)
+...\)")
+
+(defvar which-key-keymap-history nil
+  "History of keymap selections in functions like
+`which-key-show-keymap'.")
+
+;;; Internal Vars
+
+(defvar which-key--buffer nil
+  "Internal: Holds reference to which-key buffer.")
+(defvar which-key--timer nil
+  "Internal: Holds reference to open window timer.")
+(defvar which-key--secondary-timer-active nil
+  "Internal: Non-nil if the secondary timer is active.")
+(defvar which-key--paging-timer nil
+  "Internal: Holds reference to timer for paging.")
+(defvar which-key--frame nil
+  "Internal: Holds reference to which-key frame.
+Used when `which-key-popup-type' is frame.")
+(defvar which-key--echo-keystrokes-backup nil
+  "Internal: Backup the initial value of `echo-keystrokes'.")
+(defvar which-key--prefix-help-cmd-backup nil
+  "Internal: Backup the value of `prefix-help-command'.")
+(defvar which-key--last-try-2-loc nil
+  "Internal: Last location of side-window when two locations
+used.")
+(defvar which-key--automatic-display nil
+  "Internal: Non-nil if popup was triggered with automatic
+update.")
+(defvar which-key--debug-buffer-name nil
+  "If non-nil, use this buffer for debug messages.")
+(defvar which-key--multiple-locations nil)
+(defvar which-key--inhibit-next-operator-popup nil)
+(defvar which-key--prior-show-keymap-args nil)
+(defvar which-key--previous-frame-size nil)
+(defvar which-key--prefix-title-alist nil)
+(defvar which-key--evil-keys-regexp (eval-when-compile
+                                      (regexp-opt '("-state"))))
+(defvar which-key--ignore-non-evil-keys-regexp
+  (eval-when-compile
+    (regexp-opt '("mouse-" "wheel-" "remap" "drag-" "scroll-bar"
+                  "select-window" "switch-frame" "which-key"))))
+(defvar which-key--ignore-keys-regexp
+  (eval-when-compile
+    (regexp-opt '("mouse-" "wheel-" "remap" "drag-" "scroll-bar"
+                  "select-window" "switch-frame" "-state"
+                  "which-key"))))
+
+(defvar which-key--pages-obj nil)
+(cl-defstruct which-key--pages
+  pages
+  height
+  widths
+  keys/page
+  page-nums
+  num-pages
+  total-keys
+  prefix
+  prefix-title)
+
+(defvar which-key--saved-window-configuration nil)
+
+(defun which-key--rotate (list n)
+  (let* ((len (length list))
+         (n (if (< n 0) (+ len n) n))
+         (n (mod n len)))
+    (append (last list (- len n)) (butlast list (- len n)))))
+
+(defun which-key--pages-set-current-page (pages-obj n)
+  (setf (which-key--pages-pages pages-obj)
+        (which-key--rotate (which-key--pages-pages pages-obj) n))
+  (setf (which-key--pages-widths pages-obj)
+        (which-key--rotate (which-key--pages-widths pages-obj) n))
+  (setf (which-key--pages-keys/page pages-obj)
+        (which-key--rotate (which-key--pages-keys/page pages-obj) n))
+  (setf (which-key--pages-page-nums pages-obj)
+        (which-key--rotate (which-key--pages-page-nums pages-obj) n))
+  pages-obj)
+
+(defsubst which-key--on-first-page ()
+  (=3D (which-key--pages-page-nums which-key--pages-obj) 1))
+
+(defsubst which-key--on-last-page ()
+  (=3D (which-key--pages-page-nums which-key--pages-obj)
+     (which-key--pages-num-pages which-key--pages-obj)))
+
+(defsubst which-key--current-prefix ()
+  (and which-key--pages-obj
+       (which-key--pages-prefix which-key--pages-obj)))
+
+(defmacro which-key--debug-message (&rest msg)
+  `(when which-key--debug-buffer-name
+     (let ((buf (get-buffer-create which-key--debug-buffer-name))
+           (fmt-msg (format ,@msg)))
+       (with-current-buffer buf
+         (goto-char (point-max))
+         (insert "\n" fmt-msg "\n")))))
+
+(defsubst which-key--safe-lookup-key (keymap key)
+  "Version of `lookup-key' that allows KEYMAP to be nil.
+Also convert numeric results of `lookup-key' to nil. KEY is not
+checked."
+  (when (keymapp keymap)
+    (let ((result (lookup-key keymap key)))
+      (when (and result (not (numberp result)))
+        result))))
+
+(defsubst which-key--safe-lookup-key-description (keymap key)
+  "Version of `lookup-key' that allows KEYMAP to be nil.
+Also convert numeric results of `lookup-key' to nil. KEY
+should be formatted as an input for `kbd'."
+  (let ((key (ignore-errors (kbd key))))
+    (when (and key (keymapp keymap))
+      (let ((result (lookup-key keymap key)))
+        (when (and result (not (numberp result)))
+          result)))))
+
+;;; Third-party library support
+;;;; Evil
+
+(defvar evil-state nil)
+
+(defcustom which-key-allow-evil-operators (boundp 'evil-this-operator)
+  "Allow popup to show for evil operators.
+The popup is normally inhibited in the middle of commands, but
+setting this to non-nil will override this behavior for evil
+operators."
+  :group 'which-key
+  :type 'boolean)
+
+(defcustom which-key-show-operator-state-maps nil
+  "Experimental: Try to show the right keys following an evil
+command that reads a motion, such as \"y\", \"d\" and \"c\" from
+normal state. This is experimental, because there might be some
+valid keys missing and it might be showing some invalid keys."
+  :group 'which-key
+  :type 'boolean)
+
+;;;; God-mode
+
+(defvar which-key--god-mode-support-enabled nil
+  "Support god-mode if non-nil. This is experimental,
+so you need to explicitly opt-in for now. Please report any
+problems at github.")
+
+(defvar which-key--god-mode-key-string nil
+  "Holds key string to use for god-mode support.")
+
+(defun which-key--god-mode-lookup-command-advice (orig-fun arg1 &rest args)
+  (setq which-key--god-mode-key-string arg1)
+  (unwind-protect
+      (apply orig-fun arg1 args)
+    (when (bound-and-true-p which-key-mode)
+      (which-key--hide-popup))))
+
+(defun which-key-enable-god-mode-support (&optional disable)
+  "Enable support for god-mode if non-nil.
+This is experimental, so you need to explicitly opt-in for
+now. Please report any problems at github. If DISABLE is non-nil
+disable support."
+  (interactive "P")
+  (setq which-key--god-mode-support-enabled (null disable))
+  (if disable
+      (advice-remove 'god-mode-lookup-command
+                     #'which-key--god-mode-lookup-command-advice)
+    (advice-add 'god-mode-lookup-command :around
+                #'which-key--god-mode-lookup-command-advice)))
+
+;;; Mode
+
+;;;###autoload
+(define-minor-mode which-key-mode
+  "Toggle which-key-mode."
+  :global t
+  :group 'which-key
+  :lighter which-key-lighter
+  :keymap (let ((map (make-sparse-keymap)))
+            (mapc
+             (lambda (prefix)
+               (define-key map
+                 (kbd (concat prefix " " which-key-paging-key))
+                 #'which-key-C-h-dispatch))
+             which-key-paging-prefixes)
+            map)
+  (if which-key-mode
+      (progn
+        (setq which-key--echo-keystrokes-backup echo-keystrokes)
+        (when (or (eq which-key-show-prefix 'echo)
+                  (eq which-key-popup-type 'minibuffer))
+          (which-key--setup-echo-keystrokes))
+        (unless (member prefix-help-command which-key--paging-functions)
+          (setq which-key--prefix-help-cmd-backup prefix-help-command))
+        (when (or which-key-use-C-h-commands
+                  which-key-show-early-on-C-h)
+          (setq prefix-help-command #'which-key-C-h-dispatch))
+        (when which-key-show-remaining-keys
+          (add-hook 'pre-command-hook #'which-key--lighter-restore))
+        (add-hook 'pre-command-hook #'which-key--hide-popup)
+        (add-hook 'window-size-change-functions
+                  #'which-key--hide-popup-on-frame-size-change)
+        (which-key--start-timer))
+    (setq echo-keystrokes which-key--echo-keystrokes-backup)
+    (when which-key--prefix-help-cmd-backup
+      (setq prefix-help-command which-key--prefix-help-cmd-backup))
+    (when which-key-show-remaining-keys
+      (remove-hook 'pre-command-hook #'which-key--lighter-restore))
+    (remove-hook 'pre-command-hook #'which-key--hide-popup)
+    (remove-hook 'window-size-change-functions
+                 #'which-key--hide-popup-on-frame-size-change)
+    (which-key--stop-timer)))
+
+(defun which-key--init-buffer ()
+  "Initialize which-key buffer"
+  (unless (buffer-live-p which-key--buffer)
+    (setq which-key--buffer (get-buffer-create which-key-buffer-name))
+    (with-current-buffer which-key--buffer
+      ;; suppress confusing minibuffer message
+      (let (message-log-max)
+        (toggle-truncate-lines 1)
+        (message ""))
+      (setq-local cursor-type nil)
+      (setq-local cursor-in-non-selected-windows nil)
+      (setq-local mode-line-format nil)
+      (setq-local header-line-format nil)
+      (setq-local word-wrap nil)
+      (setq-local show-trailing-whitespace nil)
+      (run-hooks 'which-key-init-buffer-hook))))
+
+(defun which-key--setup-echo-keystrokes ()
+  "Reduce `echo-keystrokes' if necessary (it will interfere if
+it's set too high)."
+  (when (and echo-keystrokes
+             (> (abs (- echo-keystrokes which-key-echo-keystrokes)) 0.0000=
01))
+    (if (> which-key-idle-delay which-key-echo-keystrokes)
+        (setq echo-keystrokes which-key-echo-keystrokes)
+      (setq which-key-echo-keystrokes (/ (float which-key-idle-delay) 4)
+            echo-keystrokes which-key-echo-keystrokes))))
+
+(defun which-key-remove-default-unicode-chars ()
+  "Use of `which-key-dont-use-unicode' is preferred to this
+function, but it's included here in case someone cannot set that
+variable early enough in their configuration, if they are using a
+starter kit for example."
+  (when (string-equal which-key-separator " =E2=86=92 ")
+    (setq which-key-separator " : ")))
+
+;;; Default configuration functions for use by users.
+
+;;;###autoload
+(defun which-key-setup-side-window-right ()
+  "Apply suggested settings for side-window that opens on right."
+  (interactive)
+  (setq which-key-popup-type 'side-window
+        which-key-side-window-location 'right
+        which-key-show-prefix 'top))
+
+;;;###autoload
+(defun which-key-setup-side-window-right-bottom ()
+  "Apply suggested settings for side-window that opens on right
+if there is space and the bottom otherwise."
+  (interactive)
+  (setq which-key-popup-type 'side-window
+        which-key-side-window-location '(right bottom)
+        which-key-show-prefix 'top))
+
+;;;###autoload
+(defun which-key-setup-side-window-bottom ()
+  "Apply suggested settings for side-window that opens on bottom."
+  (interactive)
+  (which-key--setup-echo-keystrokes)
+  (setq which-key-popup-type 'side-window
+        which-key-side-window-location 'bottom
+        which-key-show-prefix 'echo))
+
+;;;###autoload
+(defun which-key-setup-minibuffer ()
+  "Apply suggested settings for minibuffer.
+Do not use this setup if you use the paging commands. Instead use
+`which-key-setup-side-window-bottom', which is nearly identical
+but more functional."
+  (interactive)
+  (which-key--setup-echo-keystrokes)
+  (setq which-key-popup-type 'minibuffer
+        which-key-show-prefix 'left))
+
+;;; Helper functions to modify replacement lists.
+
+;;;###autoload
+(defun which-key-add-keymap-based-replacements (keymap key replacement &re=
st more)
+  "Replace the description of KEY using REPLACEMENT in KEYMAP.
+KEY should take a format suitable for use in `kbd'. REPLACEMENT
+should be a cons cell of the form \(STRING . COMMAND\) for each
+REPLACEMENT, where STRING is the replacement string and COMMAND
+is a symbol corresponding to the intended command to be
+replaced. COMMAND can be nil if the binding corresponds to a key
+prefix. An example is
+
+\(which-key-add-keymap-based-replacements global-map
+  \"C-x w\" \\=3D'\(\"Save as\" . write-file\)\).
+
+For backwards compatibility, REPLACEMENT can also be a string,
+but the above format is preferred, and the option to use a string
+for REPLACEMENT will eventually be removed."
+  (while key
+    (let ((def
+           (cond
+            ((consp replacement) replacement)
+            ((stringp replacement)
+             (cons replacement
+                   (or (which-key--safe-lookup-key-description keymap key)
+                       (make-sparse-keymap))))
+            (t
+             (user-error "replacement is neither a cons cell or a string")=
))))
+      (define-key keymap (kbd key) def))
+    (setq key (pop more)
+          replacement (pop more))))
+(put 'which-key-add-keymap-based-replacements 'lisp-indent-function 'defun)
+
+;;;###autoload
+(defun which-key-add-key-based-replacements
+    (key-sequence replacement &rest more)
+  "Replace the description of KEY-SEQUENCE with REPLACEMENT.
+KEY-SEQUENCE is a string suitable for use in `kbd'. REPLACEMENT
+may either be a string, as in
+
+\(which-key-add-key-based-replacements \"C-x 1\" \"maximize\"\)
+
+a cons of two strings as in
+
+\(which-key-add-key-based-replacements \"C-x 8\"
+                                        \\=3D'(\"unicode\" . \"Unicode key=
s\")\)
+
+or a function that takes a \(KEY . BINDING\) cons and returns a
+replacement.
+
+In the second case, the second string is used to provide a longer
+name for the keys under a prefix.
+
+MORE allows you to specifcy additional KEY REPLACEMENT pairs.  All
+replacements are added to `which-key-replacement-alist'."
+  ;; TODO: Make interactive
+  (while key-sequence
+    ;; normalize key sequences before adding
+    (let ((key-seq (key-description (kbd key-sequence)))
+          (replace (or (and (functionp replacement) replacement)
+                       (car-safe replacement)
+                       replacement)))
+      (push (cons (cons (concat "\\`" (regexp-quote key-seq) "\\'") nil)
+                  (if (functionp replace) replace (cons nil replace)))
+            which-key-replacement-alist)
+      (when (and (not (functionp replacement)) (consp replacement))
+        (push (cons key-seq (cdr-safe replacement))
+              which-key--prefix-title-alist)))
+    (setq key-sequence (pop more) replacement (pop more))))
+(put 'which-key-add-key-based-replacements 'lisp-indent-function 'defun)
+
+;;;###autoload
+(defun which-key-add-major-mode-key-based-replacements
+    (mode key-sequence replacement &rest more)
+  "Functions like `which-key-add-key-based-replacements'.
+The difference is that MODE specifies the `major-mode' that must
+be active for KEY-SEQUENCE and REPLACEMENT (MORE contains
+addition KEY-SEQUENCE REPLACEMENT pairs) to apply."
+  ;; TODO: Make interactive
+  (when (not (symbolp mode))
+    (error "MODE should be a symbol corresponding to a value of major-mode=
"))
+  (let ((mode-alist
+         (or (cdr-safe (assq mode which-key-replacement-alist)) (list)))
+        (title-mode-alist
+         (or (cdr-safe (assq mode which-key--prefix-title-alist)) (list))))
+    (while key-sequence
+      ;; normalize key sequences before adding
+      (let ((key-seq (key-description (kbd key-sequence)))
+            (replace (or (and (functionp replacement) replacement)
+                         (car-safe replacement)
+                         replacement)))
+        (push (cons (cons (concat "\\`" (regexp-quote key-seq) "\\'") nil)
+                    (if (functionp replace) replace (cons nil replace)))
+              mode-alist)
+        (when (and (not (functionp replacement)) (consp replacement))
+          (push (cons key-seq (cdr-safe replacement))
+                title-mode-alist)))
+      (setq key-sequence (pop more) replacement (pop more)))
+    (if (assq mode which-key-replacement-alist)
+        (setcdr (assq mode which-key-replacement-alist) mode-alist)
+      (push (cons mode mode-alist) which-key-replacement-alist))
+    (if (assq mode which-key--prefix-title-alist)
+        (setcdr (assq mode which-key--prefix-title-alist) title-mode-alist)
+      (push (cons mode title-mode-alist) which-key--prefix-title-alist))))
+(put 'which-key-add-major-mode-key-based-replacements
+     'lisp-indent-function 'defun)
+
+(defun which-key-define-key-recursively (map key def &optional at-root)
+  "Recursively bind KEY in MAP to DEF on every level of MAP except the fir=
st.
+If AT-ROOT is non-nil the binding is also placed at the root of MAP."
+  (when at-root (define-key map key def))
+  (map-keymap
+   (lambda (_ev df)
+     (when (keymapp df)
+       (which-key-define-key-recursively df key def t)))
+   map))
+
+;;; Functions for computing window sizes
+
+(defun which-key--text-width-to-total (text-width)
+  "Convert window text-width to window total-width.
+TEXT-WIDTH is the desired text width of the window.  The function
+calculates what total width is required for a window in the
+selected to have a text-width of TEXT-WIDTH columns.  The
+calculation considers possible fringes and scroll bars.  This
+function assumes that the desired window has the same character
+width as the frame."
+  (let ((char-width (frame-char-width)))
+    (+ text-width
+       (/ (frame-fringe-width) char-width)
+       (/ (frame-scroll-bar-width) char-width)
+       (if (which-key--char-enlarged-p) 1 0)
+       ;; add padding to account for possible wide (unicode) characters
+       3)))
+
+(defun which-key--total-width-to-text (total-width)
+  "Convert window total-width to window text-width.
+TOTAL-WIDTH is the desired total width of the window.  The function calcul=
ates
+what text width fits such a window.  The calculation considers possible fr=
inges
+and scroll bars.  This function assumes that the desired window has the sa=
me
+character width as the frame."
+  (let ((char-width (frame-char-width)))
+    (- total-width
+       (/ (frame-fringe-width) char-width)
+       (/ (frame-scroll-bar-width) char-width)
+       (if (which-key--char-enlarged-p) 1 0)
+       ;; add padding to account for possible wide (unicode) characters
+       3)))
+
+(defun which-key--char-enlarged-p (&optional _frame)
+  (> (frame-char-width)
+     (/ (float (frame-pixel-width)) (window-total-width (frame-root-window=
)))))
+
+(defun which-key--char-reduced-p (&optional _frame)
+  (< (frame-char-width)
+     (/ (float (frame-pixel-width)) (window-total-width (frame-root-window=
)))))
+
+(defun which-key--char-exact-p (&optional _frame)
+  (=3D (frame-char-width)
+     (/ (float (frame-pixel-width)) (window-total-width (frame-root-window=
)))))
+
+(defun which-key--width-or-percentage-to-width (width-or-percentage)
+  "Return window total width.
+If WIDTH-OR-PERCENTAGE is a whole number, return it unchanged.  Otherwise,=
 it
+should be a percentage (a number between 0 and 1) out of the frame's width.
+More precisely, it should be a percentage out of the frame's root window's
+total width."
+  (if (wholenump width-or-percentage)
+      width-or-percentage
+    (round (* width-or-percentage (window-total-width (frame-root-window))=
))))
+
+(defun which-key--height-or-percentage-to-height (height-or-percentage)
+  "Return window total height.
+If HEIGHT-OR-PERCENTAGE is a whole number, return it unchanged.  Otherwise=
, it
+should be a percentage (a number between 0 and 1) out of the frame's heigh=
t.
+More precisely, it should be a percentage out of the frame's root window's
+total height."
+  (if (wholenump height-or-percentage)
+      height-or-percentage
+    (round (* height-or-percentage (window-total-height (frame-root-window=
))))))
+
+(defun which-key--frame-size-changed-p ()
+  "Non-nil if a change in frame size is detected."
+  (let ((new-size (cons (frame-width) (frame-height))))
+    (cond ((null which-key--previous-frame-size)
+           (setq which-key--previous-frame-size new-size)
+           nil)
+          ((not (equal which-key--previous-frame-size new-size))
+           (setq which-key--previous-frame-size new-size)))))
+
+;;; Show/hide which-key buffer
+
+(defun which-key--hide-popup ()
+  "This function is called to hide the which-key buffer."
+  (unless (or which-key-persistent-popup
+              (member real-this-command which-key--paging-functions))
+    (setq which-key--last-try-2-loc nil)
+    (setq which-key--pages-obj nil)
+    (setq which-key--automatic-display nil)
+    (setq which-key--prior-show-keymap-args nil)
+    (when (and which-key-idle-secondary-delay which-key--secondary-timer-a=
ctive)
+      (which-key--start-timer))
+    (which-key--lighter-restore)
+    (which-key--hide-popup-ignore-command)))
+
+(defun which-key--hide-popup-ignore-command ()
+  "Version of `which-key--hide-popup' without the check of
+`real-this-command'."
+  (cl-case which-key-popup-type
+    ;; Not necessary to hide minibuffer
+    ;; (minibuffer (which-key--hide-buffer-minibuffer))
+    (side-window (which-key--hide-buffer-side-window))
+    (frame (which-key--hide-buffer-frame))
+    (custom (funcall which-key-custom-hide-popup-function))))
+
+(defun which-key--hide-popup-on-frame-size-change (&optional _)
+  "Hide which-key popup if the frame is resized (to trigger a new popup)."
+  (when (which-key--frame-size-changed-p)
+    (which-key--hide-popup)))
+
+(defun which-key--hide-buffer-side-window ()
+  "Hide which-key buffer when side-window popup is used."
+  (when (buffer-live-p which-key--buffer)
+    ;; in case which-key buffer was shown in an existing window, `quit-win=
dow'
+    ;; will re-show the previous buffer, instead of closing the window
+    (quit-windows-on which-key--buffer)
+    (when (and which-key-preserve-window-configuration
+               which-key--saved-window-configuration)
+      (set-window-configuration which-key--saved-window-configuration)
+      (setq which-key--saved-window-configuration nil))))
+
+(defun which-key--hide-buffer-frame ()
+  "Hide which-key buffer when frame popup is used."
+  (when (frame-live-p which-key--frame)
+    (delete-frame which-key--frame)))
+
+(defun which-key--popup-showing-p ()
+  (and (bufferp which-key--buffer)
+       (or (window-live-p (get-buffer-window which-key--buffer))
+           (let ((window (get-buffer-window which-key--buffer t)))
+             (and (window-live-p window)
+                  (frame-visible-p (window-frame window)))))))
+
+(defun which-key--show-popup (act-popup-dim)
+  "Show the which-key buffer.
+ACT-POPUP-DIM includes the dimensions, (height . width) of the
+buffer text to be displayed in the popup.  Return nil if no window
+is shown, or if there is no need to start the closing timer."
+  (when (and (> (car act-popup-dim) 0)
+             (> (cdr act-popup-dim) 0))
+    (cl-case which-key-popup-type
+      ;; Not called for minibuffer
+      ;; (minibuffer (which-key--show-buffer-minibuffer act-popup-dim))
+      (side-window (which-key--show-buffer-side-window act-popup-dim))
+      (frame (which-key--show-buffer-frame act-popup-dim))
+      (custom (funcall which-key-custom-show-popup-function act-popup-dim)=
))))
+
+(defun which-key--fit-buffer-to-window-horizontally
+    (&optional window &rest params)
+  "Slightly modified version of `fit-buffer-to-window'.
+Use &rest params because `fit-buffer-to-window' has a different
+call signature in different emacs versions"
+  (let ((fit-window-to-buffer-horizontally t)
+        (window-min-height 1))
+    (apply #'fit-window-to-buffer window params)))
+
+(defun which-key--show-buffer-side-window (act-popup-dim)
+  "Show which-key buffer when popup type is side-window."
+  (when (and which-key-preserve-window-configuration
+             (not which-key--saved-window-configuration))
+    (setq which-key--saved-window-configuration (current-window-configurat=
ion)))
+  (let* ((height (car act-popup-dim))
+         (width (cdr act-popup-dim))
+         (alist
+          (if which-key-allow-imprecise-window-fit
+              `((window-width .  ,(which-key--text-width-to-total width))
+                (window-height . ,height)
+                (side . ,which-key-side-window-location)
+                (slot . ,which-key-side-window-slot))
+            `((window-width . which-key--fit-buffer-to-window-horizontally)
+              (window-height . (lambda (w) (fit-window-to-buffer w nil 1)))
+              (side . ,which-key-side-window-location)
+              (slot . ,which-key-side-window-slot)))))
+    ;; Previously used `display-buffer-in-major-side-window' here, but
+    ;; apparently that is meant to be an internal function. See emacs bug =
#24828
+    ;; and advice given there.
+    (cond
+     ((eq which-key--multiple-locations t)
+      ;; possibly want to switch sides in this case so we can't reuse the =
window
+      (delete-windows-on which-key--buffer)
+      (display-buffer-in-side-window which-key--buffer alist))
+     ((get-buffer-window which-key--buffer)
+      (display-buffer-reuse-window which-key--buffer alist))
+     (t
+      (display-buffer-in-side-window which-key--buffer alist)))))
+
+(defun which-key--show-buffer-frame (act-popup-dim)
+  "Show which-key buffer when popup type is frame."
+  (let* (;(orig-window (selected-window))
+         (frame-height (+ (car act-popup-dim)
+                          (if (with-current-buffer which-key--buffer
+                                mode-line-format)
+                              1
+                            0)))
+         ;; without adding 2, frame sometimes isn't wide enough for the bu=
ffer.
+         ;; this is probably because of the fringes. however, setting frin=
ges
+         ;; sizes to 0 (instead of adding 2) didn't always make the frame =
wide
+         ;; enough. don't know why it is so.
+         (frame-width (+ (cdr act-popup-dim) 2))
+         (new-window (if (and (frame-live-p which-key--frame)
+                              (eq which-key--buffer
+                                  (window-buffer
+                                   (frame-root-window which-key--frame))))
+                         (which-key--show-buffer-reuse-frame
+                          frame-height frame-width)
+                       (which-key--show-buffer-new-frame
+                        frame-height frame-width))))
+    (when new-window
+      ;; display successful
+      (setq which-key--frame (window-frame new-window))
+      new-window)))
+
+(defun which-key--show-buffer-new-frame (frame-height frame-width)
+  "Helper for `which-key--show-buffer-frame'."
+  (let* ((frame-params `((height . ,frame-height)
+                         (width . ,frame-width)
+                         ;; tell the window manager to respect the given s=
izes
+                         (user-size . t)
+                         ;; which-key frame doesn't need a minibuffer
+                         (minibuffer . nil)
+                         (name . "which-key")
+                         ;; no need for scroll bars in which-key frame
+                         (vertical-scroll-bars . nil)
+                         ;; (left-fringe . 0)
+                         ;; (right-fringe . 0)
+                         ;; (right-divider-width . 0)
+                         ;; make sure frame is visible
+                         (visibility . t)))
+         (alist `((pop-up-frame-parameters . ,frame-params)))
+         (orig-frame (selected-frame))
+         (new-window (display-buffer-pop-up-frame which-key--buffer alist)=
))
+    (when new-window
+      ;; display successful
+      (redirect-frame-focus (window-frame new-window) orig-frame)
+      new-window)))
+
+(defun which-key--show-buffer-reuse-frame (frame-height frame-width)
+  "Helper for `which-key--show-buffer-frame'."
+  (let ((window
+         (display-buffer-reuse-window
+          which-key--buffer `((reusable-frames . ,which-key--frame)))))
+    (when window
+      ;; display successful
+      (set-frame-size (window-frame window) frame-width frame-height)
+      window)))
+
+;;; Max dimension of available window functions
+
+(defun which-key--popup-max-dimensions ()
+  "Dimesion functions should return the maximum possible (height
+. width) of the intended popup. SELECTED-WINDOW-WIDTH is the
+width of currently active window, not the which-key buffer
+window."
+  (cl-case which-key-popup-type
+    (minibuffer (which-key--minibuffer-max-dimensions))
+    (side-window (which-key--side-window-max-dimensions))
+    (frame (which-key--frame-max-dimensions))
+    (custom (funcall which-key-custom-popup-max-dimensions-function
+                     (window-width)))))
+
+(defun which-key--minibuffer-max-dimensions ()
+  "Return max-dimensions of minibuffer (height . width).
+Measured in lines and characters respectively."
+  (cons
+   ;; height
+   (if (floatp max-mini-window-height)
+       (floor (* (frame-text-lines)
+                 max-mini-window-height))
+     max-mini-window-height)
+   ;; width
+   (max 0 (- (frame-text-cols) which-key-unicode-correction))))
+
+(defun which-key--side-window-max-dimensions ()
+  "Return max-dimensions of the side-window popup (height .
+width) in lines and characters respectively."
+  (cons
+   ;; height
+   (if (member which-key-side-window-location '(left right))
+       ;; 1 is a kludge to make sure there is no overlap
+       (- (frame-height) (window-text-height (minibuffer-window)) 1)
+     ;; (window-mode-line-height which-key--window))
+     ;; FIXME: change to something like
+     ;; (min which-*-height (calculate-max-height))
+     (which-key--height-or-percentage-to-height
+      which-key-side-window-max-height))
+   ;; width
+   (max 0
+        (- (if (member which-key-side-window-location '(left right))
+               (which-key--total-width-to-text
+                (which-key--width-or-percentage-to-width
+                 which-key-side-window-max-width))
+             (which-key--total-width-to-text
+              (which-key--width-or-percentage-to-width
+               1.0)))
+           which-key-unicode-correction))))
+
+(defun which-key--frame-max-dimensions ()
+  "Return max-dimensions of the frame popup (height .
+width) in lines and characters respectively."
+  (cons which-key-frame-max-height which-key-frame-max-width))
+
+;;; Sorting functions
+
+(defun which-key--string< (a b &optional alpha)
+  (let ((da (downcase a))
+        (db (downcase b)))
+    (cond
+     ((and alpha (not which-key-sort-uppercase-first))
+      (if (string-equal da db)
+          (not (string-lessp a b))
+        (string-lessp da db)))
+     ((and alpha which-key-sort-uppercase-first)
+      (if (string-equal da db)
+          (string-lessp a b)
+        (string-lessp da db)))
+     ((not which-key-sort-uppercase-first)
+      (let ((aup (not (string-equal da a)))
+            (bup (not (string-equal db b))))
+        (if (eq aup bup)
+            (string-lessp a b)
+          bup)))
+     (t (string-lessp a b)))))
+
+(defun which-key--key-description< (a b &optional alpha)
+  "Sorting function used for `which-key-key-order' and
+`which-key-key-order-alpha'."
+  (save-match-data
+    (let* ((a (which-key--extract-key a))
+           (b (which-key--extract-key b))
+           (rngrgxp "^\\([^ ]+\\) \\.\\. [^ ]+")
+           (a (if (string-match rngrgxp a) (match-string 1 a) a))
+           (b (if (string-match rngrgxp b) (match-string 1 b) b))
+           (aem? (string-equal a ""))
+           (bem? (string-equal b ""))
+           (a1? (=3D 1 (length a)))
+           (b1? (=3D 1 (length b)))
+           (srgxp "^\\(RET\\|SPC\\|TAB\\|DEL\\|LFD\\|ESC\\|NUL\\)")
+           (asp? (string-match-p srgxp a))
+           (bsp? (string-match-p srgxp b))
+           (prrgxp "^\\(M\\|C\\|S\\|A\\|H\\|s\\)-")
+           (apr? (string-match-p prrgxp a))
+           (bpr? (string-match-p prrgxp b))
+           (afn? (string-match-p "<f[0-9]+>" a))
+           (bfn? (string-match-p "<f[0-9]+>" b)))
+      (cond ((or aem? bem?) (and aem? (not bem?)))
+            ((and asp? bsp?)
+             (if (string-equal (substring a 0 3) (substring b 0 3))
+                 (which-key--key-description<
+                  (substring a 3) (substring b 3) alpha)
+               (which-key--string< a b alpha)))
+            ((or asp? bsp?) asp?)
+            ((and a1? b1?) (which-key--string< a b alpha))
+            ((or a1? b1?) a1?)
+            ((and afn? bfn?)
+             (< (string-to-number
+                 (replace-regexp-in-string "<f\\([0-9]+\\)>" "\\1" a))
+                (string-to-number
+                 (replace-regexp-in-string "<f\\([0-9]+\\)>" "\\1" b))))
+            ((or afn? bfn?) afn?)
+            ((and apr? bpr?)
+             (if (string-equal (substring a 0 2) (substring b 0 2))
+                 (which-key--key-description<
+                  (substring a 2) (substring b 2) alpha)
+               (which-key--string< a b alpha)))
+            ((or apr? bpr?) apr?)
+            (t (which-key--string< a b alpha))))))
+
+(defsubst which-key-key-order-alpha (acons bcons)
+  "Order key descriptions A and B.
+Order is lexicographic within a \"class\", where the classes and
+the ordering of classes are listed below.
+
+special (SPC,TAB,...) < single char < mod (C-,M-,...) < other.
+Sorts single characters alphabetically with lowercase coming
+before upper."
+  (which-key--key-description< (car acons) (car bcons) t))
+
+(defsubst which-key-key-order (acons bcons)
+  "Order key descriptions A and B.
+Order is lexicographic within a \"class\", where the classes and
+the ordering of classes are listed below.
+
+special (SPC,TAB,...) < single char < mod (C-,M-,...) < other."
+  (which-key--key-description< (car acons) (car bcons)))
+
+(defsubst which-key-description-order (acons bcons)
+  "Order descriptions of A and B.
+Uses `string-lessp' after applying lowercase."
+  (string-lessp (downcase (cdr acons)) (downcase (cdr bcons))))
+
+(defsubst which-key--group-p (description)
+  (or (string-equal description "prefix")
+      (string-match-p "^group:" description)
+      (keymapp (intern description))))
+
+(defun which-key-prefix-then-key-order (acons bcons)
+  "Order first by whether A and/or B is a prefix with no prefix
+coming before a prefix. Within these categories order using
+`which-key-key-order'."
+  (let ((apref? (which-key--group-p (cdr acons)))
+        (bpref? (which-key--group-p (cdr bcons))))
+    (if (not (eq apref? bpref?))
+        (and (not apref?) bpref?)
+      (which-key-key-order acons bcons))))
+
+(defun which-key-prefix-then-key-order-reverse (acons bcons)
+  "Order first by whether A and/or B is a prefix with prefix
+coming before a prefix. Within these categories order using
+`which-key-key-order'."
+  (let ((apref? (which-key--group-p (cdr acons)))
+        (bpref? (which-key--group-p (cdr bcons))))
+    (if (not (eq apref? bpref?))
+        (and apref? (not bpref?))
+      (which-key-key-order acons bcons))))
+
+(defun which-key-local-then-key-order (acons bcons)
+  "Order first by whether A and/or B is a local binding with
+local bindings coming first. Within these categories order using
+`which-key-key-order'."
+  (let ((aloc? (which-key--local-binding-p acons))
+        (bloc? (which-key--local-binding-p bcons)))
+    (if (not (eq aloc? bloc?))
+        (and aloc? (not bloc?))
+      (which-key-key-order acons bcons))))
+
+;;; Functions for retrieving and formatting keys
+
+(defsubst which-key--string-width (maybe-string)
+  "If MAYBE-STRING is a string use `which-key--string-width' o/w return 0."
+  (if (stringp maybe-string) (string-width maybe-string) 0))
+
+(defsubst which-key--butlast-string (str)
+  (mapconcat #'identity (butlast (split-string str)) " "))
+
+(defun which-key--match-replacement (key-binding replacement)
+  ;; these are mode specific ones to ignore. The mode specific case is
+  ;; handled in the selection of alist
+  (when (and (consp key-binding) (not (symbolp (car replacement))))
+    (let ((key-regexp (caar replacement))
+          (binding-regexp (cdar replacement))
+          case-fold-search)
+      (and (or (null key-regexp)
+               (string-match-p key-regexp
+                               (car key-binding)))
+           (or (null binding-regexp)
+               (string-match-p binding-regexp
+                               (cdr key-binding)))))))
+
+(defsubst which-key--replace-in-binding (key-binding repl)
+  (cond ((or (not (consp repl)) (null (cdr repl)))
+         key-binding)
+        ((functionp (cdr repl))
+         (funcall (cdr repl) key-binding))
+        ((consp (cdr repl))
+         (cons
+          (cond ((and (caar repl) (cadr repl))
+                 (replace-regexp-in-string
+                  (caar repl) (cadr repl) (car key-binding) t))
+                ((cadr repl) (cadr repl))
+                (t (car key-binding)))
+          (cond ((and (cdar repl) (cddr repl))
+                 (replace-regexp-in-string
+                  (cdar repl) (cddr repl) (cdr key-binding) t))
+                ((cddr repl) (cddr repl))
+                (t (cdr key-binding)))))))
+
+(defun which-key--replace-in-repl-list-once (key-binding repls)
+  (cl-dolist (repl repls)
+    (when (which-key--match-replacement key-binding repl)
+      (cl-return `(replaced . ,(which-key--replace-in-binding key-binding =
repl))))))
+
+(defun which-key--replace-in-repl-list-many (key-binding repls)
+  (let (found)
+    (dolist (repl repls)
+      (when (which-key--match-replacement key-binding repl)
+        (setq found 't)
+        (setq key-binding (which-key--replace-in-binding key-binding repl)=
)))
+    (when found `(replaced . ,key-binding))))
+
+(defun which-key--maybe-replace (key-binding)
+  "Use `which-key--replacement-alist' to maybe replace KEY-BINDING.
+KEY-BINDING is a cons cell of the form \(KEY . BINDING\) each of
+which are strings. KEY is of the form produced by `key-binding'."
+  (let* ((replacer (if which-key-allow-multiple-replacements
+                       #'which-key--replace-in-repl-list-many
+                     #'which-key--replace-in-repl-list-once)))
+    (pcase
+        (apply replacer
+               (list key-binding
+                     (cdr-safe (assq major-mode which-key-replacement-alis=
t))))
+      (`(replaced . ,repl)
+       (if which-key-allow-multiple-replacements
+           (pcase (apply replacer (list repl which-key-replacement-alist))
+             (`(replaced . ,repl) repl)
+             ('() repl))
+         repl))
+      ('()
+       (pcase (apply replacer (list key-binding which-key-replacement-alis=
t))
+         (`(replaced . ,repl) repl)
+         ('() key-binding))))))
+
+(defsubst which-key--current-key-list (&optional key-str)
+  (append (listify-key-sequence (which-key--current-prefix))
+          (when key-str
+            (listify-key-sequence (kbd key-str)))))
+
+(defsubst which-key--current-key-string (&optional key-str)
+  (key-description (which-key--current-key-list key-str)))
+
+(defun which-key--local-binding-p (keydesc)
+  (eq (which-key--safe-lookup-key-description
+       (current-local-map)
+       (which-key--current-key-string (car keydesc)))
+      (intern (cdr keydesc))))
+
+(defun which-key--map-binding-p (map keydesc)
+  "Does MAP contain KEYDESC =3D (key . binding)?"
+  (or
+   (when (bound-and-true-p evil-state)
+     (let ((lookup
+            (which-key--safe-lookup-key-description
+             map
+             (which-key--current-key-string
+              (format "<%s-state> %s" evil-state (car keydesc))))))
+       (or (eq lookup (intern (cdr keydesc)))
+           (and (keymapp lookup) (string=3D (cdr keydesc) "Prefix Command"=
)))))
+   (let ((lookup
+          (which-key--safe-lookup-key-description
+           map (which-key--current-key-string (car keydesc)))))
+     (or (eq lookup (intern (cdr keydesc)))
+         (and (keymapp lookup) (string=3D (cdr keydesc) "Prefix Command"))=
))))
+
+(defun which-key--maybe-get-prefix-title (keys)
+  "KEYS is a string produced by `key-description'.
+A title is possibly returned using
+`which-key--prefix-title-alist'.  An empty string is returned if
+no title exists."
+  (cond
+   ((not (string-equal keys ""))
+    (let* ((title-res
+            (cdr-safe (assoc-string keys which-key--prefix-title-alist)))
+           (repl-res
+            (cdr-safe (which-key--maybe-replace (cons keys ""))))
+           (binding (key-binding (kbd keys)))
+           (alternate (when (and binding (symbolp binding))
+                        (symbol-name binding))))
+      (cond (title-res title-res)
+            ((not (string-equal repl-res "")) repl-res)
+            ((and (eq which-key-show-prefix 'echo) alternate)
+             alternate)
+            ((and (member which-key-show-prefix '(bottom top mode-line))
+                  (eq which-key-side-window-location 'bottom)
+                  echo-keystrokes)
+             (if alternate alternate
+               (concat "Following " keys)))
+            (t ""))))
+   (t "")))
+
+(defun which-key--propertize (string &rest properties)
+  "Version of `propertize' that checks type of STRING."
+  (when (stringp string)
+    (apply #'propertize string properties)))
+
+(defun which-key--propertize-key (key)
+  "Add a face to KEY.
+If KEY contains any \"special keys\" defined in
+`which-key-special-keys' then truncate and add the corresponding
+`which-key-special-key-face'."
+  (let ((key-w-face (which-key--propertize key 'face 'which-key-key-face))
+        (regexp (concat "\\("
+                        (mapconcat #'identity which-key-special-keys
+                                   "\\|")
+                        "\\)"))
+        case-fold-search)
+    (save-match-data
+      (if (and which-key-special-keys
+               (string-match regexp key))
+          (let ((beg (match-beginning 0)) (end (match-end 0)))
+            (concat (substring key-w-face 0 beg)
+                    (which-key--propertize (substring key-w-face beg (1+ b=
eg))
+                                           'face 'which-key-special-key-fa=
ce)
+                    (substring key-w-face end
+                               (which-key--string-width key-w-face))))
+        key-w-face))))
+
+(defsubst which-key--truncate-description (desc avl-width)
+  "Truncate DESC description to `which-key-max-description-length'."
+  (let* ((max which-key-max-description-length)
+	 (max (cl-etypecase max
+		(null nil)
+		(integer max)
+		(float (truncate (* max avl-width)))
+		(function (let ((val (funcall max avl-width)))
+			    (if (floatp val) (truncate val) val))))))
+    (if (and max (> (length desc) max))
+        (let ((dots (and (not (equal which-key-ellipsis ""))
+			 (which-key--propertize
+			  which-key-ellipsis 'face
+			  (get-text-property (1- (length desc)) 'face desc)))))
+	  (if dots
+              (concat (substring desc 0 (- max (length dots))) dots)
+	    (substring desc 0 max)))
+      desc)))
+
+(defun which-key--highlight-face (description)
+  "Return the highlight face for DESCRIPTION if it has one."
+  (let (face)
+    (dolist (el which-key-highlighted-command-list)
+      (unless face
+        (cond ((consp el)
+               (when (string-match-p (car el) description)
+                 (setq face (cdr el))))
+              ((stringp el)
+               (when (string-match-p el description)
+                 (setq face 'which-key-highlighted-command-face)))
+              (t
+               (message "which-key: warning: element %s of \
+which-key-highlighted-command-list is not a string or a cons
+cell" el)))))
+    face))
+
+(defun which-key--propertize-description
+    (description group local hl-face &optional original-description)
+  "Add face to DESCRIPTION where the face chosen depends on
+whether the description represents a group or a command. Also
+make some minor adjustments to the description string, like
+removing a \"group:\" prefix.
+
+ORIGINAL-DESCRIPTION is the description given by
+`describe-buffer-bindings'."
+  (when description
+    (let* ((desc description)
+           (desc (if (string-match-p "^group:" desc)
+                     (substring desc 6) desc))
+           (desc (if group (concat which-key-prefix-prefix desc) desc)))
+      (make-text-button
+       desc nil
+       'face (cond (hl-face hl-face)
+                   (group 'which-key-group-description-face)
+                   (local 'which-key-local-map-description-face)
+                   (t 'which-key-command-description-face))
+       'help-echo (cond
+                   ((and original-description
+                         (fboundp (intern original-description))
+                         (documentation (intern original-description))
+                         ;; tooltip-mode doesn't exist in emacs-nox
+                         (boundp 'tooltip-mode) tooltip-mode)
+                    (documentation (intern original-description)))
+                   ((and original-description
+                         (fboundp (intern original-description))
+                         (documentation (intern original-description))
+                         (let* ((doc (documentation
+                                      (intern original-description)))
+                                (str (replace-regexp-in-string "\n" " " do=
c))
+                                (max (floor (* (frame-width) 0.8))))
+                           (if (> (length str) max)
+                               (concat (substring str 0 max) "...")
+                             str)))))))))
+
+(defun which-key--extract-key (key-str)
+  "Pull the last key (or key range) out of KEY-STR."
+  (save-match-data
+    (let ((key-range-regexp "\\`.*\\([^ \t]+ \\.\\. [^ \t]+\\)\\'"))
+      (if (string-match key-range-regexp key-str)
+          (match-string 1 key-str)
+        (car (last (split-string key-str " ")))))))
+
+(defun which-key--maybe-add-docstring (current original)
+  "Maybe concat a docstring to CURRENT and return result.
+Specifically, do this if ORIGINAL is a command with a docstring
+and `which-key-show-docstrings' is non-nil. If
+`which-key-show-docstrings' is the symbol docstring-only, just
+return the docstring."
+  (let* ((orig-sym (intern original))
+         (doc (when (commandp orig-sym)
+                (documentation orig-sym)))
+         (doc (when doc
+                (replace-regexp-in-string
+                 (concat "^\\(?::"
+                         (regexp-opt '("around" "override"
+                                       "after" "after-until" "after-while"
+                                       "before" "before-until" "before-whi=
le"
+                                       "filter-args" "filter-return"))
+                         " advice: [^\n]+\n"
+                         "\\)+\n")
+                 "" doc)))
+         (docstring (when doc
+                      (which-key--propertize (car (split-string doc "\n"))
+                                             'face 'which-key-docstring-fa=
ce))))
+    (cond ((not (and which-key-show-docstrings docstring))
+           current)
+          ((eq which-key-show-docstrings 'docstring-only)
+           docstring)
+          (t
+           (format "%s %s" current docstring)))))
+
+(defun which-key--format-and-replace (unformatted &optional preserve-full-=
key)
+  "Take a list of (key . desc) cons cells in UNFORMATTED, add
+faces and perform replacements according to the three replacement
+alists. Returns a list (key separator description)."
+  (let ((sep-w-face
+         (which-key--propertize which-key-separator
+                                'face 'which-key-separator-face))
+        (local-map (current-local-map))
+	(avl-width (cdr (which-key--popup-max-dimensions)))
+        new-list)
+    (dolist (key-binding unformatted)
+      (let* ((keys (car key-binding))
+             (orig-desc (cdr key-binding))
+             (group (which-key--group-p orig-desc))
+             (local (eq (which-key--safe-lookup-key-description
+                         local-map keys)
+                        (intern orig-desc)))
+             (hl-face (which-key--highlight-face orig-desc))
+             (key-binding (which-key--maybe-replace key-binding))
+             (final-desc (which-key--propertize-description
+                          (cdr key-binding) group local hl-face orig-desc)=
))
+        (when final-desc
+          (setq final-desc
+                (which-key--truncate-description
+                 (which-key--maybe-add-docstring final-desc orig-desc)
+		 avl-width)))
+        (when (consp key-binding)
+          (push
+           (list (which-key--propertize-key
+                  (if preserve-full-key
+                      (car key-binding)
+                    (which-key--extract-key (car key-binding))))
+                 sep-w-face
+                 final-desc)
+           new-list))))
+    (nreverse new-list)))
+
+(defun which-key--compute-binding (binding)
+  "Replace BINDING with remapped binding if it exists.
+
+Requires `which-key-compute-remaps' to be non-nil"
+  (let (remap)
+    (if (and which-key-compute-remaps
+             (setq remap (command-remapping binding)))
+        (copy-sequence (symbol-name remap))
+      (copy-sequence (symbol-name binding)))))
+
+(defun which-key--get-menu-item-binding (def)
+  "Retrieve binding for menu-item"
+  ;; see `keymap--menu-item-binding'
+  (let* ((binding (nth 2 def))
+         (plist (nthcdr 3 def))
+         (filter (plist-get plist :filter)))
+    (if filter (funcall filter binding) binding)))
+
+(defun which-key--get-keymap-bindings-1
+    (keymap start &optional prefix filter all ignore-commands)
+  "See `which-key--get-keymap-bindings'."
+  (let ((bindings start)
+        (prefix-map (if prefix (lookup-key keymap prefix) keymap)))
+    (when (keymapp prefix-map)
+      (map-keymap
+       (lambda (ev def)
+         (let* ((key (vconcat prefix (list ev)))
+                (key-desc (key-description key)))
+           (cond
+            ((assoc key-desc bindings))
+            ((and (listp ignore-commands) (symbolp def) (memq def ignore-c=
ommands)))
+            ((or (string-match-p
+                  which-key--ignore-non-evil-keys-regexp key-desc)
+                 (eq ev 'menu-bar)))
+            ((and (keymapp def)
+                  (string-match-p which-key--evil-keys-regexp key-desc)))
+            ((and (keymapp def)
+                  (or all
+                      ;; event 27 is escape, so this will pick up meta
+                      ;; bindings and hopefully not too much more
+                      (and (numberp ev) (=3D ev 27))))
+             (setq bindings
+                   (which-key--get-keymap-bindings-1
+                    keymap bindings key nil all ignore-commands)))
+            (def
+             (let* ((def (if (eq 'menu-item (car-safe def))
+                             (which-key--get-menu-item-binding def)
+                           def))
+                    (binding
+                     (cons key-desc
+                           (cond
+                            ((symbolp def) (which-key--compute-binding def=
))
+                            ((keymapp def) "prefix")
+                            ((eq 'lambda (car-safe def)) "lambda")
+                            ((eq 'closure (car-safe def)) "closure")
+                            ((stringp def) def)
+                            ((vectorp def) (key-description def))
+                            ((and (consp def)
+                                  ;; looking for (STRING . DEFN)
+                                  (stringp (car def)))
+                             (concat (when (keymapp (cdr-safe def))
+                                       "group:")
+                                     (car def)))
+                            (t "unknown")))))
+               (when (or (null filter)
+                         (and (functionp filter)
+                              (funcall filter binding)))
+                 (push binding bindings)))))))
+       prefix-map))
+    bindings))
+
+(defun which-key--get-keymap-bindings
+    (keymap &optional start prefix filter all evil)
+  "Retrieve top-level bindings from KEYMAP.
+PREFIX limits bindings to those starting with this key
+sequence. START is a list of existing bindings to add to.  If ALL
+is non-nil, recursively retrieve all bindings below PREFIX. If
+EVIL is non-nil, extract active evil bidings."
+  (let ((bindings start)
+        (ignore '(self-insert-command ignore ignore-event company-ignore))
+        (evil-map
+         (when (and evil (bound-and-true-p evil-local-mode))
+           (lookup-key keymap (kbd (format "<%s-state>" evil-state))))))
+    (when (keymapp evil-map)
+      (setq bindings (which-key--get-keymap-bindings-1
+                      evil-map bindings prefix filter all ignore)))
+    (which-key--get-keymap-bindings-1
+     keymap bindings prefix filter all ignore)))
+
+(defun which-key--get-current-bindings (&optional prefix filter)
+  "Generate a list of current active bindings."
+  (let (bindings)
+    (dolist (map (current-active-maps t) bindings)
+      (when (cdr map)
+        (setq bindings
+              (which-key--get-keymap-bindings
+               map bindings prefix filter))))))
+
+(defun which-key--get-bindings (&optional prefix keymap filter recursive)
+  "Collect key bindings.
+If KEYMAP is nil, collect from current buffer using the current
+key sequence as a prefix. Otherwise, collect from KEYMAP. FILTER
+is a function to use to filter the bindings. If RECURSIVE is
+non-nil, then bindings are collected recursively for all prefixes."
+  (let* ((unformatted
+          (cond ((keymapp keymap)
+                 (which-key--get-keymap-bindings
+                  keymap nil prefix filter recursive))
+                (keymap
+                 (error "%s is not a keymap" keymap))
+                (t
+                 (which-key--get-current-bindings prefix filter)))))
+    (when which-key-sort-order
+      (setq unformatted
+            (sort unformatted which-key-sort-order)))
+    (which-key--format-and-replace unformatted recursive)))
+
+;;; Functions for laying out which-key buffer pages
+
+(defun which-key--normalize-columns (columns)
+  "Pad COLUMNS to the same length using empty strings."
+  (let ((max-len (cl-reduce (lambda (a x) (max a (length x))) columns
+                            :initial-value 0)))
+    (mapcar
+     (lambda (c)
+       (if (< (length c) max-len)
+           (append c (make-list (- max-len (length c)) ""))
+         c))
+     columns)))
+
+(defsubst which-key--join-columns (columns)
+  "Transpose columns into rows, concat rows into lines and rows into page."
+  (let* ((padded (which-key--normalize-columns (nreverse columns)))
+         (rows (apply #'cl-mapcar #'list padded)))
+    (mapconcat (lambda (row) (mapconcat #'identity row " ")) rows "\n")))
+
+(defsubst which-key--max-len (keys index &optional initial-value)
+  "Internal function for finding the max length of the INDEX
+element in each list element of KEYS."
+  (cl-reduce
+   (lambda (x y) (max x (which-key--string-width (nth index y))))
+   keys :initial-value (if initial-value initial-value 0)))
+
+(defun which-key--pad-column (col-keys avl-width)
+  "Take a column of (key separator description) COL-KEYS,
+calculate the max width in the column and pad all cells out to
+that width."
+  (let* ((col-key-width  (+ which-key-add-column-padding
+                            (which-key--max-len col-keys 0)))
+         (col-sep-width  (which-key--max-len col-keys 1))
+	 (avl-width      (- avl-width col-key-width col-sep-width))
+         (col-desc-width (min avl-width
+			      (which-key--max-len
+                               col-keys 2
+			       which-key-min-column-description-width)))
+         (col-width      (+ col-key-width col-sep-width col-desc-width))
+	 (col-format     (concat "%" (int-to-string col-key-width)
+                                 "s%s%-" (int-to-string col-desc-width) "s=
")))
+    (cons col-width
+          (mapcar (lambda (k) (apply #'format col-format k))
+		  col-keys))))
+
+(defun which-key--partition-list (n list)
+  "Partition LIST into N-sized sublists."
+  (let (res)
+    (while list
+      (setq res (cons (cl-subseq list 0 (min n (length list))) res)
+            list (nthcdr n list)))
+    (nreverse res)))
+
+(defun which-key--list-to-pages (keys avl-lines avl-width)
+  "Convert list of KEYS to columns based on dimensions AVL-LINES and AVL-W=
IDTH.
+Returns a `which-key--pages' object that holds the page strings,
+as well as metadata."
+  (let ((cols-w-widths (mapcar (lambda (c) (which-key--pad-column c avl-wi=
dth))
+			       (which-key--partition-list avl-lines keys)))
+        (page-width 0) (n-pages 0) (n-keys 0) (n-columns 0)
+        page-cols pages page-widths keys/page col)
+    (if (> (apply #'max (mapcar #'car cols-w-widths)) avl-width)
+        ;; give up if no columns fit
+        nil
+      (while cols-w-widths
+        ;; start new page
+        (cl-incf n-pages)
+        (setq col (pop cols-w-widths))
+        (setq page-cols (list (cdr col)))
+        (setq page-width (car col))
+        (setq n-keys (length (cdr col)))
+        (setq n-columns 1)
+        ;; add additional columns as long as they fit
+        (while (and cols-w-widths
+                    (or (null which-key-max-display-columns)
+                        (< n-columns which-key-max-display-columns))
+                    (<=3D (+ page-width 1 (caar cols-w-widths)) avl-width))
+          (setq col (pop cols-w-widths))
+          (push (cdr col) page-cols)
+          (cl-incf page-width (1+ (car col)))
+          (cl-incf n-keys (length (cdr col)))
+          (cl-incf n-columns))
+        (push (which-key--join-columns page-cols) pages)
+        (push n-keys keys/page)
+        (push page-width page-widths))
+      (make-which-key--pages
+       :pages (nreverse pages)
+       :height (if (> n-pages 1) avl-lines (min avl-lines n-keys))
+       :widths (nreverse page-widths)
+       :keys/page (reverse keys/page)
+       :page-nums (number-sequence 1 n-pages)
+       :num-pages n-pages
+       :total-keys (apply #'+ keys/page)))))
+
+(defun which-key--create-pages-1
+    (keys available-lines available-width &optional min-lines vertical)
+  "Create page strings using `which-key--list-to-pages'.
+Will try to find the best number of rows and columns using the
+given dimensions and the length and widths of ITEMS. Use VERTICAL
+if the ITEMS are laid out vertically and the number of columns
+should be minimized."
+  (let ((result (which-key--list-to-pages
+                 keys available-lines available-width))
+        (min-lines (or min-lines 0))
+        found prev-result)
+    (if (or (null result)
+            vertical
+            (> (which-key--pages-num-pages result) 1)
+            (=3D 1 available-lines))
+        result
+      ;; simple search for a fitting page
+      (while (and (> available-lines min-lines)
+                  (not found))
+        (setq available-lines (- available-lines 1)
+              prev-result result
+              result (which-key--list-to-pages
+                      keys available-lines available-width)
+              found (> (which-key--pages-num-pages result) 1)))
+      (if found prev-result result))))
+
+(defun which-key--create-pages (keys &optional prefix-keys prefix-title)
+  "Create page strings using `which-key--list-to-pages'.
+Will try to find the best number of rows and columns using the
+given dimensions and the length and wdiths of KEYS. SEL-WIN-WIDTH
+is the width of the live window."
+  (let* ((max-dims (which-key--popup-max-dimensions))
+         (max-lines (car max-dims))
+         (max-width (cdr max-dims))
+         (prefix-desc (key-description prefix-keys))
+         (full-prefix (which-key--full-prefix prefix-desc))
+         (prefix (when (eq which-key-show-prefix 'left)
+                   (+ 2 (which-key--string-width full-prefix))))
+         (prefix-top-bottom (member which-key-show-prefix '(bottom top)))
+         (avl-lines (if prefix-top-bottom (- max-lines 1) max-lines))
+         (min-lines (min avl-lines which-key-min-display-lines))
+         (avl-width (if prefix (- max-width prefix) max-width))
+         (vertical (or (and (eq which-key-popup-type 'side-window)
+                            (member which-key-side-window-location '(left =
right)))
+		       (eq which-key-max-display-columns 1)))
+         result)
+    (setq result
+          (which-key--create-pages-1
+           keys avl-lines avl-width min-lines vertical))
+    (when (and result
+               (> (which-key--pages-num-pages result) 0))
+      (setf (which-key--pages-prefix result) prefix-keys)
+      (setf (which-key--pages-prefix-title result)
+            (or prefix-title
+                (which-key--maybe-get-prefix-title
+                 (key-description prefix-keys))))
+      (when prefix-top-bottom
+	;; Add back the line earlier reserved for the page information.
+        (setf (which-key--pages-height result) max-lines))
+      (when (and (=3D (which-key--pages-num-pages result) 1)
+                 (> which-key-min-display-lines
+                    (which-key--pages-height result)))
+        ;; result is shorter than requested, so we artificially increase t=
he
+        ;; height. See #325. Note this only has an effect if
+        ;; `which-key-allow-imprecise-window-fit' is non-nil.
+        (setf (which-key--pages-height result) which-key-min-display-lines=
))
+      (which-key--debug-message "Frame height: %s
+Minibuffer height: %s
+Max dimensions: (%s,%s)
+Available for bindings: (%s,%s)
+Actual lines: %s" (frame-height) (window-text-height (minibuffer-window))
+max-lines max-width avl-lines avl-width (which-key--pages-height result))
+      result)))
+
+(defun which-key--lighter-status ()
+  "Possibly show number of keys and total in the mode line."
+  (when which-key-show-remaining-keys
+    (let ((n-shown (car (which-key--pages-keys/page which-key--pages-obj)))
+          (n-tot (which-key--pages-total-keys which-key--pages-obj)))
+      (setcar (cdr (assq 'which-key-mode minor-mode-alist))
+              (format " WK: %s/%s keys" n-shown n-tot)))))
+
+(defun which-key--lighter-restore ()
+  "Restore the lighter for which-key."
+  (when which-key-show-remaining-keys
+    (setcar (cdr (assq 'which-key-mode minor-mode-alist))
+            which-key-lighter)))
+
+(defun which-key--echo (text)
+  "Echo TEXT to minibuffer without logging."
+  (let (message-log-max)
+    (message "%s" text)))
+
+(defun which-key--next-page-hint (prefix-keys)
+  "Return string for next page hint."
+  (let* ((paging-key (concat prefix-keys " " which-key-paging-key))
+         (paging-key-bound (eq 'which-key-C-h-dispatch
+                               (key-binding (kbd paging-key))))
+         (key (key-description (vector help-char)))
+         (key (if paging-key-bound
+                  (concat key " or " which-key-paging-key)
+                key)))
+    (when (and which-key-use-C-h-commands
+               (not (equal (vector help-char)
+                           (vconcat (kbd prefix-keys)))))
+      (which-key--propertize (format "[%s paging/help]" key)
+                             'face 'which-key-note-face))))
+
+(eval-and-compile
+  (if (fboundp 'universal-argument--description)
+      (defalias 'which-key--universal-argument--description
+        #'universal-argument--description)
+    (defun which-key--universal-argument--description ()
+      ;; Backport of the definition of universal-argument--description in
+      ;; emacs25 on 2015-12-04
+      (when prefix-arg
+        (concat "C-u"
+                (pcase prefix-arg
+                  (`(-) " -")
+                  (`(,(and (pred integerp) n))
+                   (let ((str ""))
+                     (while (and (> n 4) (=3D (mod n 4) 0))
+                       (setq str (concat str " C-u"))
+                       (setq n (/ n 4)))
+                     (if (=3D n 4) str (format " %s" prefix-arg))))
+                  (_ (format " %s" prefix-arg))))))))
+
+(defun which-key--full-prefix (prefix-keys &optional -prefix-arg dont-prop=
-keys)
+  "Return a description of the full key sequence up to now,
+including prefix arguments."
+  (let* ((left (eq which-key-show-prefix 'left))
+         (prefix-arg (if -prefix-arg -prefix-arg prefix-arg))
+         (str (concat
+               (which-key--universal-argument--description)
+               (when prefix-arg " ")
+               prefix-keys))
+         (dash (if (and (not (string=3D prefix-keys ""))
+                        (null left)) "-" "")))
+    (if (or (eq which-key-show-prefix 'echo) dont-prop-keys)
+        (concat str dash)
+      (concat (which-key--propertize-key str)
+              (which-key--propertize dash 'face 'which-key-key-face)))))
+
+(defun which-key--get-popup-map ()
+  "Generate transient-map for use in the top level binding display."
+  (unless which-key--automatic-display
+    (let ((map (make-sparse-keymap)))
+      (define-key map (kbd which-key-paging-key) #'which-key-C-h-dispatch)
+      (when which-key-use-C-h-commands
+        ;; Show next page even when C-h is pressed
+        (define-key map (vector help-char) #'which-key-C-h-dispatch))
+      map)))
+
+(defun which-key--process-page (pages-obj)
+  "Add information to the basic list of key bindings, including
+if applicable the current prefix, the name of the current prefix,
+and a page count."
+  (let* ((page (car (which-key--pages-pages pages-obj)))
+         (height (which-key--pages-height pages-obj))
+         (n-pages (which-key--pages-num-pages pages-obj))
+         (page-n (car (which-key--pages-page-nums pages-obj)))
+         (prefix-desc (key-description (which-key--pages-prefix pages-obj)=
))
+         (prefix-title (which-key--pages-prefix-title pages-obj))
+         (full-prefix (which-key--full-prefix prefix-desc))
+         (nxt-pg-hint (which-key--next-page-hint prefix-desc))
+         ;; not used in left case
+         (status-line
+          (concat (which-key--propertize prefix-title 'face 'which-key-not=
e-face)
+                  (when (< 1 n-pages)
+                    (which-key--propertize (format " (%s of %s)" page-n n-=
pages)
+                                           'face 'which-key-note-face)))))
+    (pcase which-key-show-prefix
+      (`left
+       (let* ((page-cnt (which-key--propertize (format "%s/%s" page-n n-pa=
ges)
+                                               'face 'which-key-separator-=
face))
+              (first-col-width (+ 2 (max (which-key--string-width full-pre=
fix)
+                                         (which-key--string-width page-cnt=
))))
+              (prefix (format (concat "%-" (int-to-string first-col-width)=
 "s")
+                              full-prefix))
+              (page-cnt (if (> n-pages 1)
+                            (format
+                             (concat "%-" (int-to-string first-col-width) =
"s")
+                             page-cnt)
+                          (make-string first-col-width 32)))
+              lines first-line new-end)
+         (if (=3D 1 height)
+             (cons (concat prefix page) nil)
+           (setq lines (split-string page "\n")
+                 first-line (concat prefix (car lines) "\n" page-cnt)
+                 new-end (concat "\n" (make-string first-col-width 32)))
+           (cons
+            (concat first-line (mapconcat #'identity (cdr lines) new-end))
+            nil))))
+      (`top
+       (cons
+        (concat (when (or (=3D 0 echo-keystrokes)
+                          (not (eq which-key-side-window-location 'bottom)=
))
+                  (concat full-prefix " "))
+                status-line " " nxt-pg-hint "\n" page)
+        nil))
+      (`bottom
+       (cons
+        (concat page "\n"
+                (when (or (=3D 0 echo-keystrokes)
+                          (not (eq which-key-side-window-location 'bottom)=
))
+                  (concat full-prefix " "))
+                status-line " " nxt-pg-hint)
+        nil))
+      (`echo
+       (cons page
+             (lambda ()
+               (which-key--echo
+                (concat full-prefix (when prefix-desc " ")
+                        status-line (when status-line " ")
+                        nxt-pg-hint)))))
+      (`mode-line
+       (cons page
+             (lambda ()
+               (with-current-buffer which-key--buffer
+                 (setq-local mode-line-format
+                             (concat " " full-prefix
+                                     " " status-line
+                                     " " nxt-pg-hint))))))
+      (_ (cons page nil)))))
+
+(defun which-key--show-page (&optional n)
+  "Show current page.
+N changes the current page to the Nth page relative to the
+current one."
+  (which-key--init-buffer) ;; in case it was killed
+  (let ((prefix-keys (which-key--current-key-string))
+        golden-ratio-mode)
+    (if (null which-key--pages-obj)
+        (message "%s- which-key can't show keys: There is not \
+enough space based on your settings and frame size." prefix-keys)
+      (when n
+        (setq which-key--pages-obj
+              (which-key--pages-set-current-page which-key--pages-obj n)))
+      (let ((page-echo (which-key--process-page which-key--pages-obj))
+            (height (which-key--pages-height which-key--pages-obj))
+            (width (car (which-key--pages-widths which-key--pages-obj))))
+        (which-key--lighter-status)
+        (if (eq which-key-popup-type 'minibuffer)
+            (which-key--echo (car page-echo))
+          (with-current-buffer which-key--buffer
+            (erase-buffer)
+            (insert (car page-echo))
+            (goto-char (point-min)))
+          (when (cdr page-echo) (funcall (cdr page-echo)))
+          (which-key--show-popup (cons height width)))))
+    ;; used for paging at top-level
+    (if (fboundp 'set-transient-map)
+        (set-transient-map (which-key--get-popup-map))
+      (with-no-warnings
+        (set-temporary-overlay-map (which-key--get-popup-map))))))
+
+;;; Paging functions
+
+;;;###autoload
+(defun which-key-reload-key-sequence (&optional key-seq)
+  "Simulate entering the key sequence KEY-SEQ.
+KEY-SEQ should be a list of events as produced by
+`listify-key-sequence'. If nil, KEY-SEQ defaults to
+`which-key--current-key-list'. Any prefix arguments that were
+used are reapplied to the new key sequence."
+  (let* ((key-seq (or key-seq (which-key--current-key-list)))
+         (next-event (mapcar (lambda (ev) (cons t ev)) key-seq)))
+    (setq prefix-arg current-prefix-arg
+          unread-command-events next-event)))
+
+(defun which-key-turn-page (delta)
+  "Show the next page of keys."
+  (which-key-reload-key-sequence)
+  (if which-key--last-try-2-loc
+      (let ((which-key-side-window-location which-key--last-try-2-loc)
+            (which-key--multiple-locations t))
+        (which-key--show-page delta))
+    (which-key--show-page delta))
+  (which-key--start-paging-timer))
+
+;;;###autoload
+(defun which-key-show-standard-help (&optional _)
+  "Call the command in `which-key--prefix-help-cmd-backup'.
+Usually this is `describe-prefix-bindings'."
+  (interactive)
+  (let ((which-key-inhibit t)
+        (popup-showing (which-key--popup-showing-p)))
+    (which-key--hide-popup-ignore-command)
+    (cond ((and (eq which-key--prefix-help-cmd-backup
+                    'describe-prefix-bindings)
+                ;; If the popup is not showing, we call
+                ;; `describe-prefix-bindings' directly.
+                popup-showing)
+           ;; This is essentially what `describe-prefix-bindings' does. We=
 can't
+           ;; use this function directly, because the prefix will not be c=
orrect
+           ;; when we enter using `which-key-C-h-dispatch'.
+           (describe-bindings (kbd (which-key--current-key-string))))
+          ((functionp which-key--prefix-help-cmd-backup)
+           (funcall which-key--prefix-help-cmd-backup)))))
+
+;;;###autoload
+(defun which-key-show-next-page-no-cycle ()
+  "Show next page of keys unless on the last page, in which case
+call `which-key-show-standard-help'."
+  (interactive)
+  (let ((which-key-inhibit t))
+    (if (which-key--on-last-page)
+        (which-key-show-standard-help)
+      (which-key-turn-page 1))))
+
+;;;###autoload
+(defun which-key-show-previous-page-no-cycle ()
+  "Show previous page of keys unless on the first page, in which
+case do nothing."
+  (interactive)
+  (let ((which-key-inhibit t))
+    (unless (which-key--on-first-page)
+      (which-key-turn-page -1))))
+
+;;;###autoload
+(defun which-key-show-next-page-cycle (&optional _)
+  "Show the next page of keys, cycling from end to beginning
+after last page."
+  (interactive)
+  (let ((which-key-inhibit t))
+    (which-key-turn-page 1)))
+
+;;;###autoload
+(defun which-key-show-previous-page-cycle (&optional _)
+  "Show the previous page of keys, cycling from beginning to end
+after first page."
+  (interactive)
+  (let ((which-key-inhibit t))
+    (which-key-turn-page -1)))
+
+;;;###autoload
+(defun which-key-show-top-level (&optional _)
+  "Show top-level bindings."
+  (interactive)
+  (which-key--create-buffer-and-show nil nil nil "Top-level bindings"))
+
+;;;###autoload
+(defun which-key-show-major-mode (&optional all)
+  "Show top-level bindings in the map of the current major mode.
+
+This function will also detect evil bindings made using
+`evil-define-key' in this map. These bindings will depend on the
+current evil state. "
+  (interactive "P")
+  (let ((map-sym (intern (format "%s-map" major-mode))))
+    (if (and (boundp map-sym) (keymapp (symbol-value map-sym)))
+        (which-key--show-keymap
+         "Major-mode bindings"
+         (symbol-value map-sym)
+         (apply-partially #'which-key--map-binding-p (symbol-value map-sym=
))
+         all)
+      (message "which-key: No map named %s" map-sym))))
+
+;;;###autoload
+(defun which-key-show-full-major-mode ()
+  "Show all bindings in the map of the current major mode.
+
+This function will also detect evil bindings made using
+`evil-define-key' in this map. These bindings will depend on the
+current evil state. "
+  (interactive)
+  (which-key-show-major-mode t))
+
+;;;###autoload
+(defun which-key-dump-bindings (prefix buffer-name)
+  "Dump bindings from PREFIX into buffer named BUFFER-NAME.
+
+PREFIX should be a string suitable for `kbd'."
+  (interactive "sPrefix: \nB")
+  (let* ((buffer (get-buffer-create buffer-name))
+         (keys (which-key--get-bindings (kbd prefix))))
+    (with-current-buffer buffer
+      (point-max)
+      (save-excursion
+        (dolist (key keys)
+          (insert (apply #'format "%s%s%s\n" key)))))
+    (switch-to-buffer-other-window buffer)))
+
+;;;###autoload
+(defun which-key-undo-key (&optional _)
+  "Undo last keypress and force which-key update."
+  (interactive)
+  (let* ((key-lst (butlast (which-key--current-key-list)))
+         (which-key-inhibit t))
+    (cond (which-key--prior-show-keymap-args
+           (if (keymapp (cdr (car-safe which-key--prior-show-keymap-args)))
+               (let ((args (pop which-key--prior-show-keymap-args)))
+                 (which-key--show-keymap (car args) (cdr args)))
+             (which-key--hide-popup)))
+          (key-lst
+           (which-key-reload-key-sequence key-lst)
+           (which-key--create-buffer-and-show (apply #'vector key-lst)))
+          (t (setq which-key--automatic-display nil)
+             (which-key-show-top-level)))))
+(defalias 'which-key-undo #'which-key-undo-key)
+
+(defun which-key-abort (&optional _)
+  "Abort key sequence."
+  (interactive)
+  (let ((which-key-inhibit t))
+    (which-key--hide-popup-ignore-command)
+    (keyboard-quit)))
+
+(defun which-key-digit-argument (key)
+  "Version of `digit-argument' for use in `which-key-C-h-map'."
+  (interactive)
+  (let ((last-command-event (string-to-char key)))
+    (digit-argument key))
+  (let ((current-prefix-arg prefix-arg))
+    (which-key-reload-key-sequence)))
+
+(defun which-key-toggle-docstrings (&optional _)
+  "Toggle the display of docstrings."
+  (interactive)
+  (unless (eq which-key-show-docstrings 'docstring-only)
+    (setq which-key-show-docstrings (null which-key-show-docstrings)))
+  (which-key-reload-key-sequence)
+  (which-key--create-buffer-and-show (which-key--current-prefix)))
+
+;;;###autoload
+(defun which-key-C-h-dispatch ()
+  "Dispatch C-h commands by looking up key in
+`which-key-C-h-map'. This command is always accessible (from any
+prefix) if `which-key-use-C-h-commands' is non nil."
+  (interactive)
+  (cond ((and (not (which-key--popup-showing-p))
+              which-key-show-early-on-C-h)
+         (let ((current-prefix
+                (butlast
+                 (listify-key-sequence (which-key--this-command-keys)))))
+           (which-key-reload-key-sequence current-prefix)
+           (if which-key-idle-secondary-delay
+               (which-key--start-timer which-key-idle-secondary-delay t)
+             (which-key--start-timer 0.05 t))))
+        ((not (which-key--popup-showing-p))
+         (which-key-show-standard-help))
+        (t
+         (if (not (which-key--popup-showing-p))
+             (which-key-show-standard-help)
+           (let* ((prefix-keys (which-key--current-key-string))
+                  (full-prefix (which-key--full-prefix prefix-keys current=
-prefix-arg t))
+                  (prompt (concat (when (string-equal prefix-keys "")
+                                    (which-key--propertize
+                                     (concat " "
+                                             (which-key--pages-prefix-title
+                                              which-key--pages-obj))
+                                     'face 'which-key-note-face))
+                                  full-prefix
+                                  (which-key--propertize
+                                   (substitute-command-keys
+                                    which-key-C-h-map-prompt)
+                                   'face 'which-key-note-face)))
+                  (key (let ((key (read-key prompt)))
+                         (if (numberp key)
+                             (string key)
+                           (vector key))))
+                  (cmd (lookup-key which-key-C-h-map key))
+                  (which-key-inhibit t))
+             (if cmd (funcall cmd key) (which-key-turn-page 0)))))))
+
+;;; Update
+
+(defun which-key--any-match-p (regexps string)
+  "Non-nil if any of REGEXPS match STRING."
+  (catch 'match
+    (dolist (regexp regexps)
+      (when (string-match-p regexp string)
+        (throw 'match t)))))
+
+(defun which-key--try-2-side-windows
+    (bindings prefix-keys prefix-title loc1 loc2 &rest _ignore)
+  "Try to show BINDINGS (PAGE-N) in LOC1 first.
+
+Only if no bindings fit fallback to LOC2."
+  (let (pages1)
+    (let ((which-key-side-window-location loc1)
+          (which-key--multiple-locations t))
+      (setq pages1 (which-key--create-pages
+                    bindings prefix-keys prefix-title)))
+    (if pages1
+        (progn
+          (setq which-key--pages-obj pages1)
+          (let ((which-key-side-window-location loc1)
+                (which-key--multiple-locations t))
+            (which-key--show-page))
+          loc1)
+      (let ((which-key-side-window-location loc2)
+            (which-key--multiple-locations t))
+        (setq which-key--pages-obj
+              (which-key--create-pages bindings prefix-keys prefix-title))
+        (which-key--show-page)
+        loc2))))
+
+(defun which-key--read-keymap ()
+  "Read keymap symbol from minibuffer."
+  (intern
+   (completing-read "Keymap: " obarray
+                    (lambda (m)
+                      (and (boundp m)
+                           (keymapp (symbol-value m))
+                           (not (equal (symbol-value m)
+                                       (make-sparse-keymap)))))
+                    t
+                    (let ((sym (symbol-at-point)))
+                      (and (boundp sym)
+                           (keymapp (symbol-value sym))
+                           (symbol-name sym)))
+                    'which-key-keymap-history)))
+
+;;;###autoload
+(defun which-key-show-keymap (keymap &optional no-paging)
+  "Show the top-level bindings in KEYMAP using which-key.
+KEYMAP is selected interactively from all available keymaps.
+
+If NO-PAGING is non-nil, which-key will not intercept subsequent
+keypresses for the paging functionality."
+  (interactive (list (which-key--read-keymap)))
+  (which-key--show-keymap (symbol-name keymap)
+                          (symbol-value keymap)
+                          nil nil no-paging))
+
+;;;###autoload
+(defun which-key-show-full-keymap (keymap)
+  "Show all bindings in KEYMAP using which-key.
+KEYMAP is selected interactively from all available keymaps."
+  (interactive (list (which-key--read-keymap)))
+  (which-key--show-keymap (symbol-name keymap)
+                          (symbol-value keymap)
+                          nil t))
+
+;;;###autoload
+(defun which-key-show-minor-mode-keymap (&optional all)
+  "Show the top-level bindings in KEYMAP using which-key.
+KEYMAP is selected interactively by mode in
+`minor-mode-map-alist'."
+  (interactive)
+  (let ((mode-sym
+         (intern
+          (completing-read
+           "Minor Mode: "
+           (mapcar #'car
+                   (cl-remove-if-not
+                    (lambda (entry)
+                      (and (symbol-value (car entry))
+                           (not (equal (cdr entry) (make-sparse-keymap)))))
+                    minor-mode-map-alist))
+           nil t nil 'which-key-keymap-history))))
+    (which-key--show-keymap (symbol-name mode-sym)
+                            (cdr (assq mode-sym minor-mode-map-alist))
+                            all)))
+;;;###autoload
+(defun which-key-show-full-minor-mode-keymap ()
+  "Show all bindings in KEYMAP using which-key.
+KEYMAP is selected interactively by mode in
+`minor-mode-map-alist'."
+  (interactive)
+  (which-key-show-minor-mode-keymap t))
+
+(defun which-key--show-keymap
+    (keymap-name keymap &optional prior-args all no-paging filter)
+  (when prior-args (push prior-args which-key--prior-show-keymap-args))
+  (let ((bindings (which-key--get-bindings nil keymap filter all)))
+    (if (=3D (length bindings) 0)
+        (message "which-key: No bindings found in %s" keymap-name)
+      (cond ((listp which-key-side-window-location)
+             (setq which-key--last-try-2-loc
+                   (apply #'which-key--try-2-side-windows
+                          bindings nil keymap-name
+                          which-key-side-window-location)))
+            (t (setq which-key--pages-obj
+                     (which-key--create-pages bindings nil keymap-name))
+               (which-key--show-page)))
+      (unless no-paging
+        (let* ((key (read-key))
+               (key-desc (key-description (list key)))
+               (next-def (lookup-key keymap (vector key))))
+          (cond ((and which-key-use-C-h-commands
+                      (numberp key) (=3D key help-char))
+                 (which-key-C-h-dispatch))
+                ((keymapp next-def)
+                 (which-key--hide-popup-ignore-command)
+                 (which-key--show-keymap
+                  (concat keymap-name " " key-desc)
+                  next-def
+                  (cons keymap-name keymap)))
+                (t (which-key--hide-popup))))))))
+
+(defun which-key--evil-operator-filter (binding)
+  (let ((def (intern (cdr binding))))
+    (and (functionp def)
+         (not (evil-get-command-property def :suppress-operator)))))
+
+(defun which-key--show-evil-operator-keymap ()
+  (if which-key--inhibit-next-operator-popup
+      (setq which-key--inhibit-next-operator-popup nil)
+    (let ((keymap
+           (make-composed-keymap (list evil-operator-shortcut-map
+                                       evil-operator-state-map
+                                       evil-motion-state-map))))
+      (when (keymapp keymap)
+        (let ((formatted-keys
+               (which-key--get-bindings
+                nil keymap #'which-key--evil-operator-filter)))
+          (cond ((=3D (length formatted-keys) 0)
+                 (message "which-key: Keymap empty"))
+                ((listp which-key-side-window-location)
+                 (setq which-key--last-try-2-loc
+                       (apply #'which-key--try-2-side-windows
+                              formatted-keys nil "evil operator/motion key=
s"
+                              which-key-side-window-location)))
+                (t (setq which-key--pages-obj
+                         (which-key--create-pages
+                          formatted-keys
+                          nil "evil operator/motion keys"))
+                   (which-key--show-page)))))
+      (let* ((key (read-key)))
+        (when (member key '(?f ?F ?t ?T ?`))
+          ;; these keys trigger commands that read the next char manually
+          (setq which-key--inhibit-next-operator-popup t))
+        (cond ((and which-key-use-C-h-commands (numberp key) (=3D key help=
-char))
+               (which-key-C-h-dispatch))
+              ((and (numberp key) (=3D key ?\C-\[))
+               (which-key--hide-popup)
+               (keyboard-quit))
+              (t
+               (which-key--hide-popup)
+               (setq unread-command-events (vector key))))))))
+
+(defun which-key--create-buffer-and-show
+    (&optional prefix-keys from-keymap filter prefix-title)
+  "Fill `which-key--buffer' with key descriptions and reformat.
+Finally, show the buffer."
+  (let ((start-time (current-time))
+        (formatted-keys (which-key--get-bindings
+                         prefix-keys from-keymap filter))
+        (prefix-desc (key-description prefix-keys)))
+    (cond ((=3D (length formatted-keys) 0)
+           (message "%s-  which-key: There are no keys to show" prefix-des=
c))
+          ((listp which-key-side-window-location)
+           (setq which-key--last-try-2-loc
+                 (apply #'which-key--try-2-side-windows
+                        formatted-keys prefix-keys prefix-title
+                        which-key-side-window-location)))
+          (t (setq which-key--pages-obj
+                   (which-key--create-pages
+                    formatted-keys prefix-keys prefix-title))
+             (which-key--show-page)))
+    (which-key--debug-message
+     "On prefix \"%s\" which-key took %.0f ms." prefix-desc
+     (* 1000 (float-time (time-since start-time))))))
+
+(defun which-key--this-command-keys ()
+  "Version of `this-single-command-keys' corrected for key-chords and god-=
mode."
+  (let ((this-command-keys (this-single-command-keys)))
+    (when (and (vectorp this-command-keys)
+               (> (length this-command-keys) 0)
+               (eq (aref this-command-keys 0) 'key-chord)
+               (bound-and-true-p key-chord-mode))
+      (setq this-command-keys (this-single-command-raw-keys)))
+    (when (and which-key--god-mode-support-enabled
+               (bound-and-true-p god-local-mode)
+               (eq this-command 'god-mode-self-insert))
+      (setq this-command-keys (when which-key--god-mode-key-string
+                                (kbd which-key--god-mode-key-string))))
+    this-command-keys))
+
+(defun which-key--update ()
+  "Function run by timer to possibly trigger
+`which-key--create-buffer-and-show'."
+  (let ((prefix-keys (which-key--this-command-keys))
+        delay-time)
+    (cond ((and (> (length prefix-keys) 0)
+                (or (keymapp (key-binding prefix-keys))
+                    ;; Some keymaps are stored here like iso-transl-ctl-x-=
8-map
+                    (keymapp (which-key--safe-lookup-key
+                              key-translation-map prefix-keys))
+                    ;; just in case someone uses one of these
+                    (keymapp (which-key--safe-lookup-key
+                              function-key-map prefix-keys)))
+                (not which-key-inhibit)
+                (or (null which-key-allow-regexps)
+                    (which-key--any-match-p
+                     which-key-allow-regexps (key-description prefix-keys)=
))
+                (or (null which-key-inhibit-regexps)
+                    (not
+                     (which-key--any-match-p
+                      which-key-inhibit-regexps (key-description prefix-ke=
ys))))
+                ;; Do not display the popup if a command is currently being
+                ;; executed
+                (or (and which-key-allow-evil-operators
+                         (bound-and-true-p evil-this-operator))
+                    (and which-key--god-mode-support-enabled
+                         (bound-and-true-p god-local-mode)
+                         (eq this-command 'god-mode-self-insert))
+                    (null this-command))
+                (let ((max-dim (which-key--popup-max-dimensions)))
+                  (> (min (car-safe max-dim) (cdr-safe max-dim)) 0)))
+           (when (and (not (equal prefix-keys (which-key--current-prefix)))
+                      (or (null which-key-delay-functions)
+                          (null (setq delay-time
+                                      (run-hook-with-args-until-success
+                                       'which-key-delay-functions
+                                       (key-description prefix-keys)
+                                       (length prefix-keys))))
+                          (sit-for delay-time)))
+             (setq which-key--automatic-display t)
+             (which-key--create-buffer-and-show prefix-keys)
+             (when (and which-key-idle-secondary-delay
+                        (not which-key--secondary-timer-active))
+               (which-key--start-timer which-key-idle-secondary-delay t))))
+          ((and which-key-show-transient-maps
+                ;; Assuming that if this is not true we're in
+                ;; `which-key-show-top-level', which would then be overwri=
tten.
+                (> (length prefix-keys) 0)
+                (keymapp overriding-terminal-local-map)
+                ;; basic test for it being a hydra
+                (not (eq (lookup-key overriding-terminal-local-map "\C-u")
+                         'hydra--universal-argument)))
+           (which-key--create-buffer-and-show
+            nil overriding-terminal-local-map))
+          ((and which-key-show-operator-state-maps
+                (bound-and-true-p evil-state)
+                (eq evil-state 'operator)
+                (not (which-key--popup-showing-p)))
+           (which-key--show-evil-operator-keymap))
+          (which-key--automatic-display
+           (which-key--hide-popup)))))
+
+;;; Timers
+
+(defun which-key--start-timer (&optional delay secondary)
+  "Activate idle timer to trigger `which-key--update'."
+  (which-key--stop-timer)
+  (setq which-key--secondary-timer-active secondary)
+  (setq which-key--timer
+        (run-with-idle-timer (or delay which-key-idle-delay)
+                             t #'which-key--update)))
+
+(defun which-key--stop-timer ()
+  "Deactivate idle timer for `which-key--update'."
+  (when which-key--timer (cancel-timer which-key--timer)))
+
+(defun which-key--start-paging-timer ()
+  "Activate timer to restart which-key after paging."
+  (when which-key--paging-timer (cancel-timer which-key--paging-timer))
+  (which-key--stop-timer)
+  (setq which-key--paging-timer
+        (run-with-idle-timer
+         0.2 t (lambda ()
+                 (when (or (not (member real-last-command
+                                        which-key--paging-functions))
+                           (and (< 0 (length (this-single-command-keys)))
+                                (not (equal (which-key--current-prefix)
+                                            (which-key--this-command-keys)=
))))
+                   (cancel-timer which-key--paging-timer)
+                   (if which-key-idle-secondary-delay
+                       ;; we haven't executed a command yet so the secanda=
ry
+                       ;; timer is more relevant here
+                       (which-key--start-timer which-key-idle-secondary-de=
lay t)
+                     (which-key--start-timer)))))))
+
+(provide 'which-key)
+;;; which-key.el ends here
--=20
2.42.0


--=-=-=--




Acknowledgement sent to Jeremy Bryant <jb@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#68929; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 15 Apr 2024 11:30:14 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.