2

I am trying to write a global minor mode. The following illustrates my problem:

(define-minor-mode global-foo-mode :global t :lighter " FOO")

then run

M-x global-foo-mode

The message displayed is

Global-Foo mode disabled

The current buffer does not display the FOO lighter in its mode line, but every other buffer does. Subsequent invocations of M-x global-foo-mode in various buffers seem to enable and disable the mode on the current buffer, but not globally as I would expect. Can anyone help me understand what I'm doing wrong here?

8

The problem is that you are leaving out the required argument DOC when you call define-minor-mode. (Or more accurately, you are passing :global as the DOC parameter)

Either provide a doc string or nil as the second argument:

(define-minor-mode global-foo-mode nil :global t :lighter " FOO")

Note that define-minor-mode is a macro. You can see how it is expanded. Put point just after the closing paren and call M-x pp-macroexpand-last-sexp. Try this with and without the nil in there, and you'll see that in your case :global is being used where the docstring should be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.