Mercurial > emacs
annotate lisp/emacs-lisp/easy-mmode.el @ 50833:c25ad03e3598
*** empty log message ***
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 06 May 2003 02:50:01 +0000 |
parents | e0775ee7f599 |
children | 418f1ce2a14e |
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 |
38761 | 3 ;; Copyright (C) 1997, 2000, 2001 Free Software Foundation, Inc. |
18388 | 4 |
38455 | 5 ;; Author: Georges Brun-Cottan <Georges.Brun-Cottan@inria.fr> |
6 ;; Maintainer: Stefan Monnier <monnier@gnu.org> | |
7 | |
8 ;; Keywords: extensions lisp | |
18388 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
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 ;; <mode>-hook : The hook run at the end of the toggle function. |
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
39 ;; see `define-minor-mode' documentation |
18388 | 40 ;; |
41 ;; eval | |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
42 ;; (pp (macroexpand '(define-minor-mode <your-mode> <doc>))) |
18388 | 43 ;; to check the result before using it. |
44 | |
45 ;; The order in which minor modes are installed is important. Keymap | |
46 ;; lookup proceeds down minor-mode-map-alist, and the order there | |
47 ;; tends to be the reverse of the order in which the modes were | |
48 ;; installed. Perhaps there should be a feature to let you specify | |
49 ;; orderings. | |
50 | |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
51 ;; Additionally to `define-minor-mode', the package provides convenient |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
52 ;; ways to define keymaps, and other helper functions for major and minor modes. |
18388 | 53 |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
54 ;;; Code: |
18388 | 55 |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
56 (eval-when-compile (require 'cl)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
57 |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
58 (defun easy-mmode-pretty-mode-name (mode &optional lighter) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
59 "Turn the symbol MODE into a string intended for the user. |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
60 If provided LIGHTER will be used to help choose capitalization." |
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) |
32048
39617f078b9d
(easy-mmode-pretty-mode-name): Prettier.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31981
diff
changeset
|
62 (name (concat (replace-regexp-in-string |
39617f078b9d
(easy-mmode-pretty-mode-name): Prettier.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31981
diff
changeset
|
63 "-Minor" " minor" |
39617f078b9d
(easy-mmode-pretty-mode-name): Prettier.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31981
diff
changeset
|
64 (capitalize (replace-regexp-in-string |
39617f078b9d
(easy-mmode-pretty-mode-name): Prettier.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31981
diff
changeset
|
65 "-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
|
66 " mode"))) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
67 (if (not (stringp lighter)) name |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
68 (setq lighter (replace-regexp-in-string "\\`\\s-+\\|\\-s+\\'" "" lighter)) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
69 (replace-regexp-in-string lighter lighter name t t)))) |
29399
addeae19bf96
(easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29039
diff
changeset
|
70 |
18388 | 71 ;;;###autoload |
26551
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
72 (defalias 'easy-mmode-define-minor-mode 'define-minor-mode) |
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
73 ;;;###autoload |
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
74 (defmacro define-minor-mode (mode doc &optional init-value lighter keymap &rest body) |
18388 | 75 "Define a new minor mode MODE. |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
76 This function defines the associated control variable MODE, keymap MODE-map, |
33131
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
77 toggle command MODE, and hook MODE-hook. |
18388 | 78 |
79 DOC is the documentation for the mode toggle command. | |
26551
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
80 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
|
81 Optional LIGHTER is displayed in the modeline when the mode is on. |
18388 | 82 Optional KEYMAP is the default (defvar) keymap bound to the mode keymap. |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
83 If it is a list, it is passed to `easy-mmode-define-keymap' |
33131
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
84 in order to build a valid keymap. It's generally better to use |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
85 a separate MODE-map variable than to use this argument. |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
86 The above three arguments can be skipped if keyword arguments are |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
87 used (see below). |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
88 |
26551
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
89 BODY contains code that will be executed each time the mode is (dis)activated. |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
90 It will be executed after any toggling but before running the hooks. |
47788
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
91 Before the actual body code, you can write |
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
92 keyword arguments (alternating keywords and values). |
50300
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
93 These following keyword arguments are supported (other keywords |
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
94 will be passed to `defcustom' if the minor mode is global): |
47788
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
95 :group GROUP Custom group name to use in all generated `defcustom' forms. |
47463
2b213bd55695
(define-minor-mode): Add a :require arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47043
diff
changeset
|
96 :global GLOBAL If non-nil specifies that the minor mode is not meant to be |
47788
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
97 buffer-local, so don't make the variable MODE buffer-local. |
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
98 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
|
99 :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
|
100 :lighter SPEC Same as the LIGHTER argument. |
47788
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
101 :require SYM Same as in `defcustom'. |
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
102 |
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
103 For example, you could write |
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
104 (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
|
105 :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
|
106 ...BODY CODE...)" |
1174e4c84d58
(define-minor-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
47657
diff
changeset
|
107 |
33131
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
108 ;; Allow skipping the first three args. |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
109 (cond |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
110 ((keywordp init-value) |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
111 (setq body (list* init-value lighter keymap body) |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
112 init-value nil lighter nil keymap nil)) |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
113 ((keywordp lighter) |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
114 (setq body (list* lighter keymap body) lighter nil keymap nil)) |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
115 ((keywordp keymap) (push keymap body) (setq keymap nil))) |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
116 |
18388 | 117 (let* ((mode-name (symbol-name mode)) |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
118 (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
|
119 (globalp nil) |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
120 (group nil) |
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
121 (extra-args nil) |
50300
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
122 (extra-keywords nil) |
47463
2b213bd55695
(define-minor-mode): Add a :require arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47043
diff
changeset
|
123 (require t) |
29548
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
124 (keymap-sym (if (and keymap (symbolp keymap)) keymap |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
125 (intern (concat mode-name "-map")))) |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
126 (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
|
127 (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
|
128 (hook-off (intern (concat mode-name "-off-hook"))) |
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
129 keyw) |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
130 |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
131 ;; Check keys. |
50300
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
132 (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
|
133 (setq body (cdr body)) |
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
134 (case keyw |
33131
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
135 (:init-value (setq init-value (pop body))) |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
136 (:lighter (setq lighter (pop body))) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
137 (:global (setq globalp (pop body))) |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
138 (:extra-args (setq extra-args (pop body))) |
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
139 (:group (setq group (nconc group (list :group (pop body))))) |
47463
2b213bd55695
(define-minor-mode): Add a :require arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47043
diff
changeset
|
140 (:require (setq require (pop body))) |
50300
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
141 (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
|
142 |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
143 (unless group |
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
144 ;; 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
|
145 (setq group |
48838
e0689be193e2
(define-minor-mode): Use `custom-current-group'.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
47788
diff
changeset
|
146 `(:group ',(or (custom-current-group) |
e0689be193e2
(define-minor-mode): Use `custom-current-group'.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
47788
diff
changeset
|
147 (intern (replace-regexp-in-string |
e0689be193e2
(define-minor-mode): Use `custom-current-group'.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
47788
diff
changeset
|
148 "-mode\\'" "" mode-name)))))) |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
149 |
18388 | 150 `(progn |
25408
68c51b1a537f
(easy-mmode-define-minor-mode):
Karl Heuer <kwzh@gnu.org>
parents:
24935
diff
changeset
|
151 ;; Define the variable to enable or disable the mode. |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
152 ,(if (not globalp) |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
153 `(progn |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
154 (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
|
155 Use the command `%s' to change this variable." pretty-name mode)) |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
156 (make-variable-buffer-local ',mode)) |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
157 |
29548
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
158 (let ((curfile (or (and (boundp 'byte-compile-current-file) |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
159 byte-compile-current-file) |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
160 load-file-name))) |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
161 `(defcustom ,mode ,init-value |
35562
6b8b7796f28b
(define-minor-mode): Docstring fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
34149
diff
changeset
|
162 ,(format "Non-nil if %s is enabled. |
33131
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
163 See the command `%s' for a description of this minor-mode. |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
164 Setting this variable directly does not take effect; |
29399
addeae19bf96
(easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29039
diff
changeset
|
165 use either \\[customize] or the function `%s'." |
33131
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
166 pretty-name mode mode) |
50300
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
167 :set 'custom-set-minor-mode |
29548
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
168 :initialize 'custom-initialize-default |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
169 ,@group |
29548
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
170 :type 'boolean |
47463
2b213bd55695
(define-minor-mode): Add a :require arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47043
diff
changeset
|
171 ,@(cond |
2b213bd55695
(define-minor-mode): Add a :require arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47043
diff
changeset
|
172 ((not (and curfile require)) nil) |
2b213bd55695
(define-minor-mode): Add a :require arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47043
diff
changeset
|
173 ((not (eq require t)) `(:require ,require)) |
2b213bd55695
(define-minor-mode): Add a :require arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47043
diff
changeset
|
174 (t `(:require |
2b213bd55695
(define-minor-mode): Add a :require arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47043
diff
changeset
|
175 ',(intern (file-name-nondirectory |
50300
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
176 (file-name-sans-extension curfile)))))) |
7e4e15b857f3
(define-minor-mode): Use custom-set-minor-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49598
diff
changeset
|
177 ,@(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
|
178 |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
179 ;; The actual function. |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
180 (defun ,mode (&optional arg ,@extra-args) |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
181 ,(or doc |
33131
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
182 (format (concat "Toggle %s on or off. |
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
183 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
|
184 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
|
185 With zero or negative ARG turn mode off. |
33131
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
186 \\{%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
|
187 ;; 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
|
188 ;; 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
|
189 (interactive (list (or current-prefix-arg 'toggle))) |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
190 (setq ,mode |
46900
3c3d686b25fa
(easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46873
diff
changeset
|
191 (cond |
3c3d686b25fa
(easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46873
diff
changeset
|
192 ((eq arg 'toggle) (not ,mode)) |
3c3d686b25fa
(easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46873
diff
changeset
|
193 (arg (> (prefix-numeric-value arg) 0)) |
3c3d686b25fa
(easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46873
diff
changeset
|
194 (t |
3c3d686b25fa
(easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46873
diff
changeset
|
195 (if (null ,mode) t |
3c3d686b25fa
(easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46873
diff
changeset
|
196 (message |
3c3d686b25fa
(easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46873
diff
changeset
|
197 "Toggling %s off; better pass an explicit argument." |
3c3d686b25fa
(easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46873
diff
changeset
|
198 ',mode) |
3c3d686b25fa
(easy-mmode-define-global-mode): Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46873
diff
changeset
|
199 nil)))) |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
200 ,@body |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
201 ;; The on/off hooks are here for backward compatibility only. |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
202 (run-hooks ',hook (if ,mode ',hook-on ',hook-off)) |
47043
360c6fcdde04
(define-minor-mode): Use customize-mark-as-set for global minor modes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46900
diff
changeset
|
203 (if (interactive-p) |
360c6fcdde04
(define-minor-mode): Use customize-mark-as-set for global minor modes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46900
diff
changeset
|
204 (progn |
360c6fcdde04
(define-minor-mode): Use customize-mark-as-set for global minor modes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46900
diff
changeset
|
205 ,(if globalp `(customize-mark-as-set ',mode)) |
50635
e0775ee7f599
(define-minor-mode): Only echo a message if the body didn't do so already.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50300
diff
changeset
|
206 (unless (current-message) |
47043
360c6fcdde04
(define-minor-mode): Use customize-mark-as-set for global minor modes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
46900
diff
changeset
|
207 (message ,(format "%s %%sabled" pretty-name) |
50635
e0775ee7f599
(define-minor-mode): Only echo a message if the body didn't do so already.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50300
diff
changeset
|
208 (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
|
209 (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
|
210 ;; 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
|
211 ,mode) |
29548
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
212 ;; Autoloading an easy-mmode-define-minor-mode autoloads |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
213 ;; everything up-to-here. |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
214 :autoload-end |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
215 |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
216 ;; The toggle's hook. |
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
217 (defcustom ,hook nil |
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
218 ,(format "Hook run at the end of function `%s'." mode-name) |
48838
e0689be193e2
(define-minor-mode): Use `custom-current-group'.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
47788
diff
changeset
|
219 ,@group |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
220 :type 'hook) |
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
221 |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
222 ;; 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
|
223 ,(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
|
224 `(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
|
225 (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
|
226 (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
|
227 ((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
|
228 (t (error "Invalid keymap %S" ,keymap)))) |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
229 ,(format "Keymap for `%s'." mode-name))) |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
230 |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
231 (add-minor-mode ',mode ',lighter |
29548
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
232 ,(if keymap keymap-sym |
30876
76bba9fc3c22
(define-minor-mode): Use `symbol-value' to keep the byte-compiler quiet.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29548
diff
changeset
|
233 `(if (boundp ',keymap-sym) |
76bba9fc3c22
(define-minor-mode): Use `symbol-value' to keep the byte-compiler quiet.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29548
diff
changeset
|
234 (symbol-value ',keymap-sym)))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48838
diff
changeset
|
235 |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
236 ;; If the mode is global, call the function according to the default. |
47657
e8df9e898436
(define-minor-mode): Don't add properties
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47463
diff
changeset
|
237 ,(if globalp |
e8df9e898436
(define-minor-mode): Don't add properties
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47463
diff
changeset
|
238 `(if (and load-file-name (not (equal ,init-value ,mode))) |
e8df9e898436
(define-minor-mode): Don't add properties
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47463
diff
changeset
|
239 (eval-after-load load-file-name '(,mode (if ,mode 1 -1)))))))) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
240 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
241 ;;; |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
242 ;;; make global minor mode |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
243 ;;; |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
244 |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
245 ;;;###autoload |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
246 (defmacro easy-mmode-define-global-mode (global-mode mode turn-on |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
247 &rest keys) |
33131
8d1ed5c84809
(define-minor-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33001
diff
changeset
|
248 "Make GLOBAL-MODE out of the buffer-local minor MODE. |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
249 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
|
250 and that should try to turn MODE on if applicable for that buffer. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
251 KEYS is a list of CL-style keyword arguments: |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
252 :group to specify the custom group." |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
253 (let* ((global-mode-name (symbol-name global-mode)) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
254 (pretty-name (easy-mmode-pretty-mode-name mode)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
255 (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
|
256 (group nil) |
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
257 (extra-args nil) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
258 (buffers (intern (concat global-mode-name "-buffers"))) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
259 (cmmh (intern (concat global-mode-name "-cmmh")))) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
260 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
261 ;; Check keys. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
262 (while (keywordp (car keys)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
263 (case (pop keys) |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
264 (:extra-args (setq extra-args (pop keys))) |
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
265 (:group (setq group (nconc group (list :group (pop keys))))) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
266 (t (setq keys (cdr keys))))) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
267 |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
268 (unless group |
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
269 ;; 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
|
270 (setq group |
48838
e0689be193e2
(define-minor-mode): Use `custom-current-group'.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
47788
diff
changeset
|
271 `(:group ',(or (custom-current-group) |
e0689be193e2
(define-minor-mode): Use `custom-current-group'.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
47788
diff
changeset
|
272 (intern (replace-regexp-in-string |
e0689be193e2
(define-minor-mode): Use `custom-current-group'.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
47788
diff
changeset
|
273 "-mode\\'" "" (symbol-name mode))))))) |
e0689be193e2
(define-minor-mode): Use `custom-current-group'.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
47788
diff
changeset
|
274 |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
275 `(progn |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
276 ;; The actual global minor-mode |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
277 (define-minor-mode ,global-mode |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
278 ,(format "Toggle %s in every buffer. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
279 With prefix ARG, turn %s on if and only if ARG is positive. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
280 %s is actually not turned on in every buffer but only in those |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
281 in which `%s' turns it on." |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
282 pretty-name pretty-global-name pretty-name turn-on) |
33162
ccf6cd7d4512
(define-minor-mode): Remove :toggle arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33131
diff
changeset
|
283 :global t :extra-args ,extra-args ,@group |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
284 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
285 ;; 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
|
286 (if ,global-mode |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
287 (progn |
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
|
288 (add-hook 'find-file-hook ',buffers) |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
289 (add-hook 'change-major-mode-hook ',cmmh)) |
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
|
290 (remove-hook 'find-file-hook ',buffers) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
291 (remove-hook 'change-major-mode-hook ',cmmh)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
292 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
293 ;; Go through existing buffers. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
294 (dolist (buf (buffer-list)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
295 (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
|
296 (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
|
297 |
29548
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
298 ;; Autoloading easy-mmode-define-global-mode |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
299 ;; autoloads everything up-to-here. |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
300 :autoload-end |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
301 |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
302 ;; List of buffers left to process. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
303 (defvar ,buffers nil) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
304 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
305 ;; The function that calls TURN-ON in each buffer. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
306 (defun ,buffers () |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
307 (remove-hook 'post-command-hook ',buffers) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
308 (while ,buffers |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
309 (let ((buf (pop ,buffers))) |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
310 (when (buffer-live-p buf) |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
311 (with-current-buffer buf (,turn-on)))))) |
46873
7be80f782e2c
(easy-mmode-define-global-mode): Put `definition-name' properties on
Richard M. Stallman <rms@gnu.org>
parents:
43709
diff
changeset
|
312 (put ',buffers 'definition-name ',global-mode) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
313 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
314 ;; The function that catches kill-all-local-variables. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
315 (defun ,cmmh () |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
316 (add-to-list ',buffers (current-buffer)) |
46873
7be80f782e2c
(easy-mmode-define-global-mode): Put `definition-name' properties on
Richard M. Stallman <rms@gnu.org>
parents:
43709
diff
changeset
|
317 (add-hook 'post-command-hook ',buffers)) |
7be80f782e2c
(easy-mmode-define-global-mode): Put `definition-name' properties on
Richard M. Stallman <rms@gnu.org>
parents:
43709
diff
changeset
|
318 (put ',cmmh 'definition-name ',global-mode)))) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
319 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
320 ;;; |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
321 ;;; easy-mmode-defmap |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
322 ;;; |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
323 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
324 (if (fboundp 'set-keymap-parents) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
325 (defalias 'easy-mmode-set-keymap-parents 'set-keymap-parents) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
326 (defun easy-mmode-set-keymap-parents (m parents) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
327 (set-keymap-parent |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
328 m |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
329 (cond |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
330 ((not (consp parents)) parents) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
331 ((not (cdr parents)) (car parents)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
332 (t (let ((m (copy-keymap (pop parents)))) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
333 (easy-mmode-set-keymap-parents m parents) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
334 m)))))) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
335 |
31981
533a4e5f06e2
(easy-mmode-define-keymap): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30876
diff
changeset
|
336 ;;;###autoload |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
337 (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
|
338 "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
|
339 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
|
340 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
|
341 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
|
342 Optional map M can be used to modify an existing map. |
33433
e8794ae4f856
(easy-mmode-define-keymap):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33358
diff
changeset
|
343 ARGS is a list of additional keyword arguments." |
50635
e0775ee7f599
(define-minor-mode): Only echo a message if the body didn't do so already.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50300
diff
changeset
|
344 (let (inherit dense) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
345 (while args |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
346 (let ((key (pop args)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
347 (val (pop args))) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
348 (case key |
33433
e8794ae4f856
(easy-mmode-define-keymap):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33358
diff
changeset
|
349 (:name (setq name val)) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
350 (:dense (setq dense val)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
351 (:inherit (setq inherit val)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
352 (:group) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
353 (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
|
354 (unless (keymapp m) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
355 (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
|
356 (setq m (if dense (make-keymap name) (make-sparse-keymap name)))) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
357 (dolist (b bs) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
358 (let ((keys (car b)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
359 (binding (cdr b))) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
360 (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
|
361 (cond |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
362 ((symbolp key) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
363 (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
|
364 ((null binding) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
365 (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
|
366 ((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
|
367 (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
|
368 (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
|
369 (cond |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
370 ((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
|
371 ((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
|
372 m)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
373 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
374 ;;;###autoload |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
375 (defmacro easy-mmode-defmap (m bs doc &rest args) |
31981
533a4e5f06e2
(easy-mmode-define-keymap): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30876
diff
changeset
|
376 `(defconst ,m |
533a4e5f06e2
(easy-mmode-define-keymap): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30876
diff
changeset
|
377 (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
|
378 ,doc)) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
379 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
380 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
381 ;;; |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
382 ;;; easy-mmode-defsyntax |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
383 ;;; |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
384 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
385 (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
|
386 (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
|
387 (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
|
388 (dolist (cs css) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
389 (let ((char (car cs)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
390 (syntax (cdr cs))) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
391 (if (sequencep char) |
28086
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
392 (mapcar (lambda (c) (modify-syntax-entry c syntax st)) char) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
393 (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
|
394 (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
|
395 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
|
396 st)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
397 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
398 ;;;###autoload |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
399 (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
|
400 "Define variable ST as a syntax-table. |
37406
3886350a8826
(easy-mmode-defsyntax): Unquote `doc'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35562
diff
changeset
|
401 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
|
402 `(progn |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
403 (autoload 'easy-mmode-define-syntax "easy-mmode") |
37406
3886350a8826
(easy-mmode-defsyntax): Unquote `doc'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35562
diff
changeset
|
404 (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
|
405 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
406 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
407 |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
408 ;;; |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
409 ;;; easy-mmode-define-navigation |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
410 ;;; |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
411 |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
412 (defmacro easy-mmode-define-navigation (base re &optional name endfun) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
413 "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
|
414 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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 the next entry) and recentering if necessary. |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
420 ENDFUN should return the end position (with or without moving point)." |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
421 (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
|
422 (prev-sym (intern (concat base-name "-prev"))) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
423 (next-sym (intern (concat base-name "-next")))) |
28239
21cd65af5197
(easy-mmode-define-navigation): Only use `ding' for interactive use
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28235
diff
changeset
|
424 (unless name (setq name (symbol-name base-name))) |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
425 `(progn |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
426 (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
|
427 ,(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
|
428 (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
|
429 ,(format "Go to the next COUNT'th %s." name) |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
430 (interactive) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
431 (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
|
432 (if (< count 0) (,prev-sym (- count)) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
433 (if (looking-at ,re) (incf count)) |
33358
a86c95343fa5
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33165
diff
changeset
|
434 (if (not (re-search-forward ,re nil t count)) |
a86c95343fa5
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33165
diff
changeset
|
435 (if (looking-at ,re) |
a86c95343fa5
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33165
diff
changeset
|
436 (goto-char (or ,(if endfun `(,endfun)) (point-max))) |
a86c95343fa5
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33165
diff
changeset
|
437 (error ,(format "No next %s" name))) |
a86c95343fa5
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33165
diff
changeset
|
438 (goto-char (match-beginning 0)) |
38324
ce45998cedf2
(define-minor-mode): Use eval-after-load
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37406
diff
changeset
|
439 (when (and (eq (current-buffer) (window-buffer (selected-window))) |
ce45998cedf2
(define-minor-mode): Use eval-after-load
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37406
diff
changeset
|
440 (interactive-p)) |
33358
a86c95343fa5
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33165
diff
changeset
|
441 (let ((endpt (or (save-excursion |
a86c95343fa5
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33165
diff
changeset
|
442 ,(if endfun `(,endfun) |
a86c95343fa5
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33165
diff
changeset
|
443 `(re-search-forward ,re nil t 2))) |
a86c95343fa5
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33165
diff
changeset
|
444 (point-max)))) |
a86c95343fa5
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33165
diff
changeset
|
445 (unless (pos-visible-in-window-p endpt nil t) |
a86c95343fa5
(easy-mmode-define-navigation):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33165
diff
changeset
|
446 (recenter '(0)))))))) |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
447 (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
|
448 ,(format "Go to the previous COUNT'th %s" (or name base-name)) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
449 (interactive) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
450 (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
|
451 (if (< count 0) (,next-sym (- count)) |
28239
21cd65af5197
(easy-mmode-define-navigation): Only use `ding' for interactive use
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28235
diff
changeset
|
452 (unless (re-search-backward ,re nil t count) |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
453 (error ,(format "No previous %s" name)))))))) |
28086
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
454 |
18388 | 455 (provide 'easy-mmode) |
456 | |
457 ;;; easy-mmode.el ends here |