4
votes

This question may be a duplicate of this question, but I can't get the following to work properly in my emacs.

I am trying to enter minor mode mlint-mode whenever I enter major mode matlab-mode (both modes available at their SourceForge page). I have the following in my .emacs file:

(add-hook 'matlab-mode-hook
      (function (lambda()
                  (mlint-mode))))

which looks like the answer to the question I linked above. When opening a .m file, I get the following error:

File mode specification error: (void-function mlint-mode)

Could someone please assist in helping me write the correct hook to enter mlint-mode when I open a .m file? FWIW, I'm running emacs 23.1.50.1.

1
Why not just (add-hook 'matlab-mode-hook 'mlint-mode)? Are you sure you have actually loaded the minor mode?hmakholm left over Monica
that's the first thing I tried, and it didn't work. see @Lindydancer's answer below..Dang Khoa
You don't do it that way because most minor modes toggle their functionality when called with no argument (just like when you call them interactively). So if mlint mode was already enabled for a buffer and you changed to matlab-mode, the above form would have the effect of switching mlint mode off. As such, you usually want to pass an argument (frequently 1 or t, but check the appropriate docstring) when enabling a minor mode with a hook function.phils

1 Answers

10
votes

I think the correct name is mlint-minor-mode. Also, remember to ensure that all matlab stuff is known by Emacs, this can be done using:

(require 'matlab-load)

As a side note, it is typically a bad idea to use lambda functions in hooks. If you inspect the value of the hook you will see a lot of unrelated things. Also, if you modify your lambda expression and re-add it, both the old and the new version will be on the hook.

Instead, you can do something like:

(defun my-matlab-hook ()
   (mlint-minor-mode 1))
(add-hook 'matlab-mode-hook 'my-matlab-hook)

The "1" is ensures that mlint mode is turned on or stay on if enabled earlier.