0

I have the following statement in two installations of emacs

(setq default-directory "~/.emacs.d/") 

followed by

(load-file "keyboard.el")  

One installation finds the file, the other doesn't. I have to add the directory beforehand for it to be loaded.

What could be the problem?

How would I display default-directory in init.el to see if it is being set properly?

P.S. : I'm very much finding my way around the system, so excuse the dumb question.

1
  • One question per post. ||| I don't quite understand your question. "How would I display default-directory in init.el to see if it is being set properly?" - Is this what you want?? Commented Sep 1, 2023 at 16:03

2 Answers 2

1

You should learn how to look up help information. You can use C-h f to look up help for any function. If you look up the help for the require function, you will see this:

(require FEATURE &optional FILENAME NOERROR)

If FEATURE is not already loaded, load it from FILENAME.

If FEATURE is not a member of the list features, then the feature was
not yet loaded; so load it from file FILENAME.

If FILENAME is omitted, the printname of FEATURE is used as the file
name, and [blah blah blah].

To find the file, this function searches the directories in load-path.

That last line is the information you need. When you load a file, it looks at the load-path variable, expecting to find a list of strings where each string is the name of a directory. It doesn’t look in the default-directory, which just tells Emacs where to save the file you have opened in the current buffer.

Incidentally, C-h ? will show you a list of all the things you can ask for help information on. You can answer virtually any question you have with the built–in help.

0

@db48x answered your question wrt load-path.

I'll add this:

If you put this in your init file: (setq default-directory "~/.emacs.d/") that simply changes the value of variable default-directory, which is always buffer-local. In other words, you're changing the value of that variable only for the buffer that happens to be current at that moment during your init-file load.

That's pretty much never what you want. You would need to be sure of which buffer is current when that's evaluated, and even then it's likely not the way to go. Even using a let-binding would likely be better, but still, this is not what you want to do.

If you want to set the default value of default-directory, then you can use setq-default.

2
  • I'm fairly new to all this and thought I needed to set default-directory so that emacs could find lisp files referred to. Will they automatically load if they are in ~/.emacs.d ? Commented Sep 1, 2023 at 21:03
  • Variable load-path is a list of directories that Emacs will look in, to find Lisp files when you use require or load-library. If ~/.emacs.d is in your load-path then anything in that directory (but not below it) will be found. Commented Sep 1, 2023 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.