How can I override the default mode file in Emacs?

578 views Asked by At

I would like to override the default Emacs cc-mode.el with another file. In my .emacs, I have the following line:

(add-to-list 'load-path "/usr/home/smooth/emacs" t)

This works correctly to load local Emacs configuration files. For example

(require 'go-mode-autoloads)

works to load go-mode.el from the above directory.

I tried placing the required cc-mode.el file into the above directory in the hope that it would override the default Emacs c-mode. However, it did not load the cc-mode.el file which I had put in /usr/home/smooth/emacs. Instead it continued to use the default one.

How can I make Emacs use my cc-mode.el file and not the default one? I have already extensively searched with Google and tried the Emacs Wiki, but I couldn't find the correct page.

Alternatively, how I can I set Emacs to use another file for c-mode than the system default? I don't mind renaming the current cc-mode.el to another name.

My version of Emacs is 25.2.

2

There are 2 answers

1
Smooth Criminal On BEST ANSWER

Looking at Emacs Wiki, I noticed there was no "t" at the end of the "load-path", so I removed that and it started working. The "t" above may be the origin of the problem. What is very strange is that the misbehaviour in cc-mode I was trying to get around has also disappeared. The above "t" may have caused some sort of other errors. See emacswiki.org/emacs/LoadPath for the Emacs Wiki page.

I found this page: gnu.org/software/emacs/manual/html_node/elisp/…. It says Normally, if element is added, it is added to the front of symbol, but if the optional argument append is non-nil, it is added at the end. It seems I was adding at the end. I'm not sure why that broke cc-mode so horribly, since it was working until I switched to emacs 25.2 a few days ago. It's now working well.

0
Drew On

You can use load-library (or load) to unconditionally load a library, even if the feature(s) it provides have already been provided (e.g. by another library or another version of the same library already having been loaded).

Just put the library you want to load in a directory that is near the beginning of your load-path and then call load-library.

[Note, however, that loading (or reloading) a library does NOT cancel out defvars and defcustoms that might already have been evaluated. For example, if library foo.el has a defcustom for foo-option and it has been loaded, and then you load your own version of foo.el that has such a defcustom but with a different default value, yours will be ignored. This is part of the behavior of defvar and defcustom.]