• Software
  • [Emacs] Something weird going on

Hello everyone, recently I got myself into using emacs and I am really enjoying it. Got myself used to all the basic shortcuts, installed some packages and themes to customize it a bit. Some packages I installed them from within emacs via list-packages from the default package list and from the list of packages by marmalade. Furthermore there are 2 other packages i had to install manually and let them load via the .emacs file on startup. My custom Emacs settings were always persistent even after closing and relaunching emacs several times.

All was going fine I was also doing serious work on it and enjoying it. Then I closed emacs yesterday to shutdown the computer. I launched the editor today and was baffled to see that everything returned to default settings as if it was freshly installed. All the customization in my .emacs and the files in the install-path are all being completely ignored. Even if I try to select a certain(installed) mode such as php-mode it doesnt recognize it anymore.

Any ideas what could be causing this issue?

Here is my .emacs file:
(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.
 '(ansi-color-names-vector ["#2d3743" "#ff4242" "#74af68" "#dbdb95" "#34cae2" "#008b8b" "#00ede1" "#e1e1e0"])
 '(custom-enabled-themes (quote (monokai)))
 '(custom-safe-themes (quote ("b216f5d5060cfececd1f133d71be81b94d2da38c1d099081acf767e931be0506" "71efabb175ea1cf5c9768f10dad62bb2606f41d110152f4ace675325d28df8bd" "c4f5af36d97eebe07ab85faefdc8cd8baa849b1e1b5c7eb6bdd3bff5d4840fec" default))))
(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.
 )
 (add-to-list 'load-path "~/.emacs.d/manual/")

(add-to-list 'auto-mode-alist'())
(global-linum-mode t)

(require 'package)

;; Add the original Emacs Lisp Package Archive
(add-to-list 'package-archives
             '("elpa" . "http://tromey.com/elpa/"))

;; Add the user-contributed repository
(add-to-list 'package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/"))

(setq inhibit-startup-screen t)

(setq backup-directory-alist '(("." . "~/.emacs.d/backup"))
  backup-by-copying t    ; Don't delink hardlinks
  version-control t      ; Use version numbers on backups
  delete-old-versions t  ; Automatically delete excess backups
  kept-new-versions 20   ; how many of the newest versions to keep
  kept-old-versions 5    ; and how many of the old
  )

(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.jsp\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
Note I am using it on my laptop which runs Windows and not on GNU/Linux.

Furthermore, I never worked with lisp so the lines you see above are merely copy and paste. The syntax highlighting seems messed up here, could it be that there is some syntax error in the file? But if there was, Emacs would alert me on startup that it can't evaluate the file, already came across something like that before and fixed it.
If there's a Lisp error in your init files, emacs would give you an explicit error. Try to load the file manually to make sure it's ok. You can do this like this:
M-x load-file /path/to/.emacs
If emacs is launched with the option "-Q" it purposefully ignores every init file. You should check your command line options.

Also, the GNU project maintains a Emacs FAQ for MS Windows. Possibly relevant:
3.5 Where do I put my init file?

On Windows, the .emacs file may be called _emacs for backward compatibility with DOS and FAT filesystems where filenames could not start with a dot. Some users prefer to continue using such a name, because Explorer cannot create a file with a name starting with a dot, even though the filesystem and most other programs can handle it. In Emacs 22 and later, the init file may also be called .emacs.d/init.el. Many of the other files that are created by lisp packages are now stored in the .emacs.d directory too, so this keeps all your Emacs related files in one place.

All the files mentioned above should go in your HOME directory. The HOME directory is determined by following the steps below:

If the environment variable HOME is set, use the directory it indicates.
If the registry entry HKCU\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates.
If the registry entry HKLM\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates. Not recommended, as it results in users sharing the same HOME directory.
If C:.emacs exists, then use C:/. This is for backward compatibility, as previous versions defaulted to C:/ if HOME was not set.
Use the user's AppData directory, usually a directory called Application Data under the user's profile directory, the location of which varies according to Windows version and whether the computer is part of a domain.
Within Emacs, <~> at the beginning of a file name is expanded to your HOME directory, so you can always find your .emacs file with C-x C-f ~/.emacs.

3.5.1 Troubleshooting init file problems

If you've set HOME to a directory using one of the above methods, and Emacs still doesn't load your init file, the first thing you should do is check to see what Emacs thinks HOME is set to. You can do this by evaluating the following expression in the *scratch* buffer using C-x C-e:

(insert (getenv "HOME"))
Look carefully at what is printed and make sure the value is valid. For example, if the value has trailing whitespace, Emacs won't be able to find the directory. Also, be sure that the value isn't a relative drive letter (e.g., d: without a backslash); if it is, then HOME is going to be whatever the current directory on that drive is, which is likely not what you want to happen.
Let me know if that doesn't help. We can push the investigation further.
Tried loading the .emacs file and emacs gave an error "file web-mode undefined" something like that. I commented everything related to the web-mode package in .emacs and tried reloading the file into emacs, it gave a success message yet nothing really changed.

It isn't really recognizing anything that I have installed or any code in the .emacs file for example list-packages command is not looking for the marmalade packages(whose code is explicitly written in the .emacs file), only the default ones.

But here is what happened then. I tried opening the file via C-x C-f ~/.emacs and it opened an empty file! then I tried navigating to the home directory via ~/ and it turned out that it was pointing to another directory as the home and no more to the one within AppData. I pasted back the code into the new emacs file and saved it, some of the modifications not related to installed packages worked fine such as
(global-linum-mode t)
But all the previously installed packages are not found, simply because the home path has changed and it is pointing to a new .emacs.d directory.

I have no idea how it came to this change though, didn't do anything to change any paths.
This seems to be a problem with the package manager you're using. I suggest you go find help on their website. I had never heard of marmalade before you mentioned it. It would be best to mention which version of emacs you're using, you can get it with
M-x version
Manual package management can be cumbersome so I suggest you stick to the package maneger. However I can expose here how I manage packages on my system, I hope it will help. (I am only familiar with Unix systems, you'll have to transpose this to Windows).

What's a package?
A package is a piece of code written in Emacs Lisp. Emacs consists of a tiny core written in C and the rest of the editor (~80% of total lines of code) consists of elisp functions manipulating it. A package is just elisp code which can be used to modify your environment at runtime.

How to use a package?
There's a builtin function inside emacs that is used to import a package: load. It will search for a package in its Load Path, which is mainly a list of directories on your computer. Once found, it will execute the elisp code, and makes the objects created available to the runtime.

Here's the simplest case represented in a stupid example:

Imagine you want to install a package Foo which contains the following files:
Foo/
 |- foo.el
 |- README
 |- anotherfile.el
Download this package locally and move it to /home/user/.emacs.d/Foo (or whatever directory you want. We'll call this the package root dir).

The first step should always be to read the README file and any other documentation you can find. If there are any special requirements you want to know about them first.

If nothing important is noted, add your package root dir to the load path. To do so you have to command the editor to do it, in Lisp. The fastest way to execute lisp code is M-: (I'm assuming you understand by now that this means pressing the keys "Alt" and ":" simultaneously). Evaluate the following expression:
(add-to-list 'load-path "/home/usres/.emacs.d/Foo")
This should return the new value of the load-path variable with the package root dir as a first item.

Finally, you can load the package. Calling
M-x load RET foo
or if you prefer in elisp:
(load 'package-name)
How to install a package persistantly on my editor?
You've already mentioned the .emacs file. It's (as you have guessed) also an elisp file. This is usually enough:
(add-to-list 'load-path /package/root/dir)
(require 'package)
Notice I used require instead of load. They both act similarly, but require will only load a package if it hasn't been loaded previously.

I hope this is helpful. If something is unclear, please tell me. Although I used the above method, I still think you're better off using a package manager. But keep in mind that knowledge of the old manual wouldn't hurt.
@rahmu thanks for the detailed answer, that is greatly appreciated :)

@xterm nice one :P