1

I have something like (to be simplify)

(require 'package)

(setq package-archives
      '(("org"          . "http://orgmode.org/elpa/")
        ("melpa"        . "http://melpa.org/packages/")
        ("melpa-stable" . "http://stable.melpa.org/packages/")
        ("gnu"          . "http://elpa.gnu.org/packages/")))

(setq package-enable-at-startup nil)
(package-initialize t)

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(let ((default-directory (expand-file-name user-emacs-directory "elpa")))
 (normal-top-level-add-subdirs-to-load-path))

(require 'use-package)

(use-package helm
  :ensure t
  :commands (helm-M-x
         helm-mini
         helm-find-files
         helm-show-kill-ring)
  :init
  (add-hook 'after-init-hook 'helm-mode)

  :config
    (helm-autoresize-mode 1))

in my .emacs. But I was told that Symbol's function definition is void: helm-mode after startup emacs.

After reading the manual of Packaging Basics and this answer, I find I still don't understand the mechanism of package.el.

I notice that the words load and activate are used in the manual, I suppose that load is 'Emacs adds the package’s content directory to load-path, and evaluates the autoload definitions in name-autoloads.el.' and activate is to 'fully require'. I know if I change (package-initialize t) into (package-initialize) everything will be fine.

I confirm that something like "/Users/gaki/.emacs.d/elpa/helm-20160112.258" is in load-path and helm-mode is autoload. Isn't it can be autoload and even in the after-init-hook ?

Community
  • 1
  • 1
Saddle Point
  • 3,074
  • 4
  • 23
  • 33
  • The question is not clear (to me). Could you clarify just what you are asking? If you are asking for an explanation of the package system then that is not a good fit for this site (which is generally for specific Q&A). It would be too broad to guess what is unclear to you and try to explain it. But if you can formulate a more specific question then perhaps it can stand. – Drew Jan 13 '16 at 04:02
  • You should not need to add the elpa directory (or its subdirectories) to the load-path, the package system will do that when correctly configured. – jpkotta Jan 13 '16 at 16:39

1 Answers1

2

A look at the code for package-activate and its helper package-activate-1 shows that a package's autoloads file is not loaded unless the package has been 'activated'.

You've told Emacs not to activate any packages by using (package-initialize t), and you've prevented it from activating them after loading your init file with (setq package-enable-at-startup nil), so none of your package autoloads are known to Emacs.

I suggest changing (package-initialize t) to (package-initialize).

Note that the documentation you linked to describes the NO-ACTIVATE argument as "for internal use only".

p.s. Activation does not require the package features -- there would be no purpose to the autoloads if it did -- so this should not take a very significant amount of time, unless perhaps you have a really large number of packages? What kind of time difference are you actually seeing here? (https://emacs.stackexchange.com/a/19263/454 may help with answering that.)

Community
  • 1
  • 1
phils
  • 71,335
  • 11
  • 153
  • 198
  • Thanks for you answer ! I've believed that after `load`, the `load-path` will be set and `autoload` will be read and will be `fully require` if `activate`. Now I know emacs itself won't read the `autoload`s if `NO-ACTIVATE`. I try to speed up the emacs startup and the package `esup` told me that `(package-initialize)` is the bottleneck. After some Googling, I find that `(package-initialized t)` maybe a solution. But the `use-package` package seem will add `autoload` for items specified in `:commands`, `:bind`. Even I've added `helm-mode` in the `:commands` part, the error is still there. – Saddle Point Jan 13 '16 at 04:21
  • I can't imagine any time-saving (surely very small?!) from preventing package activation will be worth the hassle of your packages not being correctly configured. – phils Jan 13 '16 at 04:43