Mercurial > emacs
annotate lisp/emacs-lisp/easy-mmode.el @ 110971:80846b446563
lisp/subr.el (last): Use `safe-length' instead of `length' (bug#7206).
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Thu, 14 Oct 2010 01:15:03 +0200 |
parents | 280c8ae2476d |
children | cdad894f9ed0 |
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 | 2 |
104912
ad1f780103d9
(easy-mmode-defmap): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents:
104732
diff
changeset
|
3 ;; Copyright (C) 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
106815 | 4 ;; 2008, 2009, 2010 Free Software Foundation, Inc. |
18388 | 5 |
38455 | 6 ;; Author: Georges Brun-Cottan <Georges.Brun-Cottan@inria.fr> |
7 ;; Maintainer: Stefan Monnier <monnier@gnu.org> | |
110015
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
109954
diff
changeset
|
8 ;; Package: emacs |
38455 | 9 |
10 ;; Keywords: extensions lisp | |
18388 | 11 |
12 ;; This file is part of GNU Emacs. | |
13 | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94317
diff
changeset
|
14 ;; GNU Emacs is free software: you can redistribute it and/or modify |
18388 | 15 ;; it under the terms of the GNU General Public License as published by |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94317
diff
changeset
|
16 ;; the Free Software Foundation, either version 3 of the License, or |
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94317
diff
changeset
|
17 ;; (at your option) any later version. |
18388 | 18 |
19 ;; GNU Emacs is distributed in the hope that it will be useful, | |
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 ;; GNU General Public License for more details. | |
23 | |
24 ;; You should have received a copy of the GNU General Public License | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94317
diff
changeset
|
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
18388 | 26 |
27 ;;; Commentary: | |
28 | |
29 ;; Minor modes are useful and common. This package makes defining a | |
30 ;; minor mode easy, by focusing on the writing of the minor mode | |
31 ;; functionalities themselves. Moreover, this package enforces a | |
32 ;; conventional naming of user interface primitives, making things | |
33 ;; natural for the minor-mode end-users. | |
34 | |
35 ;; For each mode, easy-mmode defines the following: | |
36 ;; <mode> : The minor mode predicate. A buffer-local variable. | |
37 ;; <mode>-map : The keymap possibly associated to <mode>. | |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
38 ;; see `define-minor-mode' documentation |
18388 | 39 ;; |
40 ;; eval | |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
41 ;; (pp (macroexpand '(define-minor-mode <your-mode> <doc>))) |
18388 | 42 ;; to check the result before using it. |
43 | |
44 ;; The order in which minor modes are installed is important. Keymap | |
45 ;; lookup proceeds down minor-mode-map-alist, and the order there | |
46 ;; tends to be the reverse of the order in which the modes were | |
47 ;; installed. Perhaps there should be a feature to let you specify | |
48 ;; orderings. | |
49 | |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
50 ;; 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
|
51 ;; ways to define keymaps, and other helper functions for major and minor modes. |
18388 | 52 |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
53 ;;; Code: |
18388 | 54 |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
55 (eval-when-compile (require 'cl)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
56 |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
57 (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
|
58 "Turn the symbol MODE into a string intended for the user. |
62149
e64f1e2ecec2
(easy-mmode-pretty-mode-name): Explain
Eli Zaretskii <eliz@gnu.org>
parents:
61861
diff
changeset
|
59 If provided, LIGHTER will be used to help choose capitalization by, |
e64f1e2ecec2
(easy-mmode-pretty-mode-name): Explain
Eli Zaretskii <eliz@gnu.org>
parents:
61861
diff
changeset
|
60 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
|
61 (let* ((case-fold-search t) |
62181
14a20ce36638
(easy-mmode-pretty-mode-name): Improve commentary.
Eli Zaretskii <eliz@gnu.org>
parents:
62149
diff
changeset
|
62 ;; 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
|
63 (name (concat (replace-regexp-in-string |
62181
14a20ce36638
(easy-mmode-pretty-mode-name): Improve commentary.
Eli Zaretskii <eliz@gnu.org>
parents:
62149
diff
changeset
|
64 ;; If the original mode name included "-minor" (some |
14a20ce36638
(easy-mmode-pretty-mode-name): Improve commentary.
Eli Zaretskii <eliz@gnu.org>
parents:
62149
diff
changeset
|
65 ;; of them don't, e.g. auto-revert-mode), then |
14a20ce36638
(easy-mmode-pretty-mode-name): Improve commentary.
Eli Zaretskii <eliz@gnu.org>
parents:
62149
diff
changeset
|
66 ;; replace it with " minor". |
32048
39617f078b9d
(easy-mmode-pretty-mode-name): Prettier.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31981
diff
changeset
|
67 "-Minor" " minor" |
62149
e64f1e2ecec2
(easy-mmode-pretty-mode-name): Explain
Eli Zaretskii <eliz@gnu.org>
parents:
61861
diff
changeset
|
68 ;; "foo-bar-minor" -> "Foo-Bar-Minor" |
32048
39617f078b9d
(easy-mmode-pretty-mode-name): Prettier.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31981
diff
changeset
|
69 (capitalize (replace-regexp-in-string |
62149
e64f1e2ecec2
(easy-mmode-pretty-mode-name): Explain
Eli Zaretskii <eliz@gnu.org>
parents:
61861
diff
changeset
|
70 ;; "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
|
71 "-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
|
72 " mode"))) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
73 (if (not (stringp lighter)) name |
62149
e64f1e2ecec2
(easy-mmode-pretty-mode-name): Explain
Eli Zaretskii <eliz@gnu.org>
parents:
61861
diff
changeset
|
74 ;; Strip leading and trailing whitespace from LIGHTER. |
e64f1e2ecec2
(easy-mmode-pretty-mode-name): Explain
Eli Zaretskii <eliz@gnu.org>
parents:
61861
diff
changeset
|
75 (setq lighter (replace-regexp-in-string "\\`\\s-+\\|\\s-+\\'" "" |
e64f1e2ecec2
(easy-mmode-pretty-mode-name): Explain
Eli Zaretskii <eliz@gnu.org>
parents:
61861
diff
changeset
|
76 lighter)) |
e64f1e2ecec2
(easy-mmode-pretty-mode-name): Explain
Eli Zaretskii <eliz@gnu.org>
parents:
61861
diff
changeset
|
77 ;; Replace any (case-insensitive) matches for LIGHTER in NAME |
e64f1e2ecec2
(easy-mmode-pretty-mode-name): Explain
Eli Zaretskii <eliz@gnu.org>
parents:
61861
diff
changeset
|
78 ;; with a literal LIGHTER. E.g., if NAME is "Iimage mode" and |
e64f1e2ecec2
(easy-mmode-pretty-mode-name): Explain
Eli Zaretskii <eliz@gnu.org>
parents:
61861
diff
changeset
|
79 ;; LIGHTER is " iImag", then this will produce "iImage mode". |
e64f1e2ecec2
(easy-mmode-pretty-mode-name): Explain
Eli Zaretskii <eliz@gnu.org>
parents:
61861
diff
changeset
|
80 ;; (LIGHTER normally comes from the mode-line string passed to |
e64f1e2ecec2
(easy-mmode-pretty-mode-name): Explain
Eli Zaretskii <eliz@gnu.org>
parents:
61861
diff
changeset
|
81 ;; define-minor-mode, and normally includes at least one leading |
e64f1e2ecec2
(easy-mmode-pretty-mode-name): Explain
Eli Zaretskii <eliz@gnu.org>
parents:
61861
diff
changeset
|
82 ;; space.) |
e64f1e2ecec2
(easy-mmode-pretty-mode-name): Explain
Eli Zaretskii <eliz@gnu.org>
parents:
61861
diff
changeset
|
83 (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
|
84 |
18388 | 85 ;;;###autoload |
26551
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
86 (defalias 'easy-mmode-define-minor-mode 'define-minor-mode) |
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
87 ;;;###autoload |
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
88 (defmacro define-minor-mode (mode doc &optional init-value lighter keymap &rest body) |
18388 | 89 "Define a new minor mode MODE. |
109948
c66428d4b9ed
Doc fix for define-minor-mode (Bug#6880).
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
90 This defines the control variable MODE and the toggle command MODE. |
c66428d4b9ed
Doc fix for define-minor-mode (Bug#6880).
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
91 DOC is the documentation for the mode toggle command. |
18388 | 92 |
26551
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
93 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
|
94 Optional LIGHTER is displayed in the modeline when the mode is on. |
109948
c66428d4b9ed
Doc fix for define-minor-mode (Bug#6880).
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
95 Optional KEYMAP is the default keymap bound to the mode keymap. |
c66428d4b9ed
Doc fix for define-minor-mode (Bug#6880).
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
96 If non-nil, it should be a variable name (whose value is a keymap), |
c66428d4b9ed
Doc fix for define-minor-mode (Bug#6880).
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
97 a keymap, or a list of arguments for `easy-mmode-define-keymap'. |
c66428d4b9ed
Doc fix for define-minor-mode (Bug#6880).
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
98 If KEYMAP is a keymap or list, this also defines the variable MODE-map. |
33131
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
99 |
109948
c66428d4b9ed
Doc fix for define-minor-mode (Bug#6880).
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
100 BODY contains code to execute each time the mode is enabled or disabled. |
c66428d4b9ed
Doc fix for define-minor-mode (Bug#6880).
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
101 It is executed after toggling the mode, and before running MODE-hook. |
c66428d4b9ed
Doc fix for define-minor-mode (Bug#6880).
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
102 Before the actual body code, you can write keyword arguments, i.e. |
c66428d4b9ed
Doc fix for define-minor-mode (Bug#6880).
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
103 alternating keywords and values. These following special keywords |
c66428d4b9ed
Doc fix for define-minor-mode (Bug#6880).
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
104 are supported (other keywords are passed to `defcustom' if the minor |
c66428d4b9ed
Doc fix for define-minor-mode (Bug#6880).
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
105 mode is global): |
c66428d4b9ed
Doc fix for define-minor-mode (Bug#6880).
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
106 |
47788
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
107 :group GROUP Custom group name to use in all generated `defcustom' forms. |
61318
8c8c06fad8d3
(define-global-minor-mode): Don't use custom-current-group.
Lute Kamstra <lute@gnu.org>
parents:
61175
diff
changeset
|
108 Defaults to MODE without the possible trailing \"-mode\". |
61861
d60a6aee7c8d
(define-minor-mode): Fix docstring.
Lute Kamstra <lute@gnu.org>
parents:
61318
diff
changeset
|
109 Don't use this default group name unless you have written a |
d60a6aee7c8d
(define-minor-mode): Fix docstring.
Lute Kamstra <lute@gnu.org>
parents:
61318
diff
changeset
|
110 `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
|
111 :global GLOBAL If non-nil specifies that the minor mode is not meant to be |
61318
8c8c06fad8d3
(define-global-minor-mode): Don't use custom-current-group.
Lute Kamstra <lute@gnu.org>
parents:
61175
diff
changeset
|
112 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
|
113 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
|
114 :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
|
115 :lighter SPEC Same as the LIGHTER argument. |
51320
418f1ce2a14e
(define-minor-mode): Add edebug spec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50635
diff
changeset
|
116 :keymap MAP Same as the KEYMAP argument. |
47788
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
117 :require SYM Same as in `defcustom'. |
108241
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
118 :variable PLACE The location (as can be used with `setf') to use instead |
108250
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
119 of the variable MODE to store the state of the mode. PLACE |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
120 can also be of the form (GET . SET) where GET is an expression |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
121 that returns the current state and SET is a function that takes |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
122 a new state and sets it. |
47788
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
123 |
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
124 For example, you could write |
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
125 (define-minor-mode foo-mode \"If enabled, foo on you!\" |
50300
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
126 :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
|
127 ...BODY CODE...)" |
51320
418f1ce2a14e
(define-minor-mode): Add edebug spec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50635
diff
changeset
|
128 (declare (debug (&define name stringp |
418f1ce2a14e
(define-minor-mode): Add edebug spec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50635
diff
changeset
|
129 [&optional [¬ keywordp] sexp |
418f1ce2a14e
(define-minor-mode): Add edebug spec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50635
diff
changeset
|
130 &optional [¬ keywordp] sexp |
418f1ce2a14e
(define-minor-mode): Add edebug spec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50635
diff
changeset
|
131 &optional [¬ keywordp] sexp] |
418f1ce2a14e
(define-minor-mode): Add edebug spec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50635
diff
changeset
|
132 [&rest [keywordp sexp]] |
418f1ce2a14e
(define-minor-mode): Add edebug spec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50635
diff
changeset
|
133 def-body))) |
47788
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
134 |
33131
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
135 ;; Allow skipping the first three args. |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
136 (cond |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
137 ((keywordp init-value) |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
138 (setq body (list* init-value lighter keymap body) |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
139 init-value nil lighter nil keymap nil)) |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
140 ((keywordp lighter) |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
141 (setq body (list* lighter keymap body) lighter nil keymap nil)) |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
142 ((keywordp keymap) (push keymap body) (setq keymap nil))) |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
143 |
78860
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
144 (let* ((last-message (make-symbol "last-message")) |
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
145 (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
|
146 (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
|
147 (globalp nil) |
64357
25d7b8b15748
(define-minor-mode): Avoid constructing a defcustom with two :set or
Luc Teirlinck <teirllm@auburn.edu>
parents:
64295
diff
changeset
|
148 (set nil) |
64295
f2e16ba201e0
(define-minor-mode): Do not override explicitly specified :initialize keyword.
Luc Teirlinck <teirllm@auburn.edu>
parents:
64085
diff
changeset
|
149 (initialize nil) |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
150 (group nil) |
64357
25d7b8b15748
(define-minor-mode): Avoid constructing a defcustom with two :set or
Luc Teirlinck <teirllm@auburn.edu>
parents:
64295
diff
changeset
|
151 (type nil) |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
152 (extra-args nil) |
50300
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
153 (extra-keywords nil) |
108250
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
154 (variable nil) ;The PLACE where the state is stored. |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
155 (setter nil) ;The function (if any) to set the mode var. |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
156 (modefun mode) ;The minor mode function name we're defining. |
47463
2b213bd55695
(define-minor-mode): Add a :require arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47043
diff
changeset
|
157 (require t) |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
158 (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
|
159 (hook-on (intern (concat mode-name "-on-hook"))) |
50300
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
160 (hook-off (intern (concat mode-name "-off-hook"))) |
51320
418f1ce2a14e
(define-minor-mode): Add edebug spec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50635
diff
changeset
|
161 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
|
162 |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
163 ;; Check keys. |
50300
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
164 (while (keywordp (setq keyw (car body))) |
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
165 (setq body (cdr body)) |
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
166 (case keyw |
33131
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
167 (:init-value (setq init-value (pop body))) |
105945
503b88c15efc
(define-minor-mode): Purecopy :lighter.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105372
diff
changeset
|
168 (:lighter (setq lighter (purecopy (pop body)))) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
169 (:global (setq globalp (pop body))) |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
170 (:extra-args (setq extra-args (pop body))) |
64357
25d7b8b15748
(define-minor-mode): Avoid constructing a defcustom with two :set or
Luc Teirlinck <teirllm@auburn.edu>
parents:
64295
diff
changeset
|
171 (:set (setq set (list :set (pop body)))) |
64295
f2e16ba201e0
(define-minor-mode): Do not override explicitly specified :initialize keyword.
Luc Teirlinck <teirllm@auburn.edu>
parents:
64085
diff
changeset
|
172 (: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
|
173 (:group (setq group (nconc group (list :group (pop body))))) |
64357
25d7b8b15748
(define-minor-mode): Avoid constructing a defcustom with two :set or
Luc Teirlinck <teirllm@auburn.edu>
parents:
64295
diff
changeset
|
174 (: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
|
175 (:require (setq require (pop body))) |
51320
418f1ce2a14e
(define-minor-mode): Add edebug spec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50635
diff
changeset
|
176 (:keymap (setq keymap (pop body))) |
108250
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
177 (:variable (setq variable (pop body)) |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
178 (if (not (functionp (cdr-safe variable))) |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
179 ;; PLACE is not of the form (GET . SET). |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
180 (setq mode variable) |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
181 (setq mode (car variable)) |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
182 (setq setter (cdr variable)))) |
50300
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
183 (t (push keyw extra-keywords) (push (pop body) extra-keywords)))) |
32999
6bc392d6aef3
(define-minor-mode): Generate `turn-on-MODE' and `turn-off-MODE'
Miles Bader <miles@gnu.org>
parents:
32491
diff
changeset
|
184 |
51320
418f1ce2a14e
(define-minor-mode): Add edebug spec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50635
diff
changeset
|
185 (setq keymap-sym (if (and keymap (symbolp keymap)) keymap |
418f1ce2a14e
(define-minor-mode): Add edebug spec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50635
diff
changeset
|
186 (intern (concat mode-name "-map")))) |
418f1ce2a14e
(define-minor-mode): Add edebug spec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50635
diff
changeset
|
187 |
64357
25d7b8b15748
(define-minor-mode): Avoid constructing a defcustom with two :set or
Luc Teirlinck <teirllm@auburn.edu>
parents:
64295
diff
changeset
|
188 (unless set (setq set '(:set 'custom-set-minor-mode))) |
25d7b8b15748
(define-minor-mode): Avoid constructing a defcustom with two :set or
Luc Teirlinck <teirllm@auburn.edu>
parents:
64295
diff
changeset
|
189 |
64295
f2e16ba201e0
(define-minor-mode): Do not override explicitly specified :initialize keyword.
Luc Teirlinck <teirllm@auburn.edu>
parents:
64085
diff
changeset
|
190 (unless initialize |
64357
25d7b8b15748
(define-minor-mode): Avoid constructing a defcustom with two :set or
Luc Teirlinck <teirllm@auburn.edu>
parents:
64295
diff
changeset
|
191 (setq initialize '(:initialize 'custom-initialize-default))) |
64295
f2e16ba201e0
(define-minor-mode): Do not override explicitly specified :initialize keyword.
Luc Teirlinck <teirllm@auburn.edu>
parents:
64085
diff
changeset
|
192 |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
193 (unless group |
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
194 ;; 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
|
195 (setq group |
61318
8c8c06fad8d3
(define-global-minor-mode): Don't use custom-current-group.
Lute Kamstra <lute@gnu.org>
parents:
61175
diff
changeset
|
196 `(:group ',(intern (replace-regexp-in-string |
8c8c06fad8d3
(define-global-minor-mode): Don't use custom-current-group.
Lute Kamstra <lute@gnu.org>
parents:
61175
diff
changeset
|
197 "-mode\\'" "" mode-name))))) |
62635
a33f6ed6e52e
(define-global-minor-mode): Use `after-change-major-mode-hook' instead
Luc Teirlinck <teirllm@auburn.edu>
parents:
62433
diff
changeset
|
198 |
64357
25d7b8b15748
(define-minor-mode): Avoid constructing a defcustom with two :set or
Luc Teirlinck <teirllm@auburn.edu>
parents:
64295
diff
changeset
|
199 (unless type (setq type '(:type 'boolean))) |
25d7b8b15748
(define-minor-mode): Avoid constructing a defcustom with two :set or
Luc Teirlinck <teirllm@auburn.edu>
parents:
64295
diff
changeset
|
200 |
18388 | 201 `(progn |
25408
68c51b1a537f
(easy-mmode-define-minor-mode):
Karl Heuer <kwzh@gnu.org>
parents:
24935
diff
changeset
|
202 ;; Define the variable to enable or disable the mode. |
108241
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
203 ,(cond |
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
204 ;; If :variable is specified, then the var will be |
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
205 ;; declared elsewhere. |
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
206 (variable nil) |
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
207 ((not globalp) |
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
208 `(progn |
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
209 (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
|
210 Use the command `%s' to change this variable." pretty-name mode)) |
108241
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
211 (make-variable-buffer-local ',mode))) |
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
212 (t |
65094
e1fcf3783add
(define-minor-mode): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64586
diff
changeset
|
213 (let ((base-doc-string |
e1fcf3783add
(define-minor-mode): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64586
diff
changeset
|
214 (concat "Non-nil if %s is enabled. |
77672
6e620a52f54b
(define-minor-mode): Fix generated doc string.
Richard M. Stallman <rms@gnu.org>
parents:
77424
diff
changeset
|
215 See the command `%s' for a description of this minor mode." |
65094
e1fcf3783add
(define-minor-mode): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64586
diff
changeset
|
216 (if body " |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
217 Setting this variable directly does not take effect; |
72587
e2ff121d30ca
(define-minor-mode): Reference manual about customization, rather than
Richard M. Stallman <rms@gnu.org>
parents:
71728
diff
changeset
|
218 either customize it (see the info node `Easy Customization') |
e2ff121d30ca
(define-minor-mode): Reference manual about customization, rather than
Richard M. Stallman <rms@gnu.org>
parents:
71728
diff
changeset
|
219 or call the function `%s'.")))) |
63141
c531a8daedc6
(define-minor-mode): If BODY is empty, give the variable a doc string
Richard M. Stallman <rms@gnu.org>
parents:
63023
diff
changeset
|
220 `(defcustom ,mode ,init-value |
c531a8daedc6
(define-minor-mode): If BODY is empty, give the variable a doc string
Richard M. Stallman <rms@gnu.org>
parents:
63023
diff
changeset
|
221 ,(format base-doc-string pretty-name mode mode) |
64357
25d7b8b15748
(define-minor-mode): Avoid constructing a defcustom with two :set or
Luc Teirlinck <teirllm@auburn.edu>
parents:
64295
diff
changeset
|
222 ,@set |
64295
f2e16ba201e0
(define-minor-mode): Do not override explicitly specified :initialize keyword.
Luc Teirlinck <teirllm@auburn.edu>
parents:
64085
diff
changeset
|
223 ,@initialize |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
224 ,@group |
64357
25d7b8b15748
(define-minor-mode): Avoid constructing a defcustom with two :set or
Luc Teirlinck <teirllm@auburn.edu>
parents:
64295
diff
changeset
|
225 ,@type |
65094
e1fcf3783add
(define-minor-mode): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
64586
diff
changeset
|
226 ,@(unless (eq require t) `(:require ,require)) |
108241
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
227 ,@(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
|
228 |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
229 ;; The actual function. |
108241
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
230 (defun ,modefun (&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
|
231 ,(or doc |
33131
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
232 (format (concat "Toggle %s on or off. |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
233 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
|
234 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
|
235 With zero or negative ARG turn mode off. |
33131
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
236 \\{%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
|
237 ;; 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
|
238 ;; 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
|
239 (interactive (list (or current-prefix-arg 'toggle))) |
78860
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
240 (let ((,last-message (current-message))) |
108250
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
241 (,@(if setter (list setter) |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
242 (list (if (symbolp mode) 'setq 'setf) mode)) |
108241
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
243 (if (eq arg 'toggle) |
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
244 (not ,mode) |
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
245 ;; A nil argument also means ON now. |
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
246 (> (prefix-numeric-value arg) 0))) |
78860
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
247 ,@body |
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
248 ;; The on/off hooks are here for backward compatibility only. |
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
249 (run-hooks ',hook (if ,mode ',hook-on ',hook-off)) |
105371
0769a73f1d18
* image-mode.el (image-toggle-display):
Juanma Barranquero <lekktu@gmail.com>
parents:
104912
diff
changeset
|
250 (if (called-interactively-p 'any) |
78860
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
251 (progn |
108250
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
252 ,(if (and globalp (symbolp mode)) |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
253 `(customize-mark-as-set ',mode)) |
78860
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
254 ;; Avoid overwriting a message shown by the body, |
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
255 ;; but do overwrite previous messages. |
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
256 (unless (and (current-message) |
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
257 (not (equal ,last-message |
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
258 (current-message)))) |
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
259 (message ,(format "%s %%sabled" pretty-name) |
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
260 (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
|
261 (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
|
262 ;; 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
|
263 ,mode) |
51320
418f1ce2a14e
(define-minor-mode): Add edebug spec.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50635
diff
changeset
|
264 |
61318
8c8c06fad8d3
(define-global-minor-mode): Don't use custom-current-group.
Lute Kamstra <lute@gnu.org>
parents:
61175
diff
changeset
|
265 ;; Autoloading a define-minor-mode autoloads everything |
8c8c06fad8d3
(define-global-minor-mode): Don't use custom-current-group.
Lute Kamstra <lute@gnu.org>
parents:
61175
diff
changeset
|
266 ;; 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
|
267 :autoload-end |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
268 |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
269 ;; 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
|
270 ,(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
|
271 `(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
|
272 (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
|
273 (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
|
274 ((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
|
275 (t (error "Invalid keymap %S" ,keymap)))) |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
276 ,(format "Keymap for `%s'." mode-name))) |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
277 |
108250
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
278 ,(if (not (symbolp mode)) |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
279 (if (or lighter keymap) |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
280 (error ":lighter and :keymap unsupported with mode expression %s" mode)) |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
281 `(with-no-warnings |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
282 (add-minor-mode ',mode ',lighter |
108241
731a16c5bb20
Use define-minor-mode for less obvious cases.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108154
diff
changeset
|
283 ,(if keymap keymap-sym |
108250
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
284 `(if (boundp ',keymap-sym) ,keymap-sym)) |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
285 nil |
2fb37c89f2f7
Define auto-save-mode with define-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108241
diff
changeset
|
286 ,(unless (eq mode modefun) 'modefun))))))) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
287 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
288 ;;; |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
289 ;;; make global minor mode |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
290 ;;; |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
291 |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
292 ;;;###autoload |
75643
39dd9f1dfbb0
(define-globalized-minor-mode): Rename from define-global-minor-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
293 (defalias 'easy-mmode-define-global-mode 'define-globalized-minor-mode) |
61175
ef26a481327e
(define-global-minor-mode): Renamed from easy-mmode-define-global-mode.
Richard M. Stallman <rms@gnu.org>
parents:
61168
diff
changeset
|
294 ;;;###autoload |
75643
39dd9f1dfbb0
(define-globalized-minor-mode): Rename from define-global-minor-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
295 (defalias 'define-global-minor-mode 'define-globalized-minor-mode) |
39dd9f1dfbb0
(define-globalized-minor-mode): Rename from define-global-minor-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
296 ;;;###autoload |
39dd9f1dfbb0
(define-globalized-minor-mode): Rename from define-global-minor-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
297 (defmacro define-globalized-minor-mode (global-mode mode turn-on &rest keys) |
74995
5faab2f9dd46
(define-global-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
74306
diff
changeset
|
298 "Make a global mode GLOBAL-MODE corresponding to buffer-local minor MODE. |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
299 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
|
300 and that should try to turn MODE on if applicable for that buffer. |
66721
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
301 KEYS is a list of CL-style keyword arguments. As the minor mode |
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
302 defined by this function is always global, any :global keyword is |
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
303 ignored. Other keywords have the same meaning as in `define-minor-mode', |
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
304 which see. In particular, :group specifies the custom group. |
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
305 The most useful keywords are those that are passed on to the |
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
306 `defcustom'. It normally makes no sense to pass the :lighter |
75643
39dd9f1dfbb0
(define-globalized-minor-mode): Rename from define-global-minor-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
307 or :keymap keywords to `define-globalized-minor-mode', since these |
66721
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
308 are usually passed to the buffer-local version of the minor mode. |
63023
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
309 |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
310 If MODE's set-up depends on the major mode in effect when it was |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
311 enabled, then disabling and reenabling MODE should make MODE work |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
312 correctly with the current major mode. This is important to |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
313 prevent problems with derived modes, that is, major modes that |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
314 call another major mode in their body." |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
315 |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
316 (let* ((global-mode-name (symbol-name global-mode)) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
317 (pretty-name (easy-mmode-pretty-mode-name mode)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
318 (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
|
319 (group nil) |
66721
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
320 (extra-keywords nil) |
63023
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
321 (MODE-buffers (intern (concat global-mode-name "-buffers"))) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
322 (MODE-enable-in-buffers |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
323 (intern (concat global-mode-name "-enable-in-buffers"))) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
324 (MODE-check-buffers |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
325 (intern (concat global-mode-name "-check-buffers"))) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
326 (MODE-cmhh (intern (concat global-mode-name "-cmhh"))) |
66721
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
327 (MODE-major-mode (intern (concat (symbol-name mode) "-major-mode"))) |
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
328 keyw) |
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 ;; Check keys. |
66721
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
331 (while (keywordp (setq keyw (car keys))) |
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
332 (setq keys (cdr keys)) |
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
333 (case keyw |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
334 (:group (setq group (nconc group (list :group (pop keys))))) |
66721
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
335 (:global (setq keys (cdr keys))) |
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
336 (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
|
337 |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
338 (unless group |
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
339 ;; 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
|
340 (setq group |
61318
8c8c06fad8d3
(define-global-minor-mode): Don't use custom-current-group.
Lute Kamstra <lute@gnu.org>
parents:
61175
diff
changeset
|
341 `(:group ',(intern (replace-regexp-in-string |
8c8c06fad8d3
(define-global-minor-mode): Don't use custom-current-group.
Lute Kamstra <lute@gnu.org>
parents:
61175
diff
changeset
|
342 "-mode\\'" "" (symbol-name mode)))))) |
48838
e0689be193e2
(define-minor-mode): Use `custom-current-group'.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
47788
diff
changeset
|
343 |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
344 `(progn |
63023
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
345 (defvar ,MODE-major-mode nil) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
346 (make-variable-buffer-local ',MODE-major-mode) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
347 ;; The actual global minor-mode |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
348 (define-minor-mode ,global-mode |
106708
fecbb2b5a355
emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Make
Eli Zaretskii <eliz@gnu.org>
parents:
105945
diff
changeset
|
349 ;; Very short lines to avoid too long lines in the generated |
fecbb2b5a355
emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Make
Eli Zaretskii <eliz@gnu.org>
parents:
105945
diff
changeset
|
350 ;; doc string. |
77424
d3f723361ea3
(define-globalized-minor-mode): Improve doc string of generated command.
Richard M. Stallman <rms@gnu.org>
parents:
75643
diff
changeset
|
351 ,(format "Toggle %s in every possible buffer. |
106708
fecbb2b5a355
emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Make
Eli Zaretskii <eliz@gnu.org>
parents:
105945
diff
changeset
|
352 With prefix ARG, turn %s on if and only if |
fecbb2b5a355
emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Make
Eli Zaretskii <eliz@gnu.org>
parents:
105945
diff
changeset
|
353 ARG is positive. |
fecbb2b5a355
emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Make
Eli Zaretskii <eliz@gnu.org>
parents:
105945
diff
changeset
|
354 %s is enabled in all buffers where |
fecbb2b5a355
emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Make
Eli Zaretskii <eliz@gnu.org>
parents:
105945
diff
changeset
|
355 \`%s' would do it. |
77424
d3f723361ea3
(define-globalized-minor-mode): Improve doc string of generated command.
Richard M. Stallman <rms@gnu.org>
parents:
75643
diff
changeset
|
356 See `%s' for more information on %s." |
d3f723361ea3
(define-globalized-minor-mode): Improve doc string of generated command.
Richard M. Stallman <rms@gnu.org>
parents:
75643
diff
changeset
|
357 pretty-name pretty-global-name pretty-name turn-on |
d3f723361ea3
(define-globalized-minor-mode): Improve doc string of generated command.
Richard M. Stallman <rms@gnu.org>
parents:
75643
diff
changeset
|
358 mode pretty-name) |
66721
67170e911864
(define-global-minor-mode): Pass all specified keyword args on to
Luc Teirlinck <teirllm@auburn.edu>
parents:
65094
diff
changeset
|
359 :global t ,@group ,@(nreverse extra-keywords) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
360 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
361 ;; 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
|
362 (if ,global-mode |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
363 (progn |
63023
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
364 (add-hook 'after-change-major-mode-hook |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
365 ',MODE-enable-in-buffers) |
108154
cede0252a395
Make it possible to locally disable a globally enabled mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108144
diff
changeset
|
366 (add-hook 'fundamental-mode-hook ',MODE-enable-in-buffers) |
63023
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
367 (add-hook 'find-file-hook ',MODE-check-buffers) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
368 (add-hook 'change-major-mode-hook ',MODE-cmhh)) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
369 (remove-hook 'after-change-major-mode-hook ',MODE-enable-in-buffers) |
108154
cede0252a395
Make it possible to locally disable a globally enabled mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108144
diff
changeset
|
370 (remove-hook 'fundamental-mode-hook ',MODE-enable-in-buffers) |
63023
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
371 (remove-hook 'find-file-hook ',MODE-check-buffers) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
372 (remove-hook 'change-major-mode-hook ',MODE-cmhh)) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
373 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
374 ;; Go through existing buffers. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
375 (dolist (buf (buffer-list)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
376 (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
|
377 (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
|
378 |
75643
39dd9f1dfbb0
(define-globalized-minor-mode): Rename from define-global-minor-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
75346
diff
changeset
|
379 ;; Autoloading define-globalized-minor-mode autoloads everything |
62433
50ff61f0f99d
(define-minor-mode): Don't generate a defcustom for the mode hook variable.
Lute Kamstra <lute@gnu.org>
parents:
62181
diff
changeset
|
380 ;; 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
|
381 :autoload-end |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
382 |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
383 ;; List of buffers left to process. |
63023
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
384 (defvar ,MODE-buffers nil) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
385 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
386 ;; The function that calls TURN-ON in each buffer. |
63023
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
387 (defun ,MODE-enable-in-buffers () |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
388 (dolist (buf ,MODE-buffers) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
389 (when (buffer-live-p buf) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
390 (with-current-buffer buf |
108144
c46b2d0614cb
Let the user turn off locally a globalized minor mode
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107843
diff
changeset
|
391 (unless (eq ,MODE-major-mode major-mode) |
c46b2d0614cb
Let the user turn off locally a globalized minor mode
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107843
diff
changeset
|
392 (if ,mode |
c46b2d0614cb
Let the user turn off locally a globalized minor mode
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107843
diff
changeset
|
393 (progn |
c46b2d0614cb
Let the user turn off locally a globalized minor mode
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107843
diff
changeset
|
394 (,mode -1) |
c46b2d0614cb
Let the user turn off locally a globalized minor mode
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107843
diff
changeset
|
395 (,turn-on) |
c46b2d0614cb
Let the user turn off locally a globalized minor mode
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107843
diff
changeset
|
396 (setq ,MODE-major-mode major-mode)) |
c46b2d0614cb
Let the user turn off locally a globalized minor mode
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107843
diff
changeset
|
397 (,turn-on) |
c46b2d0614cb
Let the user turn off locally a globalized minor mode
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107843
diff
changeset
|
398 (setq ,MODE-major-mode major-mode))))))) |
63023
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
399 (put ',MODE-enable-in-buffers 'definition-name ',global-mode) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
400 |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
401 (defun ,MODE-check-buffers () |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
402 (,MODE-enable-in-buffers) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
403 (setq ,MODE-buffers nil) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
404 (remove-hook 'post-command-hook ',MODE-check-buffers)) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
405 (put ',MODE-check-buffers 'definition-name ',global-mode) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
406 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
407 ;; The function that catches kill-all-local-variables. |
63023
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
408 (defun ,MODE-cmhh () |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
409 (add-to-list ',MODE-buffers (current-buffer)) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
410 (add-hook 'post-command-hook ',MODE-check-buffers)) |
cc9dd228e2e6
(define-global-minor-mode): Make it keep track of which major mode it
Luc Teirlinck <teirllm@auburn.edu>
parents:
62635
diff
changeset
|
411 (put ',MODE-cmhh 'definition-name ',global-mode)))) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
412 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
413 ;;; |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
414 ;;; easy-mmode-defmap |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
415 ;;; |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
416 |
96187
c8bbd45f39e0
(easy-mmode-set-keymap-parents): Evaluate definition when compiling.
Glenn Morris <rgm@gnu.org>
parents:
94655
diff
changeset
|
417 (eval-and-compile |
c8bbd45f39e0
(easy-mmode-set-keymap-parents): Evaluate definition when compiling.
Glenn Morris <rgm@gnu.org>
parents:
94655
diff
changeset
|
418 (if (fboundp 'set-keymap-parents) |
c8bbd45f39e0
(easy-mmode-set-keymap-parents): Evaluate definition when compiling.
Glenn Morris <rgm@gnu.org>
parents:
94655
diff
changeset
|
419 (defalias 'easy-mmode-set-keymap-parents 'set-keymap-parents) |
c8bbd45f39e0
(easy-mmode-set-keymap-parents): Evaluate definition when compiling.
Glenn Morris <rgm@gnu.org>
parents:
94655
diff
changeset
|
420 (defun easy-mmode-set-keymap-parents (m parents) |
c8bbd45f39e0
(easy-mmode-set-keymap-parents): Evaluate definition when compiling.
Glenn Morris <rgm@gnu.org>
parents:
94655
diff
changeset
|
421 (set-keymap-parent |
c8bbd45f39e0
(easy-mmode-set-keymap-parents): Evaluate definition when compiling.
Glenn Morris <rgm@gnu.org>
parents:
94655
diff
changeset
|
422 m |
c8bbd45f39e0
(easy-mmode-set-keymap-parents): Evaluate definition when compiling.
Glenn Morris <rgm@gnu.org>
parents:
94655
diff
changeset
|
423 (cond |
c8bbd45f39e0
(easy-mmode-set-keymap-parents): Evaluate definition when compiling.
Glenn Morris <rgm@gnu.org>
parents:
94655
diff
changeset
|
424 ((not (consp parents)) parents) |
c8bbd45f39e0
(easy-mmode-set-keymap-parents): Evaluate definition when compiling.
Glenn Morris <rgm@gnu.org>
parents:
94655
diff
changeset
|
425 ((not (cdr parents)) (car parents)) |
c8bbd45f39e0
(easy-mmode-set-keymap-parents): Evaluate definition when compiling.
Glenn Morris <rgm@gnu.org>
parents:
94655
diff
changeset
|
426 (t (let ((m (copy-keymap (pop parents)))) |
c8bbd45f39e0
(easy-mmode-set-keymap-parents): Evaluate definition when compiling.
Glenn Morris <rgm@gnu.org>
parents:
94655
diff
changeset
|
427 (easy-mmode-set-keymap-parents m parents) |
c8bbd45f39e0
(easy-mmode-set-keymap-parents): Evaluate definition when compiling.
Glenn Morris <rgm@gnu.org>
parents:
94655
diff
changeset
|
428 m))))))) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
429 |
31981
533a4e5f06e2
(easy-mmode-define-keymap): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30876
diff
changeset
|
430 ;;;###autoload |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
431 (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
|
432 "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
|
433 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
|
434 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
|
435 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
|
436 Optional map M can be used to modify an existing map. |
94317
8f25e59015ea
Tom Tromey <tromey at redhat.com>
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
437 ARGS is a list of additional keyword arguments. |
8f25e59015ea
Tom Tromey <tromey at redhat.com>
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
438 |
8f25e59015ea
Tom Tromey <tromey at redhat.com>
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
439 Valid keywords and arguments are: |
8f25e59015ea
Tom Tromey <tromey at redhat.com>
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
440 |
8f25e59015ea
Tom Tromey <tromey at redhat.com>
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
441 :name Name of the keymap; overrides NAME argument. |
8f25e59015ea
Tom Tromey <tromey at redhat.com>
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
442 :dense Non-nil for a dense keymap. |
8f25e59015ea
Tom Tromey <tromey at redhat.com>
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
443 :inherit Parent keymap. |
8f25e59015ea
Tom Tromey <tromey at redhat.com>
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
444 :group Ignored. |
8f25e59015ea
Tom Tromey <tromey at redhat.com>
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
445 :suppress Non-nil to call `suppress-keymap' on keymap, |
8f25e59015ea
Tom Tromey <tromey at redhat.com>
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
446 'nodigits to suppress digits as prefix arguments." |
8f25e59015ea
Tom Tromey <tromey at redhat.com>
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
447 (let (inherit dense suppress) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
448 (while args |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
449 (let ((key (pop args)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
450 (val (pop args))) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
451 (case key |
33433
e8794ae4f856
(easy-mmode-define-keymap):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33358
diff
changeset
|
452 (:name (setq name val)) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
453 (:dense (setq dense val)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
454 (:inherit (setq inherit val)) |
94317
8f25e59015ea
Tom Tromey <tromey at redhat.com>
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
455 (:suppress (setq suppress val)) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
456 (:group) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
457 (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
|
458 (unless (keymapp m) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
459 (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
|
460 (setq m (if dense (make-keymap name) (make-sparse-keymap name)))) |
94317
8f25e59015ea
Tom Tromey <tromey at redhat.com>
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
461 (when suppress |
8f25e59015ea
Tom Tromey <tromey at redhat.com>
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
462 (suppress-keymap m (eq suppress 'nodigits))) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
463 (dolist (b bs) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
464 (let ((keys (car b)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
465 (binding (cdr b))) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
466 (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
|
467 (cond |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
468 ((symbolp key) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
469 (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
|
470 ((null binding) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
471 (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
|
472 ((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
|
473 (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
|
474 (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
|
475 (cond |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
476 ((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
|
477 ((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
|
478 m)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
479 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
480 ;;;###autoload |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
481 (defmacro easy-mmode-defmap (m bs doc &rest args) |
104912
ad1f780103d9
(easy-mmode-defmap): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents:
104732
diff
changeset
|
482 "Define a constant M whose value is the result of `easy-mmode-define-keymap'. |
ad1f780103d9
(easy-mmode-defmap): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents:
104732
diff
changeset
|
483 The M, BS, and ARGS arguments are as per that function. DOC is |
ad1f780103d9
(easy-mmode-defmap): Add doc-string.
Glenn Morris <rgm@gnu.org>
parents:
104732
diff
changeset
|
484 the constant's documentation." |
31981
533a4e5f06e2
(easy-mmode-define-keymap): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30876
diff
changeset
|
485 `(defconst ,m |
533a4e5f06e2
(easy-mmode-define-keymap): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30876
diff
changeset
|
486 (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
|
487 ,doc)) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
488 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
489 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
490 ;;; |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
491 ;;; easy-mmode-defsyntax |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
492 ;;; |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
493 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
494 (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
|
495 (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
|
496 (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
|
497 (dolist (cs css) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
498 (let ((char (car cs)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
499 (syntax (cdr cs))) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
500 (if (sequencep char) |
84897
992e87082552
(easy-mmode-define-syntax): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78217
diff
changeset
|
501 (mapc (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
|
502 (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
|
503 (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
|
504 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
|
505 st)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
506 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
507 ;;;###autoload |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
508 (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
|
509 "Define variable ST as a syntax-table. |
37406
3886350a8826
(easy-mmode-defsyntax): Unquote `doc'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35562
diff
changeset
|
510 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
|
511 `(progn |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
512 (autoload 'easy-mmode-define-syntax "easy-mmode") |
37406
3886350a8826
(easy-mmode-defsyntax): Unquote `doc'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35562
diff
changeset
|
513 (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
|
514 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
515 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
516 |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
517 ;;; |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
518 ;;; easy-mmode-define-navigation |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
519 ;;; |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
520 |
85463
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
521 (defmacro easy-mmode-define-navigation (base re &optional name endfun narrowfun |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
522 &rest body) |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
523 "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
|
524 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
|
525 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
|
526 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
|
527 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
|
528 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
|
529 the next entry) and recentering if necessary. |
53056
a9d324df91c7
(easy-mmode-define-navigation): Take additional
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52881
diff
changeset
|
530 ENDFUN should return the end position (with or without moving point). |
a9d324df91c7
(easy-mmode-define-navigation): Take additional
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52881
diff
changeset
|
531 NARROWFUN non-nil means to check for narrowing before moving, and if |
85463
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
532 found, do `widen' first and then call NARROWFUN with no args after moving. |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
533 BODY is executed after moving to the destination location." |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
534 (declare (indent 5) (debug (exp exp exp def-form def-form &rest def-body))) |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
535 (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
|
536 (prev-sym (intern (concat base-name "-prev"))) |
53056
a9d324df91c7
(easy-mmode-define-navigation): Take additional
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52881
diff
changeset
|
537 (next-sym (intern (concat base-name "-next"))) |
85463
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
538 (when-narrowed |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
539 (lambda (body) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
540 (if (null narrowfun) body |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
541 `(let ((was-narrowed |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
542 (prog1 (or (< (- (point-max) (point-min)) (buffer-size))) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
543 (widen)))) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
544 ,body |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
545 (when was-narrowed (,narrowfun))))))) |
51643
3161ec452b93
(easy-mmode-define-navigation): Avoid
Andreas Schwab <schwab@suse.de>
parents:
51320
diff
changeset
|
546 (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
|
547 `(progn |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
548 (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
|
549 ,(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
|
550 (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
|
551 ,(format "Go to the next COUNT'th %s." name) |
74306
e6443f563ae7
(easy-mmode-define-navigation): Fix interactive spec of the functions
Chong Yidong <cyd@stupidchicken.com>
parents:
72587
diff
changeset
|
552 (interactive "p") |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
553 (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
|
554 (if (< count 0) (,prev-sym (- count)) |
52881
a2ef3d8f83d4
(easy-mmode-define-navigation): Avoid
Dave Love <fx@gnu.org>
parents:
52401
diff
changeset
|
555 (if (looking-at ,re) (setq count (1+ count))) |
85463
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
556 ,(funcall when-narrowed |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
557 `(if (not (re-search-forward ,re nil t count)) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
558 (if (looking-at ,re) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
559 (goto-char (or ,(if endfun `(,endfun)) (point-max))) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
560 (error "No next %s" ,name)) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
561 (goto-char (match-beginning 0)) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
562 (when (and (eq (current-buffer) (window-buffer (selected-window))) |
105372
bd2966850aac
Use `called-interactively-p' instead of `interactive-p'.
Juanma Barranquero <lekktu@gmail.com>
parents:
105371
diff
changeset
|
563 (called-interactively-p 'interactive)) |
85463
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
564 (let ((endpt (or (save-excursion |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
565 ,(if endfun `(,endfun) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
566 `(re-search-forward ,re nil t 2))) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
567 (point-max)))) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
568 (unless (pos-visible-in-window-p endpt nil t) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
569 (recenter '(0))))))) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
570 ,@body)) |
67293
32fa638322e0
(easy-mmode-define-navigation): Put `definition-name' properties on the
Juri Linkov <juri@jurta.org>
parents:
66721
diff
changeset
|
571 (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
|
572 (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
|
573 ,(format "Go to the previous COUNT'th %s" (or name base-name)) |
74306
e6443f563ae7
(easy-mmode-define-navigation): Fix interactive spec of the functions
Chong Yidong <cyd@stupidchicken.com>
parents:
72587
diff
changeset
|
574 (interactive "p") |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
575 (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
|
576 (if (< count 0) (,next-sym (- count)) |
85463
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
577 ,(funcall when-narrowed |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
578 `(unless (re-search-backward ,re nil t count) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
579 (error "No previous %s" ,name))) |
771c063a16df
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85114
diff
changeset
|
580 ,@body)) |
67293
32fa638322e0
(easy-mmode-define-navigation): Put `definition-name' properties on the
Juri Linkov <juri@jurta.org>
parents:
66721
diff
changeset
|
581 (put ',prev-sym 'definition-name ',base)))) |
53056
a9d324df91c7
(easy-mmode-define-navigation): Take additional
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52881
diff
changeset
|
582 |
28086
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
583 |
18388 | 584 (provide 'easy-mmode) |
585 | |
78860
03a3e0a6776c
(define-minor-mode): Fix staging brain damage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
586 ;; arch-tag: d48a5250-6961-4528-9cb0-3c9ea042a66a |
18388 | 587 ;;; easy-mmode.el ends here |