Reputation: 1
In Emacs, I am putting on the menu an item to load the init.el file, since I am in there almost daily. menu code is working fine, but the file isn't loading. So in a buffer, for troubleshooting, I enter:
(load user-init-file)
and use C-x C-e
to execute it.
Turns out if fails because it needs double backslashes in the path.
user-init-file resolves to "c:\steve\emacs\init.el"
But should be `
"c:\\steve\\emacs\\init.el"
is there a function already to convert to the double backslashes? Or how do I do that with a search/replace?
This is similar to other search questions I found except this is for replacing within a string instead of within a buffer.
Upvotes: 0
Views: 1051
Reputation: 30718
I think you probably just want (load-file user-init-file)
. load-file
does not use load-path
, and it does not try to append .elc
or .el
.
(If you use MS Windows notation for a file name then you can see what Emacs really thinks the file name is, by calling file-truename
on it.)
If you really want to use load
, try (load user-init-file nil nil t)
.
load
tries to expand its FILE
arg, automatically adding .elc
and .el
. The 4th argument is NOSUFFIX
, which if non-nil prevents that behavior.
C-h f load
:
**
load-** is a built-in function in
C source code`.
(load FILE &optional NOERROR NOMESSAGE NOSUFFIX MUST-SUFFIX)
Execute a file of Lisp code named FILE.
First try
FILE
with.elc
appended, then try with.el
, then tryFILE
unmodified (the exact suffixes in the exact order are determined byload-suffixes
). Environment variable references inFILE
are replaced with their values by callingsubstitute-in-file-name
. This function searches the directories inload-path
.If optional second arg
NOERROR
is non-nil
, report no error ifFILE
doesn't exist. Print messages at start and end of loading unless optional third argNOMESSAGE
is non-nil
(butforce-load-messages
overrides that).If optional fourth arg
NOSUFFIX
is non-nil
, don't try adding suffixes.elc
or.el
to the specified nameFILE
.If optional fifth arg
MUST-SUFFIX
is non-nil
, insist on the suffix.elc
or.el
; don't accept justFILE
unless it ends in one of those suffixes or includes a directory name.If
NOSUFFIX
isnil
, then if a file could not be found, try looking for a different representation of the file by adding non-empty suffixes to its name, before trying another file. Emacs uses this feature to find compressed versions of files when Auto Compression mode is enabled.If
NOSUFFIX
is non-nil
, disable this feature.The suffixes that this function tries out, when
NOSUFFIX
isnil
, are given by the return value ofget-load-suffixes
and the values listed inload-file-rep-suffixes
. IfMUST-SUFFIX
is non-nil
, only the return value ofget-load-suffixes
is used, i.e. the file name is required to have a non-empty suffix.When searching suffixes, this function normally stops at the first one that exists. If the option
load-prefer-newer
is non-nil, however, it tries all suffixes, and uses whichever file is the newest.Loading a file records its definitions, and its
provide
andrequire
calls, in an element ofload-history
whose car is the file name loaded. Seeload-history
.While the file is in the process of being loaded, the variable
load-in-progress
is non-nil
and the variableload-file-name
is bound to the file's name.Return
t
if the file exists and loads successfully.
Upvotes: 2