2

How to load all function in package with use-package ?

I modified crux package, and make my own simple-crux.el

Inside simple-crux.el, say I have function foo, bar and baz.

when I use

(use-package simple-crux
  :load-path "~/.emacs.d/somewhare"
  :bind ("C-c w" . foo))

I only have foo function loaded when emacs start. I have all three function, only after I invoke C-c w (foo function)

I can have all three function loaded after emacs start using (require 'simple-crux), but it is different case.

Things that make me confused

  • why use-package only load function mentioned in :bind, and other functions are loaded after the specified binding invoked (in my simple-crux.el). even I have add ###autoload on the top of every function.

  • But why I can have all function from helm, magit, etc. even I don't hook them to emacs startup nor I don't invoke their specified binding. (with the same use-package scheme as my simple-crux.el)

  (use-package magit
    :ensure t
    :bind ("C-c g" . magit-status))
  • If you want to autoload other commands you can use :commands keyword. The reason that commands from other packages are autoloaded is that you probably installed them with package manager which loads them for you in package-initialize. – mkcms Feb 25 '18 at 9:19
2

You can load all function from packages in use-package using :demand keyword.

as mention here

You can override package deferral with the :demand keyword. Thus, even if you use :bind, using :demand will force loading to occur immediately and not establish an autoload for the bound key.

After trying :demand, I have all my function from simple-crux.el loaded in emacs startup.

I also tried to install crux using use-package as follow

(use-package crux
  :ensure t)

And I get all crux functions loaded after emacs start, probably as what mkcms comment

The reason that commands from other packages are autoloaded is that you probably installed them with package manager which loads them for you in package-initialize

but the mysterious thing happened again. I try to put :demand in magit

(use-package magit
  :ensure t
  :demand)

But I still can't get all magit function loaded. e.g I can't find magit-bookmark--log-jump function, but most of other function in magit (that comes with ###autoload) are loaded.

;;;###autoload
(defun magit-bookmark--log-jump (bookmark)
 ......

Update 1: 2018-02-26

All the mysterious problem solved :) (it's not mysterious, it's the lack of my knowledge)

  • When we use :bind only in use-package

Function that can be invoked trough mini-buffer is only function with :bind (of course that function must have (interactive) )

  • Using :bind and :diminish together

The result same as using :bind only

  • Using :diminish without :bind

We have all the function with (interactive) loaded, and can be invoked trough mini-buffer, even that function does not have ###autoload and :bind

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.