Using the :general with use-package sometimes doesn't work

953 Views Asked by At

I started converting my evil-define-key calls to use the :general extension to use-package, and sometimes they work, and sometimes not. Re-evaluating the (use-package ...) s-expression doesn't change the behavior, so I'm assuming I have a configuration issue.

This code works, as typing g l in the normal mode state, calls the link-hint:

  (use-package link-hint
    :bind
    ("s-o" . link-hint-open-link)

    :general
    (:states 'normal :keymaps 'global-map
             "gl" 'link-hint-open-link
             "gL" 'link-hint-copy-link))

However, the following code, which looks very similar, does not add a g p binding in normal mode:

  (use-package consult
    ;; Enable automatic preview at point in the *Completions* buffer. This is
    ;; relevant when you use the default completion UI.
    :hook (completion-list-mode . consult-preview-at-point-mode)

    :init
    ;; Use Consult to select xref locations with preview
    (setq xref-show-xrefs-function #'consult-xref
          xref-show-definitions-function #'consult-xref)

    :general
    (:states 'normal :keymaps 'global-mode-map
             "gp" 'consult-yank-pop
             "gs" 'consult-line))

I don't believe the issue is with the :general extension, but really with general.el adding to the g sequence, as the following doesn't work either:

(general-define-key
  :states 'normal :keymaps 'global-mode-map
  "gp" '(consult-yank-pop :which-key "yank pop")
  "gs" '(consult-line :which-key "visual search"))

And perhaps the issue isn't with general at all, as the following doesn't work either:

(evil-define-key 'normal 'global-mode-map (kbd "gp") 'consult-yank-pop)

So I guess my real question is why gl works, but gs and gp do not.

2

There are 2 best solutions below

0
Howard Abrams On

While I don't know why my initial code sometimes works, a reliable way to change the global map with the :general extension to use-package is to drop the global-mode-map. In other words:

(use-package consult
  ...
    :general
    (:states 'normal
             "gp" 'consult-yank-pop
             "gs" 'consult-line)
0
K.G.G On

The first snippet of code works because you typed the name of the keymap correctly: "global-map". In the others you typed "global-mode-map", which does not exist.