I've tried runemacs --user d:\path\to\init\.emacs
but it gives
Error (initialization): Invalid user name d:\path\to\init\.emacs
I mean custom file in custom location like on my pendrive etc. and not in my default locations in user folder. I try to create a cmd files with corresponding inits for different configuration.
Traditionally, file ~/. emacs is used as the init file, although Emacs also looks at ~/. emacs. el , ~/.
Emacs normally finds your init file in a location under your home directory. See The Emacs Initialization File. Emacs looks for your init file using the filenames ~/. emacs.
To create a new file, use Control-X-Control-F, just as if the file already existed. When emacs asks you for the file name, type in the name you want your new file to have, and emacs will create the file, and display an empty buffer for you to type in. Emacs will perform file name completion for you.
emacs config file usually resides in your home directory. See also The Emacs Initialization File. If you need to start with a blank . emacs , try touch ~/.
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=%~dp0 C:\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 ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With