What are the arguments for define-globalized-minor-mode in Emacs

elisp, emacs

Solution

A globalized minor mode is a global minor mode that is created from an existing (non-global) minor mode. Nothing more.

The first arg to `define-globalized-minor-mode` is the name (a symbol) of the global minor mode you want to create. The second arg is the existing (non-global) minor mode function (a symbol) that you want to use to create the global one.

The third arg is a function that turns the minor mode on. The minor mode function typically is a toggle command. Invoking it interactively with no args does not turn the mode on. (Invoking it from Lisp with no args does turn it on.)

And some minor modes have a defined (named) separate command to turn them on. E.g., `turn-on-visual-line-mode` is a separate command from `visual-line-mode`. It is equivalent to `(lambda () visual-line-mode 1))`. So you could pass as the third arg either the symbol `turn-on-visual-line-mode`or the equivalent lambda form.

That's really all there is to it.

Problem

I want a non-global minor mode to be enabled on the Emacs start up. I found it can be done with that code: ``` (define-globalized-minor-mode my-global-mode the-mode (lambda () (the-mode t)) ) (my-global-mode t) ``` But I don't get it. What do two last arguments of the `define-globalized-minor-mode` do? `the-mode` and a `lambda`. More precisely why do I need both, isn't it tautology?

Original source