Question

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?

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top