jwiegley / use-package

A use-package declaration for simplifying your .emacs
https://jwiegley.github.io/use-package
GNU General Public License v3.0
4.42k stars 260 forks source link

Why do these two different use-package declarations (for the same package) have different effects? #885

Closed simurgh9 closed 3 years ago

simurgh9 commented 4 years ago

What I want to accomplish is to add a keybinding C-<backspace> to the eshell-mod-map that calls func. That can be done like this,

(use-package eshell
  :init
  (defun add-func-keybinding ()
    (define-key
      eshell-mode-map
      (kbd "C-<backspace>")
      (lambda ()
        (interactive)
        (func "arg"))))
  :hook
  (eshell-mode . add-func-keybinding))

Now C-<backspace> only calls func when inside an eshell buffer. I thought this should be equivalent to,

(use-package eshell
  :after esh-mode
  :bind
  (:map eshell-mode-map
     ("C-<backspace>" . (lambda () (interactive) (func "arg")))))

However, this binds C-<backspace> to func everywhere. e. g., if I press C-<backspace> in the *scratch* buffer, that also calls func. This does not happen when the configuration is done as in the former use-package declaration, there the keybinding is kept only inside the eshell buffer.

However, I fail to see the difference between the two declarations. I would like to fix the latter so it has the same effect as the former, since the latter is a bit clearer and nicer. How can I do this?

conao3 commented 3 years ago

eshell-mode-map is defined in esh-mode, please use below use-package.

(use-package eshell
  :bind
  (:map eshell-mode-map
        :package esh-mode
        ("C-<backspace>" . (lambda () (interactive) (func "arg")))))

or, plsese use use-package to esh-mode to remove :package argument.

(use-package esh-mode
  :bind
  (:map eshell-mode-map
        ("C-<backspace>" . (lambda () (interactive) (func "arg")))))
simurgh9 commented 3 years ago

There also seems to be a bug involved.