annotate lisp/prim/symbols.el @ 171:929b76928fce r20-3b12

Import from CVS: tag r20-3b12
author cvs
date Mon, 13 Aug 2007 09:47:52 +0200
parents 131b0175ea99
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; symbols.el --- functions for working with symbols and symbol values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
18 ;; along with XEmacs; see the file COPYING. If not, write to the
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
19 ;; Free Software Foundation, 59 Temple Place - Suite 330,
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
20 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Not yet dumped into XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; The idea behind magic variables is that you can specify arbitrary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; behavior to happen when setting or retrieving a variable's value. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; purpose of this is to make it possible to cleanly provide support for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; obsolete variables (e.g. unread-command-event, which is obsolete for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; unread-command-events) and variable compatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; (e.g. suggest-key-bindings, the FSF equivalent of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; teach-extended-commands-p and teach-extended-commands-timeout).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; There are a large number of functions pertaining to a variable's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; value:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; boundp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; globally-boundp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; makunbound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; symbol-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; set / setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; default-boundp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; default-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; set-default / setq-default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; make-variable-buffer-local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; make-local-variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; kill-local-variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; kill-console-local-variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; symbol-value-in-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; symbol-value-in-console
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; local-variable-p / local-variable-if-set-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; Plus some "meta-functions":
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; defvaralias
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; variable-alias
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; indirect-variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; I wanted an implementation that:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; -- would work with all the above functions, but (a) didn't require
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; a separate handler for every function, and (b) would work OK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; even if more functions are added (e.g. `set-symbol-value-in-buffer'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; or `makunbound-default') or if more arguments are added to a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; -- avoided consing if at all possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; -- didn't slow down operations on non-magic variables (therefore,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; storing the magic information using `put' is ruled out).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; perhaps this should check whether the functions are bound, so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; some handlers can be unspecified. That requires that all functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;; are defined before `define-magic-variable-handlers' is called,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; though.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; perhaps there should be something that combines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; `define-magic-variable-handlers' with `defvaralias'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (defun define-magic-variable-handlers (variable handler-class harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 "Set the magic variable handles for VARIABLE to those in HANDLER-CLASS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 HANDLER-CLASS should be a symbol. The handlers are constructed by adding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 the handler type to HANDLER-CLASS. HARG is passed as the HARG value for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 each of the handlers."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 #'(lambda (htype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (set-magic-variable-handler variable htype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (intern (concat (symbol-value handler-class)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (symbol-value htype)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 harg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 '(get-value set-value other-predicate other-action)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;; unread-command-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (defun mvh-first-of-list-get-value (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (car (apply fun harg args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (defun mvh-first-of-list-set-value (sym value setfun getfun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (apply setfun harg (cons value (apply getfun harg args)) args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (defun mvh-first-of-list-other-predicate (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (apply fun harg args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (defun mvh-first-of-list-other-action (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (apply fun harg args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (define-magic-variable-handlers 'unread-command-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 'mvh-first-of-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 'unread-command-events)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; last-command-char, last-input-char, unread-command-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (defun mvh-char-to-event-get-value (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (event-to-character (apply fun harg args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (defun mvh-char-to-event-set-value (sym value setfun getfun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (let ((event (apply getfun harg args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (if (event-live-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (setq event (allocate-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (apply setfun harg event args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (character-to-event value event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (defun mvh-char-to-event-other-predicate (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (apply fun harg args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (defun mvh-char-to-event-other-action (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (apply fun harg args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (define-magic-variable-handlers 'last-command-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 'mvh-char-to-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 'last-command-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (define-magic-variable-handlers 'last-input-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 'mvh-char-to-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 'last-input-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (define-magic-variable-handlers 'unread-command-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 'mvh-char-to-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 'unread-command-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;; suggest-key-bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (set-magic-variable-handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 'suggest-key-bindings 'get-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 #'(lambda (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (and (apply fun 'teach-extended-commands-p args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (apply fun 'teach-extended-commands-timeout args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (set-magic-variable-handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 'suggest-key-bindings 'set-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 #'(lambda (sym value setfun getfun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (apply setfun 'teach-extended-commands-p (not (null value)) args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (if value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (apply 'teach-extended-commands-timeout
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (if (numberp value) value 2) args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (set-magic-variable-handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 'suggest-key-bindings 'other-action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 #'(lambda (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (apply fun 'teach-extended-commands-p args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (apply fun 'teach-extended-commands-timeout args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (set-magic-variable-handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 'suggest-key-bindings 'other-predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 #'(lambda (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (and (apply fun 'teach-extended-commands-p args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (apply fun 'teach-extended-commands-timeout args))))