Übersicht Letzte Änderungen Neuigkeiten Suchen ElispSektion KurzAnleitung Impressum
Kamerun: Erlangung der Unabhängigkeit 1960

MinorMode

An Emacs buffer must be in exactly one major mode. It might also be in one or more minor modes that provide additional functionality.

A minor mode is often appropriate for use with more than one major mode. It sometimes adds functionality that is orthogonal to that provided by the major mode. For example, font-lock (minor) mode provides syntax-sensitive highlighting; it can be used with most major modes to provide appropriate highlighting (see EnablingFontLock).

Most minor modes have a command that turns them on and off. For example:

Some do not. For example:

Some modes do not have a single-point of entry, but set a variable for whether they are turned on, or should be disabled.

Defining minor modes

The easiest way to define a minor mode is with the define-minor-mode macro from easy-mmode.el.

Discussion

How do I check whether a given minor mode is active?

Test the value of the mode variable. Example: (if delete-selection-mode ...)

The mode variable might not be known, so you can add this protection:

(if (boundp 'unknown-mode)
  (if unknown-mode)
    ...))

Caution: I am 99% sure of this idiom, but can someone check it and then remove this notice.

But some minor modes don’t have a variable, e.g., auto-fill-mode. – rubikitch

True. I was going to say “File a bug”, but checking the code defining ‘auto-fill-mode’ I see this comment:

(put 'auto-fill-function :minor-mode-function 'auto-fill-mode)
;; FIXME: turn into a proper minor mode.
;; Add a global minor mode version of it.
(defun auto-fill-mode (&optional arg)
...

So I guess the answer is: (1) file a bug, (2) volunteer to fix the code. ;-) – DrewAdams

I filed a bug: #2470. – DrewAdams


CategoryGlossary