Emacs: can't autostart projectile installed through MELPA

autostart, emacs, melpa

Solution

By default, Emacs initializes packages after evaluated `init.el`. Hence, in a standard setup, packages are not yet available while `init` is evaluated.

Use `(add-hook 'after-init-hook #'projectile-global-mode)` to enable Projectile only after packages are initialized, or explicitly initialize packages at the beginning of your `init.el` with the following code:

(require 'package)
(setq package-enable-at-startup nil) ; To avoid initializing twice
(package-initialize)

Problem

I'm fairly new to emacs. In fact I'm learning the editor and trying to setup something that will replicate "go to a file inside the project" feature known from Code::Blocks or certain plugins of notepad++. 'projectile' fulfills this need, and I installed it through MELPA. Package installed properly, as I can start it with `M-x projectile-global-mode` and `C-c p` commands are recognized. However, if I put it into my `.emacs` file, Emacs starts with an error: ``` Symbol's function definition is void: projectile-global-mode ``` Contents of my `.emacs` file are as follows: ``` (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. ) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. ) (global-whitespace-mode 1) (global-linum-mode 1) (require 'package) (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t) (projectile-global-mode 1) ``` When I try to `(require 'projectile)` first, I only end up with another error: ``` 'File error: Cannot open load file, projectile' ``` I'm using Emacs 24.3.1. How do I put this on autostart properly?

Original source

Related problems