Okay, I did that, and it seems to be this: (defconst M2-mode-font-lock-keywords ' ( "///\\(/?/?[^/]\\|\\(//\\)*////[^/]\\)*\\(//\\)*///" . 'font-lock-string-face) ) (define-derived-mode M2-mode prog-mode "Macaulay2" (setq font-lock-defaults '( M2-mode-font-lock-keywords )) ) (add-to-list 'auto-mode-alist '("\\.m2\\'" . M2-mode))