0
C-h v
user-init-file

shows

~/.emacs

but I want this user-init-file point to ~/emacs.d/init.el

Requirement is to be able to switch between .emacs and .emacs.d/init.el and .emacs.el anytime, without deleting/replacing these init files

I do not see any options here

Question:

Without deleting .emacs file from its place, What is the procedure for emacs user to pick different init file, for future emacs session?

overexchange
  • 113
  • 5
  • 1
    Refer to https://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html . If `~/.emacs` exists, that takes precedence over `~/.emacs.d/init.el`. Simply delete or rename `~/.emacs` to something that Emacs doesn't look for, and then it'll find your `init.el` file. – phils May 15 '17 at 02:35
  • @phils I read that content. But deleting file looks weird. I have my own work in `.emacs`. I paste the same reference – overexchange May 15 '17 at 02:37
  • You shouldn't have both an `~/.emacs` file and a `~/.emacs.d/init.el` file. They are alternative names for a single purpose, and they are *both* "your own work" in that they are expected to be your personal init file. Pick whichever filename works best for you, and remove the other file. You can most certainly put custom code into multiple different .el files, but those particular filenames are reserved for use as the init filename. – phils May 15 '17 at 02:39
  • If you're trying to maintain *multiple* emacs configurations then https://emacs.stackexchange.com/q/4253 might be helpful. – phils May 15 '17 at 02:43
  • @phils you mean changing `HOME` environment variable to `/home/xyz/.emacs.d` instead of `/home/xyz`? But, It is an environment variable used by OS processes and shell script. – overexchange May 15 '17 at 02:48
  • 1
    You can generally work around that, but there are other answers to that question as well. *I don't actually know what you're trying to do, though.* Do you need one emacs configuration, or multiple emacs configurations? Or do you only need to load a particular elisp file in some cases, but not others? Or something else? – phils May 15 '17 at 02:50
  • @phils I need to be be able to switch between `.emacs` and `.emacs.d/init.el` and `.emacs.el` anytime, without deleting/replacing these files. How can we solve this, using emacs option? – overexchange May 15 '17 at 02:51
  • In that case you'll need to write a wrapper script for starting Emacs which temporarily renames the higher-priority init files to names which Emacs will ignore, so that it will find the init file you *want* it to use, and then renames the files back again. Emacs has no command-line option for this, because you're not expected to have more than one of those filenames. – phils May 15 '17 at 02:53
  • @phils Looks like the answer is: `emacs -q --load "~/.emacs.d/init.el"`. So, `-q` will avoid loading `~/.emacs`(if available), `--load` option will load specified config file – overexchange May 15 '17 at 03:05
  • Well that isn't the same thing as Emacs using that file as the init file; but if it meets your needs then yes, that's a simple solution. I assume you saw this approach at https://emacs.stackexchange.com/a/4258 , but if not then make sure you've read that. – phils May 15 '17 at 03:08
  • Please clarify the question, in light of the comments (if that helps). As it stands now, the question is unclear and risks being closed. Try to be specific. – Drew May 15 '17 at 04:32
  • @Drew Query updated – overexchange May 15 '17 at 04:36
  • If `emacs -q --load "~/.emacs.d/init.el"` answers your question that please consider posting it as an answer. You can accept your own answer. – Drew May 15 '17 at 04:41

2 Answers2

1

Start emacs with below options,

emacs -q --load "~/.emacs.d/init.el"

where:

-q - Do not load any initialization file

--load - Load a Lisp library named file with the function load. If file is not an absolute file name, Emacs first looks for it in the current directory, then in the directories listed in load-path

overexchange
  • 113
  • 5
  • And to reiterate for the benefit of anyone else reading this, be aware that this technique isn't the same thing as Emacs using `~/.emacs.d/init.el` as the init file. https://emacs.stackexchange.com/a/4258 has additional information. – phils May 15 '17 at 05:17
1

Without clarifying why you want to alternate between those two specific files, it's hard to give a good answer, but besides overexchange's use of --load (aka -l), you can also use a trick such as:

ln -s ~/.emacs ~/.emacs.elc
emacs

to run Emacs using ~/.emacs and then

ln -s ~/.emacs.d/init.el ~/.emacs.elc
emacs

to run Emacs using ~/.emacs.d/init.el.

Stefan
  • 26,154
  • 3
  • 46
  • 84