From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: JD Smith Newsgroups: gmane.emacs.bugs Subject: bug#68236: [PATCH] help.el: allow help-quick to use local commands/quick-sections Date: Wed, 3 Jan 2024 22:08:56 -0500 Message-ID: <1B0F351A-C393-4C1B-B883-814F2C33E802@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.300.61.1.2\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20650"; mail-complaints-to="usenet@ciao.gmane.io" To: 68236@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jan 04 04:10:22 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rLE7h-0005DK-GN for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 04 Jan 2024 04:10:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLE7O-0004mU-39; Wed, 03 Jan 2024 22:10:02 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLE7N-0004lv-0G for bug-gnu-emacs@gnu.org; Wed, 03 Jan 2024 22:10:01 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLE7L-0002RR-7u for bug-gnu-emacs@gnu.org; Wed, 03 Jan 2024 22:10:00 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rLE7O-0000Ge-JI for bug-gnu-emacs@gnu.org; Wed, 03 Jan 2024 22:10:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: JD Smith Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 04 Jan 2024 03:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 68236 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.1704337766970 (code B ref -1); Thu, 04 Jan 2024 03:10:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 4 Jan 2024 03:09:26 +0000 Original-Received: from localhost ([127.0.0.1]:53383 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rLE6n-0000FZ-Ha for submit@debbugs.gnu.org; Wed, 03 Jan 2024 22:09:26 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:59144) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rLE6k-0000FJ-CX for submit@debbugs.gnu.org; Wed, 03 Jan 2024 22:09:23 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLE6a-0004ib-Tv for bug-gnu-emacs@gnu.org; Wed, 03 Jan 2024 22:09:13 -0500 Original-Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLE6Y-0002LL-Ew for bug-gnu-emacs@gnu.org; Wed, 03 Jan 2024 22:09:12 -0500 Original-Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-427f4407624so476501cf.3 for ; Wed, 03 Jan 2024 19:09:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704337748; x=1704942548; darn=gnu.org; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:from:to:cc:subject:date:message-id:reply-to; bh=mmL6jv4KCuK2GtYn3wydPJAuNl8RlD0YajhFpkejIys=; b=GIEc+JjX9hquVl45sZOBsvaMfTjzyrltZ6p0feMVOPe67aHAQKG7Mli3l13jT9o6Bl xj4YxeQ8LtxZzUMdvIT0fqpymZ4CiKVjZV5qcpLyE+Zhkn84yIyWxl500vTqHxYLTt9z y6GyurjR0oawUbLo5ztrGxmy4nCTfJVfGOH4dY/YdbQVMedGXwi9IlqskxBFxw9uznV4 F2PdHqa0Kk1/uu7kLWpmDR3czs6O3WDpsiDzEfeCRYDdiUUVZL9V26pfI7Vis6voNdl1 ekOOhSnUXlOGTNxG25G3fdoJxhzPIXwWFZIHV41nEa/rDsTABYDi6sQVk13nPF3nLNeR diQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704337748; x=1704942548; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mmL6jv4KCuK2GtYn3wydPJAuNl8RlD0YajhFpkejIys=; b=vqbKrjIVwn3DPE/UQrxtyb00FDKMAs3RkseoH2RoXPnWtPdUrWtwXeKHOxM59Jwo4Q n1ZXteK5a2fGD0APsA6cNnkycqPCPNE++B2+0l//UvTJSdJuzQpekP8y1RrGDivl0s5F G4KPRGYyBA4UbrnKwcc5eZGnQ0n67maYrv0eb/KnUyFZxBziyyE5cZCKW6zmSZcXyA9M 8QA8ZYVg6kcvvcHfhcZeHHqX9n/1unGKpBhizmYqZZcuqO6BR8XcP7afIbevJPebafTC wyc1QfE934iTqcW2jSymltaJjYsYmVwXEkb8oGF2ot58xVWfELfP0qvMf1gyKXYt3HXp zB9A== X-Gm-Message-State: AOJu0Yx8DlCkkD6CwQ6lRbUT7jVsuTIIeb9LB6244EzUPBCcV4Rqrfhw AshCnd49HaomJEkCwCLKwc6xML9Arlrbbg== X-Google-Smtp-Source: AGHT+IEBWAR1FstEZs25FVxoSaQxTUD/ArgT45mZ2YxcMrFat4Md4jBasfvzouRYzaDDM6/c6vjKlQ== X-Received: by 2002:ac8:5705:0:b0:428:2654:eac1 with SMTP id 5-20020ac85705000000b004282654eac1mr11436qtw.107.1704337748062; Wed, 03 Jan 2024 19:09:08 -0800 (PST) Original-Received: from smtpclient.apple (cm-24-53-187-34.buckeyecom.net. [24.53.187.34]) by smtp.gmail.com with ESMTPSA id fv22-20020a05622a4a1600b00427f0fdcd44sm8021820qtb.1.2024.01.03.19.09.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jan 2024 19:09:07 -0800 (PST) X-Mailer: Apple Mail (2.3774.300.61.1.2) Received-SPF: pass client-ip=2607:f8b0:4864:20::82d; envelope-from=jdtsmith@gmail.com; helo=mail-qt1-x82d.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:277294 Archived-At: Someone came up with the great idea of using help.el=E2=80=99s = `help-quick' command for a personal =E2=80=9Cscratch pad=E2=80=9D of = useful/hard-to-remember bindings, and then to bind `help-quick-sections' = locally in various modes. Unfortunately, `help-quick' first sets the = buffer to *Quick Help* and then builds its list of command bindings and = descriptions. This means that only the default value of = `help-quick-sections=E2=80=99 will ever be consulted, and no local key = bindings can be expressed. =20 The fix is simple; build the list of quick help information first in the = current buffer (from which C-h C-q is called) and then displaying it in = the *Quick Help* buffer. With this, people can use quick help and its = handy binding to prompt with their own personal hard-to-remember key = bindings/command info. What=E2=80=99s cool is that help-quick omits = =E2=80=9Cempty=E2=80=9D sections, so you could even add a variety of = sections, and they will appear if and only if bindings are actually = available in the buffer where quick help is invoked. +++ diff -u lisp/help.el lisp/help_fix_quick.el --- lisp/help.el 2024-01-03 21:54:46 +++ lisp/help_fix_quick.el 2024-01-03 21:52:46 @@ -173,78 +173,79 @@ (defun help-quick () "Display a quick-help buffer." (interactive) - (with-current-buffer (get-buffer-create "*Quick Help*") - (let ((inhibit-read-only t) (padding 2) blocks) + (let ((buf (get-buffer-create "*Quick Help*")) + (inhibit-read-only t) (padding 2) blocks) =20 - ;; Go through every section and prepare a text-rectangle to be - ;; inserted later. - (dolist (section help-quick-sections) - (let ((max-key-len 0) (max-cmd-len 0) keys) - (dolist (ent (reverse (cdr section))) - (catch 'skip - (let* ((bind (where-is-internal (car ent) nil t)) - (key (if bind - (propertize - (key-description bind) - 'face 'help-key-binding) - (throw 'skip nil)))) - (setq max-cmd-len (max (length (cdr ent)) max-cmd-len) - max-key-len (max (length key) max-key-len)) - (push (list key (cdr ent) (car ent)) keys)))) - (when keys - (let ((fmt (format "%%-%ds %%-%ds%s" max-key-len = max-cmd-len - (make-string padding ?\s))) - (width (+ max-key-len 1 max-cmd-len padding))) - (push `(,width - ,(propertize - (concat - (car section) - (make-string (- width (length (car section))) = ?\s)) - 'face 'bold) - ,@(mapcar (lambda (ent) - (format fmt - (propertize - (car ent) - 'quick-help-cmd - (caddr ent)) - (cadr ent))) - keys)) - blocks))))) + ;; Go through every section and prepare a text-rectangle to be + ;; inserted later. + (dolist (section help-quick-sections) + (let ((max-key-len 0) (max-cmd-len 0) keys) + (dolist (ent (reverse (cdr section))) + (catch 'skip + (let* ((bind (where-is-internal (car ent) nil t)) + (key (if bind + (propertize + (key-description bind) + 'face 'help-key-binding) + (throw 'skip nil)))) + (setq max-cmd-len (max (length (cdr ent)) max-cmd-len) + max-key-len (max (length key) max-key-len)) + (push (list key (cdr ent) (car ent)) keys)))) + (when keys + (let ((fmt (format "%%-%ds %%-%ds%s" max-key-len max-cmd-len + (make-string padding ?\s))) + (width (+ max-key-len 1 max-cmd-len padding))) + (push `(,width + ,(propertize + (concat + (car section) + (make-string (- width (length (car section))) = ?\s)) + 'face 'bold) + ,@(mapcar (lambda (ent) + (format fmt + (propertize + (car ent) + 'quick-help-cmd + (caddr ent)) + (cadr ent))) + keys)) + blocks))))) =20 - ;; Insert each rectangle in order until they don't fit into the - ;; frame any more, in which case the next sections are inserted - ;; in a new "line". + ;; Insert each rectangle in order until they don't fit into the + ;; frame any more, in which case the next sections are inserted + ;; in a new "line". + (with-current-buffer buf (erase-buffer) (dolist (block (nreverse blocks)) - (when (> (+ (car block) (current-column)) (frame-width)) + (when (> (+ (car block) (current-column)) (frame-width)) (goto-char (point-max)) (newline 2)) - (save-excursion + (save-excursion (insert-rectangle (cdr block))) - (end-of-line)) + (end-of-line)) (delete-trailing-whitespace) =20 (save-excursion - (goto-char (point-min)) - (while-let ((match (text-property-search-forward = 'quick-help-cmd))) + (goto-char (point-min)) + (while-let ((match (text-property-search-forward = 'quick-help-cmd))) (make-text-button (prop-match-beginning match) (prop-match-end match) 'mouse-face 'highlight 'button t 'keymap button-map 'action #'describe-symbol - 'button-data (prop-match-value match))))) + 'button-data (prop-match-value match)))) =20 - (help-mode) + (help-mode)) =20 ;; Display the buffer at the bottom of the frame... - (with-selected-window (display-buffer-at-bottom (current-buffer) = '()) + (with-selected-window (display-buffer-at-bottom buf '()) ;; ... mark it as dedicated to prevent focus from being stolen (set-window-dedicated-p (selected-window) t) ;; ... and shrink it immediately. - (fit-window-to-buffer)) - (message - (substitute-command-keys "Toggle the quick help buffer using = \\[help-quick-toggle].")))) + (fit-window-to-buffer))) + (message + (substitute-command-keys "Toggle the quick help buffer using = \\[help-quick-toggle]."))) =20 (defun help-quick-toggle () "Toggle the quick-help window."