2

From time to time my Emacs doesn't load my init file at startup and gives me the following error message:

File error: Cannot open load file, no such file or directory, session

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init' option to view a complete error backtrace.
File error: Cannot open load file, no such file or directory, session

The Problem turns out to be this code in my customization file:

(custom-set-variables
 ....
 '(session-use-package t nil (session))

It is a variable from the session package which saves my history in Emacs. I have to delete this line and everything works again. Why is this added to my customization file and how can I avoid this annoying error? How could I investigate myself which event triggers this setting in my customization file?

Edit: The part of my init which loads the package looks like this:

(use-package session
:ensure t
:init
(add-hook 'after-init-hook 'session-initialize))
clemera
  • 3,401
  • 13
  • 40
  • The problem seems to be that emacs tries to `require` the session package (as per the `REQUEST` argument to `custom-set-variables`), and fails (probably because it is not found in `load-path`). Have you checked whether your init file contains everything needed to correctly and reliably load the `session` package? – François Févotte Aug 24 '15 at 21:50
  • @Francesco It is in the same path as all my other installed packages(elpa). I use `use-package` for this. I have added the part which loads the package to the question. The problem is I can not reproduce the error yet. It just happens sometimes. – clemera Aug 24 '15 at 23:20
  • 2
    When do you load your customization file? If it's before the `after-init-hook`, then that might be the problem. – sykora Aug 25 '15 at 13:51
  • @sykora Thanks, I should have thought of that, that might be the problem! Just post it as an answer if you like and I will accept it in a couple of days, if it was :) – clemera Aug 25 '15 at 14:19
  • 1
    When do you run `package-initialize`? This is when `load-path` gets populated and should happen before you load your customization file. – François Févotte Aug 26 '15 at 09:14
  • @Francesco I used to loaded it before buf now after @sykora 's answer I changed it to load after my `init` file is loaded, via the `after-init-hook`. Maybe this will fix the problem. – clemera Aug 26 '15 at 09:28
  • 1
    Yep, it probably will. But IIUC, the problem is not with `session-initialize` but rather `package-initialize`. Of course, if you load your custom file at the very end, everything should work fine. – François Févotte Aug 26 '15 at 14:43
  • @Francesco Thanks, indeed the problem was that the customization file was loaded before the load path initialization. – clemera Aug 26 '15 at 15:55

1 Answers1

2

The problem seems to be that emacs tries to require the session package (as per the REQUEST argument to custom-set-variables), and fails (probably because it is not found in load-path).

You have to make sure that your load-path is correctly populated before you load your customization file. In particular, if session is installed as an ELPA package, it means that package-initialize must be called before the customization file is loaded.

François Févotte
  • 5,917
  • 1
  • 24
  • 37