2

I read somewhere the two files were interchangeable, so I cut/paste the content of the former, shown below, to the latter. But then Xreader was missing when I tried to view a document generated by AUCTEX, which tells me they are not interchangeable.

 (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.  '(TeX-view-program-list (quote
 (("Xreader" ("xreader %o") "xreader"))))  '(TeX-view-program-selection
 (quote
     (((output-dvi has-no-display-manager)
       "dvi2tty")
      ((output-dvi style-pstricks)
       "dvips and gv")
      (output-dvi "xdvi")
      (output-pdf "Xreader")
      (output-html "xdg-open"))))) (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.  ) (put 'upcase-region 'disabled nil)

What are the different purposes of .emacs and .emacs.d/init.el?

UPDATE:

Here's the content of .emacs.d/init.el after the modification discussed above:

(require 'package)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
(require 'org)
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done t)
(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.
 '(TeX-view-program-list (quote (("Xreader" ("xreader %o") "xreader"))))
 '(TeX-view-program-selection
   (quote
    (((output-dvi has-no-display-manager)
      "dvi2tty")
     ((output-dvi style-pstricks)
      "dvips and gv")
     (output-dvi "xdvi")
     (output-pdf "Xreader")
     (output-html "xdg-open")))))
(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.
 )
(put 'upcase-region 'disabled nil)

enter image description here

  • 2
    They do not have different purposes, but only one of them gets used. If you have a ~/.emacs file then ~/.emacs.d/init.el will not be read at all. – phils Feb 21 at 0:28
  • The related question emacs.stackexchange.com/q/1 will probably be helpful. – phils Feb 21 at 0:30
  • I redid cut/paste from .emacs to .emacs.d/init.el and deleted the former, and that does not solve the problem. The suggested post is that from which I got the idea to put init code in the second file. – Erwann Feb 21 at 1:32
  • 1
    @phils. I get /home/er/.emacc, which is not a file that exists. – Erwann Feb 21 at 6:41
  • 1
    No, '. emacc' !is not a typo, that's Y I said it does not exist. ~/.emacs.d $ echo $PWD prints /home/er/.emacs.d. File permissions of either .emacs and /emacs.d/init.el are -rw-rw-r-- – Erwann Feb 21 at 7:33
1

.emacs.d

A folder containing emacs config files.

Located at ~/.emacs.d/


.emacs

An init/config file with personal EmacsLisp code used to configure emacs when it starts up.

Usually located at ~/.emacs, ~/.emacs.el, or ~/.emacs.d/init.el.


init.el

Defaulted to by emacs during startup when the other .emacs and .emacs.el are both not available.

Usually located at ~/.emacs.d/init.el


custom set variables

(This is a response to a question asked about storing your custom-set-variables in some place other than the .emacs file)

Q: Can you store custom-set-variables in a place other than .emacs?
A: Yes

Many people do this by having their custom-set-variables inside their own file (lots of times called custom.el)
This is done by adding the following code into your main init file:

(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load custom-file)

Which will now load your custom-set-variables and custom-set-faces from the file located in ~/.emacs.d/custom.el

Now inside your custom.el file (located in ~/.emacs.d/custom.el) you can have your custom-set-variables and custom-set-faces code.


on moving code from .emacs and init.el

I would be careful about where you put stuff and where emacs puts stuff, as sometimes they may not be the same place.

For example:

At one point I was adding config stuff in custom variables/custom themes that was in my .emacs file. I was loading a .org file into my .emacs file with extra config as well. But whenever I would evaluate my .emacs, the changes I made in the custom variables/custom themes weren't showing up all the time. Little did I know that the custom themes and custom variables that I was editing in my .emacs where not being evaluated by emacs at all and it was a completely different version that was getting evaluated which was located in my init.el file. So the only variables that would get loaded whenver I evaluated emacs where ones that I had set in emacs customize groups which were then getting placed in the init.el file and evaluated while what I was adding into the .emacs was being ignored.


To make a long story short: Be sure you know what emacs is really evaluating and what it isn't.

  • Can you improve formatting of your question? Directory names make more sense when they're showed in monospace (which you can achieve by surrounding them with backticks). Also, your explanation would be a bit better if you cleared up the wording and separated it into paragraphs. – DoMiNeLa10 Feb 24 at 17:13
  • ~/.emacs.d/init.el is intended as an alternative name for ~/.emacs or ~/.emacs.el. It is not intended to be loaded manually from any other configuration files. See (emacs) Find Init. – Basil Feb 24 at 19:41
  • @Basil you are correct. However I am just stating that it is possible to load it in. But I will add in that it is not meant to be loaded in like that but can if you so choose. Thanks! – Gabriel Wolf Feb 24 at 19:58
  • @GabrielWolf Thanks for adding that clarification. Why mention the possibility of manually loading the file at all, though, when it is not recommended, non-standard, and when any file (including ~/.emacs and ~/.emacs.el) can also be manually loaded? What makes ~/.emacs.d/init.el so special in this regard compared to any other file? – Basil Feb 24 at 20:07
  • 1
    @Erwann I just added a section for that into my answer. Hope it helps! – Gabriel Wolf Mar 2 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.