Disable warning about emacs.d in load path
Asked Answered
S

4

20

In latest version of ̀emacs ( from 24.3.50 snapshot) there is a warning at startup when .emacs.d happens to be in the load path.

Warning (initialization): Your `load-path' seems to contain
your `.emacs.d' directory: ~/.emacs.d/
This is likely to cause problems...
Consider using a subdirectory instead, e.g.: /home/adriean/.emacs.d/lisp

Is there a way to disable just this warning?

(since I wanna keep my emacs.d in the load path, for now as a quick brute hack I went for (setq warning-minimum-level :error), but I would prefer to get rid of this as soon as possible)

Slyke answered 16/7, 2014 at 10:56 Comment(2)
Apparently, it was never recommended to put ~/.emacs.d in the load-path (I do it, but I'll probably switch to ~/.emacs.d/lisp when I jump to 24.4). lists.gnu.org/archive/html/emacs-devel/2012-03/msg00056.htmlKos
see also Emacs.SEBurden
H
26

Don't disable the warning. It's there for a good reason: ~/.emacs.d shouldn't be in your load-path.

This is because Emacs writes files to this directory, and therefore it's possible (there are existing cases) for those files to conflict with the names of elisp libraries. If you have this directory in your load path, and you have such a name clash, then Emacs will attempt to load the wrong file if that library is required.

Just change your configuration. It's trivial to move the elisp libraries you've placed in that directory into a sub-directory, and then update the code which was adding ~/.emacs.d to your load-path, so that it adds the new sub-directory instead:

(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp"))
Heyerdahl answered 16/7, 2014 at 22:15 Comment(4)
I know it's better not to do it, but I asked for a quick and temporary fix. External libraries are in their own subir el-get,elpa,plugins, just some of my personnal elisp files are in the emacs.d And you should have give reasons not to do it rather than just paraphrasing the error message.Slyke
Answer updated. I know it's not what you asked for, but moving the libraries is a quick fix, so I can't see any benefit in trying to circumvent the warning.Heyerdahl
Sorry I'm a newbie, for other newbies do the following sequence of commands in your shell: cd emacs.d, mkdir lisp, mv * ./lisp, emacs -nw, C-x C-f ~/.emacs, edit line as aboveMcclelland
AudioDroid: No, you certainly don't want to mv * ./lisp ! that would move all files! You only want to move any .el and .elc files which you have placed there yourself, with the exception of your init file. Don't move anything else, and certainly not anything which Emacs has written to that directory.Heyerdahl
M
10

Precaution

Your .emacs.d can safely be in your load-path only at the end. This will ensure that if a file in your .emacs.d conflicts with a library, the library will take precedence. With add-to-list, you can do this by setting the third parameter (APPEND) to t:

(add-to-list 'load-path (expand-file-name "~/.emacs.d") t)

Disabling the warning

Adding 'initialization to warning-suppress-types or warning-suppress-log-types will suppress the warning, but you also won't see errors or warnings if something goes wrong in your init file.

The solution I use in my .emacs.d is an advice that selectively ignores this warning based on the warning message:

(defadvice display-warning
    (around no-warn-.emacs.d-in-load-path (type message &rest unused) activate)
  "Ignore the warning about the `.emacs.d' directory being in `load-path'."
  (unless (and (eq type 'initialization)
               (string-prefix-p "Your `load-path' seems to contain\nyour `.emacs.d' directory"
                                message t))
    ad-do-it))

This will need updating if the warning message changes.

Organization tip

If you want to keep personal files directly in your .emacs.d directory, it may be a good idea to unclutter it by making a dedicated directory for the savefiles of various packages, for example:

(defvar my-savefile-dir (expand-file-name "savefiles" "~/.emacs.d")
  "The directory for automatically generated save/history/etc. files.")

and then, for each package that puts its file in .emacs.d, something like this:

(setq tramp-persistency-file-name
      (expand-file-name "tramp" my-savefile-dir))

Update to organization tip

Since writing the above, I've discovered that packages usually use locate-user-emacs-file to get the paths to files in which they store their data. This function returns an absolute path to a file in user-emacs-directory. By default, user-emacs-directory contains the path to your .emacs.d, but you can change this to a directory where you want your savefiles (you'll probably also want to preserve the old value somewhere):

(defvar main-dir user-emacs-directory
  "The root directory of my Emacs configuration.")
(setq user-emacs-directory (expand-file-name "savefiles/" main-dir))
;; The trailing slash is mandatory.

This will make most packages store their files in .emacs.d/savefiles. If you want to make an exception, so that a given package stores its files directly in .emacs.d, use something like this:

(setq package-user-dir (expand-file-name "elpa" main-dir))

You'll also have to change settings of packages that get loaded before your init file, and therefore use the original value of user-emacs-directory:

(setq auto-save-list-file-prefix
      (locate-user-emacs-file "auto-save-list/.saves-"))

In addition, some packages use hardcoded paths instead of locate-user-emacs-file, but that's easy to fix too:

(setq smex-save-file (locate-user-emacs-file "smex"))

Most packages use locate-user-emacs-file though, so in my experience this method of organizing savefiles requires less code than the one from the original "organization tip" (as of writing this, the above fragments of code are the only savefile settings in my Emacs configuration, while the original method required a line for each package).

I don't know if this method is an intended use or an abuse of the user-emacs-directory variable. I use it and it works without issues so far, but your mileage may vary.

Multilingual answered 28/8, 2014 at 15:23 Comment(0)
R
2

You could add initialization to either warning-suppress-log-types (don't log the warning at all), or warning-suppress-types (log the warning, but don't pop up the warnings buffer).

Roselani answered 16/7, 2014 at 11:1 Comment(1)
adding '(warning-suppress-types '((initialization ))) to custom file did the trick.Slyke
R
2

I had the same issue recently, on 4.4.0-22-generic GNU/Linux (Ubuntu 16.04 LTS) and for me the only thing that worked is:

$ chown -R my_user ~/.emacs.d
$ # Fix the 'broken' permissions

You might get chown: cannot read directory '/home/my_user/.emacs.d': Permission denied then simply do:

sudo chown -R my_user:my_group ~/.emacs.d

It worked like a charm for me.

Ref. The source of the answer was taken from Permission issue with emacs for non-root user (Ubuntu 11.10).

Rustication answered 10/6, 2016 at 13:44 Comment(1)
By answering this question, you appear to be saying that a filesystem permissions problem caused Emacs to issue the warning message about load-path containing ~/.emacs.d/. I really don't believe that happened. Clearly you did have a permissions problem, but this surely is not an appropriate question in which to post about it.Heyerdahl

© 2022 - 2024 — McMap. All rights reserved.