3

I think the Change Log mode in emacs (spacemacs) acts crazily and I want to turn it off when editing my CHANGELOG. How do I do that for good?

  • FYI, I've updated my sample code, in case you copied it verbatim. I saw you already accepted the answer... – cyberbisson May 10 at 13:35
4

The change-log-mode exists to help with viewing and editing Change Log files like the one Emacs itself uses. You might consider simply modifying the mode's settings so it behaves like you want instead of "throwing the baby out with the bath water" so to speak. :)

Since that wasn't the specific question you asked, you can use a different mode by modifying auto-mode-alist. This variable tells Emacs what mode to load based on a regex matching of the file being loaded. For Change Logs, by default, it shows this:

'(("[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))

You can simply get rid of it like this:

(setq auto-mode-alist (rassq-delete-all 'change-log-mode auto-mode-alist))

You shouldn't need to do that, though, as adding to the list overrides settings. So you can just replace it like this:

(setq auto-mode-alist
      (append '(("[cC]hange\\.?[lL]og?\\'" . text-mode)
                ("[cC]hange[lL]og[-.][0-9]+\\'" . text-mode)
                ("\\$CHANGE_LOG\\$\\.TXT" . text-mode)
                ("[cC]hange[lL]og[-.][-0-9a-z]+\\'" . text-mode))
              auto-mode-alist))
  • 1
    You don't need the setq auto-mode-alist bit there, add-to-list modifies the list in-place. – rpluim May 10 at 12:19
  • @rpluim ah right. I shouldn't type so fast. :) – cyberbisson May 10 at 12:31
  • 1
    Hmm, you seem to have omitted quoting for your string literals. That doesn't actually work, does it? Also see rassq-delete-all. – npostavs May 10 at 12:56
  • @npostavs Thanks for the correction. What happened was I did (print "%s" auto-mode-alist) and copied the result, which stripped the quotes out. I've fixed up the examples. – cyberbisson May 10 at 13:16
-1

How about:

(defalias 'change-log-mode #'text-mode)

This suggestion has (not unreasonably) garnered some down-votes. I'm not deleting it, but it needs some extra notes:

  1. cyberbisson's answer is the correct solution to the question in the title: "How do I disassociate a filetype and mode?". In general, that's the sensible approach to take (and is of course completely fine in this case).

  2. My suggestion was 100% aimed at the specific use-case of eradicating change-log-mode. I'm mostly sure this mode has a sufficiently-limited set of uses that in practice clobbering the mode function is going to be fine. Assuming that is indeed the case, this is just a very very easy approach.

  3. I'm not recommending this approach as a general solution (although it would undoubtedly also work fine in practice in numerous other cases). DoMiNeLa10 commented that it might break things, and that's definitely possible for arbitrary uses of defalias to clobber modes, but (I suspect) not likely to be a problem for this example.

  4. This approach has one advantage (or disadvantage) over the auto-mode-alist approach in that it also prevents change-log-mode from being triggered in any other way. This is probably not relevant, but worth pointing out.

  5. M-x load-library RET add-log RET would redefine change-log-mode to its normal value, if you wanted to do that.

  • I am not the DV, but I wonder why this got downvoted. Perhaps there is a more idiomatic way? – The Unfun Cat May 10 at 10:53
  • I didn't DV (and I won't, because this solution will work), but that's an awfully big hammer for this nail. You won't be able to even manually use the mode of you do it this way. – cyberbisson May 10 at 12:35
  • The issue was "Change Log mode ... acts crazily" and they didn't want to use it, so it didn't seem entirely unreasonable to suggest a way in which nothing would ever cause it to be used. (My first inclination was updating auto-mode-alist, but I went with this approach on purpose, as big a hammer as it is.) – phils May 10 at 14:03
  • @phils this solution is bad, because overriding change-log-mode could lead to unexpected breakage. – DoMiNeLa10 May 10 at 16:54
  • I can come up with some scenarios, but honestly, I think it would be fine in practice for this particular case. cyberbisson's answer certainly matches the question title better, though. – phils May 10 at 17:36

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.