epithet icon indicating copy to clipboard operation
epithet copied to clipboard

Problem with M-x describe-bindings

Open DamienCassou opened this issue 3 years ago • 1 comments

Steps to reproduce

  1. launch emacs -Q
  2. execute the following
    (progn
      (add-to-list 'load-path "~/.emacs.d/lib/epithet")
      (require 'epithet)
      (add-hook 'help-mode-hook #'epithet-rename-buffer))
    
  3. Type M-x describe-bindings RET

Expected: You get a buffer with all bindings of the previously-selected buffer Actual: You get an empty buffer

If you follow the same steps except step 2, everything works fine.

DamienCassou avatar Jun 07 '22 11:06 DamienCassou

+1, also have this issue.

jakebox avatar Jun 27 '22 14:06 jakebox

I finally came back to this and this time I managed to figure out what goes wrong. The thing is that describe-bindings does this:

  (with-help-window (help-buffer)
    ;; Be aware that `describe-buffer-bindings' puts its output into
    ;; the current buffer.
    (with-current-buffer (help-buffer)
      (describe-buffer-bindings buffer prefix)

The help-buffer function returns the name to be used for the help buffer. There are some special cases, but purposes of this discussions you can think of it as always returning the string "*Help*". So what happens is that with-help-window creates the *Help* buffer and puts it into help-mode. Since you have epithet-rename-buffer on the help-mode-hook, it runs at that point, when the buffer is still empty and renames it to *Help: describe-bindings for SOME-major-mode. And then, after that, describe-buffer-bindings is run to write the bindings into the buffer named (help-buffer), i.e., *Help*.

So the end result is that you get two buffers: one called *Help* with all the key bindings and an empty one with the name epithet gave it, *Help: describe-bindings for SOME-major-mode.

I think the only sensible way to solve this without changing the code of describe-bindings is to have epithet-for-help refuse to rename the describe-bindings buffer until it is already fully written out. Then, you'd have to add this to your configuration:

(advice-add 'describe-bindings :after
            (lambda (&rest _)
              (with-current-buffer (help-buffer)
                (epithet-rename-buffer))))

I've made the fix (and fixed C-h m, while I was at it), and updated the suggested configuration in the README.

oantolin avatar Jul 09 '23 23:07 oantolin

Thank you very much for your fix. It doesn't work for me though: https://github.com/oantolin/epithet/issues/11.

DamienCassou avatar Jul 10 '23 18:07 DamienCassou