Closed AlynxZhou closed 2 years ago
Sorry, my mistake, there is already document for this: https://github.com/jwiegley/use-package#binding-to-keymaps.
(use-package counsel
:ensure t
:config
(counsel-mode 1)
:bind (("C-c g" . counsel-git)
("C-c j" . counsel-git-grep)
("C-c k" . counsel-rg)
("C-c l" . counsel-locate)
;; ("C-S-o" . counsel-rhythmbox)
:map minibuffer-local-map
("C-r" . counsel-minibuffer-history)))
(use-package counsel-projectile
:ensure t
:after (counsel projectile)
:config
(counsel-projectile-mode 1))
;; others
(use-package projectile
:ensure t
:config
(projectile-mode 1)
:bind (("M-s" . projectile-ripgrep))
;; See <https://github.com/jwiegley/use-package#binding-to-keymaps>.
:bind-keymap (("C-c p" . projectile-command-map))
:custom
(projectile-completion-system 'ivy)
(projectile-cache-file
(locate-user-emacs-file ".local/cache/projectile.cache"))
(projectile-known-projects-file
(locate-user-emacs-file ".local/projectile-bookmarks.eld")))
After I changed my config to this, projectile is loaded, but counsel-projectile is still not loaded after I press C-c p
, is there something wrong in my config?
OK, I think the problem is :after (counsel projectile)
, because I have :bind
for counsel and projectile, they will be loaded after first key press, and I only after those two packages are loaded, counsel-projectile will be loaded, which means I need to press both C-c p
and C-c k
to load projectile and counsel, then counsel-projectile will be loaded.
To fix this I can added :demand t
to counsel to make it loaded after startup, or just remove counsel in :after
, since counsel-projectile only depends on projectile's custom.
I have the following code in
init.el
:Because I put
counsel-projectile
beforeprojectile
, I use:after
to make it loaded afterprojectile
. But with those config, after I start Emacs and pressC-c p
, projectile is not loaded, but the internalproject
keybindings is shown by which-key.If I comment out
:after (counsel projectile)
,projectile
is loaded correctly, but my custom forprojectile
won't be used forcounsel-projectile
, because it is loaded beforeprojectile
.