www.delorie.com/gnu/docs/elisp-manual-21/elisp_355.html   search  
Buy the book!

GNU Emacs Lisp Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

23.2.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, and the use of keymaps and other tables.

In addition, there are several conventions that are specific to minor modes.

Global minor modes distributed with Emacs should if possible support enabling and disabling via Custom (see section 14. Writing Customization Definitions). 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 invoke 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 section 15.4 Autoload), 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:

(defcustom msb-mode nil
  "Toggle msb-mode.
Setting this variable directly does not take effect;
use either \\[customize] or the function `msb-mode'."
  :set (lambda (symbol value)
	 (msb-mode (or value 0)))
  :initialize 'custom-initialize-default
  :version "20.4"
  :type    'boolean
  :group   'msb
  :require 'msb)

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003