0

Having searched for advice on how to change the load-path, I found this answer in the EmacsWiki:

https://www.emacswiki.org/emacs/LoadPath

I have evaluated a similar command in the minibuffer:

(add-to-list 'load-path "/usr/share/emacs/27.1/lisp/6502")

The intention is to add a 6502 major mode to emacs found here:

http://www.tomseddon.plus.com/beeb/6502-mode.html

Once I have entered that expression, querying the load-path variable confirms it has changed.

When I then test the change by quitting and restarting emacs I see an error which says

File is missing: Cannot open load file, No such file or directory, 6502-mode

When I then query the load-path again the change I made was forgotten.

How do I make changes to the load-path permanent?

6
  • 2
    Is your load-path addition higher up in your .emacs / init.el file so that when you (require '6502-mode) Emacs knows where to find it? And, does your 6502-mode.el file have a (provide '6502-mode) at the bottom or are you using load instead of require such that the provide statement is not needed? – lawlist Feb 7 at 19:23
  • 2
    Evaluating the (add-to-list ...) in the minibuffer only changes the currently running session of emacs. As @lawlist implies, you need to add the (add-to-list ...) to your init file. – NickD Feb 7 at 19:25
  • 1
    Think of your init file as a prolog, which establishes settings etc. that you want to be in effect when you start using Emacs interactively. – Drew Feb 7 at 20:23
  • 1
    I hope the answer is helpful: I tried to expand it a bit and include some additional information that I thought you might find useful. – NickD Feb 8 at 2:45
  • 1
    Yes, thank you. It is most helpful, it has solved the problem. Additionally, I have added (add-to-list 'auto-mode-alist '("\\.s65" . 6502-mode)) to auto-select the mode for associated files where 's65' may be replaced with any file extension. In my arduous search for the whereabouts of my init file I have also found C-h v user-init-file RET to be invaluable, thank you. – Georgina Davenport Feb 8 at 19:34
1

Evaluating lisp expressions in the minibuffer (or in the scratch buffer, or with C-x C-e in an emacs-lisp buffer, or loading lisp libraries by hand with M-x load-file or ....) only affects the current session of emacs. The moment you kill this emacs session everything that is not part of the initial emacs state is lost irretrievably. So even if you (add-to-list 'load-path ...) appropriately and you (require '6502-mode) in this session, if you are doing it interactively, you are only affecting the current session.

In order to affect a future emacs session, you need to save this initialization in a file and load that file into the future emacs session somehow. That's what the init file provides: when emacs starts up, it automatically knows to load that file. So you need to add such settings to your init file:

(add-to-list 'load-path "/usr/share/emacs/27.1/lisp/6502")
(require '6502-mode)

From that point on, every session of emacs you start up will load the init file, evaluating everything in it.


Sometimes, it is useful to start an emacs session that does NOT load your init file, e.g. there might be something wrong with it and your emacs session misbehaves: it is often useful in such cases to create an emacs session without your initializations in order to see whether emacs misbehaves the same way; if it does not, then that tells you that there is something wrong in your init file and you need to find it and fix it.

To start an emacs session without your initialization file, you can say emacs -q: the -q option tells emacs not to do its usual default action of loading the init file.


BTW, there are lots of details about the init file in the Emacs Manual: it's well worth reading that section (as is the whole manual of course, but you cannot read it in one sitting, but you should familiarize yourself with it, so you know where to go to look up something).

Another, very useful, way to read the manual is by using the Info system from within emacs. Assuming that you have the manual installed (which should be the case on any platform that you might use: Linux, Windows or MacOS), then in emacs you can say C-h i g (emacs)Init file RET which will take you to the same page in your local copy of the manual that the link above takes you in the copy that's available on the web.

Learning how to use Info to look up things in emacs will prove invaluable: I highly recommend it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.