0

I use both web-mode and racket-mode often. I am also using Pollen, a Racket language for processing text. Pollen uses compound file extensions like:

pynchon.html.pm
stephenson.css.pp
wallace.html.pmd

The relevant extensions are pm, pmd and pp.

web-mode grabs onto these file extensions due the css and html portions on the extension. I would like it to stop doing that. I would like these files to be opened in racket-mode.

This is what I have tried so far in my default.el file (I am using prelude):

;; web-mode
(require 'web-mode)
(defun my-web-mode-hook ()
  "Hooks for Web mode."
  (add-to-list 'auto-mode-alist '("\\.p[mp]\\'" ignore t))
  (add-to-list 'auto-mode-alist '("\\.pmd\\'" ignore t)))
(add-hook 'web-mode-hook 'my-web-mode-hook)

;; racket-mode
(require 'racket-mode)
(defun racket-mode-hook ()
  (add-to-list 'auto-mode-alist '("\\.p[mp]\\'" . racket-mode))
  (add-to-list 'auto-mode-alist '("\\.pmd\\'" . racket-mode)))

(add-hook 'racket-mode-hook 'racket-mode-hook)

Unfortunately my pollen files with an html extension (ex: pynchon.html.pm) still open in html-mode and my pollen files with a pp extension open in puppet-mode.

1

Welp, managed to solved it.

I removed the relevant lines from my-web-mode-hook and added the following outside of the racket-mode-hook function:

(add-to-list 'auto-mode-alist '("\\.p[pmd]+\\'" . racket-mode))

My files are now opening in racket-mode.

0

We can, in addition to just making sure that your racket files open up properly, make sure that files that end in .html.anythingelse also don't open up in html mode.

The default regexp that determines whether a file is opened in html-mode is:

"\\.[sx]?html?\\(\\.[a-zA-Z_]+\\)?\\'"

So, a filename that contains .html (or .shtml, or .xhtml) followed by either nothing, or a single period, then some more stuff. But really, we want to make sure the filename ends with .html.

So let's do that. But first, remove the old one from the list:

(require 'cl)
(setq auto-mode-alist
      (cl-remove-if (lambda (ele)
                      (equal ele
                             '("\\.[sx]?html?\\(\\.[a-zA-Z_]+\\)?\\'"
                               . html-mode)))
                    auto-mode-alist))

And now we can add a new regex matcher that makes sure we're matching at the end of the name:

(add-to-list 'auto-mode-alist '("\\.[sx]?html?$" . html-mode))

And now, if you try to open whatever.html, it'll open in HTML mode as before, but if you try to open whatever.html.pm, it'll open in racket-mode.

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.