5

looks like Emacs tries to be smart, switching to an annoying change-log-mode often when i am editing a changelog file. I would like to disable it, but i just find info about how to interactively disable a mode while editing a buffer, or how to enable a mode when a file matches a pattern.

I cannot find any info about how to disable a major mode totally and in any case. Ideally i would even remove it from my installation, as i will be never using it

  • Emacs does not try to be smart, Emacs is just Emacs. – Thorbjørn Ravn Andersen Apr 2 '16 at 23:09
  • 1
    Just a note: maybe you just want to use another file name, since "ChangeLog" is the standard name for files that follow the particular format defined in the GNU Coding Standards. Or maybe you want to adjust and use that existing format. Or maybe you want to tweak change-log-mode so it understands your format. – Stefan Apr 4 '16 at 13:06
  • Thanks Stefan. Honestly, in this case the match is too inclusive. It matches a lot of documents which have nothing to do with that standard, for example documents terminating in .md. I think that the GNU standard does not include Markdown, right? Also, the mode does not seem as usable and helpful as other Emacs modes. Maybe it is targeted at experts – danza Apr 4 '16 at 20:45
9

Emacs keeps a list of regexp-mode pairs in an alist called auto-mode-alist. Any file you open has it's name matched against the nodes in the alist; every match activates a mode.

So, what you want to do, it sounds like, is purge change-log-mode from auto-mode-alist, which you can do in your init.el/.emacs.d/etc like so:

(rassq-delete-all 'change-log-mode auto-mode-alist)
  • 1
    Oy. Didn't know about rassq-delete-all. Thanks, I learned something new. +1. – Harald Hanche-Olsen Apr 2 '16 at 18:14
2

Here are two sledgehammer approaches:

(defun change-log-mode () t)

which redefines change-log-mode to do nothing, and

(fset 'change-log-mode (symbol-function 'fundamental-mode))

which makes change-log-mode turn on fundamental mode instead.

A third approach might be to use an overriding advice.

And a somewhat less drastic approach is to remove all mention of the offending mode from auto-mode-alist:

(require 'cl)
(setq auto-mode-alist
      (remove-if (lambda (pair) (eq (cdr pair) 'change-log-mode))
                 auto-mode-alist))

This way, you are not disabling the mode altogether, but it should never be automatically applied (unless some other mechanism turns it on).

  • If you go for the approach at the end, see the answer by @Gastove for a less verbose way. – Harald Hanche-Olsen Apr 2 '16 at 18:15
  • 1
    I got downvote, I see. But actually, my answer is the only one that answers the OP's question: He wanted to completely disable change-log-mode, not merely ensure it is not automatically turned on. Even so, I agree that the answer by @Gastove serves the OP better, and so I was the first to upvote it. – Harald Hanche-Olsen Apr 3 '16 at 7:11
  • I will choose the answer by Gastove, but thanks for your very exhaustive answer! – danza Apr 4 '16 at 20:42
1

You need to modify the auto-mode-alist variable. This is “alist of filename patterns vs corresponding major mode functions”. Its value looks like this (at least for me):

(
 …
 ("[cC]hange\\.?[lL]og?\\'" . change-log-mode)
 ("[cC]hange[lL]og[-.][0-9]+\\'" . change-log-mode)
 ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode)
 …
 ("[cC]hange[lL]og[-.][-0-9a-z]+\\'" . change-log-mode)
 …
)

So, you just need to either push something that matches these regexps on top of the list or remove these items. I think pushing is a better idea because you don't need to traverse all contents of the list, so here we go:

(push '("[cC]hange\\.?[lL]og?\\'" . text-mode) auto-mode-alist)

Here I “disabled” the first regexp, so plain text-mode will be used for files that match it from now on (this method has the additional benefit that you can specify which mode to use instead because fundamental-mode may be not very interesting). You can do the same to the other regexps.

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.