6

Aquamacs has a default html-helper-modeto edit .html files that has weird behaviors. I would like to switch back to regular html-mode by default.

I read that I needed to change the magic-mode-alist to do so. From what I understand from the documentation, adding this to my .emacs should do the deal:

(setq magic-mode-alist '(("\\.html" . html-mode)))

Unfortunately it does not change anything. I read elsewhere that setting it to nil should work but it did not either.

Any idea what I am missing?

Thanks in advance.

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
Mad Echet
  • 3,723
  • 7
  • 28
  • 44

2 Answers2

5

According the page I linked, the first variable to modify is magic-mode-alist which has precedence on auto-mode-alist.

I just added a value at the beginning of the list of matches using the exact same regular expression that was in magic-mode-alist pointing to html-helper-mode:

(add-to-list 'magic-mode-alist 
    '("\\(?:<\\?xml\\s +[^>]*>\\)?\\s *<\\(?:!--\\(?:[^-]\\|-[^-]\\)*-->\\s *<\\)*\\(?:!DOCTYPE\\s +[^>]*>\\s *<\\s *\\(?:!--\\(?:[^-]\\|-[^-]\\)*-->\\s *\<\\)*\\)?[Hh][Tt][Mm][Ll]"
        . html-mode))

Works like a charm. Enjoy Aquamacs without whacky html-helper-mode.

Mad Echet
  • 3,723
  • 7
  • 28
  • 44
  • It's 2018 and this is still an heroic answer IMO. I opted for [`web-mode`](http://web-mode.org) over `html-mode`. Thank you! – ephsmith Aug 18 '18 at 18:19
4

magic-mode-alist looks at the contents of the file. You want to edit auto-mode-alist, which looks at filenames. See the same page you linked for a discussion of that variable.

And you don't want to just set it to a value, because it will already have some values in it. Use the function add-to-list, as follows:

(add-to-list 'auto-mode-alist '("\\.html\\'" . html-mode)
zck
  • 2,712
  • 2
  • 25
  • 44
  • Thanks. It makes a lot of sense but I don't understand why I did not work. I tried removing the former value as well to force the new value adding `(delete '("\\.html$" . html-helper-mode) auto-mode-alist)` but it did not work either though I could check that there was not any link to `html-helper-mode` in `auto-mode-alist`. There must be a place where aquamacs overrides this setting but I can't find where. (you miss a parenthesis in your line ;) ) – Mad Echet Dec 27 '12 at 17:41
  • 1
    Ok, magic-mode-alist has precedence on auto-mode-alist, I need to add a match there before. I am getting closer. I'll post the final solution. Thanks. – Mad Echet Dec 27 '12 at 18:08
  • Thank you for sending me in the right direction, I posted the working solution below. – Mad Echet Dec 27 '12 at 18:38