reddit / emacs

Cannot require files with custom load-path

Pay08 · 2022-11-16 11:43
Anything that needs a `(add-to-list 'load-path "foo")` before it, I cannot load with `(require 'foo)`, giving me a file not found error. A normal `load` works, but isn't an ideal solution. Why does this happen and how can I resolve it?
7890yuiop · 2022-11-16 14:01
I suggest you provide a detailed example, because that's not enough information to say anything more than "you're doing something wrong".
Pay08 · 2022-11-16 14:06
The only detailed example I can give is (add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e/") (require 'mu4e) This gives the error "Cannot open load file: No such file or directory". mu4e.el is in `site-lisp/mu4e/`.
twleo · 2022-11-16 14:14
are you sure that `/usr/share/emacs/site-lisp/mu4e/mu4e.el` exists?
7890yuiop · 2022-11-16 14:17
I presume `add-to-path` is a reddit-only typo?
Pay08 · 2022-11-16 14:17
Oh, yes, sorry.
Pay08 · 2022-11-16 14:18
Yes, alongside a .elc.
twleo · 2022-11-16 14:40
print the `load-path` and make sure the directory is actually added. can use `(locate-library "mu4e")` to check
Pay08 · 2022-11-16 15:09
It's in there and is correct.
arthurno1 · 2022-11-16 20:20
Did you try to run manually (add-to-list ...), for example, via M-: or in scratch buffer, and to require mu4e.el afterwards? Just to be sure, you are not adding that directory to your load-path *after* you have tried to load the file itself, because of the initialization order in your Emacs configuration. Also double check that you haven't misspelled your path in your config.
Pay08 · 2022-11-16 20:38
>you are not adding that directory to your load-path *after* you have tried to load the file itself Nope. >Also double check that you haven't misspelled your path in your config. Also no. Company has path autocomplete, just to be sure. >Did you try to run manually (add-to-list ...) That didn't work, unfortunately.
arthurno1 · 2022-11-16 20:56
> That didn't work, unfortunately. That *ought* to work :). Works just fine here. If you paste (add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e/") in your scratch buffer, place cursor at the end, after the ')', and C-x C-e or M-x eval-last-sexp, it should push that path onto your load-path list. It just worked here: ("/usr/share/emacs/site-lisp/mu4e/" "/usr/local/share/emacs/29.0.50/site-lisp" "/usr/local/share/emacs/site-lisp" "/home/arthur/.config/emacs/lisp" "/home/arthur/.config/emacs/lisp/vc" "/home/arthur/.config/emacs/lisp/url" "/home/arthur/.config/emacs/lisp/textmodes" "/home/arthur/.config/emacs/lisp/progmodes" "/home/arthur/.config/emacs/lisp/play" "/home/arthur/.config/emacs/lisp/org" "/home/arthur/.config/emacs/lisp/nxml" "/home/arthur/.config/emacs/lisp/net" ...) You can also do: (push "/usr/share/emacs/site-lisp/mu4e/" load-path) You can check that the folder is in your path by typing M-: load-path RET.
Pay08 · 2022-11-16 20:58
Sorry, I should clarify. It did put it onto the load list (or rather, it was already there), but the error persists.
7890yuiop · 2022-11-16 21:10
You said that `load` works, though. What does that look like? (load "mu4e") ;; ? (load "/usr/share/emacs/site-lisp/mu4e/mu4e") ;; ? (load "/usr/share/emacs/site-lisp/mu4e/mu4e.el") ;; ? (load "/usr/share/emacs/site-lisp/mu4e/mu4e.elc") ;; ? All of the above? Some of the above? Other? ---- And did you evaluate `(locate-library "mu4e")` like /u/twleo recommended? I can't tell from your reply. What does that return?
Pay08 · 2022-11-16 21:24
It's simply `(load "mu4e")`. `(locate-library "mu4e")` does indeed return the same path I use in `add-to-list`.
7890yuiop · 2022-11-16 22:31
It should have returned the path to a *file*, whereas the path you add to `load-path` should be for a *directory*. n.b. Quoting exact output (as a general approach when seeking assistance) helps everyone else *a lot*. Otherwise things can be far less clear than you imagine them to be. Starting from `emacs -Q` what do you get after evaluating each of the following, one at a time, in the scratch buffer using `C-j` ? (load "mu4e") (add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e") (require 'mu4e) (load "mu4e")
Pay08 · 2022-11-16 22:35
It did return the path to the file. The directory of the file was the same as the one I added to load-path. I didn't copy-paste because I wasn't at the computer.
Pay08 · 2022-11-16 22:42
> (load "mu4e") file-missing error. > (add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e") It prints a bunch of paths, including the mu4e one, although not all of load-path. > (require 'mu4e) It prints "mu4e" (quotations not included) > (load "mu4e") Prints t.
7890yuiop · 2022-11-16 22:48
> (add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e") > > It prints a bunch of paths, including the mu4e one, although not all of load-path. > > (require 'mu4e) > > It prints "mu4e" (quotations not included) Ok, so that's showing things *working*, contrary to your original question. The only difference I'm aware of is that I removed the trailing `/` from the directory (which is strictly the correct form for these list items, but the trailing slash also shouldn't have tripped anything up). Repeat the test from a new `emacs -Q` with the trailing slash included though. If that still works... you either didn't actually have a problem, or something in your config is breaking things in a very funky manner (in which case you'll just have to recursively bisect your config until you find out what that is).
Pay08 · 2022-11-16 23:00
The slash isn't causing the issue. I just did C-j on the require in my init file, but it didn't print anything, however, mu4e commands are available.
7890yuiop · 2022-11-17 03:13
Be careful how you're testing... `C-j` is only bound to an evaluate+print command in `lisp-interaction-mode` (e.g. scratch buffer), not in `emacs-lisp-mode` (e.g. your init file). You can use `C-x C-e` in both (which evaluates without inserting the return value). Also `require` doesn't *try* to load anything if the library in question has already been loaded.
Pay08 · 2022-11-17 03:50
Weirdly enough, that evaluates to mu4e. Is it possible that there's something wrong with whatever gives these errors? (presumably emacs-lisp-mode)
7890yuiop · 2022-11-17 04:08
At this point I'm not seeing a problem at all. I believe you've now tested the example you said was failing, and shown that it's succeeding. Do you have any different example which is (still) failing?
Pay08 · 2022-11-17 04:28
Yes, it isn't failing. My problem is that the error that *says* it is failing still persists.
7890yuiop · 2022-11-17 05:42
Ok, well you'll need to come up with a recipe to reproduce *that* then, because whatever problem you're still seeing does not appear to be related to the example/recipe you've shown here. I.e. Your problem does not seem to be what you thought it was. (Try replacing your init file with one containing *only* the code which you believed was causing the error.) I'm bowing out at this point, but if you describe the real problem clearly (perhaps as a new post) I'm sure someone else will be able to help you with that. My advice for all of your future requests for assistance is: help other people to help you: * Provide a minimal recipe to reproduce your problem -- this will help to ensure that the problem is actually being caused by the thing you think is causing it, and it will avoid people spending time on things which are not actually relevant. * Whenever possible, start your recipes from `emacs -Q` and/or an empty init file -- other people do not have your config. * *Never* manually type the code or output from Emacs (or worse, from memory) into your questions/comments -- you may make typos or otherwise mis-represent something. You can find most messages from Emacs in the \*Messages\* buffer. Copy and paste code and messages *verbatim* to ensure you provide accurate information. * Any time there is an error message, include it -- again, copy and paste it verbatim to guarantee that it is accurate. * In general, provide as much specific detail as possible, and ensure it's accurate information, because the information you provide is the only thing that anyone else has to work with. If you do these things, you will get better and faster results, without causing any frustration.
a-c-d-w · 2022-11-17 06:28
Are you providing the features at the end of each file?