In my ~/.emacs.d/init.el, I have just three lines:
(push (expand-file-name "lisp" user-emacs-directory) load-path)
(require 'init-vars)
(provide 'init)
In my ~/.emacs.d/lisp/init-vars.el, I have below three lines:
(require 'dired)
(setq dired-use-ls-dired nil)
(provide 'init-vars)
Flycheck reports error at line 2 of ~/.emacs.d/init.el:
Cannot open load file: No such file or directory, init-vars
What am I missing here?
If I change the line to (require 'init-vars (expand-file-name "lisp/init-vars.el" user-emacs-directory)) then the error is gone. I don't get why load-path isn't working.
Flycheck does not run the code, but compiles it instead (to get the compiler's warnings). When the compiler processes the
(require 'init-vars)it will try to loadinit-varsfrom the "current"load-pathbut since the first line was compiled rather than executed, the Emacs session where the file is compiled still has the defaultload-pathvalue, with the extra~/.emacs.d/lispdirectory added to it.One way to fix the problem is with
eval-when-compile:BTW, I recommend you use
add-to-listinstead ofpushhere (or else, usecl-pushnew) so that repeated execution of that code doesn't keep adding redundant copies of that directory to yourload-path.