ErgoEmacsEmacsLispBlogEmacsLispBuy Tutorial
Web Hosting by 1&1

23.3.1 Conventions for Writing Minor Modes

There are conventions for writing minor modes just as there are for major modes. Several of the major mode conventions apply to minor modes as well: those regarding the name of the mode initialization function, the names of global symbols, the use of a hook at the end of the initialization function, and the use of keymaps and other tables.

In addition, there are several conventions that are specific to minor modes. (The easiest way to follow all the conventions is to use the macro define-minor-mode; Defining Minor Modes.)

Global minor modes distributed with Emacs should if possible support enabling and disabling via Custom (see Customization). To do this, the first step is to define the mode variable with defcustom, and specify :type 'boolean.

If just setting the variable is not sufficient to enable the mode, you should also specify a :set method which enables the mode by invoking the mode command. Note in the variable's documentation string that setting the variable other than via Custom may not take effect.

Also mark the definition with an autoload cookie (see autoload cookie), and specify a :require so that customizing the variable will load the library that defines the mode. This will copy suitable definitions into loaddefs.el so that users can use customize-option to enable the mode. For example:

     
     ;;;###autoload
     (defcustom msb-mode nil
       "Toggle msb-mode.
     Setting this variable directly does not take effect;
     use either \\[customize] or the function `msb-mode'."
       :set 'custom-set-minor-mode
       :initialize 'custom-initialize-default
       :version "20.4"
       :type    'boolean
       :group   'msb
       :require 'msb)
blog comments powered by Disqus