annotate lisp/prim/symbols.el @ 12:bcdc7deadc19 r19-15b7

Import from CVS: tag r19-15b7
author cvs
date Mon, 13 Aug 2007 08:48:16 +0200
parents 376386a54a3c
children 0293115a14e9
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; Not yet dumped into XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; The idea behind magic variables is that you can specify arbitrary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; behavior to happen when setting or retrieving a variable's value. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; purpose of this is to make it possible to cleanly provide support for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; obsolete variables (e.g. unread-command-event, which is obsolete for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; unread-command-events) and variable compatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; (e.g. suggest-key-bindings, the FSF equivalent of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; teach-extended-commands-p and teach-extended-commands-timeout).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; There are a large number of functions pertaining to a variable's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; value:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; boundp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; globally-boundp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; makunbound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; symbol-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; set / setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; default-boundp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; default-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; set-default / setq-default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; make-variable-buffer-local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; make-local-variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; kill-local-variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; kill-console-local-variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; symbol-value-in-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; symbol-value-in-console
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; local-variable-p / local-variable-if-set-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; Plus some "meta-functions":
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; defvaralias
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; variable-alias
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; indirect-variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; I wanted an implementation that:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; -- would work with all the above functions, but (a) didn't require
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; a separate handler for every function, and (b) would work OK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; even if more functions are added (e.g. `set-symbol-value-in-buffer'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; or `makunbound-default') or if more arguments are added to a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; -- avoided consing if at all possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; -- didn't slow down operations on non-magic variables (therefore,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; storing the magic information using `put' is ruled out).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; perhaps this should check whether the functions are bound, so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; some handlers can be unspecified. That requires that all functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; are defined before `define-magic-variable-handlers' is called,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;; though.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; perhaps there should be something that combines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; `define-magic-variable-handlers' with `defvaralias'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (defun define-magic-variable-handlers (variable handler-class harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 "Set the magic variable handles for VARIABLE to those in HANDLER-CLASS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 HANDLER-CLASS should be a symbol. The handlers are constructed by adding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 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
86 each of the handlers."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 #'(lambda (htype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (set-magic-variable-handler variable htype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (intern (concat (symbol-value handler-class)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 "-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (symbol-value htype)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 harg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 '(get-value set-value other-predicate other-action)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;; unread-command-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (defun mvh-first-of-list-get-value (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (car (apply fun harg args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defun mvh-first-of-list-set-value (sym value setfun getfun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (apply setfun harg (cons value (apply getfun harg args)) args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (defun mvh-first-of-list-other-predicate (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (apply fun harg args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (defun mvh-first-of-list-other-action (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (apply fun harg args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (define-magic-variable-handlers 'unread-command-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 'mvh-first-of-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 'unread-command-events)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; last-command-char, last-input-char, unread-command-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (defun mvh-char-to-event-get-value (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (event-to-character (apply fun harg args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (defun mvh-char-to-event-set-value (sym value setfun getfun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (let ((event (apply getfun harg args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (if (event-live-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (setq event (allocate-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (apply setfun harg event args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (character-to-event value event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defun mvh-char-to-event-other-predicate (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (apply fun harg args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (defun mvh-char-to-event-other-action (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (apply fun harg args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (define-magic-variable-handlers 'last-command-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 'mvh-char-to-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 'last-command-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (define-magic-variable-handlers 'last-input-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 'mvh-char-to-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 'last-input-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (define-magic-variable-handlers 'unread-command-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 'mvh-char-to-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 'unread-command-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;; suggest-key-bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (set-magic-variable-handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 'suggest-key-bindings 'get-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 #'(lambda (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (and (apply fun 'teach-extended-commands-p args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (apply fun 'teach-extended-commands-timeout args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (set-magic-variable-handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 'suggest-key-bindings 'set-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 #'(lambda (sym value setfun getfun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (apply setfun 'teach-extended-commands-p (not (null value)) args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (if value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (apply 'teach-extended-commands-timeout
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (if (numberp value) value 2) args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (set-magic-variable-handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 'suggest-key-bindings 'other-action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 #'(lambda (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (apply fun 'teach-extended-commands-p args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (apply fun 'teach-extended-commands-timeout args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (set-magic-variable-handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 'suggest-key-bindings 'other-predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 #'(lambda (sym fun args harg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (and (apply fun 'teach-extended-commands-p args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (apply fun 'teach-extended-commands-timeout args))))