is there a way to specify custom init file on emacs startup? is there a way to specify custom init file on emacs startup? windows windows

is there a way to specify custom init file on emacs startup?


I am guessing that your end goal is to run Emacs from a USB drive which you can carry around. There are two ways to have Emacs start with a different init file:

(1) the -q --load way

This is simply to run

emacs -q --load path-to-your-init.el

which starts Emacs without any initialization, then loads path-to-your-init.el

Gotchas of this way: in this case, Emacs doesn't really consider the el file to be an init file, in fact, Emacs hasn't gone through initialization at all, which means the following post-initialization steps are skipped:

  • enabling packages, that is, evaluating (package-initialize)

  • running hook after-init-hook, that is, evaluating (run-hooks after-init-hook)

You may have to add post-initialization stuff in your alternate init file.

Also, Customize interface won't let you save settings if Emacs is started with -q option.

(2) the HOME way

Create my-emacs.bat with contents:

set HOME=%~dp0C:\path-to-your\Emacs\bin\runemacs.exe --xrm "emacs.Background: light green"

When you click on that bat file, Emacs creates folder named .emacs.d not in your usual user directory, but in where the bat file is. You can put your own init.el in that .emacs.d folder. With this Emacs, evaluating (find-file "~/.emacs.d/init.el") opens your own portable init.el and not the init file in your usual user directory. You may want to delete the --xrm "emacs.Background: light green" part, I include that because I always forget which Emacs is which.

Gotchas: this Emacs has its own package directory in its own .emacs.d directory. That may or may not be what you want. If you want to share the package directory, you can change package-user-dir or create a symbolic link to the to-be-shared package directory using Link Shell Extension.

Somethings to consider for running Emacs on a USB drive:

Emacs outsources some of its features to external tools. Grepping and comparison are outsourced to grep and diff, so you probably have installed at least GnuWin32 Grep and GnuWin32 DiffUtils on your system. And part of spell checking is outsourced to aspell, which is also a separate install. Encryption is outsourced to GPG, so Gpg4Win another separate install. For your portable Emacs to have all those features, all those external tools should be on your USB drive as well. Fortunately, GnuWin32 and aspell are portable-friendly. I don't know if GPG is. The dependency to external grep may be eliminated if you manage to make versions of lgrep and rgrep that only depend on eshell's own grep, but it seems nobody has done it, so making such lgrep/rgrep is to boldly go where no man has gone before.


You can get help on all of the emacs options by typing emacs --help on the command line. That help shows that --user expect the name of a user, not the path to an elisp file.

To load a lisp file at startup you can use the --load option:

$ emacs --help...--load, -l FILE         load Emacs Lisp FILE using the load function...

If you want to prevent your default init file from loading, you can use this option:

$ emacs --help...--no-init-file, -q          load neither ~/.emacs nor default.el...