Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entering a minor mode with a major mode in Emacs

Tags:

emacs

q

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.

like image 279
Dang Khoa Avatar asked Dec 27 '22 14:12

Dang Khoa


1 Answers

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.

like image 118
Lindydancer Avatar answered Jan 05 '23 04:01

Lindydancer