annotate lisp/emacs-lisp/easy-mmode.el @ 88265:defd9948075b

(rmail-highlight-face): Doc. (rmail-font-lock-keywords): Add the stuff necessary to make rmail-highlight-headers obsolete. (rmail-toggle-header, rmail-show-message): Don't call rmail-highlight-headers anymore. (rmail-highlight-headers): Deleted.
author Alex Schroeder <alex@gnu.org>
date Sat, 21 Jan 2006 18:21:07 +0000
parents d7ddb3e565de
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 38324
diff changeset
1 ;;; easy-mmode.el --- easy definition for major and minor modes
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
3 ;; Copyright (C) 1997, 2000, 2001, 2002, 2003, 2004, 2005
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
4 ;; Free Software Foundation, Inc.
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
38455
802c948ddb3a *** empty log message ***
Pavel Janík <Pavel@Janik.cz>
parents: 38436
diff changeset
6 ;; Author: Georges Brun-Cottan <Georges.Brun-Cottan@inria.fr>
802c948ddb3a *** empty log message ***
Pavel Janík <Pavel@Janik.cz>
parents: 38436
diff changeset
7 ;; Maintainer: Stefan Monnier <monnier@gnu.org>
802c948ddb3a *** empty log message ***
Pavel Janík <Pavel@Janik.cz>
parents: 38436
diff changeset
8
802c948ddb3a *** empty log message ***
Pavel Janík <Pavel@Janik.cz>
parents: 38436
diff changeset
9 ;; Keywords: extensions lisp
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; any later version.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
26 ;; Boston, MA 02110-1301, USA.
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; Commentary:
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; Minor modes are useful and common. This package makes defining a
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; minor mode easy, by focusing on the writing of the minor mode
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; functionalities themselves. Moreover, this package enforces a
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; conventional naming of user interface primitives, making things
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; natural for the minor-mode end-users.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; For each mode, easy-mmode defines the following:
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; <mode> : The minor mode predicate. A buffer-local variable.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; <mode>-map : The keymap possibly associated to <mode>.
29039
d8bafae6beb2 Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28239
diff changeset
39 ;; see `define-minor-mode' documentation
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; eval
29039
d8bafae6beb2 Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28239
diff changeset
42 ;; (pp (macroexpand '(define-minor-mode <your-mode> <doc>)))
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; to check the result before using it.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; The order in which minor modes are installed is important. Keymap
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; lookup proceeds down minor-mode-map-alist, and the order there
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; tends to be the reverse of the order in which the modes were
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; installed. Perhaps there should be a feature to let you specify
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; orderings.
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50
28081
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
51 ;; Additionally to `define-minor-mode', the package provides convenient
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
52 ;; ways to define keymaps, and other helper functions for major and minor modes.
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53
28081
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
54 ;;; Code:
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
56 (eval-when-compile (require 'cl))
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
57
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
58 (defun easy-mmode-pretty-mode-name (mode &optional lighter)
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
59 "Turn the symbol MODE into a string intended for the user.
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
60 If provided, LIGHTER will be used to help choose capitalization by,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
61 replacing its case-insensitive matches with the literal string in LIGHTER."
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
62 (let* ((case-fold-search t)
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
63 ;; Produce "Foo-Bar minor mode" from foo-bar-minor-mode.
32048
39617f078b9d (easy-mmode-pretty-mode-name): Prettier.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31981
diff changeset
64 (name (concat (replace-regexp-in-string
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
65 ;; If the original mode name included "-minor" (some
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
66 ;; of them don't, e.g. auto-revert-mode), then
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
67 ;; replace it with " minor".
32048
39617f078b9d (easy-mmode-pretty-mode-name): Prettier.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31981
diff changeset
68 "-Minor" " minor"
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
69 ;; "foo-bar-minor" -> "Foo-Bar-Minor"
32048
39617f078b9d (easy-mmode-pretty-mode-name): Prettier.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31981
diff changeset
70 (capitalize (replace-regexp-in-string
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
71 ;; "foo-bar-minor-mode" -> "foo-bar-minor"
32048
39617f078b9d (easy-mmode-pretty-mode-name): Prettier.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31981
diff changeset
72 "-mode\\'" "" (symbol-name mode))))
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
73 " mode")))
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
74 (if (not (stringp lighter)) name
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
75 ;; Strip leading and trailing whitespace from LIGHTER.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
76 (setq lighter (replace-regexp-in-string "\\`\\s-+\\|\\s-+\\'" ""
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
77 lighter))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
78 ;; Replace any (case-insensitive) matches for LIGHTER in NAME
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
79 ;; with a literal LIGHTER. E.g., if NAME is "Iimage mode" and
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
80 ;; LIGHTER is " iImag", then this will produce "iImage mode".
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
81 ;; (LIGHTER normally comes from the mode-line string passed to
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
82 ;; define-minor-mode, and normally includes at least one leading
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
83 ;; space.)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
84 (replace-regexp-in-string (regexp-quote lighter) lighter name t t))))
29399
addeae19bf96 (easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29039
diff changeset
85
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;;;###autoload
26551
271f77895660 Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 25408
diff changeset
87 (defalias 'easy-mmode-define-minor-mode 'define-minor-mode)
271f77895660 Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 25408
diff changeset
88 ;;;###autoload
271f77895660 Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 25408
diff changeset
89 (defmacro define-minor-mode (mode doc &optional init-value lighter keymap &rest body)
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 "Define a new minor mode MODE.
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
91 This function defines the associated control variable MODE, keymap MODE-map,
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
92 and toggle command MODE.
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 DOC is the documentation for the mode toggle command.
26551
271f77895660 Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 25408
diff changeset
95 Optional INIT-VALUE is the initial value of the mode's variable.
29039
d8bafae6beb2 Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28239
diff changeset
96 Optional LIGHTER is displayed in the modeline when the mode is on.
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 Optional KEYMAP is the default (defvar) keymap bound to the mode keymap.
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
98 If it is a list, it is passed to `easy-mmode-define-keymap'
33131
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
99 in order to build a valid keymap. It's generally better to use
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
100 a separate MODE-map variable than to use this argument.
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
101 The above three arguments can be skipped if keyword arguments are
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
102 used (see below).
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
103
26551
271f77895660 Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 25408
diff changeset
104 BODY contains code that will be executed each time the mode is (dis)activated.
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
105 It will be executed after any toggling but before running the hook variable
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
106 `mode-HOOK'.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
107 Before the actual body code, you can write keyword arguments (alternating
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
108 keywords and values). These following keyword arguments are supported (other
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
109 keywords will be passed to `defcustom' if the minor mode is global):
47788
1174e4c84d58 (define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47657
diff changeset
110 :group GROUP Custom group name to use in all generated `defcustom' forms.
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
111 Defaults to MODE without the possible trailing \"-mode\".
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
112 Don't use this default group name unless you have written a
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
113 `defgroup' to define that group properly.
47463
2b213bd55695 (define-minor-mode): Add a :require arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47043
diff changeset
114 :global GLOBAL If non-nil specifies that the minor mode is not meant to be
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
115 buffer-local, so don't make the variable MODE buffer-local.
47788
1174e4c84d58 (define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47657
diff changeset
116 By default, the mode is buffer-local.
47463
2b213bd55695 (define-minor-mode): Add a :require arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47043
diff changeset
117 :init-value VAL Same as the INIT-VALUE argument.
2b213bd55695 (define-minor-mode): Add a :require arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47043
diff changeset
118 :lighter SPEC Same as the LIGHTER argument.
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
119 :keymap MAP Same as the KEYMAP argument.
47788
1174e4c84d58 (define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47657
diff changeset
120 :require SYM Same as in `defcustom'.
1174e4c84d58 (define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47657
diff changeset
121
1174e4c84d58 (define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47657
diff changeset
122 For example, you could write
1174e4c84d58 (define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47657
diff changeset
123 (define-minor-mode foo-mode \"If enabled, foo on you!\"
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
124 :lighter \" Foo\" :require 'foo :global t :group 'hassle :version \"27.5\"
47788
1174e4c84d58 (define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47657
diff changeset
125 ...BODY CODE...)"
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
126 (declare (debug (&define name stringp
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
127 [&optional [&not keywordp] sexp
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
128 &optional [&not keywordp] sexp
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
129 &optional [&not keywordp] sexp]
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
130 [&rest [keywordp sexp]]
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
131 def-body)))
47788
1174e4c84d58 (define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 47657
diff changeset
132
33131
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
133 ;; Allow skipping the first three args.
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
134 (cond
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
135 ((keywordp init-value)
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
136 (setq body (list* init-value lighter keymap body)
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
137 init-value nil lighter nil keymap nil))
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
138 ((keywordp lighter)
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
139 (setq body (list* lighter keymap body) lighter nil keymap nil))
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
140 ((keywordp keymap) (push keymap body) (setq keymap nil)))
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
141
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (let* ((mode-name (symbol-name mode))
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
143 (pretty-name (easy-mmode-pretty-mode-name mode lighter))
29039
d8bafae6beb2 Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28239
diff changeset
144 (globalp nil)
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
145 (set nil)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
146 (initialize nil)
33162
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
147 (group nil)
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
148 (type nil)
33162
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
149 (extra-args nil)
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
150 (extra-keywords nil)
47463
2b213bd55695 (define-minor-mode): Add a :require arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47043
diff changeset
151 (require t)
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
152 (hook (intern (concat mode-name "-hook")))
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
153 (hook-on (intern (concat mode-name "-on-hook")))
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
154 (hook-off (intern (concat mode-name "-off-hook")))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
155 keyw keymap-sym)
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
156
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
157 ;; Check keys.
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
158 (while (keywordp (setq keyw (car body)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
159 (setq body (cdr body))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
160 (case keyw
33131
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
161 (:init-value (setq init-value (pop body)))
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
162 (:lighter (setq lighter (pop body)))
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
163 (:global (setq globalp (pop body)))
33162
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
164 (:extra-args (setq extra-args (pop body)))
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
165 (:set (setq set (list :set (pop body))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
166 (:initialize (setq initialize (list :initialize (pop body))))
33162
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
167 (:group (setq group (nconc group (list :group (pop body)))))
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
168 (:type (setq type (list :type (pop body))))
47463
2b213bd55695 (define-minor-mode): Add a :require arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47043
diff changeset
169 (:require (setq require (pop body)))
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
170 (:keymap (setq keymap (pop body)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
171 (t (push keyw extra-keywords) (push (pop body) extra-keywords))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
172
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
173 (setq keymap-sym (if (and keymap (symbolp keymap)) keymap
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
174 (intern (concat mode-name "-map"))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
175
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
176 (unless set (setq set '(:set 'custom-set-minor-mode)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
177
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
178 (unless initialize
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
179 (setq initialize '(:initialize 'custom-initialize-default)))
32999
6bc392d6aef3 (define-minor-mode): Generate `turn-on-MODE' and `turn-off-MODE'
Miles Bader <miles@gnu.org>
parents: 32491
diff changeset
180
33162
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
181 (unless group
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
182 ;; We might as well provide a best-guess default group.
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
183 (setq group
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
184 `(:group ',(intern (replace-regexp-in-string
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
185 "-mode\\'" "" mode-name)))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
186
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
187 (unless type (setq type '(:type 'boolean)))
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
188
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 `(progn
25408
68c51b1a537f (easy-mmode-define-minor-mode):
Karl Heuer <kwzh@gnu.org>
parents: 24935
diff changeset
190 ;; Define the variable to enable or disable the mode.
29414
b18a17d5d9c6 (easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29411
diff changeset
191 ,(if (not globalp)
b18a17d5d9c6 (easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29411
diff changeset
192 `(progn
b18a17d5d9c6 (easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29411
diff changeset
193 (defvar ,mode ,init-value ,(format "Non-nil if %s is enabled.
35562
6b8b7796f28b (define-minor-mode): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 34149
diff changeset
194 Use the command `%s' to change this variable." pretty-name mode))
29414
b18a17d5d9c6 (easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29411
diff changeset
195 (make-variable-buffer-local ',mode))
b18a17d5d9c6 (easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29411
diff changeset
196
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
197 (let ((base-doc-string
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
198 (concat "Non-nil if %s is enabled.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
199 See the command `%s' for a description of this minor-mode."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
200 (if body "
29039
d8bafae6beb2 Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28239
diff changeset
201 Setting this variable directly does not take effect;
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
202 use either \\[customize] or the function `%s'."))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
203 `(defcustom ,mode ,init-value
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
204 ,(format base-doc-string pretty-name mode mode)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
205 ,@set
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
206 ,@initialize
33162
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
207 ,@group
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
208 ,@type
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
209 ,@(unless (eq require t) `(:require ,require))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
210 ,@(nreverse extra-keywords))))
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
211
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
212 ;; The actual function.
33162
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
213 (defun ,mode (&optional arg ,@extra-args)
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
214 ,(or doc
33131
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
215 (format (concat "Toggle %s on or off.
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
216 Interactively, with no prefix argument, toggle the mode.
46900
3c3d686b25fa (easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46873
diff changeset
217 With universal prefix ARG turn mode on.
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
218 With zero or negative ARG turn mode off.
33131
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
219 \\{%s}") pretty-name keymap-sym))
46900
3c3d686b25fa (easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46873
diff changeset
220 ;; Use `toggle' rather than (if ,mode 0 1) so that using
3c3d686b25fa (easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46873
diff changeset
221 ;; repeat-command still does the toggling correctly.
3c3d686b25fa (easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46873
diff changeset
222 (interactive (list (or current-prefix-arg 'toggle)))
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
223 (setq ,mode
46900
3c3d686b25fa (easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46873
diff changeset
224 (cond
3c3d686b25fa (easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46873
diff changeset
225 ((eq arg 'toggle) (not ,mode))
3c3d686b25fa (easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46873
diff changeset
226 (arg (> (prefix-numeric-value arg) 0))
3c3d686b25fa (easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46873
diff changeset
227 (t
3c3d686b25fa (easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46873
diff changeset
228 (if (null ,mode) t
3c3d686b25fa (easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46873
diff changeset
229 (message
3c3d686b25fa (easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46873
diff changeset
230 "Toggling %s off; better pass an explicit argument."
3c3d686b25fa (easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46873
diff changeset
231 ',mode)
3c3d686b25fa (easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46873
diff changeset
232 nil))))
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
233 ,@body
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
234 ;; The on/off hooks are here for backward compatibility only.
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
235 (run-hooks ',hook (if ,mode ',hook-on ',hook-off))
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
236 (if (called-interactively-p)
47043
360c6fcdde04 (define-minor-mode): Use customize-mark-as-set for global minor modes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46900
diff changeset
237 (progn
360c6fcdde04 (define-minor-mode): Use customize-mark-as-set for global minor modes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46900
diff changeset
238 ,(if globalp `(customize-mark-as-set ',mode))
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
239 (unless (current-message)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
240 (message ,(format "%s %%sabled" pretty-name)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
241 (if ,mode "en" "dis")))))
47043
360c6fcdde04 (define-minor-mode): Use customize-mark-as-set for global minor modes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46900
diff changeset
242 (force-mode-line-update)
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
243 ;; Return the new setting.
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
244 ,mode)
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
245
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
246 ;; Autoloading a define-minor-mode autoloads everything
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
247 ;; up-to-here.
29548
71b284c55162 (define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29414
diff changeset
248 :autoload-end
71b284c55162 (define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29414
diff changeset
249
29414
b18a17d5d9c6 (easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29411
diff changeset
250 ;; Define the minor-mode keymap.
29548
71b284c55162 (define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29414
diff changeset
251 ,(unless (symbolp keymap) ;nil is also a symbol.
29414
b18a17d5d9c6 (easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29411
diff changeset
252 `(defvar ,keymap-sym
29548
71b284c55162 (define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29414
diff changeset
253 (let ((m ,keymap))
71b284c55162 (define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29414
diff changeset
254 (cond ((keymapp m) m)
71b284c55162 (define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29414
diff changeset
255 ((listp m) (easy-mmode-define-keymap m))
71b284c55162 (define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29414
diff changeset
256 (t (error "Invalid keymap %S" ,keymap))))
29414
b18a17d5d9c6 (easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29411
diff changeset
257 ,(format "Keymap for `%s'." mode-name)))
b18a17d5d9c6 (easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29411
diff changeset
258
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
259 (add-minor-mode ',mode ',lighter
29548
71b284c55162 (define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29414
diff changeset
260 ,(if keymap keymap-sym
30876
76bba9fc3c22 (define-minor-mode): Use `symbol-value' to keep the byte-compiler quiet.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29548
diff changeset
261 `(if (boundp ',keymap-sym)
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
262 (symbol-value ',keymap-sym)))))))
28081
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
263
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
264 ;;;
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
265 ;;; make global minor mode
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
266 ;;;
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
267
29414
b18a17d5d9c6 (easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29411
diff changeset
268 ;;;###autoload
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
269 (defalias 'easy-mmode-define-global-mode 'define-global-minor-mode)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
270 ;;;###autoload
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
271 (defmacro define-global-minor-mode (global-mode mode turn-on &rest keys)
33131
8d1ed5c84809 (define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33001
diff changeset
272 "Make GLOBAL-MODE out of the buffer-local minor MODE.
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
273 TURN-ON is a function that will be called with no args in every buffer
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
274 and that should try to turn MODE on if applicable for that buffer.
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
275 KEYS is a list of CL-style keyword arguments. As the minor mode
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
276 defined by this function is always global, any :global keyword is
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
277 ignored. Other keywords have the same meaning as in `define-minor-mode',
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
278 which see. In particular, :group specifies the custom group.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
279 The most useful keywords are those that are passed on to the
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
280 `defcustom'. It normally makes no sense to pass the :lighter
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
281 or :keymap keywords to `define-global-minor-mode', since these
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
282 are usually passed to the buffer-local version of the minor mode.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
283
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
284 If MODE's set-up depends on the major mode in effect when it was
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
285 enabled, then disabling and reenabling MODE should make MODE work
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
286 correctly with the current major mode. This is important to
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
287 prevent problems with derived modes, that is, major modes that
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
288 call another major mode in their body."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
289
33162
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
290 (let* ((global-mode-name (symbol-name global-mode))
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
291 (pretty-name (easy-mmode-pretty-mode-name mode))
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
292 (pretty-global-name (easy-mmode-pretty-mode-name global-mode))
33162
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
293 (group nil)
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
294 (extra-keywords nil)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
295 (MODE-buffers (intern (concat global-mode-name "-buffers")))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
296 (MODE-enable-in-buffers
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
297 (intern (concat global-mode-name "-enable-in-buffers")))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
298 (MODE-check-buffers
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
299 (intern (concat global-mode-name "-check-buffers")))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
300 (MODE-cmhh (intern (concat global-mode-name "-cmhh")))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
301 (MODE-major-mode (intern (concat (symbol-name mode) "-major-mode")))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
302 keyw)
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
303
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
304 ;; Check keys.
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
305 (while (keywordp (setq keyw (car keys)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
306 (setq keys (cdr keys))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
307 (case keyw
33162
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
308 (:group (setq group (nconc group (list :group (pop keys)))))
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
309 (:global (setq keys (cdr keys)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
310 (t (push keyw extra-keywords) (push (pop keys) extra-keywords))))
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
311
33162
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
312 (unless group
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
313 ;; We might as well provide a best-guess default group.
ccf6cd7d4512 (define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33131
diff changeset
314 (setq group
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
315 `(:group ',(intern (replace-regexp-in-string
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
316 "-mode\\'" "" (symbol-name mode))))))
48838
e0689be193e2 (define-minor-mode): Use `custom-current-group'.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 47788
diff changeset
317
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
318 `(progn
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
319 (defvar ,MODE-major-mode nil)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
320 (make-variable-buffer-local ',MODE-major-mode)
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
321 ;; The actual global minor-mode
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
322 (define-minor-mode ,global-mode
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
323 ,(format "Toggle %s in every buffer.
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
324 With prefix ARG, turn %s on if and only if ARG is positive.
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
325 %s is actually not turned on in every buffer but only in those
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
326 in which `%s' turns it on."
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
327 pretty-name pretty-global-name pretty-name turn-on)
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
328 :global t ,@group ,@(nreverse extra-keywords)
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
329
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
330 ;; Setup hook to handle future mode changes and new buffers.
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
331 (if ,global-mode
29414
b18a17d5d9c6 (easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29411
diff changeset
332 (progn
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
333 (add-hook 'after-change-major-mode-hook
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
334 ',MODE-enable-in-buffers)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
335 (add-hook 'find-file-hook ',MODE-check-buffers)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
336 (add-hook 'change-major-mode-hook ',MODE-cmhh))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
337 (remove-hook 'after-change-major-mode-hook ',MODE-enable-in-buffers)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
338 (remove-hook 'find-file-hook ',MODE-check-buffers)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
339 (remove-hook 'change-major-mode-hook ',MODE-cmhh))
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
340
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
341 ;; Go through existing buffers.
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
342 (dolist (buf (buffer-list))
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
343 (with-current-buffer buf
33165
8b3f1e99c11a (easy-mmode-define-global-mode): Only turn mode off if it's on.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33162
diff changeset
344 (if ,global-mode (,turn-on) (when ,mode (,mode -1))))))
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
345
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
346 ;; Autoloading define-global-minor-mode autoloads everything
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
347 ;; up-to-here.
29548
71b284c55162 (define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29414
diff changeset
348 :autoload-end
71b284c55162 (define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29414
diff changeset
349
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
350 ;; List of buffers left to process.
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
351 (defvar ,MODE-buffers nil)
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
352
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
353 ;; The function that calls TURN-ON in each buffer.
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
354 (defun ,MODE-enable-in-buffers ()
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
355 (dolist (buf ,MODE-buffers)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
356 (when (buffer-live-p buf)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
357 (with-current-buffer buf
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
358 (if ,mode
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
359 (unless (eq ,MODE-major-mode major-mode)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
360 (,mode -1)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
361 (,turn-on)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
362 (setq ,MODE-major-mode major-mode))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
363 (,turn-on)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
364 (setq ,MODE-major-mode major-mode))))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
365 (put ',MODE-enable-in-buffers 'definition-name ',global-mode)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
366
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
367 (defun ,MODE-check-buffers ()
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
368 (,MODE-enable-in-buffers)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
369 (setq ,MODE-buffers nil)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
370 (remove-hook 'post-command-hook ',MODE-check-buffers))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
371 (put ',MODE-check-buffers 'definition-name ',global-mode)
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
372
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
373 ;; The function that catches kill-all-local-variables.
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
374 (defun ,MODE-cmhh ()
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
375 (add-to-list ',MODE-buffers (current-buffer))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
376 (add-hook 'post-command-hook ',MODE-check-buffers))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
377 (put ',MODE-cmhh 'definition-name ',global-mode))))
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
378
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
379 ;;;
28081
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
380 ;;; easy-mmode-defmap
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
381 ;;;
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
382
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
383 (if (fboundp 'set-keymap-parents)
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
384 (defalias 'easy-mmode-set-keymap-parents 'set-keymap-parents)
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
385 (defun easy-mmode-set-keymap-parents (m parents)
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
386 (set-keymap-parent
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
387 m
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
388 (cond
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
389 ((not (consp parents)) parents)
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
390 ((not (cdr parents)) (car parents))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
391 (t (let ((m (copy-keymap (pop parents))))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
392 (easy-mmode-set-keymap-parents m parents)
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
393 m))))))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
394
31981
533a4e5f06e2 (easy-mmode-define-keymap): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30876
diff changeset
395 ;;;###autoload
28081
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
396 (defun easy-mmode-define-keymap (bs &optional name m args)
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
397 "Return a keymap built from bindings BS.
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
398 BS must be a list of (KEY . BINDING) where
29399
addeae19bf96 (easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29039
diff changeset
399 KEY and BINDINGS are suitable for `define-key'.
addeae19bf96 (easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29039
diff changeset
400 Optional NAME is passed to `make-sparse-keymap'.
addeae19bf96 (easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29039
diff changeset
401 Optional map M can be used to modify an existing map.
33433
e8794ae4f856 (easy-mmode-define-keymap):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33358
diff changeset
402 ARGS is a list of additional keyword arguments."
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
403 (let (inherit dense)
28081
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
404 (while args
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
405 (let ((key (pop args))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
406 (val (pop args)))
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
407 (case key
33433
e8794ae4f856 (easy-mmode-define-keymap):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33358
diff changeset
408 (:name (setq name val))
29411
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
409 (:dense (setq dense val))
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
410 (:inherit (setq inherit val))
232f7e558a38 Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29406
diff changeset
411 (:group)
28081
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
412 (t (message "Unknown argument %s in defmap" key)))))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
413 (unless (keymapp m)
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
414 (setq bs (append m bs))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
415 (setq m (if dense (make-keymap name) (make-sparse-keymap name))))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
416 (dolist (b bs)
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
417 (let ((keys (car b))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
418 (binding (cdr b)))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
419 (dolist (key (if (consp keys) keys (list keys)))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
420 (cond
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
421 ((symbolp key)
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
422 (substitute-key-definition key binding m global-map))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
423 ((null binding)
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
424 (unless (keymapp (lookup-key m key)) (define-key m key binding)))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
425 ((let ((o (lookup-key m key)))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
426 (or (null o) (numberp o) (eq o 'undefined)))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
427 (define-key m key binding))))))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
428 (cond
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
429 ((keymapp inherit) (set-keymap-parent m inherit))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
430 ((consp inherit) (easy-mmode-set-keymap-parents m inherit)))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
431 m))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
432
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
433 ;;;###autoload
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
434 (defmacro easy-mmode-defmap (m bs doc &rest args)
31981
533a4e5f06e2 (easy-mmode-define-keymap): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30876
diff changeset
435 `(defconst ,m
533a4e5f06e2 (easy-mmode-define-keymap): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30876
diff changeset
436 (easy-mmode-define-keymap ,bs nil (if (boundp ',m) ,m) ,(cons 'list args))
533a4e5f06e2 (easy-mmode-define-keymap): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 30876
diff changeset
437 ,doc))
28081
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
438
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
439
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
440 ;;;
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
441 ;;; easy-mmode-defsyntax
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
442 ;;;
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
443
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
444 (defun easy-mmode-define-syntax (css args)
32491
2fc546f941df (easy-mmode-define-syntax): Use plist-get and allow :inherit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32199
diff changeset
445 (let ((st (make-syntax-table (plist-get args :copy)))
2fc546f941df (easy-mmode-define-syntax): Use plist-get and allow :inherit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32199
diff changeset
446 (parent (plist-get args :inherit)))
28081
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
447 (dolist (cs css)
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
448 (let ((char (car cs))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
449 (syntax (cdr cs)))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
450 (if (sequencep char)
28086
9ff6e6a6c6b5 (easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28081
diff changeset
451 (mapcar (lambda (c) (modify-syntax-entry c syntax st)) char)
28081
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
452 (modify-syntax-entry char syntax st))))
32491
2fc546f941df (easy-mmode-define-syntax): Use plist-get and allow :inherit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32199
diff changeset
453 (if parent (set-char-table-parent
2fc546f941df (easy-mmode-define-syntax): Use plist-get and allow :inherit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32199
diff changeset
454 st (if (symbolp parent) (symbol-value parent) parent)))
28081
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
455 st))
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
456
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
457 ;;;###autoload
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
458 (defmacro easy-mmode-defsyntax (st css doc &rest args)
32491
2fc546f941df (easy-mmode-define-syntax): Use plist-get and allow :inherit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32199
diff changeset
459 "Define variable ST as a syntax-table.
37406
3886350a8826 (easy-mmode-defsyntax): Unquote `doc'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 35562
diff changeset
460 CSS contains a list of syntax specifications of the form (CHAR . SYNTAX)."
28086
9ff6e6a6c6b5 (easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28081
diff changeset
461 `(progn
9ff6e6a6c6b5 (easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28081
diff changeset
462 (autoload 'easy-mmode-define-syntax "easy-mmode")
37406
3886350a8826 (easy-mmode-defsyntax): Unquote `doc'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 35562
diff changeset
463 (defconst ,st (easy-mmode-define-syntax ,css ,(cons 'list args)) ,doc)))
28081
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
464
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
465
6360842e5962 (easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26551
diff changeset
466
28235
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
467 ;;;
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
468 ;;; easy-mmode-define-navigation
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
469 ;;;
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
470
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
471 (defmacro easy-mmode-define-navigation (base re &optional name endfun narrowfun)
28235
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
472 "Define BASE-next and BASE-prev to navigate in the buffer.
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
473 RE determines the places the commands should move point to.
33358
a86c95343fa5 (easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33165
diff changeset
474 NAME should describe the entities matched by RE. It is used to build
28235
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
475 the docstrings of the two functions.
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
476 BASE-next also tries to make sure that the whole entry is visible by
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
477 searching for its end (by calling ENDFUN if provided or by looking for
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
478 the next entry) and recentering if necessary.
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
479 ENDFUN should return the end position (with or without moving point).
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
480 NARROWFUN non-nil means to check for narrowing before moving, and if
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
481 found, do widen first and then call NARROWFUN with no args after moving."
28235
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
482 (let* ((base-name (symbol-name base))
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
483 (prev-sym (intern (concat base-name "-prev")))
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
484 (next-sym (intern (concat base-name "-next")))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
485 (check-narrow-maybe
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
486 (when narrowfun
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
487 '(setq was-narrowed
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
488 (prog1 (or (< (- (point-max) (point-min)) (buffer-size)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
489 (widen)))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
490 (re-narrow-maybe (when narrowfun
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
491 `(when was-narrowed (,narrowfun)))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
492 (unless name (setq name base-name))
28235
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
493 `(progn
29406
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
494 (add-to-list 'debug-ignored-errors
f4b12c3efee8 (easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29399
diff changeset
495 ,(concat "^No \\(previous\\|next\\) " (regexp-quote name)))
28235
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
496 (defun ,next-sym (&optional count)
28239
21cd65af5197 (easy-mmode-define-navigation): Only use `ding' for interactive use
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28235
diff changeset
497 ,(format "Go to the next COUNT'th %s." name)
28235
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
498 (interactive)
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
499 (unless count (setq count 1))
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
500 (if (< count 0) (,prev-sym (- count))
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
501 (if (looking-at ,re) (setq count (1+ count)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
502 (let (was-narrowed)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
503 ,check-narrow-maybe
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
504 (if (not (re-search-forward ,re nil t count))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
505 (if (looking-at ,re)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
506 (goto-char (or ,(if endfun `(,endfun)) (point-max)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
507 (error "No next %s" ,name))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
508 (goto-char (match-beginning 0))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
509 (when (and (eq (current-buffer) (window-buffer (selected-window)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
510 (interactive-p))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
511 (let ((endpt (or (save-excursion
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
512 ,(if endfun `(,endfun)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
513 `(re-search-forward ,re nil t 2)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
514 (point-max))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
515 (unless (pos-visible-in-window-p endpt nil t)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
516 (recenter '(0))))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
517 ,re-narrow-maybe)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
518 (put ',next-sym 'definition-name ',base)
28235
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
519 (defun ,prev-sym (&optional count)
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
520 ,(format "Go to the previous COUNT'th %s" (or name base-name))
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
521 (interactive)
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
522 (unless count (setq count 1))
963f1d516e92 * derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28086
diff changeset
523 (if (< count 0) (,next-sym (- count))
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
524 (let (was-narrowed)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
525 ,check-narrow-maybe
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
526 (unless (re-search-backward ,re nil t count)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
527 (error "No previous %s" ,name))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
528 ,re-narrow-maybe)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
529 (put ',prev-sym 'definition-name ',base))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
530
28086
9ff6e6a6c6b5 (easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28081
diff changeset
531
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (provide 'easy-mmode)
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents: 49598
diff changeset
534 ;;; arch-tag: d48a5250-6961-4528-9cb0-3c9ea042a66a
18388
7e14277c51f3 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 ;;; easy-mmode.el ends here