tarsius / keycast

Show current command and its key in the mode line
GNU General Public License v3.0
316 stars 18 forks source link

custom-initialize-reset: Cannot turn on keycast-mode-line-mode. mode-line-end-spaces not found in mode-line-format. #34

Closed getong closed 6 months ago

getong commented 6 months ago

emacs 29.3 on macos

custom-initialize-reset: Cannot turn on keycast-mode-line-mode.  mode-line-end-spaces not found in mode-line-format.  Try customizing keycast-mode-line-insert-after.

config sample:

(use-package keycast
  :straight t
  :hook (after-init . keycast-mode-line-mode)
  :config
  (setq keycast-mode-line-format "%5s%K%C%r")
  (setq keycast-mode-line-remove-tail-elements nil)
  (setq keycast-mode-line-insert-after 'mode-line-end-spaces))

or

(use-package keycast
  :straight t
  :config
  (keycast-mode-line-mode)
  (define-minor-mode keycast-mode
    "Keycast mode"
    :global t
    (if keycast-mode
          (progn
            (add-to-list 'global-mode-string '("" keycast-mode-line " "))
            (add-hook 'pre-command-hook 'keycast--update t) )
      (remove-hook 'pre-command-hook 'keycast--update)
      (setq global-mode-string (delete '("" keycast-mode-line " ") global-mode-string)))))
tarsius commented 6 months ago

mode-line-end-spaces has been a member of mode-line-format's default value for twelve years (since https://github.com/emacsmirror/emacs/commit/5f2c76c6cee2b5d2d84ffd409839fd58d2ad16fa).

If that is not the case for you then something probably removes it (try with emacs -Q).

Look at the value of mode-line-format and decide after which actual element of that list you want to add the keycast element. Then customize keycast-mode-line-insert-after accordingly.

jn64 commented 3 months ago

If that is not the case for you then something probably removes it [mode-line-end-spaces]

That something turned out to be keycast.

Steps to repro:

  1. Enable keycast-mode-line-mode with default settings.

    The default value of keycast-mode-line-insert-after is mode-line-buffer-identification, and keycast-mode-line-remove-tail-elements is t.

    At this point, mode-line-format looks like:

    (... mode-line-buffer-identification keycast-mode-line)

    Anything after mode-line-buffer-identification, including mode-line-end-spaces, has been removed.

  2. Set keycast-mode-line-insert-after to mode-line-end-spaces

  3. Explicitly enable (not toggle) keycast-mode-line-mode e.g. by evaluating (keycast-mode-line-mode 1). Since mode-line-format currently does not contain mode-line-end-spaces, we get the reported error.


More generally, enabling keycast-mode-line-mode while it is already enabled loses information about the user's original mode-line-format:

  1. Enable keycast-mode-line-mode with default settings

  2. Explicitly enable it again (not toggle)

  3. Disable it. Oops, our mode line is fucked until we restart Emacs.

Emacs 29.4 (emacs-29.4-2.fc39.x86_64 from Fedora 39 repo) keycast 20240713.1919 (cce63c166a47593c2d2a0a4e0e1e9671a537f1cb) from MELPA


mode-line-end-spaces has been a member of mode-line-format's default value for twelve years

This is not useful information for the OP trying to understand what happened. It's more helpful to show that mode-line-end-spaces is currently in the default mode-line-format, but I expect they knew that.

tarsius commented 3 months ago

More generally, enabling keycast-mode-line-mode while it is already enabled

I consider that a user error and have added a kludge to recover from it.

jn64 commented 3 months ago

Sure, but it's an easy mistake to make. Users are gonna have (*-mode) in a use-package form and repeatedly evaluate it while tinkering.

Thanks for the fix.