annotate lisp/symbols.el @ 267:966663fcf606 r20-5b32

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