Mercurial > emacs
annotate lisp/emacs-lisp/easy-mmode.el @ 32649:47bf921bccd5
(frame-set-background-mode): `unspecified' &c are symbols, not strings.
author | Miles Bader <miles@gnu.org> |
---|---|
date | Thu, 19 Oct 2000 08:36:13 +0000 |
parents | 2fc546f941df |
children | 6bc392d6aef3 |
rev | line source |
---|---|
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
1 ;;; easy-mmode.el --- easy definition for major and minor modes. |
18388 | 2 |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
3 ;; Copyright (C) 1997,2000 Free Software Foundation, Inc. |
18388 | 4 |
5 ;; Author: Georges Brun-Cottan <Georges.Brun-Cottan@inria.fr> | |
26551
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
6 ;; Maintainer: Stefan Monnier <monnier@gnu.org> |
18388 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; Minor modes are useful and common. This package makes defining a | |
28 ;; minor mode easy, by focusing on the writing of the minor mode | |
29 ;; functionalities themselves. Moreover, this package enforces a | |
30 ;; conventional naming of user interface primitives, making things | |
31 ;; natural for the minor-mode end-users. | |
32 | |
33 ;; For each mode, easy-mmode defines the following: | |
34 ;; <mode> : The minor mode predicate. A buffer-local variable. | |
35 ;; <mode>-map : The keymap possibly associated to <mode>. | |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
36 ;; <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
|
37 ;; see `define-minor-mode' documentation |
18388 | 38 ;; |
39 ;; eval | |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
40 ;; (pp (macroexpand '(define-minor-mode <your-mode> <doc>))) |
18388 | 41 ;; to check the result before using it. |
42 | |
43 ;; The order in which minor modes are installed is important. Keymap | |
44 ;; lookup proceeds down minor-mode-map-alist, and the order there | |
45 ;; tends to be the reverse of the order in which the modes were | |
46 ;; installed. Perhaps there should be a feature to let you specify | |
47 ;; orderings. | |
48 | |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
49 ;; 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
|
50 ;; ways to define keymaps, and other helper functions for major and minor modes. |
18388 | 51 |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
52 ;;; Code: |
18388 | 53 |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
54 (eval-when-compile (require 'cl)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
55 |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
56 (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
|
57 "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
|
58 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
|
59 (let* ((case-fold-search t) |
32048
39617f078b9d
(easy-mmode-pretty-mode-name): Prettier.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31981
diff
changeset
|
60 (name (concat (replace-regexp-in-string |
39617f078b9d
(easy-mmode-pretty-mode-name): Prettier.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31981
diff
changeset
|
61 "-Minor" " minor" |
39617f078b9d
(easy-mmode-pretty-mode-name): Prettier.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31981
diff
changeset
|
62 (capitalize (replace-regexp-in-string |
39617f078b9d
(easy-mmode-pretty-mode-name): Prettier.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31981
diff
changeset
|
63 "-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
|
64 " mode"))) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
65 (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
|
66 (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
|
67 (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
|
68 |
18388 | 69 ;;;###autoload |
26551
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
70 (defalias 'easy-mmode-define-minor-mode 'define-minor-mode) |
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
71 ;;;###autoload |
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
72 (defmacro define-minor-mode (mode doc &optional init-value lighter keymap &rest body) |
18388 | 73 "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
|
74 This function defines the associated control variable MODE, keymap MODE-map, |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
75 toggle command MODE, and hook MODE-hook. |
18388 | 76 |
77 DOC is the documentation for the mode toggle command. | |
26551
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
78 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
|
79 Optional LIGHTER is displayed in the modeline when the mode is on. |
18388 | 80 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
|
81 If it is a list, it is passed to `easy-mmode-define-keymap' |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
82 in order to build a valid keymap. |
26551
271f77895660
Changed maintainer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25408
diff
changeset
|
83 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
|
84 It will be executed after any toggling but before running the hooks. |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
85 BODY can start with a list of CL-style keys specifying additional arguments. |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
86 Currently two such keyword arguments are supported: |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
87 :group followed by the group name to use for any generated `defcustom'. |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
88 :global if non-nil specifies that the minor mode is not meant to be |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
89 buffer-local. By default, the variable is made buffer-local." |
18388 | 90 (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
|
91 (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
|
92 (globalp nil) |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
93 ;; We might as well provide a best-guess default group. |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
94 (group |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
95 (list 'quote |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
96 (intern (replace-regexp-in-string "-mode\\'" "" mode-name)))) |
29548
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
97 (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
|
98 (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
|
99 (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
|
100 (hook-on (intern (concat mode-name "-on-hook"))) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
101 (hook-off (intern (concat mode-name "-off-hook")))) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
102 |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
103 ;; FIXME: compatibility that should be removed. |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
104 (when (and (consp init-value) (eq (car init-value) 'global)) |
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
105 (setq init-value (cdr init-value) globalp t)) |
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
106 |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
107 ;; Check keys. |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
108 (while (keywordp (car body)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
109 (case (pop body) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
110 (:global (setq globalp (pop body))) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
111 (:group (setq group (pop body))) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
112 (t (setq body (cdr body))))) |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
113 |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
114 ;; Add default properties to LIGHTER. |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
115 (unless (or (not (stringp lighter)) (get-text-property 0 'local-map lighter) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
116 (get-text-property 0 'keymap lighter)) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
117 (setq lighter |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
118 (apply 'propertize lighter |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
119 'local-map (make-mode-line-mouse2-map mode) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
120 (unless (get-text-property 0 'help-echo lighter) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
121 (list 'help-echo |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
122 (format "mouse-2: turn off %s" pretty-name)))))) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
123 |
18388 | 124 `(progn |
25408
68c51b1a537f
(easy-mmode-define-minor-mode):
Karl Heuer <kwzh@gnu.org>
parents:
24935
diff
changeset
|
125 ;; 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
|
126 ,(if (not globalp) |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
127 `(progn |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
128 (defvar ,mode ,init-value ,(format "Non-nil if %s is enabled. |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
129 Use the function `%s' to change this variable." pretty-name mode)) |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
130 (make-variable-buffer-local ',mode)) |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
131 |
29548
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
132 (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
|
133 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
|
134 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
|
135 `(defcustom ,mode ,init-value |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
136 ,(format "Toggle %s. |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
137 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
|
138 use either \\[customize] or the function `%s'." |
29548
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
139 pretty-name mode) |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
140 :set (lambda (symbol value) (funcall symbol (or value 0))) |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
141 :initialize 'custom-initialize-default |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
142 :group ,group |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
143 :type 'boolean |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
144 ,@(when curfile |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
145 (list |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
146 :require |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
147 (list 'quote |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
148 (intern (file-name-nondirectory |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
149 (file-name-sans-extension curfile))))))))) |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
150 |
29548
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
151 ;; The toggle's hook. Wrapped in `progn' to prevent autoloading. |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
152 (progn |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
153 (defcustom ,hook nil |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
154 ,(format "Hook run at the end of function `%s'." mode-name) |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
155 :group ,group |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
156 :type 'hook)) |
18388 | 157 |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
158 ;; The actual function. |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
159 (defun ,mode (&optional arg) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
160 ,(or doc |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
161 (format "With no argument, toggle %s. |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
162 With universal prefix ARG turn mode on. |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
163 With zero or negative ARG turn mode off. |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
164 \\{%s}" pretty-name keymap-sym)) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
165 (interactive "P") |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
166 (setq ,mode |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
167 (if arg |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
168 (> (prefix-numeric-value arg) 0) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
169 (not ,mode))) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
170 ,@body |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
171 ;; 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
|
172 (run-hooks ',hook (if ,mode ',hook-on ',hook-off)) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
173 ;; 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
|
174 (if (interactive-p) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
175 (message ,(format "%s %%sabled" pretty-name) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
176 (if ,mode "en" "dis"))) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
177 ,mode) |
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
178 |
29548
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
179 ;; 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
|
180 ;; 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
|
181 :autoload-end |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
182 |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
183 ;; 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
|
184 ,(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
|
185 `(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
|
186 (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
|
187 (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
|
188 ((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
|
189 (t (error "Invalid keymap %S" ,keymap)))) |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
190 ,(format "Keymap for `%s'." mode-name))) |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
191 |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
192 (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
|
193 ,(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
|
194 `(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
|
195 (symbol-value ',keymap-sym)))) |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
196 |
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
197 ;; If the mode is global, call the function according to the default. |
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
198 ,(if globalp `(if ,mode (,mode 1)))))) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
199 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
200 ;;; |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
201 ;;; make global minor mode |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
202 ;;; |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
203 |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
204 ;;;###autoload |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
205 (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
|
206 &rest keys) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
207 "Make GLOBAL-MODE out of the MODE buffer-local minor mode. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
208 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
|
209 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
|
210 KEYS is a list of CL-style keyword arguments: |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
211 :group to specify the custom group." |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
212 (let* ((mode-name (symbol-name mode)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
213 (global-mode-name (symbol-name global-mode)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
214 (pretty-name (easy-mmode-pretty-mode-name mode)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
215 (pretty-global-name (easy-mmode-pretty-mode-name global-mode)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
216 ;; We might as well provide a best-guess default group. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
217 (group |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
218 (list 'quote |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
219 (intern (replace-regexp-in-string "-mode\\'" "" mode-name)))) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
220 (buffers (intern (concat global-mode-name "-buffers"))) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
221 (cmmh (intern (concat global-mode-name "-cmmh")))) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
222 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
223 ;; Check keys. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
224 (while (keywordp (car keys)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
225 (case (pop keys) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
226 (:group (setq group (pop keys))) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
227 (t (setq keys (cdr keys))))) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
228 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
229 `(progn |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
230 ;; The actual global minor-mode |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
231 (define-minor-mode ,global-mode |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
232 ,(format "Toggle %s in every buffer. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
233 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
|
234 %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
|
235 in which `%s' turns it on." |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
236 pretty-name pretty-global-name pretty-name turn-on) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
237 nil nil nil :global t :group ,group |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
238 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
239 ;; 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
|
240 (if ,global-mode |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
241 (progn |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
242 (add-hook 'find-file-hooks ',buffers) |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
243 (add-hook 'change-major-mode-hook ',cmmh)) |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
244 (remove-hook 'find-file-hooks ',buffers) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
245 (remove-hook 'change-major-mode-hook ',cmmh)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
246 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
247 ;; Go through existing buffers. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
248 (dolist (buf (buffer-list)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
249 (with-current-buffer buf |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
250 (if ,global-mode (,turn-on) (,mode -1))))) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
251 |
29548
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
252 ;; 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
|
253 ;; 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
|
254 :autoload-end |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
255 |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
256 ;; List of buffers left to process. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
257 (defvar ,buffers nil) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
258 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
259 ;; The function that calls TURN-ON in each buffer. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
260 (defun ,buffers () |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
261 (remove-hook 'post-command-hook ',buffers) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
262 (while ,buffers |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
263 (let ((buf (pop ,buffers))) |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
264 (when (buffer-live-p buf) |
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
265 (with-current-buffer buf (,turn-on)))))) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
266 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
267 ;; The function that catches kill-all-local-variables. |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
268 (defun ,cmmh () |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
269 (add-to-list ',buffers (current-buffer)) |
29414
b18a17d5d9c6
(easy-mmode-define-global-mode): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29411
diff
changeset
|
270 (add-hook 'post-command-hook ',buffers))))) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
271 |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
272 ;;; |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
273 ;;; easy-mmode-defmap |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
274 ;;; |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
275 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
276 (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
|
277 (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
|
278 (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
|
279 (set-keymap-parent |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
280 m |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
281 (cond |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
282 ((not (consp parents)) parents) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
283 ((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
|
284 (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
|
285 (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
|
286 m)))))) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
287 |
31981
533a4e5f06e2
(easy-mmode-define-keymap): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30876
diff
changeset
|
288 ;;;###autoload |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
289 (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
|
290 "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
|
291 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
|
292 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
|
293 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
|
294 Optional map M can be used to modify an existing map. |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
295 ARGS is a list of additional arguments." |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
296 (let (inherit dense suppress) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
297 (while args |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
298 (let ((key (pop args)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
299 (val (pop args))) |
29411
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
300 (case key |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
301 (:dense (setq dense val)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
302 (:inherit (setq inherit val)) |
232f7e558a38
Require CL during compilation.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29406
diff
changeset
|
303 (:group) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
304 ;;((eq key :suppress) (setq suppress val)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
305 (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
|
306 (unless (keymapp m) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
307 (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
|
308 (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
|
309 (dolist (b bs) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
310 (let ((keys (car b)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
311 (binding (cdr b))) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
312 (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
|
313 (cond |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
314 ((symbolp key) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
315 (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
|
316 ((null binding) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
317 (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
|
318 ((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
|
319 (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
|
320 (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
|
321 (cond |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
322 ((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
|
323 ((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
|
324 m)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
325 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
326 ;;;###autoload |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
327 (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
|
328 `(defconst ,m |
533a4e5f06e2
(easy-mmode-define-keymap): Autoload.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
30876
diff
changeset
|
329 (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
|
330 ,doc)) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
331 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
332 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
333 ;;; |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
334 ;;; easy-mmode-defsyntax |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
335 ;;; |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
336 |
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-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
|
338 (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
|
339 (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
|
340 (dolist (cs css) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
341 (let ((char (car cs)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
342 (syntax (cdr cs))) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
343 (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
|
344 (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
|
345 (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
|
346 (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
|
347 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
|
348 st)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
349 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
350 ;;;###autoload |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
351 (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
|
352 "Define variable ST as a syntax-table. |
2fc546f941df
(easy-mmode-define-syntax): Use plist-get and allow :inherit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32199
diff
changeset
|
353 CSS contains a list of syntax specifications of the form (CHAR . SYNTAX). |
2fc546f941df
(easy-mmode-define-syntax): Use plist-get and allow :inherit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32199
diff
changeset
|
354 " |
28086
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
355 `(progn |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
356 (autoload 'easy-mmode-define-syntax "easy-mmode") |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
357 (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
|
358 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
359 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
360 |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
361 ;;; |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
362 ;;; A "macro-only" reimplementation of define-derived-mode. |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
363 ;;; |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
364 |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
365 ;;;###autoload |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
366 (defmacro define-derived-mode (child parent name &optional docstring &rest body) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
367 "Create a new mode as a variant of an existing mode. |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
368 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
369 The arguments to this command are as follow: |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
370 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
371 CHILD: the name of the command for the derived mode. |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
372 PARENT: the name of the command for the parent mode (e.g. `text-mode'). |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
373 NAME: a string which will appear in the status line (e.g. \"Hypertext\") |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
374 DOCSTRING: an optional documentation string--if you do not supply one, |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
375 the function will attempt to invent something useful. |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
376 BODY: forms to execute just before running the |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
377 hooks for the new mode. |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
378 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
379 Here is how you could define LaTeX-Thesis mode as a variant of LaTeX mode: |
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 (define-derived-mode LaTeX-thesis-mode LaTeX-mode \"LaTeX-Thesis\") |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
382 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
383 You could then make new key bindings for `LaTeX-thesis-mode-map' |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
384 without changing regular LaTeX mode. In this example, BODY is empty, |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
385 and DOCSTRING is generated by default. |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
386 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
387 On a more complicated level, the following command uses `sgml-mode' as |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
388 the parent, and then sets the variable `case-fold-search' to nil: |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
389 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
390 (define-derived-mode article-mode sgml-mode \"Article\" |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
391 \"Major mode for editing technical articles.\" |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
392 (setq case-fold-search nil)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
393 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
394 Note that if the documentation string had been left out, it would have |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
395 been generated automatically, with a reference to the keymap." |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
396 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
397 (let* ((child-name (symbol-name child)) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
398 (map (intern (concat child-name "-map"))) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
399 (syntax (intern (concat child-name "-syntax-table"))) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
400 (abbrev (intern (concat child-name "-abbrev-table"))) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
401 (hook (intern (concat child-name "-hook")))) |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
402 |
29399
addeae19bf96
(easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29039
diff
changeset
|
403 (unless parent (setq parent 'fundamental-mode)) |
addeae19bf96
(easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29039
diff
changeset
|
404 |
28086
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
405 (when (and docstring (not (stringp docstring))) |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
406 ;; DOCSTRING is really the first command and there's no docstring |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
407 (push docstring body) |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
408 (setq docstring nil)) |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
409 |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
410 (unless (stringp docstring) |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
411 ;; Use a default docstring. |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
412 (setq docstring |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
413 (format "Major mode derived from `%s' by `define-derived-mode'. |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
414 Inherits all of the parent's attributes, but has its own keymap, |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
415 abbrev table and syntax table: |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
416 |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
417 `%s', `%s' and `%s' |
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
418 |
28086
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
419 which more-or-less shadow %s's corresponding tables." |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
420 parent map syntax abbrev parent))) |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
421 |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
422 (unless (string-match (regexp-quote (symbol-name hook)) docstring) |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
423 ;; Make sure the docstring mentions the mode's hook |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
424 (setq docstring |
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
425 (concat docstring |
32199
883b83d07a24
(define-derived-mode): Tweak generated docstring parts.
Miles Bader <miles@gnu.org>
parents:
32051
diff
changeset
|
426 (if (eq parent 'fundamental-mode) |
883b83d07a24
(define-derived-mode): Tweak generated docstring parts.
Miles Bader <miles@gnu.org>
parents:
32051
diff
changeset
|
427 "\n\nThis mode " |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
428 (concat |
32199
883b83d07a24
(define-derived-mode): Tweak generated docstring parts.
Miles Bader <miles@gnu.org>
parents:
32051
diff
changeset
|
429 "\n\nIn addition to any hooks its parent mode " |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
430 (if (string-match (regexp-quote (format "`%s'" parent)) |
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
431 docstring) nil |
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
432 (format "`%s' " parent)) |
32199
883b83d07a24
(define-derived-mode): Tweak generated docstring parts.
Miles Bader <miles@gnu.org>
parents:
32051
diff
changeset
|
433 "might have run,\nthis mode ")) |
883b83d07a24
(define-derived-mode): Tweak generated docstring parts.
Miles Bader <miles@gnu.org>
parents:
32051
diff
changeset
|
434 (format "runs the hook `%s'" hook) |
883b83d07a24
(define-derived-mode): Tweak generated docstring parts.
Miles Bader <miles@gnu.org>
parents:
32051
diff
changeset
|
435 ", as the final step\nduring initialization."))) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
436 |
28086
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
437 (unless (string-match "\\\\[{[]" docstring) |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
438 ;; And don't forget to put the mode's keymap |
32199
883b83d07a24
(define-derived-mode): Tweak generated docstring parts.
Miles Bader <miles@gnu.org>
parents:
32051
diff
changeset
|
439 (setq docstring (concat docstring "\n\n\\{" (symbol-name map) "}"))) |
28086
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
440 |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
441 `(progn |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
442 (defvar ,map (make-sparse-keymap)) |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
443 (defvar ,syntax (make-char-table 'syntax-table nil)) |
29548
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
444 (defvar ,abbrev) |
71b284c55162
(define-minor-mode): If KEYMAP is a symbol, just use it.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29414
diff
changeset
|
445 (define-abbrev-table ',abbrev nil) |
29399
addeae19bf96
(easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29039
diff
changeset
|
446 (put ',child 'derived-mode-parent ',parent) |
28086
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
447 |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
448 (defun ,child () |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
449 ,docstring |
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
450 (interactive) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
451 ; Run the parent. |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
452 (combine-run-hooks |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
453 |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
454 (,parent) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
455 ; Identify special modes. |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
456 (put ',child 'special (get ',parent 'special)) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
457 ; Identify the child mode. |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
458 (setq major-mode ',child) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
459 (setq mode-name ,name) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
460 ; Set up maps and tables. |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
461 (unless (keymap-parent ,map) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
462 (set-keymap-parent ,map (current-local-map))) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
463 (let ((parent (char-table-parent ,syntax))) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
464 (unless (and parent (not (eq parent (standard-syntax-table)))) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
465 (set-char-table-parent ,syntax (syntax-table)))) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
466 (when local-abbrev-table |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
467 (mapatoms |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
468 (lambda (symbol) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
469 (or (intern-soft (symbol-name symbol) ,abbrev) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
470 (define-abbrev ,abbrev (symbol-name symbol) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
471 (symbol-value symbol) (symbol-function symbol)))) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
472 local-abbrev-table)) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
473 |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
474 (use-local-map ,map) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
475 (set-syntax-table ,syntax) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
476 (setq local-abbrev-table ,abbrev) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
477 ; Splice in the body (if any). |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
478 ,@body) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
479 ; Run the hooks, if any. |
28086
9ff6e6a6c6b5
(easy-mmode-defmap, easy-mmode-defsyntax): Autoload the functions used.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28081
diff
changeset
|
480 (run-hooks ',hook))))) |
28081
6360842e5962
(easy-mmode-define-keymap): Extend to allow more flexibility.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26551
diff
changeset
|
481 |
29399
addeae19bf96
(easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29039
diff
changeset
|
482 ;; Inspired from derived-mode-class in derived.el |
addeae19bf96
(easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29039
diff
changeset
|
483 (defun easy-mmode-derived-mode-p (mode) |
addeae19bf96
(easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29039
diff
changeset
|
484 "Non-nil if the current major mode is derived from MODE. |
addeae19bf96
(easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29039
diff
changeset
|
485 Uses the `derived-mode-parent' property of the symbol to trace backwards." |
addeae19bf96
(easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29039
diff
changeset
|
486 (let ((parent major-mode)) |
addeae19bf96
(easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29039
diff
changeset
|
487 (while (and (not (eq parent mode)) |
addeae19bf96
(easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29039
diff
changeset
|
488 (setq parent (get parent 'derived-mode-parent)))) |
addeae19bf96
(easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29039
diff
changeset
|
489 parent)) |
addeae19bf96
(easy-mmode-derive-name): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29039
diff
changeset
|
490 |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
491 |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
492 ;;; |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
493 ;;; easy-mmode-define-navigation |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
494 ;;; |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
495 |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
496 (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
|
497 "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
|
498 RE determines the places the commands should move point to. |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
499 NAME should describe the entities matched by RE and is used to build |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
500 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
|
501 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
|
502 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
|
503 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
|
504 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
|
505 (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
|
506 (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
|
507 (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
|
508 (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
|
509 `(progn |
29406
f4b12c3efee8
(easy-mmode-define-toggle): Remove (inline into define-minor-mode).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29399
diff
changeset
|
510 (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
|
511 ,(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
|
512 (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
|
513 ,(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
|
514 (interactive) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
515 (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
|
516 (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
|
517 (if (looking-at ,re) (incf count)) |
28239
21cd65af5197
(easy-mmode-define-navigation): Only use `ding' for interactive use
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28235
diff
changeset
|
518 (unless (re-search-forward ,re nil t count) |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
519 (error ,(format "No next %s" name))) |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
520 (goto-char (match-beginning 0)) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
521 (when (eq (current-buffer) (window-buffer (selected-window))) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
522 (let ((endpt (or (save-excursion |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
523 ,(if endfun `(,endfun) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
524 `(re-search-forward ,re nil t 2))) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
525 (point-max)))) |
32051
af9abfeed429
(easy-mmode-define-navigation):
Miles Bader <miles@gnu.org>
parents:
32048
diff
changeset
|
526 (unless (<= endpt (window-end)) |
af9abfeed429
(easy-mmode-define-navigation):
Miles Bader <miles@gnu.org>
parents:
32048
diff
changeset
|
527 (recenter '(0))))))) |
28235
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
528 (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
|
529 ,(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
|
530 (interactive) |
963f1d516e92
* derived.el (define-derived-mode): Don't autoload anymore.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28086
diff
changeset
|
531 (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
|
532 (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
|
533 (unless (re-search-backward ,re nil t count) |
29039
d8bafae6beb2
Update copyright and commentary.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28239
diff
changeset
|
534 (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
|
535 |
18388 | 536 (provide 'easy-mmode) |
537 | |
538 ;;; easy-mmode.el ends here |