3

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 '19 at 00:28
  • 1
    The related question https://emacs.stackexchange.com/q/1 will probably be helpful. – phils Feb 21 '19 at 00: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. –  Feb 21 '19 at 01:32
  • Do `C-h v TeX-view-program-list` and `C-h v TeX-view-program-selection` include your Xreader values? If so your problem is presumably something other than that config. – phils Feb 21 '19 at 02:43
  • To @phils: with `custom-set-variables` set only in `.emacs`, the value of the first variable is `(("Xreader" ("xreader %o") "xreader"))`. With `.emacs.d/init.el` set only in `custom-set-variables`, the same command returns 'no match'. This is consistent with the problem I have described. –  Feb 21 '19 at 04:22
  • Does `C-h v user-init-file` show you what you expect? – phils Feb 21 '19 at 05:36
  • 1
    @phils. I get `/home/er/.emacc`, which is not a file that exists. –  Feb 21 '19 at 06:41
  • Just checking: the full path of `.emacs.d` is `/home/er/.emacs.d`, right? If not, it should be! – Fran Burstall Feb 21 '19 at 07:16
  • I'm assuming `.emacc` was a typo on your part? Yes, clearly Emacs sees your home directory as `/home/er/`, so `/home/er/.emacs.d` is correct. Check file permissions? If `~/.emacs.d/init.el` isn't readable by Emacs, it would fall back to the default `~/.emacs` path (whether or not that latter file exists). – phils Feb 21 '19 at 07:28
  • 1
    No, '. emacc' ![is not a typo](https://ibb.co/ZW9xn5G), 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-- –  Feb 21 '19 at 07:33
  • FYI, that name is **not** normal. I do not know what to make of it. – phils Feb 21 '19 at 10:31

1 Answers1

2

.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. –  Feb 24 '19 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`](https://www.gnu.org/software/emacs/manual/html_node/emacs/Find-Init.html). – Basil Feb 24 '19 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 '19 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 '19 at 20:07
  • @Basil nothing really. At one point I was using it by loading it into .emacs but I soon stopped. It was a silly beginner thing. I will remove it so that nobody will see it and immediately go and do it. Best. – Gabriel Wolf Feb 24 '19 at 22:57
  • FWIW one reason to explicitly load `init.el` from `.emacs` is if you have your `.emacs.d` under version control, and want to run some local/uncommitted elisp before or after the version-controlled init file. I've heard of people using this approach, and it strikes me as an entirely reasonable way of achieving the underlying goal. – phils Feb 25 '19 at 01:58
  • I don't think this answer helps the OP, btw. It seems clear that the bizarre not-a-typo `.emacc` situation is the actual problem. – phils Feb 25 '19 at 02:00
  • @phils yes that is true however the op also asked about the distinctions between .emacs .emacs.d and init.el so this was an answer geared towards that question. – Gabriel Wolf Feb 25 '19 at 02:02
  • The premise of the question being that `.emacs` and `./.emacs.d/init.el` not interchangeable, "Be sure you know what emacs is really evaluating and what it isn't." doesn't make me feel much wiser. –  Feb 27 '19 at 21:39
  • @Erwann Well then I should hope that the beginning part explaining each of the differences will help you instead. The part at the end is just there to help anyone who might end up in the situation I was in. It isn't for everyone. – Gabriel Wolf Feb 28 '19 at 01:31
  • "Can the code `(custom-set-variables...` be evaluated in `.emacs.d/init.el` rather than `.emacs`, and how?" That I would consider a helpful answer. –  Mar 02 '19 at 02:20
  • 1
    @Erwann I just added a section for that into my answer. Hope it helps! – Gabriel Wolf Mar 02 '19 at 13:10