How to add a keybinding before a mode is loaded

Hi guys,

First post here. I installed mpdel using the package.el file and now I am trying to set the keymap for mpdel-prefix-key. From their website:

Using Start by adding these lines to your init.el file:

(add-to-list 'load-path “~/.emacs.d/lib/mpdel”) (require 'mpdel) (mpdel-mode) Then, press C-x Z l to show the current playlist. The C-x Z global prefix is configurable with mpdel-prefix-key:

(setq mpdel-prefix-key (kbd “C-. z”)) This line must come before the (require 'mpdel) line as the prefix key must be set before mpdel is loaded.

So far I have a half-way solution:

(use-package! mpdel
  :init
  (setq mpdel-prefix-key (kbd "C-c z"))
  ;; :bind ("C-c z" . mpdel-prefix-key)
  :config (mpdel-mode))

Which still is not a complete Doom Emacs way of doing it. How can I improve this solution?

Thanks

Why do you say “it is not a complete Doom Emacs way of doing it”? As far as I know keybindings can be configured in the :config section of a (use-package!...) macro invocation.

I am also unsure why the README of that package says “[the keybinding configuration] must come before the (require 'mpdel) line as the prefix key must be set before mpdel is loaded”. I thought package configuration works the opposite way: first load the code, then configure the keybinding.

I would probably slighty tune the configuration like this:

(use-package! mpdel
  :config
  (keymap-global-set "C-c z" 'mpdel-prefix-key)
  (mpdel-mode))

I think keymap-global-set is the preferred way of setting keybindings since Emacs 29.1.

Note: I didn’t test the above solution.

Why do you say “it is not a complete Doom Emacs way of doing it”? Because I thought I should be using map!

I would probably slighty tune the configuration like this:

(use-package! mpdel
  :config
  (keymap-global-set "C-c z" 'mpdel-prefix-key)
  (mpdel-mode))

I have just tried and got the following error:

Wrong type argument: commandp, mpdel-prefix-key

If nobody else chimes in, I will stick with my solution.

Thanks