;;; easy-mmode.el --- easy definition for major and minor modes
-;; Copyright (C) 1997, 2000, 2001, 2002, 2003, 2004, 2005
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1997, 2000, 2001, 2002, 2003, 2004, 2005,
+;; 2006 Free Software Foundation, Inc.
;; Author: Georges Brun-Cottan <Georges.Brun-Cottan@inria.fr>
;; Maintainer: Stefan Monnier <monnier@gnu.org>
The above three arguments can be skipped if keyword arguments are
used (see below).
-BODY contains code that will be executed each time the mode is (dis)activated.
- It will be executed after any toggling but before running the hook variable
- `mode-HOOK'.
+BODY contains code to execute each time the mode is activated or deactivated.
+ It is executed after toggling the mode,
+ and before running the hook variable `mode-HOOK'.
Before the actual body code, you can write keyword arguments (alternating
keywords and values). These following keyword arguments are supported (other
keywords will be passed to `defcustom' if the minor mode is global):
(setq body (list* lighter keymap body) lighter nil keymap nil))
((keywordp keymap) (push keymap body) (setq keymap nil)))
- (let* ((mode-name (symbol-name mode))
+ (let* ((last-message (current-message))
+ (mode-name (symbol-name mode))
(pretty-name (easy-mmode-pretty-mode-name mode lighter))
(globalp nil)
(set nil)
See the command `%s' for a description of this minor-mode."
(if body "
Setting this variable directly does not take effect;
-use either \\[customize] or the function `%s'."))))
+either customize it (see the info node `Easy Customization')
+or call the function `%s'."))))
`(defcustom ,mode ,init-value
,(format base-doc-string pretty-name mode mode)
,@set
(if (called-interactively-p)
(progn
,(if globalp `(customize-mark-as-set ',mode))
- (unless (current-message)
+ ;; Avoid overwriting a message shown by the body,
+ ;; but do overwrite previous messages.
+ (unless ,(and (current-message)
+ (not (equal last-message (current-message))))
(message ,(format "%s %%sabled" pretty-name)
(if ,mode "en" "dis")))))
(force-mode-line-update)
(unless (pos-visible-in-window-p endpt nil t)
(recenter '(0))))))
,re-narrow-maybe)))
+ (put ',next-sym 'definition-name ',base)
(defun ,prev-sym (&optional count)
,(format "Go to the previous COUNT'th %s" (or name base-name))
(interactive)
,check-narrow-maybe
(unless (re-search-backward ,re nil t count)
(error "No previous %s" ,name))
- ,re-narrow-maybe))))))
+ ,re-narrow-maybe)))
+ (put ',prev-sym 'definition-name ',base))))
(provide 'easy-mmode)