annotate lisp/subr.el @ 10989:f4693d66f90c

(adaptive-fill-regexp): Skip # or ;. Allow more than one of them (or *'s or >'s).
author Richard M. Stallman <rms@gnu.org>
date Mon, 13 Mar 1995 06:31:48 +0000
parents 0ecc478ed305
children e3c06f791fd8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 648
diff changeset
1 ;;; subr.el --- basic lisp subroutines for Emacs
787
3cece0106722 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 779
diff changeset
2
7298
4fd40bd394fe Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 7110
diff changeset
3 ;;; Copyright (C) 1985, 1986, 1992, 1994 Free Software Foundation, Inc.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
4
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
5 ;; This file is part of GNU Emacs.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
6
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
8 ;; it under the terms of the GNU General Public License as published by
707
e4253da532fb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 675
diff changeset
9 ;; the Free Software Foundation; either version 2, or (at your option)
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
10 ;; any later version.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
11
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is distributed in the hope that it will be useful,
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
15 ;; GNU General Public License for more details.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
16
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
20
787
3cece0106722 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 779
diff changeset
21 ;;; Code:
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
22
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
23
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
24 ;;;; Lisp language features.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
25
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
26 (defmacro lambda (&rest cdr)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
27 "Return a lambda expression.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
28 A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
29 self-quoting; the result of evaluating the lambda expression is the
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
30 expression itself. The lambda expression may then be treated as a
10178
be0081d9ba76 (lambda): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10025
diff changeset
31 function, i.e., stored as the function value of a symbol, passed to
be0081d9ba76 (lambda): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10025
diff changeset
32 funcall or mapcar, etc.
be0081d9ba76 (lambda): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10025
diff changeset
33
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
34 ARGS should take the same form as an argument list for a `defun'.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
35 DOCSTRING should be a string, as described for `defun'. It may be omitted.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
36 INTERACTIVE should be a call to the function `interactive', which see.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
37 It may also be omitted.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
38 BODY should be a list of lisp expressions."
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
39 ;; Note that this definition should not use backquotes; subr.el should not
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
40 ;; depend on backquote.el.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
41 (list 'function (cons 'lambda cdr)))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
42
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
43 ;;(defmacro defun-inline (name args &rest body)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
44 ;; "Create an \"inline defun\" (actually a macro).
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
45 ;;Use just like `defun'."
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
46 ;; (nconc (list 'defmacro name '(&rest args))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
47 ;; (if (stringp (car body))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
48 ;; (prog1 (list (car body))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
49 ;; (setq body (or (cdr body) body))))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
50 ;; (list (list 'cons (list 'quote
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
51 ;; (cons 'lambda (cons args body)))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
52 ;; 'args))))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
53
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
54
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
55 ;;;; Window tree functions.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
56
6441
6ca895922340 (one-window-p): New argument all-frames.
Richard M. Stallman <rms@gnu.org>
parents: 6309
diff changeset
57 (defun one-window-p (&optional nomini all-frames)
8518
44ff33b29c3e (one-window-p): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 8211
diff changeset
58 "Returns non-nil if the selected window is the only window (in its frame).
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
59 Optional arg NOMINI non-nil means don't count the minibuffer
6441
6ca895922340 (one-window-p): New argument all-frames.
Richard M. Stallman <rms@gnu.org>
parents: 6309
diff changeset
60 even if it is active.
6ca895922340 (one-window-p): New argument all-frames.
Richard M. Stallman <rms@gnu.org>
parents: 6309
diff changeset
61
6ca895922340 (one-window-p): New argument all-frames.
Richard M. Stallman <rms@gnu.org>
parents: 6309
diff changeset
62 The optional arg ALL-FRAMES t means count windows on all frames.
6ca895922340 (one-window-p): New argument all-frames.
Richard M. Stallman <rms@gnu.org>
parents: 6309
diff changeset
63 If it is `visible', count windows on all visible frames.
6ca895922340 (one-window-p): New argument all-frames.
Richard M. Stallman <rms@gnu.org>
parents: 6309
diff changeset
64 ALL-FRAMES nil or omitted means count only the selected frame,
6ca895922340 (one-window-p): New argument all-frames.
Richard M. Stallman <rms@gnu.org>
parents: 6309
diff changeset
65 plus the minibuffer it uses (which may be on another frame).
6ca895922340 (one-window-p): New argument all-frames.
Richard M. Stallman <rms@gnu.org>
parents: 6309
diff changeset
66 If ALL-FRAMES is neither nil nor t, count only the selected frame."
707
e4253da532fb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 675
diff changeset
67 (let ((base-window (selected-window)))
e4253da532fb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 675
diff changeset
68 (if (and nomini (eq base-window (minibuffer-window)))
e4253da532fb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 675
diff changeset
69 (setq base-window (next-window base-window)))
e4253da532fb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 675
diff changeset
70 (eq base-window
6441
6ca895922340 (one-window-p): New argument all-frames.
Richard M. Stallman <rms@gnu.org>
parents: 6309
diff changeset
71 (next-window base-window (if nomini 'arg) all-frames))))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
72
779
c2dbf1fe0506 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 707
diff changeset
73 (defun walk-windows (proc &optional minibuf all-frames)
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
74 "Cycle through all visible windows, calling PROC for each one.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
75 PROC is called with a window as argument.
10828
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
76
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
77 Optional second arg MINIBUF t means count the minibuffer window even
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
78 if not active. MINIBUF nil or omitted means count the minibuffer iff
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
79 it is active. MINIBUF neither t nor nil means not to count the
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
80 minibuffer even if it is active.
1959
3c827b8110db (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 1903
diff changeset
81
10828
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
82 Several frames may share a single minibuffer; if the minibuffer
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
83 counts, all windows on all frames that share that minibuffer count
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
84 too. Therefore, when a separate minibuffer frame is active,
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
85 `walk-windows' includes the windows in the frame from which you
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
86 entered the minibuffer, as well as the minibuffer window. But if the
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
87 minibuffer does not count, only windows from WINDOW's frame count.
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
88
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
89 Optional third arg ALL-FRAMES t means include windows on all frames.
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
90 ALL-FRAMES nil or omitted means cycle within the frames as specified
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
91 above. ALL-FRAMES = `visible' means include windows on all visible frames.
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
92 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
0ecc478ed305 (walk-windows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 10826
diff changeset
93 Anything else means restrict to WINDOW's frame."
5157
d39a061f984a (walk-windows): If start at minibuf window, do return to it.
Richard M. Stallman <rms@gnu.org>
parents: 5046
diff changeset
94 ;; If we start from the minibuffer window, don't fail to come back to it.
d39a061f984a (walk-windows): If start at minibuf window, do return to it.
Richard M. Stallman <rms@gnu.org>
parents: 5046
diff changeset
95 (if (window-minibuffer-p (selected-window))
d39a061f984a (walk-windows): If start at minibuf window, do return to it.
Richard M. Stallman <rms@gnu.org>
parents: 5046
diff changeset
96 (setq minibuf t))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
97 (let* ((walk-windows-start (selected-window))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
98 (walk-windows-current walk-windows-start))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
99 (while (progn
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
100 (setq walk-windows-current
779
c2dbf1fe0506 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 707
diff changeset
101 (next-window walk-windows-current minibuf all-frames))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
102 (funcall proc walk-windows-current)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
103 (not (eq walk-windows-current walk-windows-start))))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
104
4491
1e30d38d5c74 (minibuffer-window-active-p): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4414
diff changeset
105 (defun minibuffer-window-active-p (window)
1e30d38d5c74 (minibuffer-window-active-p): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4414
diff changeset
106 "Return t if WINDOW (a minibuffer window) is now active."
1e30d38d5c74 (minibuffer-window-active-p): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4414
diff changeset
107 ;; nil nil means include WINDOW's frame
1e30d38d5c74 (minibuffer-window-active-p): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4414
diff changeset
108 ;; and other frames using WINDOW as minibuffer,
1e30d38d5c74 (minibuffer-window-active-p): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4414
diff changeset
109 ;; and include minibuffer if active.
1e30d38d5c74 (minibuffer-window-active-p): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4414
diff changeset
110 (let ((prev (previous-window window nil nil)))
1e30d38d5c74 (minibuffer-window-active-p): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4414
diff changeset
111 ;; If PREV equals WINDOW, WINDOW must be on a minibuffer-only frame
1e30d38d5c74 (minibuffer-window-active-p): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4414
diff changeset
112 ;; and it's not currently being used. So return nil.
1e30d38d5c74 (minibuffer-window-active-p): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4414
diff changeset
113 (and (not (eq window prev))
1e30d38d5c74 (minibuffer-window-active-p): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4414
diff changeset
114 (let ((should-be-same (next-window prev nil nil)))
1e30d38d5c74 (minibuffer-window-active-p): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4414
diff changeset
115 ;; If next-window doesn't reverse previous-window,
1e30d38d5c74 (minibuffer-window-active-p): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4414
diff changeset
116 ;; WINDOW must be outside the cycle specified by nil nil.
1e30d38d5c74 (minibuffer-window-active-p): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4414
diff changeset
117 (eq should-be-same window)))))
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
118
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
119 ;;;; Keymap support.
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
120
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
121 (defun undefined ()
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
122 (interactive)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
123 (ding))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
124
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
125 ;Prevent the \{...} documentation construct
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
126 ;from mentioning keys that run this command.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
127 (put 'undefined 'suppress-keymap t)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
128
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
129 (defun suppress-keymap (map &optional nodigits)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
130 "Make MAP override all normally self-inserting keys to be undefined.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
131 Normally, as an exception, digits and minus-sign are set to make prefix args,
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
132 but optional second arg NODIGITS non-nil treats them like other chars."
4767
12ff77449baa (suppress-keymap): Use substitute-key-definition instead of manually
Brian Fox <bfox@gnu.org>
parents: 4620
diff changeset
133 (substitute-key-definition 'self-insert-command 'undefined map global-map)
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
134 (or nodigits
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
135 (let (loop)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
136 (define-key map "-" 'negative-argument)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
137 ;; Make plain numbers do numeric args.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
138 (setq loop ?0)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
139 (while (<= loop ?9)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
140 (define-key map (char-to-string loop) 'digit-argument)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
141 (setq loop (1+ loop))))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
142
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
143 ;Moved to keymap.c
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
144 ;(defun copy-keymap (keymap)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
145 ; "Return a copy of KEYMAP"
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
146 ; (while (not (keymapp keymap))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
147 ; (setq keymap (signal 'wrong-type-argument (list 'keymapp keymap))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
148 ; (if (vectorp keymap)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
149 ; (copy-sequence keymap)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
150 ; (copy-alist keymap)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
151
6167
1ad8f8ccdc2b (substitute-key-definition): Avoid infinite recursion.
Karl Heuer <kwzh@gnu.org>
parents: 6039
diff changeset
152 (defvar key-substitution-in-progress nil
1ad8f8ccdc2b (substitute-key-definition): Avoid infinite recursion.
Karl Heuer <kwzh@gnu.org>
parents: 6039
diff changeset
153 "Used internally by substitute-key-definition.")
1ad8f8ccdc2b (substitute-key-definition): Avoid infinite recursion.
Karl Heuer <kwzh@gnu.org>
parents: 6039
diff changeset
154
1176
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
155 (defun substitute-key-definition (olddef newdef keymap &optional oldmap prefix)
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
156 "Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
157 In other words, OLDDEF is replaced with NEWDEF where ever it appears.
1176
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
158 If optional fourth argument OLDMAP is specified, we redefine
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
159 in KEYMAP as NEWDEF those chars which are defined as OLDDEF in OLDMAP."
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
160 (or prefix (setq prefix ""))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
161 (let* ((scan (or oldmap keymap))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
162 (vec1 (vector nil))
6167
1ad8f8ccdc2b (substitute-key-definition): Avoid infinite recursion.
Karl Heuer <kwzh@gnu.org>
parents: 6039
diff changeset
163 (prefix1 (vconcat prefix vec1))
1ad8f8ccdc2b (substitute-key-definition): Avoid infinite recursion.
Karl Heuer <kwzh@gnu.org>
parents: 6039
diff changeset
164 (key-substitution-in-progress
1ad8f8ccdc2b (substitute-key-definition): Avoid infinite recursion.
Karl Heuer <kwzh@gnu.org>
parents: 6039
diff changeset
165 (cons scan key-substitution-in-progress)))
1176
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
166 ;; Scan OLDMAP, finding each char or event-symbol that
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
167 ;; has any definition, and act on it with hack-key.
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
168 (while (consp scan)
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
169 (if (consp (car scan))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
170 (let ((char (car (car scan)))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
171 (defn (cdr (car scan))))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
172 ;; The inside of this let duplicates exactly
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
173 ;; the inside of the following let that handles array elements.
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
174 (aset vec1 0 char)
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
175 (aset prefix1 (length prefix) char)
6005
bf1c9fd5669b (substitute-key-definition): Don't discard menu strings.
Richard M. Stallman <rms@gnu.org>
parents: 5912
diff changeset
176 (let (inner-def skipped)
1176
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
177 ;; Skip past menu-prompt.
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
178 (while (stringp (car-safe defn))
6005
bf1c9fd5669b (substitute-key-definition): Don't discard menu strings.
Richard M. Stallman <rms@gnu.org>
parents: 5912
diff changeset
179 (setq skipped (cons (car defn) skipped))
1176
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
180 (setq defn (cdr defn)))
7615
49176059d040 (substitute-key-definition): Skip cached menu key-equivs.
Richard M. Stallman <rms@gnu.org>
parents: 7548
diff changeset
181 ;; Skip past cached key-equivalence data for menu items.
49176059d040 (substitute-key-definition): Skip cached menu key-equivs.
Richard M. Stallman <rms@gnu.org>
parents: 7548
diff changeset
182 (and (consp defn) (consp (car defn))
49176059d040 (substitute-key-definition): Skip cached menu key-equivs.
Richard M. Stallman <rms@gnu.org>
parents: 7548
diff changeset
183 (setq defn (cdr defn)))
1176
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
184 (setq inner-def defn)
7615
49176059d040 (substitute-key-definition): Skip cached menu key-equivs.
Richard M. Stallman <rms@gnu.org>
parents: 7548
diff changeset
185 ;; Look past a symbol that names a keymap.
1176
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
186 (while (and (symbolp inner-def)
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
187 (fboundp inner-def))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
188 (setq inner-def (symbol-function inner-def)))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
189 (if (eq defn olddef)
6005
bf1c9fd5669b (substitute-key-definition): Don't discard menu strings.
Richard M. Stallman <rms@gnu.org>
parents: 5912
diff changeset
190 (define-key keymap prefix1 (nconc (nreverse skipped) newdef))
6167
1ad8f8ccdc2b (substitute-key-definition): Avoid infinite recursion.
Karl Heuer <kwzh@gnu.org>
parents: 6039
diff changeset
191 (if (and (keymapp defn)
9986
df605fcd1e75 (substitute-key-definition): Don't recursively scan
Richard M. Stallman <rms@gnu.org>
parents: 9822
diff changeset
192 ;; Avoid recursively scanning
df605fcd1e75 (substitute-key-definition): Don't recursively scan
Richard M. Stallman <rms@gnu.org>
parents: 9822
diff changeset
193 ;; where KEYMAP does not have a submap.
df605fcd1e75 (substitute-key-definition): Don't recursively scan
Richard M. Stallman <rms@gnu.org>
parents: 9822
diff changeset
194 (keymapp (lookup-key keymap prefix1))
df605fcd1e75 (substitute-key-definition): Don't recursively scan
Richard M. Stallman <rms@gnu.org>
parents: 9822
diff changeset
195 ;; Avoid recursively rescanning keymap being scanned.
6167
1ad8f8ccdc2b (substitute-key-definition): Avoid infinite recursion.
Karl Heuer <kwzh@gnu.org>
parents: 6039
diff changeset
196 (not (memq inner-def
1ad8f8ccdc2b (substitute-key-definition): Avoid infinite recursion.
Karl Heuer <kwzh@gnu.org>
parents: 6039
diff changeset
197 key-substitution-in-progress)))
7615
49176059d040 (substitute-key-definition): Skip cached menu key-equivs.
Richard M. Stallman <rms@gnu.org>
parents: 7548
diff changeset
198 ;; If this one isn't being scanned already,
49176059d040 (substitute-key-definition): Skip cached menu key-equivs.
Richard M. Stallman <rms@gnu.org>
parents: 7548
diff changeset
199 ;; scan it now.
1176
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
200 (substitute-key-definition olddef newdef keymap
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
201 inner-def
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
202 prefix1)))))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
203 (if (arrayp (car scan))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
204 (let* ((array (car scan))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
205 (len (length array))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
206 (i 0))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
207 (while (< i len)
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
208 (let ((char i) (defn (aref array i)))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
209 ;; The inside of this let duplicates exactly
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
210 ;; the inside of the previous let.
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
211 (aset vec1 0 char)
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
212 (aset prefix1 (length prefix) char)
6005
bf1c9fd5669b (substitute-key-definition): Don't discard menu strings.
Richard M. Stallman <rms@gnu.org>
parents: 5912
diff changeset
213 (let (inner-def skipped)
1176
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
214 ;; Skip past menu-prompt.
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
215 (while (stringp (car-safe defn))
6005
bf1c9fd5669b (substitute-key-definition): Don't discard menu strings.
Richard M. Stallman <rms@gnu.org>
parents: 5912
diff changeset
216 (setq skipped (cons (car defn) skipped))
1176
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
217 (setq defn (cdr defn)))
7615
49176059d040 (substitute-key-definition): Skip cached menu key-equivs.
Richard M. Stallman <rms@gnu.org>
parents: 7548
diff changeset
218 (and (consp defn) (consp (car defn))
49176059d040 (substitute-key-definition): Skip cached menu key-equivs.
Richard M. Stallman <rms@gnu.org>
parents: 7548
diff changeset
219 (setq defn (cdr defn)))
1176
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
220 (setq inner-def defn)
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
221 (while (and (symbolp inner-def)
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
222 (fboundp inner-def))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
223 (setq inner-def (symbol-function inner-def)))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
224 (if (eq defn olddef)
6005
bf1c9fd5669b (substitute-key-definition): Don't discard menu strings.
Richard M. Stallman <rms@gnu.org>
parents: 5912
diff changeset
225 (define-key keymap prefix1
bf1c9fd5669b (substitute-key-definition): Don't discard menu strings.
Richard M. Stallman <rms@gnu.org>
parents: 5912
diff changeset
226 (nconc (nreverse skipped) newdef))
6167
1ad8f8ccdc2b (substitute-key-definition): Avoid infinite recursion.
Karl Heuer <kwzh@gnu.org>
parents: 6039
diff changeset
227 (if (and (keymapp defn)
9986
df605fcd1e75 (substitute-key-definition): Don't recursively scan
Richard M. Stallman <rms@gnu.org>
parents: 9822
diff changeset
228 (keymapp (lookup-key keymap prefix1))
6167
1ad8f8ccdc2b (substitute-key-definition): Avoid infinite recursion.
Karl Heuer <kwzh@gnu.org>
parents: 6039
diff changeset
229 (not (memq inner-def
1ad8f8ccdc2b (substitute-key-definition): Avoid infinite recursion.
Karl Heuer <kwzh@gnu.org>
parents: 6039
diff changeset
230 key-substitution-in-progress)))
1176
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
231 (substitute-key-definition olddef newdef keymap
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
232 inner-def
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
233 prefix1)))))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
234 (setq i (1+ i))))))
60e0dc538df3 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 1166
diff changeset
235 (setq scan (cdr scan)))))
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
236
3902
717f2e24975e (define-key-after): Renamed from define-key-in-sequence.
Richard M. Stallman <rms@gnu.org>
parents: 3901
diff changeset
237 (defun define-key-after (keymap key definition after)
3901
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
238 "Add binding in KEYMAP for KEY => DEFINITION, right after AFTER's binding.
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
239 This is like `define-key' except that the binding for KEY is placed
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
240 just after the binding for the event AFTER, instead of at the beginning
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
241 of the map.
4070
5a97f81baf65 (define-key-after): Error if KEY has two elements.
Richard M. Stallman <rms@gnu.org>
parents: 3991
diff changeset
242 The order matters when the keymap is used as a menu.
6725
e044bd05a1da (define-key-after): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 6553
diff changeset
243 KEY must contain just one event type--that is to say, it must be
e044bd05a1da (define-key-after): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 6553
diff changeset
244 a string or vector of length 1."
3901
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
245 (or (keymapp keymap)
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
246 (signal 'wrong-type-argument (list 'keymapp keymap)))
4188
10fd517cb2e9 (define-key-after): Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents: 4070
diff changeset
247 (if (> (length key) 1)
4070
5a97f81baf65 (define-key-after): Error if KEY has two elements.
Richard M. Stallman <rms@gnu.org>
parents: 3991
diff changeset
248 (error "multi-event key specified in `define-key-after'"))
3927
1f1fefc400ed (define-key-after): Delete duplicate bindings that come
Richard M. Stallman <rms@gnu.org>
parents: 3902
diff changeset
249 (let ((tail keymap) done inserted
3901
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
250 (first (aref key 0)))
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
251 (while (and (not done) tail)
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
252 ;; Delete any earlier bindings for the same key.
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
253 (if (eq (car-safe (car (cdr tail))) first)
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
254 (setcdr tail (cdr (cdr tail))))
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
255 ;; When we reach AFTER's binding, insert the new binding after.
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
256 ;; If we reach an inherited keymap, insert just before that.
3927
1f1fefc400ed (define-key-after): Delete duplicate bindings that come
Richard M. Stallman <rms@gnu.org>
parents: 3902
diff changeset
257 ;; If we reach the end of this keymap, insert at the end.
3901
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
258 (if (or (eq (car-safe (car tail)) after)
3927
1f1fefc400ed (define-key-after): Delete duplicate bindings that come
Richard M. Stallman <rms@gnu.org>
parents: 3902
diff changeset
259 (eq (car (cdr tail)) 'keymap)
1f1fefc400ed (define-key-after): Delete duplicate bindings that come
Richard M. Stallman <rms@gnu.org>
parents: 3902
diff changeset
260 (null (cdr tail)))
3901
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
261 (progn
3927
1f1fefc400ed (define-key-after): Delete duplicate bindings that come
Richard M. Stallman <rms@gnu.org>
parents: 3902
diff changeset
262 ;; Stop the scan only if we find a parent keymap.
1f1fefc400ed (define-key-after): Delete duplicate bindings that come
Richard M. Stallman <rms@gnu.org>
parents: 3902
diff changeset
263 ;; Keep going past the inserted element
1f1fefc400ed (define-key-after): Delete duplicate bindings that come
Richard M. Stallman <rms@gnu.org>
parents: 3902
diff changeset
264 ;; so we can delete any duplications that come later.
1f1fefc400ed (define-key-after): Delete duplicate bindings that come
Richard M. Stallman <rms@gnu.org>
parents: 3902
diff changeset
265 (if (eq (car (cdr tail)) 'keymap)
1f1fefc400ed (define-key-after): Delete duplicate bindings that come
Richard M. Stallman <rms@gnu.org>
parents: 3902
diff changeset
266 (setq done t))
1f1fefc400ed (define-key-after): Delete duplicate bindings that come
Richard M. Stallman <rms@gnu.org>
parents: 3902
diff changeset
267 ;; Don't insert more than once.
1f1fefc400ed (define-key-after): Delete duplicate bindings that come
Richard M. Stallman <rms@gnu.org>
parents: 3902
diff changeset
268 (or inserted
1f1fefc400ed (define-key-after): Delete duplicate bindings that come
Richard M. Stallman <rms@gnu.org>
parents: 3902
diff changeset
269 (setcdr tail (cons (cons (aref key 0) definition) (cdr tail))))
1f1fefc400ed (define-key-after): Delete duplicate bindings that come
Richard M. Stallman <rms@gnu.org>
parents: 3902
diff changeset
270 (setq inserted t)))
3901
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
271 (setq tail (cdr tail)))))
c78753b7eea8 (define-key-in-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 3860
diff changeset
272
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
273 (defun keyboard-translate (from to)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
274 "Translate character FROM to TO at a low level.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
275 This function creates a `keyboard-translate-table' if necessary
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
276 and then modifies one entry in it."
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
277 (or (arrayp keyboard-translate-table)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
278 (setq keyboard-translate-table ""))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
279 (if (or (> from (length keyboard-translate-table))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
280 (> to (length keyboard-translate-table)))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
281 (progn
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
282 (let* ((i (length keyboard-translate-table))
4235
55182207415d (keyboard-translate): Properly lengthen existing table.
Richard M. Stallman <rms@gnu.org>
parents: 4188
diff changeset
283 (table (concat keyboard-translate-table
55182207415d (keyboard-translate): Properly lengthen existing table.
Richard M. Stallman <rms@gnu.org>
parents: 4188
diff changeset
284 (make-string (- 256 i) 0))))
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
285 (while (< i 256)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
286 (aset table i i)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
287 (setq i (1+ i)))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
288 (setq keyboard-translate-table table))))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
289 (aset keyboard-translate-table from to))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
290
2071
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
291
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
292 ;;;; The global keymap tree.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
293
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
294 ;;; global-map, esc-map, and ctl-x-map have their values set up in
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
295 ;;; keymap.c; we just give them docstrings here.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
296
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
297 (defvar global-map nil
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
298 "Default global keymap mapping Emacs keyboard input into commands.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
299 The value is a keymap which is usually (but not necessarily) Emacs's
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
300 global map.")
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
301
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
302 (defvar esc-map nil
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
303 "Default keymap for ESC (meta) commands.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
304 The normal global definition of the character ESC indirects to this keymap.")
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
305
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
306 (defvar ctl-x-map nil
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
307 "Default keymap for C-x commands.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
308 The normal global definition of the character C-x indirects to this keymap.")
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
309
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
310 (defvar ctl-x-4-map (make-sparse-keymap)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
311 "Keymap for subcommands of C-x 4")
2569
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
312 (defalias 'ctl-x-4-prefix ctl-x-4-map)
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
313 (define-key ctl-x-map "4" 'ctl-x-4-prefix)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
314
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
315 (defvar ctl-x-5-map (make-sparse-keymap)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
316 "Keymap for frame commands.")
2569
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
317 (defalias 'ctl-x-5-prefix ctl-x-5-map)
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
318 (define-key ctl-x-map "5" 'ctl-x-5-prefix)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
319
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
320
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
321 ;;;; Event manipulation functions.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
322
10693
0875851842f0 (listify-key-sequence-1, event-modifiers): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents: 10681
diff changeset
323 ;; The call to `read' is to ensure that the value is computed at load time
0875851842f0 (listify-key-sequence-1, event-modifiers): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents: 10681
diff changeset
324 ;; and not compiled into the .elc file. The value is negative on most
0875851842f0 (listify-key-sequence-1, event-modifiers): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents: 10681
diff changeset
325 ;; machines, but not on all!
0875851842f0 (listify-key-sequence-1, event-modifiers): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents: 10681
diff changeset
326 (defconst listify-key-sequence-1 (logior 128 (read "?\\M-\\^@")))
3153
4c94c9faf1af (listify-key-sequence): Avoid the constant ?\M-\200.
Richard M. Stallman <rms@gnu.org>
parents: 2963
diff changeset
327
2021
8b9286bffef8 (listify-key-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1959
diff changeset
328 (defun listify-key-sequence (key)
8b9286bffef8 (listify-key-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1959
diff changeset
329 "Convert a key sequence to a list of events."
8b9286bffef8 (listify-key-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1959
diff changeset
330 (if (vectorp key)
8b9286bffef8 (listify-key-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1959
diff changeset
331 (append key nil)
8b9286bffef8 (listify-key-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1959
diff changeset
332 (mapcar (function (lambda (c)
8b9286bffef8 (listify-key-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1959
diff changeset
333 (if (> c 127)
3153
4c94c9faf1af (listify-key-sequence): Avoid the constant ?\M-\200.
Richard M. Stallman <rms@gnu.org>
parents: 2963
diff changeset
334 (logxor c listify-key-sequence-1)
2021
8b9286bffef8 (listify-key-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1959
diff changeset
335 c)))
8b9286bffef8 (listify-key-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1959
diff changeset
336 (append key nil))))
8b9286bffef8 (listify-key-sequence): New function.
Richard M. Stallman <rms@gnu.org>
parents: 1959
diff changeset
337
2040
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
338 (defsubst eventp (obj)
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
339 "True if the argument is an event object."
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
340 (or (integerp obj)
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
341 (and (symbolp obj)
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
342 (get obj 'event-symbol-elements))
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
343 (and (consp obj)
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
344 (symbolp (car obj))
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
345 (get (car obj) 'event-symbol-elements))))
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
346
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
347 (defun event-modifiers (event)
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
348 "Returns a list of symbols representing the modifier keys in event EVENT.
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
349 The elements of the list may include `meta', `control',
4414
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
350 `shift', `hyper', `super', `alt', `click', `double', `triple', `drag',
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
351 and `down'."
2040
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
352 (let ((type event))
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
353 (if (listp type)
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
354 (setq type (car type)))
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
355 (if (symbolp type)
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
356 (cdr (get type 'event-symbol-elements))
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
357 (let ((list nil))
10693
0875851842f0 (listify-key-sequence-1, event-modifiers): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents: 10681
diff changeset
358 (or (zerop (logand type ?\M-\^@))
2040
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
359 (setq list (cons 'meta list)))
10693
0875851842f0 (listify-key-sequence-1, event-modifiers): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents: 10681
diff changeset
360 (or (and (zerop (logand type ?\C-\^@))
2040
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
361 (>= (logand type 127) 32))
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
362 (setq list (cons 'control list)))
10693
0875851842f0 (listify-key-sequence-1, event-modifiers): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents: 10681
diff changeset
363 (or (and (zerop (logand type ?\S-\^@))
2040
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
364 (= (logand type 255) (downcase (logand type 255))))
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
365 (setq list (cons 'shift list)))
10693
0875851842f0 (listify-key-sequence-1, event-modifiers): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents: 10681
diff changeset
366 (or (zerop (logand type ?\H-\^@))
2040
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
367 (setq list (cons 'hyper list)))
10693
0875851842f0 (listify-key-sequence-1, event-modifiers): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents: 10681
diff changeset
368 (or (zerop (logand type ?\s-\^@))
2040
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
369 (setq list (cons 'super list)))
10693
0875851842f0 (listify-key-sequence-1, event-modifiers): Don't presume internal bit layout
Karl Heuer <kwzh@gnu.org>
parents: 10681
diff changeset
370 (or (zerop (logand type ?\A-\^@))
2040
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
371 (setq list (cons 'alt list)))
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
372 list))))
aa926beb4caa (event-modifiers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2033
diff changeset
373
2063
2f0555b428c4 (event-basic-type): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2040
diff changeset
374 (defun event-basic-type (event)
2f0555b428c4 (event-basic-type): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2040
diff changeset
375 "Returns the basic type of the given event (all modifiers removed).
2f0555b428c4 (event-basic-type): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2040
diff changeset
376 The value is an ASCII printing character (not upper case) or a symbol."
3784
d2df5ca46b39 * subr.el (event-basic-type): Deal with listy events properly.
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
377 (if (consp event)
d2df5ca46b39 * subr.el (event-basic-type): Deal with listy events properly.
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
378 (setq event (car event)))
2063
2f0555b428c4 (event-basic-type): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2040
diff changeset
379 (if (symbolp event)
2f0555b428c4 (event-basic-type): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2040
diff changeset
380 (car (get event 'event-symbol-elements))
2f0555b428c4 (event-basic-type): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2040
diff changeset
381 (let ((base (logand event (1- (lsh 1 18)))))
2f0555b428c4 (event-basic-type): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2040
diff changeset
382 (downcase (if (< base 32) (logior base 64) base)))))
2f0555b428c4 (event-basic-type): New function.
Richard M. Stallman <rms@gnu.org>
parents: 2040
diff changeset
383
2071
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
384 (defsubst mouse-movement-p (object)
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
385 "Return non-nil if OBJECT is a mouse movement event."
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
386 (and (consp object)
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
387 (eq (car object) 'mouse-movement)))
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
388
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
389 (defsubst event-start (event)
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
390 "Return the starting position of EVENT.
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
391 If EVENT is a mouse press or a mouse click, this returns the location
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
392 of the event.
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
393 If EVENT is a drag, this returns the drag's starting position.
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
394 The return value is of the form
6039
4eb7f4633370 (posn-x-y): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6005
diff changeset
395 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
2071
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
396 The `posn-' functions access elements of such lists."
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
397 (nth 1 event))
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
398
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
399 (defsubst event-end (event)
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
400 "Return the ending location of EVENT. EVENT should be a click or drag event.
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
401 If EVENT is a click event, this function is the same as `event-start'.
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
402 The return value is of the form
6039
4eb7f4633370 (posn-x-y): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6005
diff changeset
403 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
2071
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
404 The `posn-' functions access elements of such lists."
3860
70bdc91ef161 * subr.el (event-end): Modified to account for multi-click events.
Jim Blandy <jimb@redhat.com>
parents: 3784
diff changeset
405 (nth (if (consp (nth 2 event)) 2 1) event))
2071
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
406
4414
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
407 (defsubst event-click-count (event)
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
408 "Return the multi-click count of EVENT, a click or drag event.
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
409 The return value is a positive integer."
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
410 (if (integerp (nth 2 event)) (nth 2 event) 1))
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
411
2071
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
412 (defsubst posn-window (position)
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
413 "Return the window in POSITION.
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
414 POSITION should be a list of the form
6039
4eb7f4633370 (posn-x-y): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6005
diff changeset
415 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
2071
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
416 as returned by the `event-start' and `event-end' functions."
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
417 (nth 0 position))
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
418
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
419 (defsubst posn-point (position)
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
420 "Return the buffer location in POSITION.
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
421 POSITION should be a list of the form
6039
4eb7f4633370 (posn-x-y): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6005
diff changeset
422 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
2071
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
423 as returned by the `event-start' and `event-end' functions."
3991
ad2bd545983e * subr.el (posn-point): Properly extract the BUFFER-POSITION field
Jim Blandy <jimb@redhat.com>
parents: 3927
diff changeset
424 (if (consp (nth 1 position))
ad2bd545983e * subr.el (posn-point): Properly extract the BUFFER-POSITION field
Jim Blandy <jimb@redhat.com>
parents: 3927
diff changeset
425 (car (nth 1 position))
ad2bd545983e * subr.el (posn-point): Properly extract the BUFFER-POSITION field
Jim Blandy <jimb@redhat.com>
parents: 3927
diff changeset
426 (nth 1 position)))
2071
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
427
6039
4eb7f4633370 (posn-x-y): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6005
diff changeset
428 (defsubst posn-x-y (position)
4eb7f4633370 (posn-x-y): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6005
diff changeset
429 "Return the x and y coordinates in POSITION.
2071
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
430 POSITION should be a list of the form
6039
4eb7f4633370 (posn-x-y): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6005
diff changeset
431 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
2071
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
432 as returned by the `event-start' and `event-end' functions."
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
433 (nth 2 position))
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
434
7636
83dba60657ef (posn-col-row): Do something useful for scroll bar event.
Richard M. Stallman <rms@gnu.org>
parents: 7615
diff changeset
435 (defun posn-col-row (position)
7693
5fcf0620b8d3 (posn-col-row): Test for consp, not symbolp.
Karl Heuer <kwzh@gnu.org>
parents: 7640
diff changeset
436 "Return the column and row in POSITION, measured in characters.
6039
4eb7f4633370 (posn-x-y): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6005
diff changeset
437 POSITION should be a list of the form
4eb7f4633370 (posn-x-y): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6005
diff changeset
438 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
7636
83dba60657ef (posn-col-row): Do something useful for scroll bar event.
Richard M. Stallman <rms@gnu.org>
parents: 7615
diff changeset
439 as returned by the `event-start' and `event-end' functions.
83dba60657ef (posn-col-row): Do something useful for scroll bar event.
Richard M. Stallman <rms@gnu.org>
parents: 7615
diff changeset
440 For a scroll-bar event, the result column is 0, and the row
83dba60657ef (posn-col-row): Do something useful for scroll bar event.
Richard M. Stallman <rms@gnu.org>
parents: 7615
diff changeset
441 corresponds to the vertical position of the click in the scroll bar."
83dba60657ef (posn-col-row): Do something useful for scroll bar event.
Richard M. Stallman <rms@gnu.org>
parents: 7615
diff changeset
442 (let ((pair (nth 2 position))
83dba60657ef (posn-col-row): Do something useful for scroll bar event.
Richard M. Stallman <rms@gnu.org>
parents: 7615
diff changeset
443 (window (posn-window position)))
7693
5fcf0620b8d3 (posn-col-row): Test for consp, not symbolp.
Karl Heuer <kwzh@gnu.org>
parents: 7640
diff changeset
444 (if (eq (if (consp (nth 1 position))
5fcf0620b8d3 (posn-col-row): Test for consp, not symbolp.
Karl Heuer <kwzh@gnu.org>
parents: 7640
diff changeset
445 (car (nth 1 position))
5fcf0620b8d3 (posn-col-row): Test for consp, not symbolp.
Karl Heuer <kwzh@gnu.org>
parents: 7640
diff changeset
446 (nth 1 position))
7636
83dba60657ef (posn-col-row): Do something useful for scroll bar event.
Richard M. Stallman <rms@gnu.org>
parents: 7615
diff changeset
447 'vertical-scroll-bar)
83dba60657ef (posn-col-row): Do something useful for scroll bar event.
Richard M. Stallman <rms@gnu.org>
parents: 7615
diff changeset
448 (cons 0 (scroll-bar-scale pair (1- (window-height window))))
7693
5fcf0620b8d3 (posn-col-row): Test for consp, not symbolp.
Karl Heuer <kwzh@gnu.org>
parents: 7640
diff changeset
449 (if (eq (if (consp (nth 1 position))
5fcf0620b8d3 (posn-col-row): Test for consp, not symbolp.
Karl Heuer <kwzh@gnu.org>
parents: 7640
diff changeset
450 (car (nth 1 position))
5fcf0620b8d3 (posn-col-row): Test for consp, not symbolp.
Karl Heuer <kwzh@gnu.org>
parents: 7640
diff changeset
451 (nth 1 position))
7636
83dba60657ef (posn-col-row): Do something useful for scroll bar event.
Richard M. Stallman <rms@gnu.org>
parents: 7615
diff changeset
452 'horizontal-scroll-bar)
83dba60657ef (posn-col-row): Do something useful for scroll bar event.
Richard M. Stallman <rms@gnu.org>
parents: 7615
diff changeset
453 (cons (scroll-bar-scale pair (window-width window)) 0)
7640
9b1194796ef5 (posn-col-row): Use let*.
Richard M. Stallman <rms@gnu.org>
parents: 7636
diff changeset
454 (let* ((frame (if (framep window) window (window-frame window)))
9b1194796ef5 (posn-col-row): Use let*.
Richard M. Stallman <rms@gnu.org>
parents: 7636
diff changeset
455 (x (/ (car pair) (frame-char-width frame)))
9b1194796ef5 (posn-col-row): Use let*.
Richard M. Stallman <rms@gnu.org>
parents: 7636
diff changeset
456 (y (/ (cdr pair) (frame-char-height frame))))
7636
83dba60657ef (posn-col-row): Do something useful for scroll bar event.
Richard M. Stallman <rms@gnu.org>
parents: 7615
diff changeset
457 (cons x y))))))
6039
4eb7f4633370 (posn-x-y): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6005
diff changeset
458
2071
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
459 (defsubst posn-timestamp (position)
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
460 "Return the timestamp of POSITION.
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
461 POSITION should be a list of the form
6039
4eb7f4633370 (posn-x-y): New function.
Richard M. Stallman <rms@gnu.org>
parents: 6005
diff changeset
462 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
3411
d91b3097bb76 (posn-timestamp): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 3210
diff changeset
463 as returned by the `event-start' and `event-end' functions."
2071
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
464 (nth 3 position))
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
465
2071
8f410f56d98f (posn-timestamp, posn-col-row, posn-point, posn-window):
Richard M. Stallman <rms@gnu.org>
parents: 2063
diff changeset
466
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
467 ;;;; Obsolescent names for functions.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
468
2569
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
469 (defalias 'dot 'point)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
470 (defalias 'dot-marker 'point-marker)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
471 (defalias 'dot-min 'point-min)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
472 (defalias 'dot-max 'point-max)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
473 (defalias 'window-dot 'window-point)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
474 (defalias 'set-window-dot 'set-window-point)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
475 (defalias 'read-input 'read-string)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
476 (defalias 'send-string 'process-send-string)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
477 (defalias 'send-region 'process-send-region)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
478 (defalias 'show-buffer 'set-window-buffer)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
479 (defalias 'buffer-flush-undo 'buffer-disable-undo)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
480 (defalias 'eval-current-buffer 'eval-buffer)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
481 (defalias 'compiled-function-p 'byte-code-function-p)
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
482
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
483 ;; Some programs still use this as a function.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
484 (defun baud-rate ()
3210
3176c6395ada (baud-rate): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 3153
diff changeset
485 "Obsolete function returning the value of the `baud-rate' variable.
3176c6395ada (baud-rate): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 3153
diff changeset
486 Please convert your programs to use the variable `baud-rate' directly."
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
487 baud-rate)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
488
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
489
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
490 ;;;; Alternate names for functions - these are not being phased out.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
491
2569
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
492 (defalias 'string= 'string-equal)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
493 (defalias 'string< 'string-lessp)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
494 (defalias 'move-marker 'set-marker)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
495 (defalias 'eql 'eq)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
496 (defalias 'not 'null)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
497 (defalias 'rplaca 'setcar)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
498 (defalias 'rplacd 'setcdr)
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3411
diff changeset
499 (defalias 'beep 'ding) ;preserve lingual purity
2569
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
500 (defalias 'indent-to-column 'indent-to)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
501 (defalias 'backward-delete-char 'delete-backward-char)
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
502 (defalias 'search-forward-regexp (symbol-function 're-search-forward))
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
503 (defalias 'search-backward-regexp (symbol-function 're-search-backward))
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
504 (defalias 'int-to-string 'number-to-string)
6551
99ca8123a3ca (set-match-data): New alias.
Richard M. Stallman <rms@gnu.org>
parents: 6441
diff changeset
505 (defalias 'set-match-data 'store-match-data)
1903
87f63305319f * subr.el (string-to-int): Make this an alias for
Jim Blandy <jimb@redhat.com>
parents: 1867
diff changeset
506
87f63305319f * subr.el (string-to-int): Make this an alias for
Jim Blandy <jimb@redhat.com>
parents: 1867
diff changeset
507 ;;; Should this be an obsolete name? If you decide it should, you get
87f63305319f * subr.el (string-to-int): Make this an alias for
Jim Blandy <jimb@redhat.com>
parents: 1867
diff changeset
508 ;;; to go through all the sources and change them.
2569
39ad4eda7fea All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2504
diff changeset
509 (defalias 'string-to-int 'string-to-number)
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
510
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
511 ;;;; Hook manipulation functions.
388
498bcec1cf3a *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 384
diff changeset
512
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
513 (defun run-hooks (&rest hooklist)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
514 "Takes hook names and runs each one in turn. Major mode functions use this.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
515 Each argument should be a symbol, a hook variable.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
516 These symbols are processed in the order specified.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
517 If a hook symbol has a non-nil value, that value may be a function
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
518 or a list of functions to be called to run the hook.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
519 If the value is a function, it is called with no arguments.
9195
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
520 If it is a list, the elements are called, in order, with no arguments.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
521
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
522 To make a hook variable buffer-local, use `make-local-hook', not
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
523 `make-local-variable'."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
524 (while hooklist
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
525 (let ((sym (car hooklist)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
526 (and (boundp sym)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
527 (symbol-value sym)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
528 (let ((value (symbol-value sym)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
529 (if (and (listp value) (not (eq (car value) 'lambda)))
9195
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
530 (while value
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
531 (if (eq (car value) t)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
532 ;; t indicates this hook has a local binding;
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
533 ;; it means to run the global binding too.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
534 (let ((functions (default-value sym)))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
535 (while functions
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
536 (funcall (car functions))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
537 (setq functions (cdr functions))))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
538 (funcall (car value)))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
539 (setq value (cdr value)))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
540 (funcall value)))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
541 (setq hooklist (cdr hooklist))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
542
7110
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
543 (defun run-hook-with-args (hook &rest args)
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
544 "Run HOOK with the specified arguments ARGS.
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
545 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
546 value, that value may be a function or a list of functions to be
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
547 called to run the hook. If the value is a function, it is called with
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
548 the given arguments and its return value is returned. If it is a list
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
549 of functions, those functions are called, in order,
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
550 with the given arguments ARGS.
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
551 It is best not to depend on the value return by `run-hook-with-args',
9195
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
552 as that may change.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
553
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
554 To make a hook variable buffer-local, use `make-local-hook', not
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
555 `make-local-variable'."
7110
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
556 (and (boundp hook)
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
557 (symbol-value hook)
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
558 (let ((value (symbol-value hook)))
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
559 (if (and (listp value) (not (eq (car value) 'lambda)))
9195
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
560 (while value
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
561 (if (eq (car value) t)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
562 ;; t indicates this hook has a local binding;
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
563 ;; it means to run the global binding too.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
564 (let ((functions (default-value hook)))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
565 (while functions
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
566 (apply (car functions) args)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
567 (setq functions (cdr functions))))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
568 (apply (car value) args))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
569 (setq value (cdr value)))
7110
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
570 (apply value args)))))
ea2aef9d9f0e (run-hooks): Don't use mapcar--save consing.
Richard M. Stallman <rms@gnu.org>
parents: 6838
diff changeset
571
9195
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
572 (defun run-hook-with-args-until-success (hook &rest args)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
573 "Run HOOK with the specified arguments ARGS.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
574 HOOK should be a symbol, a hook variable. Its value should
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
575 be a list of functions. We call those functions, one by one,
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
576 passing arguments ARGS to each of them, until one of them
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
577 returns a non-nil value. Then we return that value.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
578 If all the functions return nil, we return nil.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
579
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
580 To make a hook variable buffer-local, use `make-local-hook', not
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
581 `make-local-variable'."
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
582 (and (boundp hook)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
583 (symbol-value hook)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
584 (let ((value (symbol-value hook))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
585 success)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
586 (while (and value (not success))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
587 (if (eq (car value) t)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
588 ;; t indicates this hook has a local binding;
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
589 ;; it means to run the global binding too.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
590 (let ((functions (default-value hook)))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
591 (while (and functions (not success))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
592 (setq success (apply (car functions) args))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
593 (setq functions (cdr functions))))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
594 (setq success (apply (car value) args)))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
595 (setq value (cdr value)))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
596 success)))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
597
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
598 (defun run-hook-with-args-until-failure (hook &rest args)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
599 "Run HOOK with the specified arguments ARGS.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
600 HOOK should be a symbol, a hook variable. Its value should
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
601 be a list of functions. We call those functions, one by one,
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
602 passing arguments ARGS to each of them, until one of them
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
603 returns nil. Then we return nil.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
604 If all the functions return non-nil, we return non-nil.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
605
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
606 To make a hook variable buffer-local, use `make-local-hook', not
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
607 `make-local-variable'."
10273
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
608 ;; We must return non-nil if there are no hook functions!
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
609 (or (not (boundp hook))
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
610 (not (symbol-value hook))
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
611 (let ((value (symbol-value hook))
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
612 (success t))
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
613 (while (and value success)
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
614 (if (eq (car value) t)
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
615 ;; t indicates this hook has a local binding;
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
616 ;; it means to run the global binding too.
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
617 (let ((functions (default-value hook)))
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
618 (while (and functions success)
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
619 (setq success (apply (car functions) args))
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
620 (setq functions (cdr functions))))
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
621 (setq success (apply (car value) args)))
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
622 (setq value (cdr value)))
b53a669d2413 (run-hook-with-args-until-failure):
Richard M. Stallman <rms@gnu.org>
parents: 10254
diff changeset
623 success)))
9195
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
624
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
625 ;; Tell C code how to call this function.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
626 (defconst run-hooks 'run-hooks
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
627 "Variable by which C primitives find the function `run-hooks'.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
628 Don't change it.")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
629
9195
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
630 (defun make-local-hook (hook)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
631 "Make the hook HOOK local to the current buffer.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
632 When a hook is local, its local and global values
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
633 work in concert: running the hook actually runs all the hook
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
634 functions listed in *either* the local value *or* the global value
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
635 of the hook variable.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
636
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
637 This function does nothing if HOOK is already local in the current buffer.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
638
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
639 Do not use `make-local-variable' to make a hook variable buffer-local."
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
640 (if (local-variable-p hook)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
641 nil
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
642 (or (boundp hook) (set hook nil))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
643 (make-local-variable hook)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
644 (set hook (list t))))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
645
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
646 (defun add-hook (hook function &optional append local)
4414
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
647 "Add to the value of HOOK the function FUNCTION.
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
648 FUNCTION is not added if already present.
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
649 FUNCTION is added (if necessary) at the beginning of the hook list
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
650 unless the optional argument APPEND is non-nil, in which case
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
651 FUNCTION is added at the end.
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
652
9195
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
653 The optional fourth argument, LOCAL, if non-nil, says to modify
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
654 the hook's buffer-local value rather than its default value.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
655 This makes no difference if the hook is not buffer-local.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
656 To make a hook variable buffer-local, always use
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
657 `make-local-hook', not `make-local-variable'.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
658
4414
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
659 HOOK should be a symbol, and FUNCTION may be any valid function. If
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
660 HOOK is void, it is first set to nil. If HOOK's value is a single
8959
d33302427a47 (remove-hook, add-hook): Copy existing list before modifying.
Richard M. Stallman <rms@gnu.org>
parents: 8928
diff changeset
661 function, it is changed to a list of functions."
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
662 (or (boundp hook) (set hook nil))
9195
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
663 (or (default-boundp hook) (set-default hook nil))
4414
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
664 ;; If the hook value is a single function, turn it into a list.
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
665 (let ((old (symbol-value hook)))
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
666 (if (or (not (listp old)) (eq (car old) 'lambda))
3356419b94c1 (add-hook): Change a single function into a list.
Richard M. Stallman <rms@gnu.org>
parents: 4235
diff changeset
667 (set hook (list old))))
9202
92d6de82426a (add-hook, remove-hook): If the hook was made local
Richard M. Stallman <rms@gnu.org>
parents: 9195
diff changeset
668 (if (or local
92d6de82426a (add-hook, remove-hook): If the hook was made local
Richard M. Stallman <rms@gnu.org>
parents: 9195
diff changeset
669 ;; Detect the case where make-local-variable was used on a hook
92d6de82426a (add-hook, remove-hook): If the hook was made local
Richard M. Stallman <rms@gnu.org>
parents: 9195
diff changeset
670 ;; and do what we used to do.
92d6de82426a (add-hook, remove-hook): If the hook was made local
Richard M. Stallman <rms@gnu.org>
parents: 9195
diff changeset
671 (and (local-variable-p hook)
92d6de82426a (add-hook, remove-hook): If the hook was made local
Richard M. Stallman <rms@gnu.org>
parents: 9195
diff changeset
672 (not (memq t (symbol-value hook)))))
9195
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
673 ;; Alter the local value only.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
674 (or (if (consp function)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
675 (member function (symbol-value hook))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
676 (memq function (symbol-value hook)))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
677 (set hook
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
678 (if append
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
679 (append (symbol-value hook) (list function))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
680 (cons function (symbol-value hook)))))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
681 ;; Alter the global value (which is also the only value,
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
682 ;; if the hook doesn't have a local value).
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
683 (or (if (consp function)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
684 (member function (default-value hook))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
685 (memq function (default-value hook)))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
686 (set-default hook
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
687 (if append
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
688 (append (default-value hook) (list function))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
689 (cons function (default-value hook)))))))
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
690
9195
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
691 (defun remove-hook (hook function &optional local)
4964
78c13f3054e5 (remove-hook): New function, analogous to add-hook. This
Richard M. Stallman <rms@gnu.org>
parents: 4767
diff changeset
692 "Remove from the value of HOOK the function FUNCTION.
78c13f3054e5 (remove-hook): New function, analogous to add-hook. This
Richard M. Stallman <rms@gnu.org>
parents: 4767
diff changeset
693 HOOK should be a symbol, and FUNCTION may be any valid function. If
78c13f3054e5 (remove-hook): New function, analogous to add-hook. This
Richard M. Stallman <rms@gnu.org>
parents: 4767
diff changeset
694 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
9195
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
695 list of hooks to run in HOOK, then nothing is done. See `add-hook'.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
696
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
697 The optional third argument, LOCAL, if non-nil, says to modify
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
698 the hook's buffer-local value rather than its default value.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
699 This makes no difference if the hook is not buffer-local.
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
700 To make a hook variable buffer-local, always use
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
701 `make-local-hook', not `make-local-variable'."
4964
78c13f3054e5 (remove-hook): New function, analogous to add-hook. This
Richard M. Stallman <rms@gnu.org>
parents: 4767
diff changeset
702 (if (or (not (boundp hook)) ;unbound symbol, or
9195
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
703 (not (default-boundp 'hook))
4964
78c13f3054e5 (remove-hook): New function, analogous to add-hook. This
Richard M. Stallman <rms@gnu.org>
parents: 4767
diff changeset
704 (null (symbol-value hook)) ;value is nil, or
78c13f3054e5 (remove-hook): New function, analogous to add-hook. This
Richard M. Stallman <rms@gnu.org>
parents: 4767
diff changeset
705 (null function)) ;function is nil, then
78c13f3054e5 (remove-hook): New function, analogous to add-hook. This
Richard M. Stallman <rms@gnu.org>
parents: 4767
diff changeset
706 nil ;Do nothing.
9202
92d6de82426a (add-hook, remove-hook): If the hook was made local
Richard M. Stallman <rms@gnu.org>
parents: 9195
diff changeset
707 (if (or local
92d6de82426a (add-hook, remove-hook): If the hook was made local
Richard M. Stallman <rms@gnu.org>
parents: 9195
diff changeset
708 ;; Detect the case where make-local-variable was used on a hook
92d6de82426a (add-hook, remove-hook): If the hook was made local
Richard M. Stallman <rms@gnu.org>
parents: 9195
diff changeset
709 ;; and do what we used to do.
92d6de82426a (add-hook, remove-hook): If the hook was made local
Richard M. Stallman <rms@gnu.org>
parents: 9195
diff changeset
710 (and (local-variable-p hook)
92d6de82426a (add-hook, remove-hook): If the hook was made local
Richard M. Stallman <rms@gnu.org>
parents: 9195
diff changeset
711 (not (memq t (symbol-value hook)))))
9195
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
712 (let ((hook-value (symbol-value hook)))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
713 (if (consp hook-value)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
714 (if (member function hook-value)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
715 (setq hook-value (delete function (copy-sequence hook-value))))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
716 (if (equal hook-value function)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
717 (setq hook-value nil)))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
718 (set hook hook-value))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
719 (let ((hook-value (default-value hook)))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
720 (if (consp hook-value)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
721 (if (member function hook-value)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
722 (setq hook-value (delete function (copy-sequence hook-value))))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
723 (if (equal hook-value function)
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
724 (setq hook-value nil)))
70b00615cb75 (add-hook): Initialize default value and local value.
Richard M. Stallman <rms@gnu.org>
parents: 8959
diff changeset
725 (set-default hook hook-value)))))
9510
f03544494d1c (add-to-list): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9202
diff changeset
726
f03544494d1c (add-to-list): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9202
diff changeset
727 (defun add-to-list (list-var element)
9535
a2908d5da32a (add-to-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 9510
diff changeset
728 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
a2908d5da32a (add-to-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 9510
diff changeset
729 If you want to use `add-to-list' on a variable that is not defined
a2908d5da32a (add-to-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 9510
diff changeset
730 until a certain package is loaded, you should put the call to `add-to-list'
a2908d5da32a (add-to-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 9510
diff changeset
731 into a hook function that will be run only after loading the package.
a2908d5da32a (add-to-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 9510
diff changeset
732 `eval-after-load' provides one way to do this. In some cases
a2908d5da32a (add-to-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 9510
diff changeset
733 other hooks, such as major mode hooks, can do the job."
9510
f03544494d1c (add-to-list): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9202
diff changeset
734 (or (member element (symbol-value list-var))
f03544494d1c (add-to-list): New function.
Richard M. Stallman <rms@gnu.org>
parents: 9202
diff changeset
735 (set list-var (cons element (symbol-value list-var)))))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
736
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
737 ;;;; Specifying things to do after certain files are loaded.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
738
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
739 (defun eval-after-load (file form)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
740 "Arrange that, if FILE is ever loaded, FORM will be run at that time.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
741 This makes or adds to an entry on `after-load-alist'.
10794
4443f78a2117 (eval-after-load): Run FORM now if FILE's already loaded.
Richard M. Stallman <rms@gnu.org>
parents: 10693
diff changeset
742 If FILE is already loaded, evaluate FORM right now.
5440
856ecdc5228a (eval-after-load): Do nothing if FORM is already on the list.
Richard M. Stallman <rms@gnu.org>
parents: 5421
diff changeset
743 It does nothing if FORM is already on the list for FILE.
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
744 FILE should be the name of a library, with no directory name."
10794
4443f78a2117 (eval-after-load): Run FORM now if FILE's already loaded.
Richard M. Stallman <rms@gnu.org>
parents: 10693
diff changeset
745 ;; Make sure there is an element for FILE.
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
746 (or (assoc file after-load-alist)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
747 (setq after-load-alist (cons (list file) after-load-alist)))
10794
4443f78a2117 (eval-after-load): Run FORM now if FILE's already loaded.
Richard M. Stallman <rms@gnu.org>
parents: 10693
diff changeset
748 ;; Add FORM to the element if it isn't there.
5440
856ecdc5228a (eval-after-load): Do nothing if FORM is already on the list.
Richard M. Stallman <rms@gnu.org>
parents: 5421
diff changeset
749 (let ((elt (assoc file after-load-alist)))
856ecdc5228a (eval-after-load): Do nothing if FORM is already on the list.
Richard M. Stallman <rms@gnu.org>
parents: 5421
diff changeset
750 (or (member form (cdr elt))
10794
4443f78a2117 (eval-after-load): Run FORM now if FILE's already loaded.
Richard M. Stallman <rms@gnu.org>
parents: 10693
diff changeset
751 (progn
4443f78a2117 (eval-after-load): Run FORM now if FILE's already loaded.
Richard M. Stallman <rms@gnu.org>
parents: 10693
diff changeset
752 (nconc elt (list form))
4443f78a2117 (eval-after-load): Run FORM now if FILE's already loaded.
Richard M. Stallman <rms@gnu.org>
parents: 10693
diff changeset
753 ;; If the file has been loaded already, run FORM right away.
4443f78a2117 (eval-after-load): Run FORM now if FILE's already loaded.
Richard M. Stallman <rms@gnu.org>
parents: 10693
diff changeset
754 (and (assoc file load-history)
4443f78a2117 (eval-after-load): Run FORM now if FILE's already loaded.
Richard M. Stallman <rms@gnu.org>
parents: 10693
diff changeset
755 (eval form)))))
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
756 form)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
757
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
758 (defun eval-next-after-load (file)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
759 "Read the following input sexp, and run it whenever FILE is loaded.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
760 This makes or adds to an entry on `after-load-alist'.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
761 FILE should be the name of a library, with no directory name."
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
762 (eval-after-load file (read)))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
763
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
764
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
765 ;;;; Input and display facilities.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
766
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
767 (defun read-quoted-char (&optional prompt)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
768 "Like `read-char', except that if the first character read is an octal
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
769 digit, we read up to two more octal digits and return the character
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
770 represented by the octal number consisting of those digits.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
771 Optional argument PROMPT specifies a string to use to prompt the user."
10681
14d924cf1114 (read-quoted-char): Don't log prompt messages.
Karl Heuer <kwzh@gnu.org>
parents: 10586
diff changeset
772 (let ((message-log-max nil) (count 0) (code 0) char)
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
773 (while (< count 3)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
774 (let ((inhibit-quit (zerop count))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
775 (help-form nil))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
776 (and prompt (message "%s-" prompt))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
777 (setq char (read-char))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
778 (if inhibit-quit (setq quit-flag nil)))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
779 (cond ((null char))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
780 ((and (<= ?0 char) (<= char ?7))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
781 (setq code (+ (* code 8) (- char ?0))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
782 count (1+ count))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
783 (and prompt (message (setq prompt
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
784 (format "%s %c" prompt char)))))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
785 ((> count 0)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
786 (setq unread-command-events (list char) count 259))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
787 (t (setq code char count 259))))
6838
ff8e7580e32d (read-quoted-char): Convert meta chars into 128+ chars.
Richard M. Stallman <rms@gnu.org>
parents: 6795
diff changeset
788 ;; Turn a meta-character into a character with the 0200 bit set.
10681
14d924cf1114 (read-quoted-char): Don't log prompt messages.
Karl Heuer <kwzh@gnu.org>
parents: 10586
diff changeset
789 (logior (if (/= (logand code ?\M-\^@) 0) 128 0)
6838
ff8e7580e32d (read-quoted-char): Convert meta chars into 128+ chars.
Richard M. Stallman <rms@gnu.org>
parents: 6795
diff changeset
790 (logand 255 code))))
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
791
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
792 (defun force-mode-line-update (&optional all)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
793 "Force the mode-line of the current buffer to be redisplayed.
6795
a379e974be7c (force-mode-line-update): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 6725
diff changeset
794 With optional non-nil ALL, force redisplay of all mode-lines."
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
795 (if all (save-excursion (set-buffer (other-buffer))))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
796 (set-buffer-modified-p (buffer-modified-p)))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
797
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
798 (defun momentary-string-display (string pos &optional exit-char message)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
799 "Momentarily display STRING in the buffer at POS.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
800 Display remains until next character is typed.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
801 If the char is EXIT-CHAR (optional third arg, default is SPC) it is swallowed;
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
802 otherwise it is then available as input (as a command if nothing else).
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
803 Display MESSAGE (optional fourth arg) in the echo area.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
804 If MESSAGE is nil, instructions to type EXIT-CHAR are displayed there."
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
805 (or exit-char (setq exit-char ?\ ))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
806 (let ((buffer-read-only nil)
6553
fca6271b0983 (momentary-string-display): Avoid modifying the undo list.
Richard M. Stallman <rms@gnu.org>
parents: 6551
diff changeset
807 ;; Don't modify the undo list at all.
fca6271b0983 (momentary-string-display): Avoid modifying the undo list.
Richard M. Stallman <rms@gnu.org>
parents: 6551
diff changeset
808 (buffer-undo-list t)
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
809 (modified (buffer-modified-p))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
810 (name buffer-file-name)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
811 insert-end)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
812 (unwind-protect
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
813 (progn
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
814 (save-excursion
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
815 (goto-char pos)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
816 ;; defeat file locking... don't try this at home, kids!
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
817 (setq buffer-file-name nil)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
818 (insert-before-markers string)
4620
5474175de175 (momentary-string-display): Scroll to keep the string on the screen.
Richard M. Stallman <rms@gnu.org>
parents: 4518
diff changeset
819 (setq insert-end (point))
5474175de175 (momentary-string-display): Scroll to keep the string on the screen.
Richard M. Stallman <rms@gnu.org>
parents: 4518
diff changeset
820 ;; If the message end is off screen, recenter now.
5474175de175 (momentary-string-display): Scroll to keep the string on the screen.
Richard M. Stallman <rms@gnu.org>
parents: 4518
diff changeset
821 (if (> (window-end) insert-end)
5474175de175 (momentary-string-display): Scroll to keep the string on the screen.
Richard M. Stallman <rms@gnu.org>
parents: 4518
diff changeset
822 (recenter (/ (window-height) 2)))
5474175de175 (momentary-string-display): Scroll to keep the string on the screen.
Richard M. Stallman <rms@gnu.org>
parents: 4518
diff changeset
823 ;; If that pushed message start off the screen,
5474175de175 (momentary-string-display): Scroll to keep the string on the screen.
Richard M. Stallman <rms@gnu.org>
parents: 4518
diff changeset
824 ;; scroll to start it at the top of the screen.
5474175de175 (momentary-string-display): Scroll to keep the string on the screen.
Richard M. Stallman <rms@gnu.org>
parents: 4518
diff changeset
825 (move-to-window-line 0)
5474175de175 (momentary-string-display): Scroll to keep the string on the screen.
Richard M. Stallman <rms@gnu.org>
parents: 4518
diff changeset
826 (if (> (point) pos)
5474175de175 (momentary-string-display): Scroll to keep the string on the screen.
Richard M. Stallman <rms@gnu.org>
parents: 4518
diff changeset
827 (progn
5474175de175 (momentary-string-display): Scroll to keep the string on the screen.
Richard M. Stallman <rms@gnu.org>
parents: 4518
diff changeset
828 (goto-char pos)
5474175de175 (momentary-string-display): Scroll to keep the string on the screen.
Richard M. Stallman <rms@gnu.org>
parents: 4518
diff changeset
829 (recenter 0))))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
830 (message (or message "Type %s to continue editing.")
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
831 (single-key-description exit-char))
2033
10cdd2928c7d (momentary-string-display): Handle any event when flushing the display.
Richard M. Stallman <rms@gnu.org>
parents: 2021
diff changeset
832 (let ((char (read-event)))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
833 (or (eq char exit-char)
1821
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1695
diff changeset
834 (setq unread-command-events (list char)))))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
835 (if insert-end
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
836 (save-excursion
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
837 (delete-region pos insert-end)))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
838 (setq buffer-file-name name)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
839 (set-buffer-modified-p modified))))
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
840
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
841
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
842 ;;;; Miscellanea.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
843
10254
1ac3c8fea14a (font-lock-defaults): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 10178
diff changeset
844 ;; A number of major modes set this locally.
1ac3c8fea14a (font-lock-defaults): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 10178
diff changeset
845 ;; Give it a global value to avoid compiler warnings.
1ac3c8fea14a (font-lock-defaults): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 10178
diff changeset
846 (defvar font-lock-defaults nil)
1ac3c8fea14a (font-lock-defaults): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 10178
diff changeset
847
1ac3c8fea14a (font-lock-defaults): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 10178
diff changeset
848 ;; Avoid compiler warnings about this variable,
1ac3c8fea14a (font-lock-defaults): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 10178
diff changeset
849 ;; which has a special meaning on certain system types.
1ac3c8fea14a (font-lock-defaults): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 10178
diff changeset
850 (defvar buffer-file-type nil
1ac3c8fea14a (font-lock-defaults): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 10178
diff changeset
851 "Non-nil if the visited file is a binary file.
1ac3c8fea14a (font-lock-defaults): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 10178
diff changeset
852 This variable is meaningful on MS-DOG and Windows NT.
1ac3c8fea14a (font-lock-defaults): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 10178
diff changeset
853 On those systems, it is automatically local in every buffer.
1ac3c8fea14a (font-lock-defaults): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 10178
diff changeset
854 On other systems, this variable is normally always nil.")
1ac3c8fea14a (font-lock-defaults): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 10178
diff changeset
855
8211
08fb5e917205 (ignore): Put doc string in right place.
Richard M. Stallman <rms@gnu.org>
parents: 7693
diff changeset
856 (defun ignore (&rest ignore)
08fb5e917205 (ignore): Put doc string in right place.
Richard M. Stallman <rms@gnu.org>
parents: 7693
diff changeset
857 "Do nothing and return nil.
08fb5e917205 (ignore): Put doc string in right place.
Richard M. Stallman <rms@gnu.org>
parents: 7693
diff changeset
858 This function accepts any number of arguments, but ignores them."
7400
c415ff549eed (ignore): Allow interactive call.
Richard M. Stallman <rms@gnu.org>
parents: 7298
diff changeset
859 (interactive)
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
860 nil)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
861
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
862 (defun error (&rest args)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
863 "Signal an error, making error message by passing all args to `format'."
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
864 (while t
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
865 (signal 'error (list (apply 'format args)))))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
866
5912
909b94d547c4 (user-original-login-name): Reduce to a defalias, since it's redundant with
Karl Heuer <kwzh@gnu.org>
parents: 5844
diff changeset
867 (defalias 'user-original-login-name 'user-login-name)
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
868
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
869 (defun start-process-shell-command (name buffer &rest args)
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
870 "Start a program in a subprocess. Return the process object for it.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
871 Args are NAME BUFFER COMMAND &rest COMMAND-ARGS.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
872 NAME is name for process. It is modified if necessary to make it unique.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
873 BUFFER is the buffer or (buffer-name) to associate with the process.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
874 Process output goes at end of that buffer, unless you specify
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
875 an output stream or filter function to handle the output.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
876 BUFFER may be also nil, meaning that this process is not associated
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
877 with any buffer
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
878 Third arg is command name, the name of a shell command.
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
879 Remaining arguments are the arguments for the command.
5460
3bd42ee22d1f (start-process-shell-command): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 5440
diff changeset
880 Wildcards and redirection are handled as usual in the shell."
9822
248462096d25 (start-process-shell-command): Don't use exec on windows-nt.
Karl Heuer <kwzh@gnu.org>
parents: 9535
diff changeset
881 (cond
248462096d25 (start-process-shell-command): Don't use exec on windows-nt.
Karl Heuer <kwzh@gnu.org>
parents: 9535
diff changeset
882 ((eq system-type 'vax-vms)
248462096d25 (start-process-shell-command): Don't use exec on windows-nt.
Karl Heuer <kwzh@gnu.org>
parents: 9535
diff changeset
883 (apply 'start-process name buffer args))
10025
3b058e13d177 (start-process-shell-command): Don't use `exec'--
Richard M. Stallman <rms@gnu.org>
parents: 9986
diff changeset
884 ;; We used to use `exec' to replace the shell with the command,
3b058e13d177 (start-process-shell-command): Don't use `exec'--
Richard M. Stallman <rms@gnu.org>
parents: 9986
diff changeset
885 ;; but that failed to handle (...) and semicolon, etc.
9822
248462096d25 (start-process-shell-command): Don't use exec on windows-nt.
Karl Heuer <kwzh@gnu.org>
parents: 9535
diff changeset
886 (t
248462096d25 (start-process-shell-command): Don't use exec on windows-nt.
Karl Heuer <kwzh@gnu.org>
parents: 9535
diff changeset
887 (start-process name buffer shell-file-name shell-command-switch
10025
3b058e13d177 (start-process-shell-command): Don't use `exec'--
Richard M. Stallman <rms@gnu.org>
parents: 9986
diff changeset
888 (mapconcat 'identity args " ")))))
114
899728e6052a Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
889
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
890 (defmacro save-match-data (&rest body)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
891 "Execute the BODY forms, restoring the global value of the match data."
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
892 (let ((original (make-symbol "match-data")))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
893 (list
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
894 'let (list (list original '(match-data)))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
895 (list 'unwind-protect
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
896 (cons 'progn body)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
897 (list 'store-match-data original)))))
144
535ec1aa78ef *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 114
diff changeset
898
10560
fd09d51dfd77 (match-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10368
diff changeset
899 (defun match-string (n &optional string)
fd09d51dfd77 (match-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10368
diff changeset
900 "Return the Nth subexpression matched by the last regexp search or match.
fd09d51dfd77 (match-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10368
diff changeset
901 If the last search or match was done against a string,
fd09d51dfd77 (match-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10368
diff changeset
902 specify that string as the second argument STRING."
fd09d51dfd77 (match-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10368
diff changeset
903 (if string
10586
5fd4e92c34a6 (match-string): Fix braino.
Richard M. Stallman <rms@gnu.org>
parents: 10569
diff changeset
904 (substring string (match-beginning n) (match-end n))
5fd4e92c34a6 (match-string): Fix braino.
Richard M. Stallman <rms@gnu.org>
parents: 10569
diff changeset
905 (buffer-substring (match-beginning n) (match-end n))))
10560
fd09d51dfd77 (match-string): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10368
diff changeset
906
5385
53077bf7c718 (shell-quote-argument): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5302
diff changeset
907 (defun shell-quote-argument (argument)
53077bf7c718 (shell-quote-argument): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5302
diff changeset
908 "Quote an argument for passing as argument to an inferior shell."
53077bf7c718 (shell-quote-argument): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5302
diff changeset
909 ;; Quote everything except POSIX filename characters.
53077bf7c718 (shell-quote-argument): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5302
diff changeset
910 ;; This should be safe enough even for really weird shells.
53077bf7c718 (shell-quote-argument): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5302
diff changeset
911 (let ((result "") (start 0) end)
6309
9217f29851c2 Don't use triple-hyphen in a character class.
Karl Heuer <kwzh@gnu.org>
parents: 6167
diff changeset
912 (while (string-match "[^-0-9a-zA-Z_./]" argument start)
5385
53077bf7c718 (shell-quote-argument): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5302
diff changeset
913 (setq end (match-beginning 0)
53077bf7c718 (shell-quote-argument): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5302
diff changeset
914 result (concat result (substring argument start end)
53077bf7c718 (shell-quote-argument): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5302
diff changeset
915 "\\" (substring argument end (1+ end)))
53077bf7c718 (shell-quote-argument): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5302
diff changeset
916 start (1+ end)))
53077bf7c718 (shell-quote-argument): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5302
diff changeset
917 (concat result (substring argument start))))
53077bf7c718 (shell-quote-argument): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5302
diff changeset
918
5844
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
919 (defun make-syntax-table (&optional oldtable)
5421
a248a39fa4b8 (make-syntax-table): New function; no longer an alias
Richard M. Stallman <rms@gnu.org>
parents: 5385
diff changeset
920 "Return a new syntax table.
a248a39fa4b8 (make-syntax-table): New function; no longer an alias
Richard M. Stallman <rms@gnu.org>
parents: 5385
diff changeset
921 It inherits all letters and control characters from the standard
a248a39fa4b8 (make-syntax-table): New function; no longer an alias
Richard M. Stallman <rms@gnu.org>
parents: 5385
diff changeset
922 syntax table; other characters are copied from the standard syntax table."
5844
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
923 (if oldtable
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
924 (copy-syntax-table oldtable)
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
925 (let ((table (copy-syntax-table))
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
926 i)
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
927 (setq i 0)
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
928 (while (<= i 31)
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
929 (aset table i 13)
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
930 (setq i (1+ i)))
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
931 (setq i ?A)
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
932 (while (<= i ?Z)
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
933 (aset table i 13)
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
934 (setq i (1+ i)))
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
935 (setq i ?a)
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
936 (while (<= i ?z)
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
937 (aset table i 13)
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
938 (setq i (1+ i)))
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
939 (setq i 128)
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
940 (while (<= i 255)
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
941 (aset table i 13)
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
942 (setq i (1+ i)))
445de172c217 (make-syntax-table): Behave like copy-syntax-table if an argument is given,
Karl Heuer <kwzh@gnu.org>
parents: 5460
diff changeset
943 table)))
10825
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
944
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
945 (defun global-set-key (key command)
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
946 "Give KEY a global binding as COMMAND.
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
947 COMMAND is a symbol naming an interactively-callable function.
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
948 KEY is a key sequence (a string or vector of characters or event types).
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
949 Non-ASCII characters with codes above 127 (such as ISO Latin-1)
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
950 can be included if you use a vector.
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
951 Note that if KEY has a local binding in the current buffer
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
952 that local binding will continue to shadow any global binding."
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
953 (interactive "KSet key globally: \nCSet key %s to command: ")
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
954 (or (vectorp key) (stringp key)
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
955 (signal 'wrong-type-argument (list 'arrayp key)))
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
956 (define-key (current-global-map) key command)
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
957 nil)
5421
a248a39fa4b8 (make-syntax-table): New function; no longer an alias
Richard M. Stallman <rms@gnu.org>
parents: 5385
diff changeset
958
10825
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
959 (defun local-set-key (key command)
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
960 "Give KEY a local binding as COMMAND.
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
961 COMMAND is a symbol naming an interactively-callable function.
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
962 KEY is a key sequence (a string or vector of characters or event types).
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
963 Non-ASCII characters with codes above 127 (such as ISO Latin-1)
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
964 can be included if you use a vector.
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
965 The binding goes in the current buffer's local map,
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
966 which in most cases is shared with all other buffers in the same major mode."
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
967 (interactive "KSet key locally: \nCSet key %s locally to command: ")
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
968 (let ((map (current-local-map)))
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
969 (or map
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
970 (use-local-map (setq map (make-sparse-keymap))))
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
971 (or (vectorp key) (stringp key)
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
972 (signal 'wrong-type-argument (list 'arrayp key)))
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
973 (define-key map key command))
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
974 nil)
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
975
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
976 (defun global-unset-key (key)
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
977 "Remove global binding of KEY.
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
978 KEY is a string representing a sequence of keystrokes."
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
979 (interactive "kUnset key globally: ")
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
980 (global-set-key key nil))
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
981
10826
bd0ab0601489 (local-unset-key): Fix args in previous change.
Karl Heuer <kwzh@gnu.org>
parents: 10825
diff changeset
982 (defun local-unset-key (key)
10825
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
983 "Remove local binding of KEY.
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
984 KEY is a string representing a sequence of keystrokes."
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
985 (interactive "kUnset key locally: ")
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
986 (if (current-local-map)
10826
bd0ab0601489 (local-unset-key): Fix args in previous change.
Karl Heuer <kwzh@gnu.org>
parents: 10825
diff changeset
987 (local-set-key key nil))
10825
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
988 nil)
4dba26c66bf5 (global_set_key, local_set_key, global_unset_key)
Richard M. Stallman <rms@gnu.org>
parents: 10794
diff changeset
989
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
990 ;; now in fns.c
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
991 ;(defun nth (n list)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
992 ; "Returns the Nth element of LIST.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
993 ;N counts from zero. If LIST is not that long, nil is returned."
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
994 ; (car (nthcdr n list)))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
995 ;
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
996 ;(defun copy-alist (alist)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
997 ; "Return a copy of ALIST.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
998 ;This is a new alist which represents the same mapping
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
999 ;from objects to objects, but does not share the alist structure with ALIST.
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
1000 ;The objects mapped (cars and cdrs of elements of the alist)
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
1001 ;are shared, however."
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
1002 ; (setq alist (copy-sequence alist))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
1003 ; (let ((tail alist))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
1004 ; (while tail
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
1005 ; (if (consp (car tail))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
1006 ; (setcar tail (cons (car (car tail)) (cdr (car tail)))))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
1007 ; (setq tail (cdr tail))))
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
1008 ; alist)
787
3cece0106722 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 779
diff changeset
1009
3cece0106722 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 779
diff changeset
1010 ;;; subr.el ends here
2504
181eef669324 * subr.el (overlay-start, overlay-end, overlay-buffer): New
Jim Blandy <jimb@redhat.com>
parents: 2428
diff changeset
1011