Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get emacs to recognize .m files as Matlab files, not objective-C files?

My .emacs file concerning Matlab is as follows:

;; Matlab mode
(autoload    'matlab-mode "matlab" "Matlab Editing Mode" t)
(setq matlab-indent-function t)
(setq matlab-shell-command "matlab")

But when I open a Matlab file, I see I'm in Objective-C mode. Since I do not plan on writing Objective-C anytimes soon, how do I default all .m files to open in Matlab mode?

like image 777
xiaolingxiao Avatar asked Apr 24 '14 03:04

xiaolingxiao


1 Answers

Your comment says you've resolved this. Something tells me you did it by adding

(add-to-list 'auto-mode-alist '("\\.m" . matlab-mode))

to your .emacs. I've got so many of these sprinkled around that I just wrote a convenience macro for it:

(defmacro by-extension (ext mode)
  `(add-to-list 'auto-mode-alist '(,(format "\\.%s" ext) . ,mode)))

which lets me write things like

(by-extension "m" matlab-mode)
like image 96
Inaimathi Avatar answered Oct 31 '22 20:10

Inaimathi