2001-07-16 12:23:00 +00:00
|
|
|
|
;;; easy-mmode.el --- easy definition for major and minor modes
|
1997-06-22 20:08:32 +00:00
|
|
|
|
|
2017-01-01 03:14:01 +00:00
|
|
|
|
;; Copyright (C) 1997, 2000-2017 Free Software Foundation, Inc.
|
1997-06-22 20:08:32 +00:00
|
|
|
|
|
2001-07-17 07:37:19 +00:00
|
|
|
|
;; Author: Georges Brun-Cottan <Georges.Brun-Cottan@inria.fr>
|
|
|
|
|
;; Maintainer: Stefan Monnier <monnier@gnu.org>
|
2010-08-29 12:17:13 -04:00
|
|
|
|
;; Package: emacs
|
2001-07-17 07:37:19 +00:00
|
|
|
|
|
|
|
|
|
;; Keywords: extensions lisp
|
1997-06-22 20:08:32 +00:00
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
2008-05-06 03:21:21 +00:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1997-06-22 20:08:32 +00:00
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 03:21:21 +00:00
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
1997-06-22 20:08:32 +00:00
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 03:21:21 +00:00
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
1997-06-22 20:08:32 +00:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; Minor modes are useful and common. This package makes defining a
|
|
|
|
|
;; minor mode easy, by focusing on the writing of the minor mode
|
|
|
|
|
;; functionalities themselves. Moreover, this package enforces a
|
|
|
|
|
;; conventional naming of user interface primitives, making things
|
|
|
|
|
;; natural for the minor-mode end-users.
|
|
|
|
|
|
|
|
|
|
;; For each mode, easy-mmode defines the following:
|
|
|
|
|
;; <mode> : The minor mode predicate. A buffer-local variable.
|
|
|
|
|
;; <mode>-map : The keymap possibly associated to <mode>.
|
2000-05-21 01:44:08 +00:00
|
|
|
|
;; see `define-minor-mode' documentation
|
1997-06-22 20:08:32 +00:00
|
|
|
|
;;
|
|
|
|
|
;; eval
|
2000-05-21 01:44:08 +00:00
|
|
|
|
;; (pp (macroexpand '(define-minor-mode <your-mode> <doc>)))
|
1997-06-22 20:08:32 +00:00
|
|
|
|
;; to check the result before using it.
|
|
|
|
|
|
|
|
|
|
;; The order in which minor modes are installed is important. Keymap
|
|
|
|
|
;; lookup proceeds down minor-mode-map-alist, and the order there
|
|
|
|
|
;; tends to be the reverse of the order in which the modes were
|
|
|
|
|
;; installed. Perhaps there should be a feature to let you specify
|
|
|
|
|
;; orderings.
|
|
|
|
|
|
2000-03-10 01:17:04 +00:00
|
|
|
|
;; Additionally to `define-minor-mode', the package provides convenient
|
|
|
|
|
;; ways to define keymaps, and other helper functions for major and minor modes.
|
1997-06-22 20:08:32 +00:00
|
|
|
|
|
2000-03-10 01:17:04 +00:00
|
|
|
|
;;; Code:
|
1997-06-22 20:08:32 +00:00
|
|
|
|
|
2000-06-04 20:59:47 +00:00
|
|
|
|
(defun easy-mmode-pretty-mode-name (mode &optional lighter)
|
|
|
|
|
"Turn the symbol MODE into a string intended for the user.
|
2005-05-07 15:06:42 +00:00
|
|
|
|
If provided, LIGHTER will be used to help choose capitalization by,
|
|
|
|
|
replacing its case-insensitive matches with the literal string in LIGHTER."
|
2000-06-04 20:59:47 +00:00
|
|
|
|
(let* ((case-fold-search t)
|
2005-05-08 19:39:20 +00:00
|
|
|
|
;; Produce "Foo-Bar minor mode" from foo-bar-minor-mode.
|
2000-10-01 00:58:35 +00:00
|
|
|
|
(name (concat (replace-regexp-in-string
|
2005-05-08 19:39:20 +00:00
|
|
|
|
;; If the original mode name included "-minor" (some
|
|
|
|
|
;; of them don't, e.g. auto-revert-mode), then
|
|
|
|
|
;; replace it with " minor".
|
2000-10-01 00:58:35 +00:00
|
|
|
|
"-Minor" " minor"
|
2005-05-07 15:06:42 +00:00
|
|
|
|
;; "foo-bar-minor" -> "Foo-Bar-Minor"
|
2000-10-01 00:58:35 +00:00
|
|
|
|
(capitalize (replace-regexp-in-string
|
2005-05-07 15:06:42 +00:00
|
|
|
|
;; "foo-bar-minor-mode" -> "foo-bar-minor"
|
2012-06-27 10:05:24 -04:00
|
|
|
|
"toggle-\\|-mode\\'" ""
|
|
|
|
|
(symbol-name mode))))
|
2000-06-04 20:59:47 +00:00
|
|
|
|
" mode")))
|
2016-02-15 21:46:17 +02:00
|
|
|
|
(setq name (replace-regexp-in-string "\\`Global-" "Global " name))
|
2000-06-04 20:59:47 +00:00
|
|
|
|
(if (not (stringp lighter)) name
|
2005-05-07 15:06:42 +00:00
|
|
|
|
;; Strip leading and trailing whitespace from LIGHTER.
|
|
|
|
|
(setq lighter (replace-regexp-in-string "\\`\\s-+\\|\\s-+\\'" ""
|
|
|
|
|
lighter))
|
|
|
|
|
;; Replace any (case-insensitive) matches for LIGHTER in NAME
|
|
|
|
|
;; with a literal LIGHTER. E.g., if NAME is "Iimage mode" and
|
|
|
|
|
;; LIGHTER is " iImag", then this will produce "iImage mode".
|
|
|
|
|
;; (LIGHTER normally comes from the mode-line string passed to
|
|
|
|
|
;; define-minor-mode, and normally includes at least one leading
|
|
|
|
|
;; space.)
|
|
|
|
|
(replace-regexp-in-string (regexp-quote lighter) lighter name t t))))
|
2000-06-02 23:07:08 +00:00
|
|
|
|
|
1997-06-22 20:08:32 +00:00
|
|
|
|
;;;###autoload
|
1999-11-23 09:08:38 +00:00
|
|
|
|
(defalias 'easy-mmode-define-minor-mode 'define-minor-mode)
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defmacro define-minor-mode (mode doc &optional init-value lighter keymap &rest body)
|
1997-06-22 20:08:32 +00:00
|
|
|
|
"Define a new minor mode MODE.
|
2012-01-30 20:52:29 -08:00
|
|
|
|
This defines the toggle command MODE and (by default) a control variable
|
|
|
|
|
MODE (you can override this with the :variable keyword, see below).
|
1997-06-22 20:08:32 +00:00
|
|
|
|
DOC is the documentation for the mode toggle command.
|
2010-08-22 15:30:26 -04:00
|
|
|
|
|
2012-02-07 00:26:54 -08:00
|
|
|
|
The defined mode command takes one optional (prefix) argument.
|
2012-09-22 23:24:26 +08:00
|
|
|
|
Interactively with no prefix argument, it toggles the mode.
|
|
|
|
|
A prefix argument enables the mode if the argument is positive,
|
|
|
|
|
and disables it otherwise.
|
|
|
|
|
|
|
|
|
|
When called from Lisp, the mode command toggles the mode if the
|
|
|
|
|
argument is `toggle', disables the mode if the argument is a
|
|
|
|
|
non-positive integer, and enables the mode otherwise (including
|
|
|
|
|
if the argument is omitted or nil or a positive integer).
|
|
|
|
|
|
|
|
|
|
If DOC is nil, give the mode command a basic doc-string
|
|
|
|
|
documenting what its argument does.
|
2012-02-07 00:26:54 -08:00
|
|
|
|
|
1999-11-23 09:08:38 +00:00
|
|
|
|
Optional INIT-VALUE is the initial value of the mode's variable.
|
2012-06-02 18:56:09 +08:00
|
|
|
|
Optional LIGHTER is displayed in the mode line when the mode is on.
|
2010-08-22 15:30:26 -04:00
|
|
|
|
Optional KEYMAP is the default keymap bound to the mode keymap.
|
|
|
|
|
If non-nil, it should be a variable name (whose value is a keymap),
|
2011-01-17 16:42:23 -05:00
|
|
|
|
or an expression that returns either a keymap or a list of
|
2016-04-18 12:32:35 -04:00
|
|
|
|
(KEY . BINDING) pairs where KEY and BINDING are suitable for
|
|
|
|
|
`define-key'. If you supply a KEYMAP argument that is not a
|
|
|
|
|
symbol, this macro defines the variable MODE-map and gives it
|
|
|
|
|
the value that KEYMAP specifies.
|
2010-08-22 15:30:26 -04:00
|
|
|
|
|
|
|
|
|
BODY contains code to execute each time the mode is enabled or disabled.
|
|
|
|
|
It is executed after toggling the mode, and before running MODE-hook.
|
|
|
|
|
Before the actual body code, you can write keyword arguments, i.e.
|
2015-02-16 04:22:16 +00:00
|
|
|
|
alternating keywords and values. If you provide BODY, then you must
|
|
|
|
|
provide (even if just nil) INIT-VALUE, LIGHTER, and KEYMAP, or provide
|
|
|
|
|
at least one keyword argument, or both; otherwise, BODY would be
|
|
|
|
|
misinterpreted as the first omitted argument. The following special
|
|
|
|
|
keywords are supported (other keywords are passed to `defcustom' if
|
|
|
|
|
the minor mode is global):
|
2010-08-22 15:30:26 -04:00
|
|
|
|
|
2002-10-07 22:49:39 +00:00
|
|
|
|
:group GROUP Custom group name to use in all generated `defcustom' forms.
|
2005-04-05 14:46:29 +00:00
|
|
|
|
Defaults to MODE without the possible trailing \"-mode\".
|
2005-04-26 14:17:51 +00:00
|
|
|
|
Don't use this default group name unless you have written a
|
|
|
|
|
`defgroup' to define that group properly.
|
2002-09-13 14:16:02 +00:00
|
|
|
|
:global GLOBAL If non-nil specifies that the minor mode is not meant to be
|
2005-04-05 14:46:29 +00:00
|
|
|
|
buffer-local, so don't make the variable MODE buffer-local.
|
2002-10-07 22:49:39 +00:00
|
|
|
|
By default, the mode is buffer-local.
|
2002-09-13 14:16:02 +00:00
|
|
|
|
:init-value VAL Same as the INIT-VALUE argument.
|
2012-01-30 20:52:29 -08:00
|
|
|
|
Not used if you also specify :variable.
|
2002-09-13 14:16:02 +00:00
|
|
|
|
:lighter SPEC Same as the LIGHTER argument.
|
2003-05-29 21:54:35 +00:00
|
|
|
|
:keymap MAP Same as the KEYMAP argument.
|
2002-10-07 22:49:39 +00:00
|
|
|
|
:require SYM Same as in `defcustom'.
|
2012-01-30 20:52:29 -08:00
|
|
|
|
:variable PLACE The location to use instead of the variable MODE to store
|
|
|
|
|
the state of the mode. This can be simply a different
|
2013-02-14 09:16:47 -08:00
|
|
|
|
named variable, or a generalized variable.
|
2015-09-17 16:08:20 -07:00
|
|
|
|
PLACE can also be of the form (GET . SET), where GET is
|
2013-02-14 09:16:47 -08:00
|
|
|
|
an expression that returns the current state, and SET is
|
|
|
|
|
a function that takes one argument, the new state, and
|
|
|
|
|
sets it. If you specify a :variable, this function does
|
|
|
|
|
not define a MODE variable (nor any of the terms used
|
|
|
|
|
in :variable).
|
|
|
|
|
|
2012-02-23 18:51:22 +00:00
|
|
|
|
:after-hook A single lisp form which is evaluated after the mode hooks
|
|
|
|
|
have been run. It should not be quoted.
|
2002-10-07 22:49:39 +00:00
|
|
|
|
|
|
|
|
|
For example, you could write
|
|
|
|
|
(define-minor-mode foo-mode \"If enabled, foo on you!\"
|
2015-11-17 15:28:50 -08:00
|
|
|
|
:lighter \" Foo\" :require \\='foo :global t :group \\='hassle :version \"27.5\"
|
2002-10-07 22:49:39 +00:00
|
|
|
|
...BODY CODE...)"
|
2012-05-17 21:46:20 -04:00
|
|
|
|
(declare (doc-string 2)
|
2014-02-24 11:55:17 +08:00
|
|
|
|
(debug (&define name string-or-null-p
|
2016-01-07 09:48:00 +08:00
|
|
|
|
[&optional [¬ keywordp] sexp
|
|
|
|
|
&optional [¬ keywordp] sexp
|
|
|
|
|
&optional [¬ keywordp] sexp]
|
|
|
|
|
[&rest [keywordp sexp]]
|
|
|
|
|
def-body)))
|
2002-10-07 22:49:39 +00:00
|
|
|
|
|
2000-11-01 23:31:59 +00:00
|
|
|
|
;; Allow skipping the first three args.
|
|
|
|
|
(cond
|
|
|
|
|
((keywordp init-value)
|
2015-02-16 04:21:06 +00:00
|
|
|
|
(setq body (if keymap `(,init-value ,lighter ,keymap ,@body)
|
|
|
|
|
`(,init-value ,lighter))
|
2000-11-01 23:31:59 +00:00
|
|
|
|
init-value nil lighter nil keymap nil))
|
|
|
|
|
((keywordp lighter)
|
2012-06-10 09:28:26 -04:00
|
|
|
|
(setq body `(,lighter ,keymap ,@body) lighter nil keymap nil))
|
2000-11-01 23:31:59 +00:00
|
|
|
|
((keywordp keymap) (push keymap body) (setq keymap nil)))
|
|
|
|
|
|
2007-09-21 18:27:34 +00:00
|
|
|
|
(let* ((last-message (make-symbol "last-message"))
|
|
|
|
|
(mode-name (symbol-name mode))
|
2000-06-04 20:59:47 +00:00
|
|
|
|
(pretty-name (easy-mmode-pretty-mode-name mode lighter))
|
2000-05-21 01:44:08 +00:00
|
|
|
|
(globalp nil)
|
2005-07-16 02:25:48 +00:00
|
|
|
|
(set nil)
|
2005-07-14 00:56:13 +00:00
|
|
|
|
(initialize nil)
|
2000-11-03 04:26:33 +00:00
|
|
|
|
(group nil)
|
2005-07-16 02:25:48 +00:00
|
|
|
|
(type nil)
|
2000-11-03 04:26:33 +00:00
|
|
|
|
(extra-args nil)
|
2003-03-24 17:41:43 +00:00
|
|
|
|
(extra-keywords nil)
|
2010-05-05 22:53:56 -04:00
|
|
|
|
(variable nil) ;The PLACE where the state is stored.
|
2015-06-17 14:52:54 -04:00
|
|
|
|
(setter `(setq ,mode)) ;The beginning of the exp to set the mode var.
|
|
|
|
|
(getter mode) ;The exp to get the mode value.
|
2010-05-05 22:53:56 -04:00
|
|
|
|
(modefun mode) ;The minor mode function name we're defining.
|
2002-09-13 14:16:02 +00:00
|
|
|
|
(require t)
|
2012-02-23 18:51:22 +00:00
|
|
|
|
(after-hook nil)
|
2000-06-04 20:59:47 +00:00
|
|
|
|
(hook (intern (concat mode-name "-hook")))
|
|
|
|
|
(hook-on (intern (concat mode-name "-on-hook")))
|
2003-03-24 17:41:43 +00:00
|
|
|
|
(hook-off (intern (concat mode-name "-off-hook")))
|
2012-01-30 20:35:57 -08:00
|
|
|
|
keyw keymap-sym tmp)
|
2000-06-04 20:59:47 +00:00
|
|
|
|
|
|
|
|
|
;; Check keys.
|
2003-03-24 17:41:43 +00:00
|
|
|
|
(while (keywordp (setq keyw (car body)))
|
|
|
|
|
(setq body (cdr body))
|
2012-06-10 09:28:26 -04:00
|
|
|
|
(pcase keyw
|
|
|
|
|
(`:init-value (setq init-value (pop body)))
|
|
|
|
|
(`:lighter (setq lighter (purecopy (pop body))))
|
2015-06-17 14:52:54 -04:00
|
|
|
|
(`:global (setq globalp (pop body))
|
|
|
|
|
(when (and globalp (symbolp mode))
|
|
|
|
|
(setq setter `(setq-default ,mode))
|
|
|
|
|
(setq getter `(default-value ',mode))))
|
2012-06-10 09:28:26 -04:00
|
|
|
|
(`:extra-args (setq extra-args (pop body)))
|
|
|
|
|
(`:set (setq set (list :set (pop body))))
|
|
|
|
|
(`:initialize (setq initialize (list :initialize (pop body))))
|
|
|
|
|
(`:group (setq group (nconc group (list :group (pop body)))))
|
|
|
|
|
(`:type (setq type (list :type (pop body))))
|
|
|
|
|
(`:require (setq require (pop body)))
|
|
|
|
|
(`:keymap (setq keymap (pop body)))
|
|
|
|
|
(`:variable (setq variable (pop body))
|
2012-01-31 21:17:17 -05:00
|
|
|
|
(if (not (and (setq tmp (cdr-safe variable))
|
|
|
|
|
(or (symbolp tmp)
|
|
|
|
|
(functionp tmp))))
|
2010-05-05 22:53:56 -04:00
|
|
|
|
;; PLACE is not of the form (GET . SET).
|
2015-06-17 14:52:54 -04:00
|
|
|
|
(progn
|
|
|
|
|
(setq setter `(setf ,variable))
|
|
|
|
|
(setq getter variable))
|
|
|
|
|
(setq getter (car variable))
|
|
|
|
|
(setq setter `(funcall #',(cdr variable)))))
|
2012-06-10 09:28:26 -04:00
|
|
|
|
(`:after-hook (setq after-hook (pop body)))
|
|
|
|
|
(_ (push keyw extra-keywords) (push (pop body) extra-keywords))))
|
2000-10-28 06:07:30 +00:00
|
|
|
|
|
2003-05-29 21:54:35 +00:00
|
|
|
|
(setq keymap-sym (if (and keymap (symbolp keymap)) keymap
|
|
|
|
|
(intern (concat mode-name "-map"))))
|
|
|
|
|
|
2015-06-17 14:52:54 -04:00
|
|
|
|
(unless set (setq set '(:set #'custom-set-minor-mode)))
|
2005-07-16 02:25:48 +00:00
|
|
|
|
|
2005-07-14 00:56:13 +00:00
|
|
|
|
(unless initialize
|
2005-07-16 02:25:48 +00:00
|
|
|
|
(setq initialize '(:initialize 'custom-initialize-default)))
|
2005-07-14 00:56:13 +00:00
|
|
|
|
|
2000-11-03 04:26:33 +00:00
|
|
|
|
(unless group
|
|
|
|
|
;; We might as well provide a best-guess default group.
|
|
|
|
|
(setq group
|
2005-04-05 14:46:29 +00:00
|
|
|
|
`(:group ',(intern (replace-regexp-in-string
|
|
|
|
|
"-mode\\'" "" mode-name)))))
|
2005-05-22 22:07:22 +00:00
|
|
|
|
|
2010-10-28 20:29:29 -07:00
|
|
|
|
;; TODO? Mark booleans as safe if booleanp? Eg abbrev-mode.
|
2005-07-16 02:25:48 +00:00
|
|
|
|
(unless type (setq type '(:type 'boolean)))
|
|
|
|
|
|
1997-06-22 20:08:32 +00:00
|
|
|
|
`(progn
|
1999-08-28 15:13:37 +00:00
|
|
|
|
;; Define the variable to enable or disable the mode.
|
2010-05-04 22:08:25 -04:00
|
|
|
|
,(cond
|
|
|
|
|
;; If :variable is specified, then the var will be
|
|
|
|
|
;; declared elsewhere.
|
|
|
|
|
(variable nil)
|
|
|
|
|
((not globalp)
|
|
|
|
|
`(progn
|
2012-05-30 21:41:17 -04:00
|
|
|
|
:autoload-end
|
2010-05-04 22:08:25 -04:00
|
|
|
|
(defvar ,mode ,init-value ,(format "Non-nil if %s is enabled.
|
2001-01-25 15:31:14 +00:00
|
|
|
|
Use the command `%s' to change this variable." pretty-name mode))
|
2010-05-04 22:08:25 -04:00
|
|
|
|
(make-variable-buffer-local ',mode)))
|
|
|
|
|
(t
|
2005-08-24 11:54:25 +00:00
|
|
|
|
(let ((base-doc-string
|
|
|
|
|
(concat "Non-nil if %s is enabled.
|
2016-04-29 23:25:07 +02:00
|
|
|
|
See the `%s' command
|
|
|
|
|
for a description of this minor mode."
|
2005-08-24 11:54:25 +00:00
|
|
|
|
(if body "
|
2000-06-05 06:06:30 +00:00
|
|
|
|
Setting this variable directly does not take effect;
|
2006-08-31 23:14:26 +00:00
|
|
|
|
either customize it (see the info node `Easy Customization')
|
|
|
|
|
or call the function `%s'."))))
|
2005-06-08 15:54:43 +00:00
|
|
|
|
`(defcustom ,mode ,init-value
|
|
|
|
|
,(format base-doc-string pretty-name mode mode)
|
2005-07-16 02:25:48 +00:00
|
|
|
|
,@set
|
2005-07-14 00:56:13 +00:00
|
|
|
|
,@initialize
|
2000-11-03 04:26:33 +00:00
|
|
|
|
,@group
|
2005-07-16 02:25:48 +00:00
|
|
|
|
,@type
|
2005-08-24 11:54:25 +00:00
|
|
|
|
,@(unless (eq require t) `(:require ,require))
|
2010-05-04 22:08:25 -04:00
|
|
|
|
,@(nreverse extra-keywords)))))
|
2000-06-11 04:55:57 +00:00
|
|
|
|
|
2000-06-04 20:59:47 +00:00
|
|
|
|
;; The actual function.
|
2010-05-04 22:08:25 -04:00
|
|
|
|
(defun ,modefun (&optional arg ,@extra-args)
|
2000-06-04 20:59:47 +00:00
|
|
|
|
,(or doc
|
2000-11-01 23:31:59 +00:00
|
|
|
|
(format (concat "Toggle %s on or off.
|
2011-11-28 14:26:39 +08:00
|
|
|
|
With a prefix argument ARG, enable %s if ARG is
|
|
|
|
|
positive, and disable it otherwise. If called from Lisp, enable
|
2012-02-07 00:26:54 -08:00
|
|
|
|
the mode if ARG is omitted or nil, and toggle it if ARG is `toggle'.
|
2011-11-28 14:26:39 +08:00
|
|
|
|
\\{%s}") pretty-name pretty-name keymap-sym))
|
2002-08-15 01:06:05 +00:00
|
|
|
|
;; Use `toggle' rather than (if ,mode 0 1) so that using
|
|
|
|
|
;; repeat-command still does the toggling correctly.
|
|
|
|
|
(interactive (list (or current-prefix-arg 'toggle)))
|
2007-09-21 18:27:34 +00:00
|
|
|
|
(let ((,last-message (current-message)))
|
2015-06-17 14:52:54 -04:00
|
|
|
|
(,@setter
|
2010-05-04 22:08:25 -04:00
|
|
|
|
(if (eq arg 'toggle)
|
2015-06-17 14:52:54 -04:00
|
|
|
|
(not ,getter)
|
2010-05-04 22:08:25 -04:00
|
|
|
|
;; A nil argument also means ON now.
|
|
|
|
|
(> (prefix-numeric-value arg) 0)))
|
2007-09-21 18:27:34 +00:00
|
|
|
|
,@body
|
|
|
|
|
;; The on/off hooks are here for backward compatibility only.
|
2015-06-17 14:52:54 -04:00
|
|
|
|
(run-hooks ',hook (if ,getter ',hook-on ',hook-off))
|
2009-10-02 00:02:02 +00:00
|
|
|
|
(if (called-interactively-p 'any)
|
2007-09-21 18:27:34 +00:00
|
|
|
|
(progn
|
2015-06-17 14:52:54 -04:00
|
|
|
|
,(if (and globalp (not variable))
|
2010-05-05 22:53:56 -04:00
|
|
|
|
`(customize-mark-as-set ',mode))
|
2007-09-21 18:27:34 +00:00
|
|
|
|
;; Avoid overwriting a message shown by the body,
|
|
|
|
|
;; but do overwrite previous messages.
|
|
|
|
|
(unless (and (current-message)
|
|
|
|
|
(not (equal ,last-message
|
|
|
|
|
(current-message))))
|
2015-06-17 14:52:54 -04:00
|
|
|
|
(let ((local ,(if globalp "" " in current buffer")))
|
2015-02-16 04:24:13 +00:00
|
|
|
|
(message ,(format "%s %%sabled%%s" pretty-name)
|
2015-06-17 14:52:54 -04:00
|
|
|
|
(if ,getter "en" "dis") local)))))
|
2012-02-23 18:51:22 +00:00
|
|
|
|
,@(when after-hook `(,after-hook)))
|
2000-11-01 23:31:59 +00:00
|
|
|
|
(force-mode-line-update)
|
2002-08-26 16:40:49 +00:00
|
|
|
|
;; Return the new setting.
|
2015-06-17 14:52:54 -04:00
|
|
|
|
,getter)
|
2003-05-29 21:54:35 +00:00
|
|
|
|
|
2005-04-05 14:46:29 +00:00
|
|
|
|
;; Autoloading a define-minor-mode autoloads everything
|
|
|
|
|
;; up-to-here.
|
2000-06-11 04:55:57 +00:00
|
|
|
|
:autoload-end
|
|
|
|
|
|
2013-05-27 12:12:52 -04:00
|
|
|
|
(defvar ,hook nil
|
|
|
|
|
,(format "Hook run after entering or leaving `%s'.
|
|
|
|
|
No problems result if this variable is not bound.
|
|
|
|
|
`add-hook' automatically binds it. (This is true for all hook variables.)"
|
2014-08-29 22:28:19 +02:00
|
|
|
|
modefun))
|
2013-05-27 12:12:52 -04:00
|
|
|
|
|
2000-06-05 06:06:30 +00:00
|
|
|
|
;; Define the minor-mode keymap.
|
2000-06-11 04:55:57 +00:00
|
|
|
|
,(unless (symbolp keymap) ;nil is also a symbol.
|
2000-06-05 06:06:30 +00:00
|
|
|
|
`(defvar ,keymap-sym
|
2000-06-11 04:55:57 +00:00
|
|
|
|
(let ((m ,keymap))
|
|
|
|
|
(cond ((keymapp m) m)
|
|
|
|
|
((listp m) (easy-mmode-define-keymap m))
|
2011-01-17 16:42:23 -05:00
|
|
|
|
(t (error "Invalid keymap %S" m))))
|
2000-06-05 06:06:30 +00:00
|
|
|
|
,(format "Keymap for `%s'." mode-name)))
|
|
|
|
|
|
2015-06-17 14:52:54 -04:00
|
|
|
|
,(let ((modevar (pcase getter (`(default-value ',v) v) (_ getter))))
|
|
|
|
|
(if (not (symbolp modevar))
|
|
|
|
|
(if (or lighter keymap)
|
|
|
|
|
(error ":lighter and :keymap unsupported with mode expression %S" getter))
|
|
|
|
|
`(with-no-warnings
|
|
|
|
|
(add-minor-mode ',modevar ',lighter
|
|
|
|
|
,(if keymap keymap-sym
|
|
|
|
|
`(if (boundp ',keymap-sym) ,keymap-sym))
|
|
|
|
|
nil
|
|
|
|
|
,(unless (eq mode modefun) `',modefun))))))))
|
2000-03-10 01:17:04 +00:00
|
|
|
|
|
2000-06-04 23:40:58 +00:00
|
|
|
|
;;;
|
|
|
|
|
;;; make global minor mode
|
|
|
|
|
;;;
|
|
|
|
|
|
2000-06-05 06:06:30 +00:00
|
|
|
|
;;;###autoload
|
2007-02-03 17:26:28 +00:00
|
|
|
|
(defalias 'easy-mmode-define-global-mode 'define-globalized-minor-mode)
|
2005-03-31 21:16:54 +00:00
|
|
|
|
;;;###autoload
|
2007-02-03 17:26:28 +00:00
|
|
|
|
(defalias 'define-global-minor-mode 'define-globalized-minor-mode)
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defmacro define-globalized-minor-mode (global-mode mode turn-on &rest keys)
|
2006-12-30 21:34:14 +00:00
|
|
|
|
"Make a global mode GLOBAL-MODE corresponding to buffer-local minor MODE.
|
2000-06-04 23:40:58 +00:00
|
|
|
|
TURN-ON is a function that will be called with no args in every buffer
|
|
|
|
|
and that should try to turn MODE on if applicable for that buffer.
|
2005-11-05 23:03:57 +00:00
|
|
|
|
KEYS is a list of CL-style keyword arguments. As the minor mode
|
|
|
|
|
defined by this function is always global, any :global keyword is
|
|
|
|
|
ignored. Other keywords have the same meaning as in `define-minor-mode',
|
|
|
|
|
which see. In particular, :group specifies the custom group.
|
|
|
|
|
The most useful keywords are those that are passed on to the
|
|
|
|
|
`defcustom'. It normally makes no sense to pass the :lighter
|
2007-02-03 17:26:28 +00:00
|
|
|
|
or :keymap keywords to `define-globalized-minor-mode', since these
|
2005-11-05 23:03:57 +00:00
|
|
|
|
are usually passed to the buffer-local version of the minor mode.
|
2005-06-04 22:13:57 +00:00
|
|
|
|
|
|
|
|
|
If MODE's set-up depends on the major mode in effect when it was
|
|
|
|
|
enabled, then disabling and reenabling MODE should make MODE work
|
|
|
|
|
correctly with the current major mode. This is important to
|
|
|
|
|
prevent problems with derived modes, that is, major modes that
|
2013-02-15 20:01:51 +00:00
|
|
|
|
call another major mode in their body.
|
|
|
|
|
|
|
|
|
|
When a major mode is initialized, MODE is actually turned on just
|
|
|
|
|
after running the major mode's hook. However, MODE is not turned
|
|
|
|
|
on if the hook has explicitly disabled it."
|
2012-05-17 21:46:20 -04:00
|
|
|
|
(declare (doc-string 2))
|
2000-11-03 04:26:33 +00:00
|
|
|
|
(let* ((global-mode-name (symbol-name global-mode))
|
2013-02-15 20:01:51 +00:00
|
|
|
|
(mode-name (symbol-name mode))
|
2000-06-04 23:40:58 +00:00
|
|
|
|
(pretty-name (easy-mmode-pretty-mode-name mode))
|
|
|
|
|
(pretty-global-name (easy-mmode-pretty-mode-name global-mode))
|
2000-11-03 04:26:33 +00:00
|
|
|
|
(group nil)
|
2005-11-05 23:03:57 +00:00
|
|
|
|
(extra-keywords nil)
|
2005-06-04 22:13:57 +00:00
|
|
|
|
(MODE-buffers (intern (concat global-mode-name "-buffers")))
|
|
|
|
|
(MODE-enable-in-buffers
|
|
|
|
|
(intern (concat global-mode-name "-enable-in-buffers")))
|
|
|
|
|
(MODE-check-buffers
|
|
|
|
|
(intern (concat global-mode-name "-check-buffers")))
|
|
|
|
|
(MODE-cmhh (intern (concat global-mode-name "-cmhh")))
|
2013-02-15 20:01:51 +00:00
|
|
|
|
(minor-MODE-hook (intern (concat mode-name "-hook")))
|
2013-02-25 20:50:45 -05:00
|
|
|
|
(MODE-set-explicitly (intern (concat mode-name "-set-explicitly")))
|
2005-11-05 23:03:57 +00:00
|
|
|
|
(MODE-major-mode (intern (concat (symbol-name mode) "-major-mode")))
|
|
|
|
|
keyw)
|
2000-06-04 23:40:58 +00:00
|
|
|
|
|
|
|
|
|
;; Check keys.
|
2005-11-05 23:03:57 +00:00
|
|
|
|
(while (keywordp (setq keyw (car keys)))
|
|
|
|
|
(setq keys (cdr keys))
|
2012-06-10 09:28:26 -04:00
|
|
|
|
(pcase keyw
|
|
|
|
|
(`:group (setq group (nconc group (list :group (pop keys)))))
|
|
|
|
|
(`:global (setq keys (cdr keys)))
|
|
|
|
|
(_ (push keyw extra-keywords) (push (pop keys) extra-keywords))))
|
2000-06-04 23:40:58 +00:00
|
|
|
|
|
2000-11-03 04:26:33 +00:00
|
|
|
|
(unless group
|
|
|
|
|
;; We might as well provide a best-guess default group.
|
|
|
|
|
(setq group
|
2005-04-05 14:46:29 +00:00
|
|
|
|
`(:group ',(intern (replace-regexp-in-string
|
|
|
|
|
"-mode\\'" "" (symbol-name mode))))))
|
2002-12-13 23:54:45 +00:00
|
|
|
|
|
2000-06-04 23:40:58 +00:00
|
|
|
|
`(progn
|
2012-05-30 21:41:17 -04:00
|
|
|
|
(progn
|
|
|
|
|
:autoload-end
|
|
|
|
|
(defvar ,MODE-major-mode nil)
|
|
|
|
|
(make-variable-buffer-local ',MODE-major-mode))
|
2000-06-04 23:40:58 +00:00
|
|
|
|
;; The actual global minor-mode
|
|
|
|
|
(define-minor-mode ,global-mode
|
2010-01-02 19:33:54 +02:00
|
|
|
|
;; Very short lines to avoid too long lines in the generated
|
|
|
|
|
;; doc string.
|
Fix minor mode docstrings for the new meaning of a nil ARG.
* abbrev.el (abbrev-mode):
* allout.el (allout-mode):
* autoinsert.el (auto-insert-mode):
* autoarg.el (autoarg-mode, autoarg-kp-mode):
* autorevert.el (auto-revert-mode, auto-revert-tail-mode)
(global-auto-revert-mode):
* battery.el (display-battery-mode):
* composite.el (global-auto-composition-mode)
(auto-composition-mode):
* delsel.el (delete-selection-mode):
* desktop.el (desktop-save-mode):
* dired-x.el (dired-omit-mode):
* dirtrack.el (dirtrack-mode):
* doc-view.el (doc-view-minor-mode):
* double.el (double-mode):
* electric.el (electric-indent-mode, electric-pair-mode):
* emacs-lock.el (emacs-lock-mode):
* epa-hook.el (auto-encryption-mode):
* follow.el (follow-mode):
* font-core.el (font-lock-mode):
* frame.el (auto-raise-mode, auto-lower-mode, blink-cursor-mode):
* help.el (temp-buffer-resize-mode):
* hilit-chg.el (highlight-changes-mode)
(highlight-changes-visible-mode):
* hi-lock.el (hi-lock-mode):
* hl-line.el (hl-line-mode, global-hl-line-mode):
* icomplete.el (icomplete-mode):
* ido.el (ido-everywhere):
* image-file.el (auto-image-file-mode):
* image-mode.el (image-minor-mode):
* iswitchb.el (iswitchb-mode):
* jka-cmpr-hook.el (auto-compression-mode):
* linum.el (linum-mode):
* longlines.el (longlines-mode):
* master.el (master-mode):
* mb-depth.el (minibuffer-depth-indicate-mode):
* menu-bar.el (menu-bar-mode):
* minibuf-eldef.el (minibuffer-electric-default-mode):
* mouse-sel.el (mouse-sel-mode):
* msb.el (msb-mode):
* mwheel.el (mouse-wheel-mode):
* outline.el (outline-minor-mode):
* paren.el (show-paren-mode):
* recentf.el (recentf-mode):
* reveal.el (reveal-mode, global-reveal-mode):
* rfn-eshadow.el (file-name-shadow-mode):
* ruler-mode.el (ruler-mode):
* savehist.el (savehist-mode):
* scroll-all.el (scroll-all-mode):
* scroll-bar.el (scroll-bar-mode):
* server.el (server-mode):
* shell.el (shell-dirtrack-mode):
* simple.el (auto-fill-mode, transient-mark-mode)
(visual-line-mode, overwrite-mode, binary-overwrite-mode)
(line-number-mode, column-number-mode, size-indication-mode)
(auto-save-mode, normal-erase-is-backspace-mode, visible-mode):
* strokes.el (strokes-mode):
* time.el (display-time-mode):
* t-mouse.el (gpm-mouse-mode):
* tool-bar.el (tool-bar-mode):
* tooltip.el (tooltip-mode):
* type-break.el (type-break-mode-line-message-mode)
(type-break-query-mode):
* view.el (view-mode):
* whitespace.el (whitespace-mode, whitespace-newline-mode)
(global-whitespace-mode, global-whitespace-newline-mode):
* xt-mouse.el (xterm-mouse-mode): Doc fix.
* emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Fix
autogenerated docstring.
2011-10-19 08:54:24 -04:00
|
|
|
|
,(format "Toggle %s in all buffers.
|
|
|
|
|
With prefix ARG, enable %s if ARG is positive;
|
|
|
|
|
otherwise, disable it. If called from Lisp, enable the mode if
|
|
|
|
|
ARG is omitted or nil.
|
|
|
|
|
|
2010-01-02 19:33:54 +02:00
|
|
|
|
%s is enabled in all buffers where
|
2015-06-30 15:06:31 -07:00
|
|
|
|
`%s' would do it.
|
2007-04-22 16:58:23 +00:00
|
|
|
|
See `%s' for more information on %s."
|
Fix minor mode docstrings for the new meaning of a nil ARG.
* abbrev.el (abbrev-mode):
* allout.el (allout-mode):
* autoinsert.el (auto-insert-mode):
* autoarg.el (autoarg-mode, autoarg-kp-mode):
* autorevert.el (auto-revert-mode, auto-revert-tail-mode)
(global-auto-revert-mode):
* battery.el (display-battery-mode):
* composite.el (global-auto-composition-mode)
(auto-composition-mode):
* delsel.el (delete-selection-mode):
* desktop.el (desktop-save-mode):
* dired-x.el (dired-omit-mode):
* dirtrack.el (dirtrack-mode):
* doc-view.el (doc-view-minor-mode):
* double.el (double-mode):
* electric.el (electric-indent-mode, electric-pair-mode):
* emacs-lock.el (emacs-lock-mode):
* epa-hook.el (auto-encryption-mode):
* follow.el (follow-mode):
* font-core.el (font-lock-mode):
* frame.el (auto-raise-mode, auto-lower-mode, blink-cursor-mode):
* help.el (temp-buffer-resize-mode):
* hilit-chg.el (highlight-changes-mode)
(highlight-changes-visible-mode):
* hi-lock.el (hi-lock-mode):
* hl-line.el (hl-line-mode, global-hl-line-mode):
* icomplete.el (icomplete-mode):
* ido.el (ido-everywhere):
* image-file.el (auto-image-file-mode):
* image-mode.el (image-minor-mode):
* iswitchb.el (iswitchb-mode):
* jka-cmpr-hook.el (auto-compression-mode):
* linum.el (linum-mode):
* longlines.el (longlines-mode):
* master.el (master-mode):
* mb-depth.el (minibuffer-depth-indicate-mode):
* menu-bar.el (menu-bar-mode):
* minibuf-eldef.el (minibuffer-electric-default-mode):
* mouse-sel.el (mouse-sel-mode):
* msb.el (msb-mode):
* mwheel.el (mouse-wheel-mode):
* outline.el (outline-minor-mode):
* paren.el (show-paren-mode):
* recentf.el (recentf-mode):
* reveal.el (reveal-mode, global-reveal-mode):
* rfn-eshadow.el (file-name-shadow-mode):
* ruler-mode.el (ruler-mode):
* savehist.el (savehist-mode):
* scroll-all.el (scroll-all-mode):
* scroll-bar.el (scroll-bar-mode):
* server.el (server-mode):
* shell.el (shell-dirtrack-mode):
* simple.el (auto-fill-mode, transient-mark-mode)
(visual-line-mode, overwrite-mode, binary-overwrite-mode)
(line-number-mode, column-number-mode, size-indication-mode)
(auto-save-mode, normal-erase-is-backspace-mode, visible-mode):
* strokes.el (strokes-mode):
* time.el (display-time-mode):
* t-mouse.el (gpm-mouse-mode):
* tool-bar.el (tool-bar-mode):
* tooltip.el (tooltip-mode):
* type-break.el (type-break-mode-line-message-mode)
(type-break-query-mode):
* view.el (view-mode):
* whitespace.el (whitespace-mode, whitespace-newline-mode)
(global-whitespace-mode, global-whitespace-newline-mode):
* xt-mouse.el (xterm-mouse-mode): Doc fix.
* emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Fix
autogenerated docstring.
2011-10-19 08:54:24 -04:00
|
|
|
|
pretty-name pretty-global-name
|
|
|
|
|
pretty-name turn-on mode pretty-name)
|
2005-11-05 23:03:57 +00:00
|
|
|
|
:global t ,@group ,@(nreverse extra-keywords)
|
2000-06-04 23:40:58 +00:00
|
|
|
|
|
|
|
|
|
;; Setup hook to handle future mode changes and new buffers.
|
|
|
|
|
(if ,global-mode
|
2000-06-05 06:06:30 +00:00
|
|
|
|
(progn
|
2005-06-04 22:13:57 +00:00
|
|
|
|
(add-hook 'after-change-major-mode-hook
|
|
|
|
|
',MODE-enable-in-buffers)
|
|
|
|
|
(add-hook 'find-file-hook ',MODE-check-buffers)
|
|
|
|
|
(add-hook 'change-major-mode-hook ',MODE-cmhh))
|
|
|
|
|
(remove-hook 'after-change-major-mode-hook ',MODE-enable-in-buffers)
|
|
|
|
|
(remove-hook 'find-file-hook ',MODE-check-buffers)
|
|
|
|
|
(remove-hook 'change-major-mode-hook ',MODE-cmhh))
|
2000-06-04 23:40:58 +00:00
|
|
|
|
|
|
|
|
|
;; Go through existing buffers.
|
|
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
|
(with-current-buffer buf
|
2013-08-02 17:23:07 -04:00
|
|
|
|
(if ,global-mode (funcall #',turn-on) (when ,mode (,mode -1))))))
|
2000-06-04 23:40:58 +00:00
|
|
|
|
|
2007-02-03 17:26:28 +00:00
|
|
|
|
;; Autoloading define-globalized-minor-mode autoloads everything
|
2005-05-17 15:17:18 +00:00
|
|
|
|
;; up-to-here.
|
2000-06-11 04:55:57 +00:00
|
|
|
|
:autoload-end
|
|
|
|
|
|
2013-05-21 00:25:14 -07:00
|
|
|
|
;; MODE-set-explicitly is set in MODE-set-explicitly and cleared by
|
|
|
|
|
;; kill-all-local-variables.
|
|
|
|
|
(defvar-local ,MODE-set-explicitly nil)
|
|
|
|
|
(defun ,MODE-set-explicitly ()
|
|
|
|
|
(setq ,MODE-set-explicitly t))
|
|
|
|
|
(put ',MODE-set-explicitly 'definition-name ',global-mode)
|
|
|
|
|
|
2013-02-15 20:01:51 +00:00
|
|
|
|
;; A function which checks whether MODE has been disabled in the major
|
|
|
|
|
;; mode hook which has just been run.
|
2013-02-25 20:50:45 -05:00
|
|
|
|
(add-hook ',minor-MODE-hook ',MODE-set-explicitly)
|
2013-02-15 20:01:51 +00:00
|
|
|
|
|
2000-06-04 23:40:58 +00:00
|
|
|
|
;; List of buffers left to process.
|
2005-06-04 22:13:57 +00:00
|
|
|
|
(defvar ,MODE-buffers nil)
|
2000-06-04 23:40:58 +00:00
|
|
|
|
|
|
|
|
|
;; The function that calls TURN-ON in each buffer.
|
2005-06-04 22:13:57 +00:00
|
|
|
|
(defun ,MODE-enable-in-buffers ()
|
|
|
|
|
(dolist (buf ,MODE-buffers)
|
|
|
|
|
(when (buffer-live-p buf)
|
|
|
|
|
(with-current-buffer buf
|
2013-02-25 20:50:45 -05:00
|
|
|
|
(unless ,MODE-set-explicitly
|
2013-02-15 20:01:51 +00:00
|
|
|
|
(unless (eq ,MODE-major-mode major-mode)
|
|
|
|
|
(if ,mode
|
|
|
|
|
(progn
|
|
|
|
|
(,mode -1)
|
2013-08-02 17:23:07 -04:00
|
|
|
|
(funcall #',turn-on))
|
|
|
|
|
(funcall #',turn-on))))
|
2013-02-15 20:01:51 +00:00
|
|
|
|
(setq ,MODE-major-mode major-mode)))))
|
2005-06-04 22:13:57 +00:00
|
|
|
|
(put ',MODE-enable-in-buffers 'definition-name ',global-mode)
|
|
|
|
|
|
|
|
|
|
(defun ,MODE-check-buffers ()
|
|
|
|
|
(,MODE-enable-in-buffers)
|
|
|
|
|
(setq ,MODE-buffers nil)
|
|
|
|
|
(remove-hook 'post-command-hook ',MODE-check-buffers))
|
|
|
|
|
(put ',MODE-check-buffers 'definition-name ',global-mode)
|
2000-06-04 23:40:58 +00:00
|
|
|
|
|
|
|
|
|
;; The function that catches kill-all-local-variables.
|
2005-06-04 22:13:57 +00:00
|
|
|
|
(defun ,MODE-cmhh ()
|
|
|
|
|
(add-to-list ',MODE-buffers (current-buffer))
|
|
|
|
|
(add-hook 'post-command-hook ',MODE-check-buffers))
|
2013-05-21 00:25:14 -07:00
|
|
|
|
(put ',MODE-cmhh 'definition-name ',global-mode))))
|
2000-06-04 23:40:58 +00:00
|
|
|
|
|
2000-03-10 01:17:04 +00:00
|
|
|
|
;;;
|
|
|
|
|
;;; easy-mmode-defmap
|
|
|
|
|
;;;
|
|
|
|
|
|
2013-02-25 20:50:45 -05:00
|
|
|
|
(defun easy-mmode-set-keymap-parents (m parents)
|
|
|
|
|
(set-keymap-parent
|
|
|
|
|
m (if (cdr parents) (make-composed-keymap parents) (car parents))))
|
2000-03-10 01:17:04 +00:00
|
|
|
|
|
2000-09-29 03:27:28 +00:00
|
|
|
|
;;;###autoload
|
2000-03-10 01:17:04 +00:00
|
|
|
|
(defun easy-mmode-define-keymap (bs &optional name m args)
|
|
|
|
|
"Return a keymap built from bindings BS.
|
|
|
|
|
BS must be a list of (KEY . BINDING) where
|
2000-06-02 23:07:08 +00:00
|
|
|
|
KEY and BINDINGS are suitable for `define-key'.
|
|
|
|
|
Optional NAME is passed to `make-sparse-keymap'.
|
|
|
|
|
Optional map M can be used to modify an existing map.
|
2008-04-24 05:47:18 +00:00
|
|
|
|
ARGS is a list of additional keyword arguments.
|
|
|
|
|
|
|
|
|
|
Valid keywords and arguments are:
|
|
|
|
|
|
|
|
|
|
:name Name of the keymap; overrides NAME argument.
|
|
|
|
|
:dense Non-nil for a dense keymap.
|
|
|
|
|
:inherit Parent keymap.
|
|
|
|
|
:group Ignored.
|
|
|
|
|
:suppress Non-nil to call `suppress-keymap' on keymap,
|
2015-11-17 15:28:50 -08:00
|
|
|
|
`nodigits' to suppress digits as prefix arguments."
|
2008-04-24 05:47:18 +00:00
|
|
|
|
(let (inherit dense suppress)
|
2000-03-10 01:17:04 +00:00
|
|
|
|
(while args
|
|
|
|
|
(let ((key (pop args))
|
|
|
|
|
(val (pop args)))
|
2012-06-10 09:28:26 -04:00
|
|
|
|
(pcase key
|
|
|
|
|
(`:name (setq name val))
|
|
|
|
|
(`:dense (setq dense val))
|
|
|
|
|
(`:inherit (setq inherit val))
|
|
|
|
|
(`:suppress (setq suppress val))
|
|
|
|
|
(`:group)
|
|
|
|
|
(_ (message "Unknown argument %s in defmap" key)))))
|
2000-03-10 01:17:04 +00:00
|
|
|
|
(unless (keymapp m)
|
|
|
|
|
(setq bs (append m bs))
|
|
|
|
|
(setq m (if dense (make-keymap name) (make-sparse-keymap name))))
|
2008-04-24 05:47:18 +00:00
|
|
|
|
(when suppress
|
|
|
|
|
(suppress-keymap m (eq suppress 'nodigits)))
|
2000-03-10 01:17:04 +00:00
|
|
|
|
(dolist (b bs)
|
|
|
|
|
(let ((keys (car b))
|
|
|
|
|
(binding (cdr b)))
|
|
|
|
|
(dolist (key (if (consp keys) keys (list keys)))
|
|
|
|
|
(cond
|
|
|
|
|
((symbolp key)
|
|
|
|
|
(substitute-key-definition key binding m global-map))
|
|
|
|
|
((null binding)
|
|
|
|
|
(unless (keymapp (lookup-key m key)) (define-key m key binding)))
|
|
|
|
|
((let ((o (lookup-key m key)))
|
|
|
|
|
(or (null o) (numberp o) (eq o 'undefined)))
|
|
|
|
|
(define-key m key binding))))))
|
|
|
|
|
(cond
|
|
|
|
|
((keymapp inherit) (set-keymap-parent m inherit))
|
|
|
|
|
((consp inherit) (easy-mmode-set-keymap-parents m inherit)))
|
|
|
|
|
m))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defmacro easy-mmode-defmap (m bs doc &rest args)
|
2009-09-10 06:20:51 +00:00
|
|
|
|
"Define a constant M whose value is the result of `easy-mmode-define-keymap'.
|
|
|
|
|
The M, BS, and ARGS arguments are as per that function. DOC is
|
|
|
|
|
the constant's documentation."
|
2000-09-29 03:27:28 +00:00
|
|
|
|
`(defconst ,m
|
|
|
|
|
(easy-mmode-define-keymap ,bs nil (if (boundp ',m) ,m) ,(cons 'list args))
|
|
|
|
|
,doc))
|
2000-03-10 01:17:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; easy-mmode-defsyntax
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
(defun easy-mmode-define-syntax (css args)
|
2000-10-15 05:25:57 +00:00
|
|
|
|
(let ((st (make-syntax-table (plist-get args :copy)))
|
|
|
|
|
(parent (plist-get args :inherit)))
|
2000-03-10 01:17:04 +00:00
|
|
|
|
(dolist (cs css)
|
|
|
|
|
(let ((char (car cs))
|
|
|
|
|
(syntax (cdr cs)))
|
|
|
|
|
(if (sequencep char)
|
2007-09-26 00:12:23 +00:00
|
|
|
|
(mapc (lambda (c) (modify-syntax-entry c syntax st)) char)
|
2000-03-10 01:17:04 +00:00
|
|
|
|
(modify-syntax-entry char syntax st))))
|
2000-10-15 05:25:57 +00:00
|
|
|
|
(if parent (set-char-table-parent
|
|
|
|
|
st (if (symbolp parent) (symbol-value parent) parent)))
|
2000-03-10 01:17:04 +00:00
|
|
|
|
st))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defmacro easy-mmode-defsyntax (st css doc &rest args)
|
2000-10-15 05:25:57 +00:00
|
|
|
|
"Define variable ST as a syntax-table.
|
2001-04-19 22:45:04 +00:00
|
|
|
|
CSS contains a list of syntax specifications of the form (CHAR . SYNTAX)."
|
2000-03-11 03:37:37 +00:00
|
|
|
|
`(progn
|
|
|
|
|
(autoload 'easy-mmode-define-syntax "easy-mmode")
|
2001-04-19 22:45:04 +00:00
|
|
|
|
(defconst ,st (easy-mmode-define-syntax ,css ,(cons 'list args)) ,doc)))
|
2000-03-10 01:17:04 +00:00
|
|
|
|
|
|
|
|
|
|
2000-03-21 15:35:06 +00:00
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; easy-mmode-define-navigation
|
|
|
|
|
;;;
|
|
|
|
|
|
2007-10-20 01:46:38 +00:00
|
|
|
|
(defmacro easy-mmode-define-navigation (base re &optional name endfun narrowfun
|
|
|
|
|
&rest body)
|
2000-03-21 15:35:06 +00:00
|
|
|
|
"Define BASE-next and BASE-prev to navigate in the buffer.
|
|
|
|
|
RE determines the places the commands should move point to.
|
2000-11-09 23:51:59 +00:00
|
|
|
|
NAME should describe the entities matched by RE. It is used to build
|
2000-03-21 15:35:06 +00:00
|
|
|
|
the docstrings of the two functions.
|
|
|
|
|
BASE-next also tries to make sure that the whole entry is visible by
|
|
|
|
|
searching for its end (by calling ENDFUN if provided or by looking for
|
|
|
|
|
the next entry) and recentering if necessary.
|
2003-11-14 16:18:01 +00:00
|
|
|
|
ENDFUN should return the end position (with or without moving point).
|
|
|
|
|
NARROWFUN non-nil means to check for narrowing before moving, and if
|
2007-10-20 01:46:38 +00:00
|
|
|
|
found, do `widen' first and then call NARROWFUN with no args after moving.
|
|
|
|
|
BODY is executed after moving to the destination location."
|
|
|
|
|
(declare (indent 5) (debug (exp exp exp def-form def-form &rest def-body)))
|
2000-03-21 15:35:06 +00:00
|
|
|
|
(let* ((base-name (symbol-name base))
|
|
|
|
|
(prev-sym (intern (concat base-name "-prev")))
|
2003-11-14 16:18:01 +00:00
|
|
|
|
(next-sym (intern (concat base-name "-next")))
|
2007-10-20 01:46:38 +00:00
|
|
|
|
(when-narrowed
|
|
|
|
|
(lambda (body)
|
|
|
|
|
(if (null narrowfun) body
|
|
|
|
|
`(let ((was-narrowed
|
|
|
|
|
(prog1 (or (< (- (point-max) (point-min)) (buffer-size)))
|
|
|
|
|
(widen))))
|
|
|
|
|
,body
|
2013-08-02 17:23:07 -04:00
|
|
|
|
(when was-narrowed (funcall #',narrowfun)))))))
|
2003-06-22 16:55:47 +00:00
|
|
|
|
(unless name (setq name base-name))
|
2000-03-21 15:35:06 +00:00
|
|
|
|
`(progn
|
|
|
|
|
(defun ,next-sym (&optional count)
|
2000-03-21 16:53:06 +00:00
|
|
|
|
,(format "Go to the next COUNT'th %s." name)
|
2006-11-28 19:22:31 +00:00
|
|
|
|
(interactive "p")
|
2000-03-21 15:35:06 +00:00
|
|
|
|
(unless count (setq count 1))
|
|
|
|
|
(if (< count 0) (,prev-sym (- count))
|
2003-10-20 19:07:02 +00:00
|
|
|
|
(if (looking-at ,re) (setq count (1+ count)))
|
2007-10-20 01:46:38 +00:00
|
|
|
|
,(funcall when-narrowed
|
|
|
|
|
`(if (not (re-search-forward ,re nil t count))
|
|
|
|
|
(if (looking-at ,re)
|
2013-08-02 17:23:07 -04:00
|
|
|
|
(goto-char (or ,(if endfun `(funcall #',endfun)) (point-max)))
|
Add new error and function `user-error'.
* lisp/subr.el (user-error): New function.
* lisp/window.el (switch-to-buffer):
* lisp/vc/smerge-mode.el (smerge-resolve-function, smerge-resolve)
(smerge-match-conflict):
* lisp/simple.el (previous-matching-history-element)
(next-matching-history-element, goto-history-element, undo-more)
(undo-start):
* lisp/progmodes/etags.el (visit-tags-table-buffer, find-tag-tag)
(find-tag-noselect, find-tag-in-order, etags-goto-tag-location)
(next-file, tags-loop-scan, list-tags, complete-tag):
* lisp/progmodes/compile.el (compilation-loop):
* lisp/mouse.el (mouse-minibuffer-check):
* lisp/man.el (Man-bgproc-sentinel, Man-goto-page):
* lisp/info.el (Info-find-node-2, Info-extract-pointer, Info-history-back)
(Info-history-forward, Info-follow-reference, Info-menu)
(Info-extract-menu-item, Info-extract-menu-counting)
(Info-forward-node, Info-backward-node, Info-next-menu-item)
(Info-last-menu-item, Info-next-preorder, Info-last-preorder)
(Info-next-reference, Info-prev-reference, Info-index)
(Info-index-next, Info-follow-nearest-node)
(Info-copy-current-node-name):
* lisp/imenu.el (imenu--make-index-alist)
(imenu-default-create-index-function, imenu-add-to-menubar):
* lisp/files.el (basic-save-buffer, recover-file):
* lisp/emacs-lisp/easy-mmode.el (easy-mmode-define-navigation):
* lisp/emacs-lisp/checkdoc.el (checkdoc-continue, checkdoc-comments)
(checkdoc-message-text, checkdoc-defun):
* lisp/dabbrev.el (dabbrev-completion, dabbrev--abbrev-at-point):
* lisp/cus-edit.el (customize-changed-options, customize-rogue)
(customize-saved, custom-variable-set, custom-variable-mark-to-save)
(custom-variable-mark-to-reset-standard)
(custom-variable-reset-backup, custom-face-mark-to-reset-standard)
(custom-file):
* lisp/completion.el (check-completion-length):
* lisp/comint.el (comint-search-arg)
(comint-previous-matching-input-string-position)
(comint-previous-matching-input)
(comint-replace-by-expanded-history-before-point, comint-send-input)
(comint-copy-old-input, comint-backward-matching-input)
(comint-goto-process-mark, comint-set-process-mark):
* lisp/calendar/calendar.el (calendar-cursor-to-date): Use it.
* lisp/bindings.el (debug-ignored-errors): Remove regexps, add `user-error'.
* src/data.c (PUT_ERROR): New macro.
(syms_of_data): Use it. Add new error type `user-error'.
* src/undo.c (user_error): New function.
(Fprimitive_undo): Use it.
* src/print.c (print_error_message): Adjust print style for `user-error'.
* src/keyboard.c (user_error): New function.
(Fexit_recursive_edit, Fabort_recursive_edit): Use it.
2012-05-04 19:16:47 -04:00
|
|
|
|
(user-error "No next %s" ,name))
|
2007-10-20 01:46:38 +00:00
|
|
|
|
(goto-char (match-beginning 0))
|
Do not call to `selected-window' where it is assumed by default.
Affected functions are `window-minibuffer-p', `window-dedicated-p',
`window-hscroll', `window-width', `window-height', `window-buffer',
`window-frame', `window-start', `window-point', `next-window'
and `window-display-table'.
* abbrev.el (abbrev--default-expand):
* bs.el (bs--show-with-configuration):
* buff-menu.el (Buffer-menu-mouse-select):
* calc/calc.el (calc):
* calendar/calendar.el (calendar-generate-window):
* calendar/diary-lib.el (diary-simple-display, diary-show-all-entries)
(diary-make-entry):
* comint.el (send-invisible, comint-dynamic-complete-filename)
(comint-dynamic-simple-complete, comint-dynamic-list-completions):
* completion.el (complete):
* dabbrev.el (dabbrev-expand, dabbrev--make-friend-buffer-list):
* disp-table.el (describe-current-display-table):
* doc-view.el (doc-view-insert-image):
* ebuff-menu.el (Electric-buffer-menu-mouse-select):
* ehelp.el (with-electric-help):
* emacs-lisp/easy-mmode.el (easy-mmode-define-navigation):
* emacs-lisp/edebug.el (edebug-two-window-p, edebug-pop-to-buffer):
* emacs-lisp/helper.el (Helper-help-scroller):
* emulation/cua-base.el (cua--post-command-handler-1):
* eshell/esh-mode.el (eshell-output-filter):
* ffap.el (ffap-gnus-wrapper):
* help-macro.el (make-help-screen):
* hilit-chg.el (highlight-compare-buffers):
* hippie-exp.el (hippie-expand, try-expand-dabbrev-visible):
* hl-line.el (global-hl-line-highlight):
* icomplete.el (icomplete-simple-completing-p):
* isearch.el (isearch-done):
* jit-lock.el (jit-lock-stealth-fontify):
* mail/rmailsum.el (rmail-summary-scroll-msg-up):
* lisp/mouse-drag.el (mouse-drag-should-do-col-scrolling):
* mpc.el (mpc-tagbrowser, mpc):
* net/rcirc.el (rcirc-any-buffer):
* play/gomoku.el (gomoku-max-width, gomoku-max-height):
* play/landmark.el (landmark-max-width, landmark-max-height):
* play/zone.el (zone):
* progmodes/compile.el (compilation-goto-locus):
* progmodes/ebrowse.el (ebrowse-view/find-file-and-search-pattern):
* progmodes/etags.el (find-tag-other-window):
* progmodes/fortran.el (fortran-column-ruler):
* progmodes/gdb-mi.el (gdb-mouse-toggle-breakpoint-fringe):
* progmodes/verilog-mode.el (verilog-point-text):
* reposition.el (reposition-window):
* rot13.el (toggle-rot13-mode):
* server.el (server-switch-buffer):
* shell.el (shell-dynamic-complete-command)
(shell-dynamic-complete-environment-variable):
* simple.el (insert-buffer, set-selective-display)
(delete-completion-window):
* speedbar.el (speedbar-timer-fn, speedbar-center-buffer-smartly)
(speedbar-recenter):
* startup.el (fancy-splash-head):
* textmodes/ispell.el (ispell-command-loop):
* textmodes/makeinfo.el (makeinfo-compilation-sentinel-region):
* tutorial.el (help-with-tutorial):
* vc/add-log.el (add-change-log-entry):
* vc/compare-w.el (compare-windows):
* vc/ediff-help.el (ediff-indent-help-message):
* vc/ediff-util.el (ediff-setup-control-buffer, ediff-position-region):
* vc/ediff-wind.el (ediff-skip-unsuitable-frames)
(ediff-setup-control-frame):
* vc/emerge.el (emerge-position-region):
* vc/pcvs-util.el (cvs-bury-buffer):
* window.el (walk-windows, mouse-autoselect-window-select):
* winner.el (winner-set-conf, winner-undo): Related users changed.
2013-08-05 18:26:57 +04:00
|
|
|
|
(when (and (eq (current-buffer) (window-buffer))
|
2009-10-02 03:48:36 +00:00
|
|
|
|
(called-interactively-p 'interactive))
|
2007-10-20 01:46:38 +00:00
|
|
|
|
(let ((endpt (or (save-excursion
|
2013-08-02 17:23:07 -04:00
|
|
|
|
,(if endfun `(funcall #',endfun)
|
2007-10-20 01:46:38 +00:00
|
|
|
|
`(re-search-forward ,re nil t 2)))
|
|
|
|
|
(point-max))))
|
|
|
|
|
(unless (pos-visible-in-window-p endpt nil t)
|
|
|
|
|
(recenter '(0)))))))
|
|
|
|
|
,@body))
|
2005-12-04 02:34:33 +00:00
|
|
|
|
(put ',next-sym 'definition-name ',base)
|
2000-03-21 15:35:06 +00:00
|
|
|
|
(defun ,prev-sym (&optional count)
|
|
|
|
|
,(format "Go to the previous COUNT'th %s" (or name base-name))
|
2006-11-28 19:22:31 +00:00
|
|
|
|
(interactive "p")
|
2000-03-21 15:35:06 +00:00
|
|
|
|
(unless count (setq count 1))
|
|
|
|
|
(if (< count 0) (,next-sym (- count))
|
2007-10-20 01:46:38 +00:00
|
|
|
|
,(funcall when-narrowed
|
|
|
|
|
`(unless (re-search-backward ,re nil t count)
|
Add new error and function `user-error'.
* lisp/subr.el (user-error): New function.
* lisp/window.el (switch-to-buffer):
* lisp/vc/smerge-mode.el (smerge-resolve-function, smerge-resolve)
(smerge-match-conflict):
* lisp/simple.el (previous-matching-history-element)
(next-matching-history-element, goto-history-element, undo-more)
(undo-start):
* lisp/progmodes/etags.el (visit-tags-table-buffer, find-tag-tag)
(find-tag-noselect, find-tag-in-order, etags-goto-tag-location)
(next-file, tags-loop-scan, list-tags, complete-tag):
* lisp/progmodes/compile.el (compilation-loop):
* lisp/mouse.el (mouse-minibuffer-check):
* lisp/man.el (Man-bgproc-sentinel, Man-goto-page):
* lisp/info.el (Info-find-node-2, Info-extract-pointer, Info-history-back)
(Info-history-forward, Info-follow-reference, Info-menu)
(Info-extract-menu-item, Info-extract-menu-counting)
(Info-forward-node, Info-backward-node, Info-next-menu-item)
(Info-last-menu-item, Info-next-preorder, Info-last-preorder)
(Info-next-reference, Info-prev-reference, Info-index)
(Info-index-next, Info-follow-nearest-node)
(Info-copy-current-node-name):
* lisp/imenu.el (imenu--make-index-alist)
(imenu-default-create-index-function, imenu-add-to-menubar):
* lisp/files.el (basic-save-buffer, recover-file):
* lisp/emacs-lisp/easy-mmode.el (easy-mmode-define-navigation):
* lisp/emacs-lisp/checkdoc.el (checkdoc-continue, checkdoc-comments)
(checkdoc-message-text, checkdoc-defun):
* lisp/dabbrev.el (dabbrev-completion, dabbrev--abbrev-at-point):
* lisp/cus-edit.el (customize-changed-options, customize-rogue)
(customize-saved, custom-variable-set, custom-variable-mark-to-save)
(custom-variable-mark-to-reset-standard)
(custom-variable-reset-backup, custom-face-mark-to-reset-standard)
(custom-file):
* lisp/completion.el (check-completion-length):
* lisp/comint.el (comint-search-arg)
(comint-previous-matching-input-string-position)
(comint-previous-matching-input)
(comint-replace-by-expanded-history-before-point, comint-send-input)
(comint-copy-old-input, comint-backward-matching-input)
(comint-goto-process-mark, comint-set-process-mark):
* lisp/calendar/calendar.el (calendar-cursor-to-date): Use it.
* lisp/bindings.el (debug-ignored-errors): Remove regexps, add `user-error'.
* src/data.c (PUT_ERROR): New macro.
(syms_of_data): Use it. Add new error type `user-error'.
* src/undo.c (user_error): New function.
(Fprimitive_undo): Use it.
* src/print.c (print_error_message): Adjust print style for `user-error'.
* src/keyboard.c (user_error): New function.
(Fexit_recursive_edit, Fabort_recursive_edit): Use it.
2012-05-04 19:16:47 -04:00
|
|
|
|
(user-error "No previous %s" ,name)))
|
2007-10-20 01:46:38 +00:00
|
|
|
|
,@body))
|
2005-12-04 02:34:33 +00:00
|
|
|
|
(put ',prev-sym 'definition-name ',base))))
|
2003-11-14 16:18:01 +00:00
|
|
|
|
|
2000-03-10 01:17:04 +00:00
|
|
|
|
|
1997-06-22 20:08:32 +00:00
|
|
|
|
(provide 'easy-mmode)
|
|
|
|
|
|
|
|
|
|
;;; easy-mmode.el ends here
|