emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding a "quick-help" menu


From: Philip Kaludercic
Subject: Re: Adding a "quick-help" menu
Date: Fri, 16 Sep 2022 21:03:54 +0000

Philip Kaludercic <philipk@posteo.net> writes:

> There is a fork of mg (MicroEmacs)[0] that binds C-h q to a command that
> pops up a buffer with these contents:
>
> FILE             BUFFER          WINDOW           MARK/KILL       MISC
> C-x C-c  exit    C-x C-k close   C-0   only other C-space  mark   C-_ undo
> C-x C-f  find    C-x k   other   C-1   only this  C-w      wipe   C-s search
> C-x C-s  save    C-x C-b list    C-2   split two  C-k      close  C-r r-search
> C-x s    all     C-x b   switch  C-x ^ enlarge    C-y      yank   M-% replace
> C-x i    insert  C-x g   goto ln C-x o other win  C-x C-x  swap   M-q reformat
> ______________________________________________________________________________
> C-h q  toggle quick help  |  C-h t  show tutorial  |  C-h b  show key bindings
>
> I notice that in GNU Emacs C-h q is bound to `help-quit', which does
> nothing if you are not in the help command loop.  Would having a
> "quick-help" menu along these lines for common operations make sense for
> GNU Emacs as well?
>
> [0] https://github.com/troglobit/mg

Here is a quick sketch of how this could look like:

--8<---------------cut here---------------start------------->8---
(defvar help-quick-sections
  '(("... FILE"
     (save-buffers-kill-terminal . "exit")
     (find-file . "find")
     (save-buffer . "save")
     (save-some-buffers . "all")
     (insert-file . "insert"))
    ("... BUFFER"
     (kill-buffer . "kill")
     (other-window . "other")
     (list-buffers . "list")
     (switch-to-buffer . "switch")
     (goto-line . "goto line"))
    ("... WINDOW"
     (delete-window . "only other")
     (delete-other-windows . "only this")
     (split-window-below . "split vert.")
     (split-window-right . "split horiz.")
     (enlarge-window . "enlarge")
     (other-window . "other"))
    ("MARK/KILL"
     (set-mark-command . "mark")
     (kill-region . "wipe")
     (kill-line . "kill")
     (yank . "yank")
     (exchange-point-and-mark . "swap"))
    ("MISC"
     (undo . "undo")
     (isearch-forward . "search")
     (isearch-backward . "rev-search")
     (query-replace . "replace")
     (fill-paragraph . "reformat"))))z

;; Inspired by a mg fork (https://github.com/troglobit/mg)
(defun help-quick ()
  "Display a quick-help buffer."
  (interactive)
  (with-current-buffer (get-buffer-create "*Quick Help*")
    (let ((inhibit-read-only t) blocks)
      (dolist (section help-quick-sections)
        (let ((max-key-len 0) (max-cmd-len 0) keys)
          (dolist (ent (reverse (cdr section)))
            (let* ((bind (where-is-internal (car ent) nil t))
                   (key (if bind
                            (propertize (key-description bind)
                                        'face 'help-key-binding)
                          " -/-")))
              (setq max-cmd-len (max (length (cdr ent))
                                     max-cmd-len)
                    max-key-len (max (length key)
                                     max-key-len))
              (push (cons key (cdr ent)) keys)))
          (let ((fmt (format "%%-%ds %%-%ds   " max-key-len max-cmd-len)))
            (push `(,(propertize
                      (concat
                       (car section)
                       (make-string (- (+ max-key-len 1 max-cmd-len 3)
                                       (length (car section)))
                                    ?\s))
                      'face 'shortdoc-heading)
                    ,@(mapcar
                       (lambda (ent)
                         (format fmt (car ent) (cdr ent)))
                       keys))
                  blocks))))

      (erase-buffer)
      (dolist (block (nreverse blocks))
        (when (> (+ (length (car block))
                    (current-column))
                 (window-width))
          (goto-char (point-max))
          (newline 2))
        (save-excursion
          (insert-rectangle block))
        (end-of-line))
      (delete-trailing-whitespace))

    ;; Display the buffer at the bottom of the page and shrink it
    ;; immediately.
    (help-mode)
    (read-only-mode t)
    (let ((win (display-buffer-at-bottom (current-buffer) '())))
      (fit-window-to-buffer win)
      (select-window win)
      (goto-char (point-min)))))
--8<---------------cut here---------------end--------------->8---



reply via email to

[Prev in Thread] Current Thread [Next in Thread]