4

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?

lfrandom
  • 1,013
  • 2
  • 10
  • 32
ZalewaPL
  • 1,104
  • 1
  • 6
  • 14
  • possible duplicate of [Emacs 24 Package System Initialization Problems](http://stackoverflow.com/questions/11127109/emacs-24-package-system-initialization-problems) –  Jul 07 '14 at 14:09
  • Unfortunately, the question you provided only solves this problem partially. projectile still refuses to work even after I manage to do (projectile-global-mode 1). – ZalewaPL Jul 07 '14 at 14:21
  • It **does** solve the problem **as you stated it**, believe me. If you now have a different problem, you should probably update the question to provide additional details. Otherwise we'll be unable to help you. –  Jul 07 '14 at 14:28

3 Answers3

7

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)
  • This works somewhat better. Error is now gone and variable is set correctly, but projectile still refuses to work. describe-variable provides some insight on this: 'Setting this variable directly does not take effect; either customize it (see the info node `Easy Customization') or call the function `projectile-global-mode'.' Still, I don't know how to work around this problem. Customization doesn't help much either. – ZalewaPL Jul 07 '14 at 14:18
  • @ZalewaPL What “variable”? You are enabling a mode here, there is more to it than just a variable. What does “refuses to work” mean? Does it fail to enable? Does a specific command fail? What **is** “this [new] problem” actually? –  Jul 07 '14 at 14:31
  • After further inspection it does in fact work, just not in the *GNU Emacs* welcome buffer. I have to open a *scratch* buffer or a dired and then I can start using `C-c p` commands. – ZalewaPL Jul 07 '14 at 16:26
  • 2
    @ZalewaPL You should probably report that to Projectile on Github. Looks like a bug to me. You can also disable the welcome screen with `(setq inhibit-startup-screen t)` to make Emacs switch to a `*scratch*` buffer right away. –  Jul 08 '14 at 08:43
0

You have to load projectile first, e.g. by using this:

(require 'projectile)
(projectile-global-mode)
ckruse
  • 9,642
  • 1
  • 25
  • 25
  • Tried that before, failed to mention in question. This yields another error: 'File error: Cannot open load file, projectile' – ZalewaPL Jul 07 '14 at 13:17
  • Did you add a `(package-initialize)` somewhere before the `(require 'projectile)` and after the `(require 'package)`? – ckruse Jul 07 '14 at 14:11
  • @ckruse Obviously not. Besides, `projectile-global-mode` is [autoloaded](https://github.com/bbatsov/projectile/blob/e8d982a02a6c6b9f13f158247b14e45128bf80e9/projectile.el#L2212). It's not required to load Projectile first, if installed from MELPA. –  Jul 07 '14 at 14:31
  • @lunaryorn not obvious to me. – ckruse Jul 07 '14 at 14:34
0

you can add

'(initial-major-mode (quote projectile-global-mode))

to your .emacs(or init.el or whatever your file is called) file in the custom-set-variable section.

Alternatively, in newer versions of emacs, the menu Options | Customize Emacs | Specific Option you can type 'initial-major-mode' and this will take you to an interface where emacs can customize itself with that setting. just remember to apply and save

sanimalp
  • 799
  • 5
  • 12