Ihor Radchenko <yanta...@posteo.net> writes:

> I see no downside supporting `help-quick' command in Org mode's column
> view. Generally, better integration with Emacs built-in functionality is
> welcome.

Great. I'll be happy to take care of it.

But first, we need to modify `help-quick' to be more reusable.
I tried to do it, but I'm not experienced in elisp.
I wanted to remove references to global variables, so I did a wrapper
function to pass arguments to `help-quick'. I understand it's not a lispy way.
I would be grateful for your comment. 

Patch in attachment.
>From 5f343fd15c53f5bc5e7515ef0cd3049b4e0ec388 Mon Sep 17 00:00:00 2001
From: Slawomir Grochowski <slawomir.grochow...@gmail.com>
Date: Sat, 6 Apr 2024 22:11:01 +0200
Subject: [PATCH] lisp/help: make `help-quick-toggle' reusable for other
 keymaps

---
 lisp/help.el | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/lisp/help.el b/lisp/help.el
index 1ef46e394f3..c32d1a2e943 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -76,7 +76,7 @@ help-map
   "C-n"  #'view-emacs-news
   "C-o"  #'describe-distribution
   "C-p"  #'view-emacs-problems
-  "C-q"  #'help-quick-toggle
+  "C-q"  #'help-quick-toggle-wrapper
   "C-s"  #'search-forward-help-for-help
   "C-t"  #'view-emacs-todo
   "C-w"  #'describe-no-warranty
@@ -178,22 +178,22 @@ help-quick-sections
 (declare-function prop-match-value "text-property-search" (match))
 
 ;; Inspired by a mg fork (https://github.com/troglobit/mg)
-(defun help-quick ()
+(defun help-quick (name-for-buffer sections &optional keymap)
   "Display a quick-help buffer showing popular commands and their bindings.
 The window showing quick-help can be toggled using \\[help-quick-toggle].
 You can click on a key binding shown in the quick-help buffer to display
 the documentation of the command bound to that key sequence."
   (interactive)
-  (with-current-buffer (get-buffer-create "*Quick Help*")
+  (with-current-buffer (get-buffer-create name-for-buffer)
     (let ((inhibit-read-only t) (padding 2) blocks)
 
       ;; Go through every section and prepare a text-rectangle to be
       ;; inserted later.
-      (dolist (section help-quick-sections)
+      (dolist (section 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))
+              (let* ((bind (where-is-internal (car ent) keymap t))
                      (key (if bind
                               (propertize
                                (key-description bind)
@@ -259,21 +259,25 @@ help-quick
     (message
      (substitute-command-keys "Toggle display of quick-help buffer using \\[help-quick-toggle]."))))
 
-(defun help-quick-toggle ()
+(defun help-quick-toggle-wrapper ()
+  (interactive)
+  (help-quick-toggle "*Quick Help*" help-quick-sections))
+
+(defun help-quick-toggle (name-for-buffer sections &optional keymap)
   "Toggle display of a window showing popular commands and their bindings.
 This toggles on and off the display of the quick-help buffer, which shows
 popular commands and their bindings as produced by `help-quick'.
 You can click on a key binding shown in the quick-help buffer to display
 the documentation of the command bound to that key sequence."
   (interactive)
-  (if (and-let* ((window (get-buffer-window "*Quick Help*")))
+  (if (and-let* ((window (get-buffer-window name-for-buffer)))
         (quit-window t window))
       ;; Clear the message we may have gotten from `C-h' and then
       ;; waiting before hitting `q'.
       (message "")
-    (help-quick)))
+    (help-quick name-for-buffer sections keymap)))
 
-(defalias 'cheat-sheet #'help-quick)
+(defalias 'cheat-sheet #'help-quick-wrapper)
 
 (defun help-quit ()
   "Just exit from the Help command's command loop."
-- 
2.30.2

JD Smith <jdtsm...@gmail.com> writes: 

> Also recall we had a discussion in bug#68236 
> <https://lists.gnu.org/archive/html/bug-gnu-emacs/2024-01/msg00124.html> 
> about expanding quick-help to include mode-local
> personalized binding shortcuts (with org as a particular target of interest).

Thank you for the link I haven't seen that topic.
 
Regards,
-- 
Slawomir Grochowski

Reply via email to