I'm writing a package with several different files, in which the placement of the root directory is important. Since I don't know where other users will put the package, I thought I'd be clever and reference the location of the root directory using a custom whose default is the parent directory of (the parent directory of the parent directory of) the file in which the file housing the customs is located which would be found out as the file corresponding to the buffer reading the file, so
(defcustom daselt-directory (file-name-parent-directory (file-name-parent-directory (file-name-directory (buffer-file-name)))) "This should be the directory in which Daselt is housed. Please include the trailing backslash." :group 'Daselt :type 'string) And when I'm reading in the file using require while Emacs is already running, this seems to work alright, but when I'm putting the same require defun into my init, I get
Debugger entered--Lisp error: (wrong-type-argument stringp nil) file-name-directory(nil) (file-name-parent-directory (file-name-directory (buffer-file-name))) So apparently, during startup buffer-file-name doesn't return anything, I guess because the file isn't really read in using a buffer. But isn't there a way I can find out the path of the file require is reading while it's reading it during startup?
requireis reading its code from?load-history.