Mercurial > emacs
annotate lisp/eieio/eieio.el @ 104402:5df6945a3eaa
Remove statement preventing it from being loaded twice.
Remove statement preventing it from being byte-compiled if loaded.
Remove `(load "cl-macs" nil t)' statement: the functions in
cl-macs are autoloaded by cl.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sat, 22 Aug 2009 14:33:55 +0000 |
parents | 2efe3dc24373 |
children |
rev | line source |
---|---|
104401
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1 ;;; eieio.el --- Enhanced Implementation of Emacs Interpreted Objects |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2 ;;; or maybe Eric's Implementation of Emacs Intrepreted Objects |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
3 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
4 ;;; Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
5 ;;; 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
6 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
7 ;; Author: Eric M. Ludlam <zappo@gnu.org> |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
8 ;; Version: 0.2 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
9 ;; Keywords: OO, lisp |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
10 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
11 ;; This file is part of GNU Emacs. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
12 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
14 ;; it under the terms of the GNU General Public License as published by |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
16 ;; (at your option) any later version. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
17 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
18 ;; GNU Emacs is distributed in the hope that it will be useful, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
21 ;; GNU General Public License for more details. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
22 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
23 ;; You should have received a copy of the GNU General Public License |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
25 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
26 ;;; Commentary: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
27 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
28 ;; EIEIO is a series of Lisp routines which implements a subset of |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
29 ;; CLOS, the Common Lisp Object System. In addition, EIEIO also adds |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
30 ;; a few new features which help it integrate more strongly with the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
31 ;; Emacs running environment. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
32 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
33 ;; See eieio.texi for complete documentation on using this package. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
34 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
35 ;; There is funny stuff going on with typep and deftype. This |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
36 ;; is the only way I seem to be able to make this stuff load properly. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
37 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
38 ;; @TODO - fix :initform to be a form, not a quoted value |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
39 ;; @TODO - For API calls like `object-p', replace with something |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
40 ;; that does not conflict with "object", meaning a lisp object. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
41 ;; @TODO - Prefix non-clos functions with `eieio-'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
42 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
43 ;;; Code: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
44 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
45 (defvar eieio-version "1.2" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
46 "Current version of EIEIO.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
47 |
104402
5df6945a3eaa
Remove statement preventing it from being loaded twice.
Chong Yidong <cyd@stupidchicken.com>
parents:
104401
diff
changeset
|
48 (require 'cl) |
104401
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
49 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
50 (defun eieio-version () |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
51 "Display the current version of EIEIO." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
52 (interactive) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
53 (message eieio-version)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
54 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
55 (eval-and-compile |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
56 ;; Abount the above. EIEIO must process it's own code when it compiles |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
57 ;; itself, thus, by eval-and-compiling outselves, we solve the problem. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
58 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
59 ;; Compatibility |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
60 (if (fboundp 'compiled-function-arglist) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
61 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
62 ;; XEmacs can only access a compiled functions arglist like this: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
63 (defalias 'eieio-compiled-function-arglist 'compiled-function-arglist) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
64 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
65 ;; Emacs doesn't have this function, but since FUNC is a vector, we can just |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
66 ;; grab the appropriate element. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
67 (defun eieio-compiled-function-arglist (func) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
68 "Return the argument list for the compiled function FUNC." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
69 (aref func 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
70 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
71 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
72 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
73 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
74 ;;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
75 ;; Variable declarations. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
76 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
77 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
78 (defvar eieio-hook nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
79 "*This hook is executed, then cleared each time `defclass' is called.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
80 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
81 (defvar eieio-error-unsupported-class-tags nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
82 "*Non nil to throw an error if an encountered tag us unsupported. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
83 This may prevent classes from CLOS applications from being used with EIEIO |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
84 since EIEIO does not support all CLOS tags.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
85 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
86 (defvar eieio-skip-typecheck nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
87 "*If non-nil, skip all slot typechecking. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
88 Set this to t permanently if a program is functioning well to get a |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
89 small speed increase. This variable is also used internally to handle |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
90 default setting for optimization purposes.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
91 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
92 (defvar eieio-optimize-primary-methods-flag t |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
93 "Non-nil means to optimize the method dispatch on primary methods.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
94 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
95 ;; State Variables |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
96 (defvar this nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
97 "Inside a method, this variable is the object in question. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
98 DO NOT SET THIS YOURSELF unless you are trying to simulate friendly slots. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
99 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
100 Note: Embedded methods are no longer supported. The variable THIS is |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
101 still set for CLOS methods for the sake of routines like |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
102 `call-next-method'") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
103 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
104 (defvar scoped-class nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
105 "This is set to a class when a method is running. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
106 This is so we know we are allowed to check private parts or how to |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
107 execute a `call-next-method'. DO NOT SET THIS YOURSELF!") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
108 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
109 (defvar eieio-initializing-object nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
110 "Set to non-nil while initializing an object.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
111 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
112 (defconst eieio-unbound (make-symbol "unbound") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
113 "Uninterned symbol representing an unbound slot in an object.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
114 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
115 ;; This is a bootstrap for eieio-default-superclass so it has a value |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
116 ;; while it is being built itself. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
117 (defvar eieio-default-superclass nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
118 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
119 (defconst class-symbol 1 "Class's symbol (self-referencing.).") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
120 (defconst class-parent 2 "Class parent slot.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
121 (defconst class-children 3 "Class children class slot.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
122 (defconst class-symbol-obarray 4 "Obarray permitting fast access to variable position indexes.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
123 ;; @todo |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
124 ;; the word "public" here is leftovers from the very first version. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
125 ;; Get rid of it! |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
126 (defconst class-public-a 5 "Class attribute index.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
127 (defconst class-public-d 6 "Class attribute defaults index.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
128 (defconst class-public-doc 7 "Class documentation strings for attributes.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
129 (defconst class-public-type 8 "Class type for a slot.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
130 (defconst class-public-custom 9 "Class custom type for a slot.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
131 (defconst class-public-custom-label 10 "Class custom group for a slot.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
132 (defconst class-public-custom-group 11 "Class custom group for a slot.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
133 (defconst class-public-printer 12 "Printer for a slot.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
134 (defconst class-protection 13 "Class protection for a slot.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
135 (defconst class-initarg-tuples 14 "Class initarg tuples list.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
136 (defconst class-class-allocation-a 15 "Class allocated attributes.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
137 (defconst class-class-allocation-doc 16 "Class allocated documentation.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
138 (defconst class-class-allocation-type 17 "Class allocated value type.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
139 (defconst class-class-allocation-custom 18 "Class allocated custom descriptor.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
140 (defconst class-class-allocation-custom-label 19 "Class allocated custom descriptor.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
141 (defconst class-class-allocation-custom-group 20 "Class allocated custom group.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
142 (defconst class-class-allocation-printer 21 "Class allocated printer for a slot.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
143 (defconst class-class-allocation-protection 22 "Class allocated protection list.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
144 (defconst class-class-allocation-values 23 "Class allocated value vector.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
145 (defconst class-default-object-cache 24 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
146 "Cache index of what a newly created object would look like. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
147 This will speed up instantiation time as only a `copy-sequence' will |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
148 be needed, instead of looping over all the values and setting them |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
149 from the default.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
150 (defconst class-options 25 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
151 "Storage location of tagged class options. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
152 Stored outright without modifications or stripping.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
153 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
154 (defconst class-num-slots 26 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
155 "Number of slots in the class definition object.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
156 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
157 (defconst object-class 1 "Index in an object vector where the class is stored.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
158 (defconst object-name 2 "Index in an object where the name is stored.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
159 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
160 (defconst method-static 0 "Index into :static tag on a method.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
161 (defconst method-before 1 "Index into :before tag on a method.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
162 (defconst method-primary 2 "Index into :primary tag on a method.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
163 (defconst method-after 3 "Index into :after tag on a method.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
164 (defconst method-num-lists 4 "Number of indexes into methods vector in which groups of functions are kept.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
165 (defconst method-generic-before 4 "Index into generic :before tag on a method.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
166 (defconst method-generic-primary 5 "Index into generic :primary tag on a method.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
167 (defconst method-generic-after 6 "Index into generic :after tag on a method.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
168 (defconst method-num-slots 7 "Number of indexes into a method's vector.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
169 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
170 ;; How to specialty compile stuff. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
171 (autoload 'byte-compile-file-form-defmethod "eieio-comp" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
172 "This function is used to byte compile methods in a nice way.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
173 (put 'defmethod 'byte-hunk-handler 'byte-compile-file-form-defmethod) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
174 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
175 (eval-when-compile (require 'eieio-comp)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
176 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
177 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
178 ;;; Important macros used in eieio. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
179 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
180 (defmacro class-v (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
181 "Internal: Return the class vector from the CLASS symbol." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
182 ;; No check: If eieio gets this far, it's probably been checked already. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
183 `(get ,class 'eieio-class-definition)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
184 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
185 (defmacro class-p (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
186 "Return t if CLASS is a valid class vector. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
187 CLASS is a symbol." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
188 ;; this new method is faster since it doesn't waste time checking lots of |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
189 ;; things. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
190 `(condition-case nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
191 (eq (aref (class-v ,class) 0) 'defclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
192 (error nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
193 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
194 ;;;###autoload |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
195 (defmacro eieio-object-p (obj) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
196 "Return non-nil if OBJ is an EIEIO object." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
197 `(condition-case nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
198 (let ((tobj ,obj)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
199 (and (eq (aref tobj 0) 'object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
200 (class-p (aref tobj object-class)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
201 (error nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
202 (defalias 'object-p 'eieio-object-p) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
203 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
204 (defmacro class-constructor (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
205 "Return the symbol representing the constructor of CLASS." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
206 `(aref (class-v ,class) class-symbol)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
207 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
208 (defmacro generic-p (method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
209 "Return t if symbol METHOD is a generic function. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
210 Only methods have the symbol `eieio-method-obarray' as a property (which |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
211 contains a list of all bindings to that method type.)" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
212 `(and (fboundp ,method) (get ,method 'eieio-method-obarray))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
213 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
214 (defun generic-primary-only-p (method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
215 "Return t if symbol METHOD is a generic function with only primary methods. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
216 Only methods have the symbol `eieio-method-obarray' as a property (which |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
217 contains a list of all bindings to that method type.) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
218 Methods with only primary implementations are executed in an optimized way." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
219 (and (generic-p method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
220 (let ((M (get method 'eieio-method-tree))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
221 (and (< 0 (length (aref M method-primary))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
222 (not (aref M method-static)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
223 (not (aref M method-before)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
224 (not (aref M method-after)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
225 (not (aref M method-generic-before)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
226 (not (aref M method-generic-primary)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
227 (not (aref M method-generic-after)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
228 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
229 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
230 (defun generic-primary-only-one-p (method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
231 "Return t if symbol METHOD is a generic function with only primary methods. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
232 Only methods have the symbol `eieio-method-obarray' as a property (which |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
233 contains a list of all bindings to that method type.) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
234 Methods with only primary implementations are executed in an optimized way." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
235 (and (generic-p method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
236 (let ((M (get method 'eieio-method-tree))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
237 (and (= 1 (length (aref M method-primary))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
238 (not (aref M method-static)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
239 (not (aref M method-before)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
240 (not (aref M method-after)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
241 (not (aref M method-generic-before)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
242 (not (aref M method-generic-primary)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
243 (not (aref M method-generic-after)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
244 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
245 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
246 (defmacro class-option-assoc (list option) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
247 "Return from LIST the found OPTION. Nil if it doesn't exist." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
248 `(car-safe (cdr (memq ,option ,list)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
249 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
250 (defmacro class-option (class option) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
251 "Return the value stored for CLASS' OPTION. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
252 Return nil if that option doesn't exist." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
253 `(class-option-assoc (aref (class-v ,class) class-options) ',option)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
254 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
255 (defmacro class-abstract-p (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
256 "Return non-nil if CLASS is abstract. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
257 Abstract classes cannot be instantiated." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
258 `(class-option ,class :abstract)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
259 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
260 (defmacro class-method-invocation-order (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
261 "Return the invocation order of CLASS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
262 Abstract classes cannot be instantiated." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
263 `(or (class-option ,class :method-invocation-order) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
264 :breadth-first)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
265 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
266 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
267 ;;; Defining a new class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
268 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
269 (defmacro defclass (name superclass slots &rest options-and-doc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
270 "Define NAME as a new class derived from SUPERCLASS with SLOTS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
271 OPTIONS-AND-DOC is used as the class' options and base documentation. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
272 SUPERCLASS is a list of superclasses to inherit from, with SLOTS |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
273 being the slots residing in that class definition. NOTE: Currently |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
274 only one slot may exist in SUPERCLASS as multiple inheritance is not |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
275 yet supported. Supported tags are: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
276 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
277 :initform - initializing form |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
278 :initarg - tag used during initialization |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
279 :accessor - tag used to create a function to access this slot |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
280 :allocation - specify where the value is stored. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
281 defaults to `:instance', but could also be `:class' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
282 :writer - a function symbol which will `write' an object's slot |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
283 :reader - a function symbol which will `read' an object |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
284 :type - the type of data allowed in this slot (see `typep') |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
285 :documentation |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
286 - A string documenting use of this slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
287 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
288 The following are extensions on CLOS: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
289 :protection - Specify protection for this slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
290 Defaults to `:public'. Also use `:protected', or `:private' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
291 :custom - When customizing an object, the custom :type. Public only. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
292 :label - A text string label used for a slot when customizing. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
293 :group - Name of a customization group this slot belongs in. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
294 :printer - A function to call to print the value of a slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
295 See `eieio-override-prin1' as an example. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
296 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
297 A class can also have optional options. These options happen in place |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
298 of documentation, (including a :documentation tag) in addition to |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
299 documentation, or not at all. Supported options are: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
300 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
301 :documentation - The doc-string used for this class. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
302 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
303 Options added to EIEIO: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
304 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
305 :allow-nil-initform - Non-nil to skip typechecking of initforms if nil. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
306 :custom-groups - List of custom group names. Organizes slots into |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
307 reasonable groups for customizations. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
308 :abstract - Non-nil to prevent instances of this class. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
309 If a string, use as an error string if someone does |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
310 try to make an instance. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
311 :method-invocation-order |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
312 - Control the method invokation order if there is |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
313 multiple inheritance. Valid values are: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
314 :breadth-first - The default. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
315 :depth-first |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
316 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
317 Options in CLOS not supported in EIEIO: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
318 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
319 :metaclass - Class to use in place of `standard-class' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
320 :default-initargs - Initargs to use when initializing new objects of |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
321 this class. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
322 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
323 Due to the way class options are set up, you can add any tags in you |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
324 wish, and reference them using the function `class-option'." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
325 ;; We must `eval-and-compile' this so that when we byte compile |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
326 ;; an eieio program, there is no need to load it ahead of time. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
327 ;; It also provides lots of nice debugging errors at compile time. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
328 `(eval-and-compile |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
329 (eieio-defclass ',name ',superclass ',slots ',options-and-doc))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
330 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
331 (defvar eieio-defclass-autoload-map (make-vector 7 nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
332 "Symbol map of superclasses we find in autoloads.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
333 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
334 (defun eieio-defclass-autoload (cname superclasses filename doc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
335 "Create autoload symbols for the EIEIO class CNAME. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
336 SUPERCLASSES are the superclasses that CNAME inherites from. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
337 DOC is the docstring for CNAME. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
338 This function creates a mock-class for CNAME and adds it into |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
339 SUPERCLASSES as children. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
340 It creates an autoload function for CNAME's constructor." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
341 ;; Assume we've already debugged inputs. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
342 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
343 (let* ((oldc (when (class-p cname) (class-v cname))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
344 (newc (make-vector class-num-slots nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
345 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
346 (if oldc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
347 nil ;; Do nothing if we already have this class. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
348 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
349 ;; Create the class in NEWC, but don't fill anything else in. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
350 (aset newc 0 'defclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
351 (aset newc class-symbol cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
352 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
353 (let ((clear-parent nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
354 ;; No parents? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
355 (when (not superclasses) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
356 (setq superclasses '(eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
357 clear-parent t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
358 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
359 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
360 ;; Hook our new class into the existing structures so we can |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
361 ;; autoload it later. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
362 (dolist (SC superclasses) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
363 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
364 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
365 ;; TODO - If we create an autoload that is in the map, that |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
366 ;; map needs to be cleared! |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
367 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
368 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
369 ;; Does our parent exist? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
370 (if (not (class-p SC)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
371 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
372 ;; Create a symbol for this parent, and then store this |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
373 ;; parent on that symbol. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
374 (let ((sym (intern (symbol-name SC) eieio-defclass-autoload-map))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
375 (if (not (boundp sym)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
376 (set sym (list cname)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
377 (add-to-list sym cname)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
378 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
379 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
380 ;; We have a parent, save the child in there. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
381 (when (not (member cname (aref (class-v SC) class-children))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
382 (aset (class-v SC) class-children |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
383 (cons cname (aref (class-v SC) class-children))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
384 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
385 ;; save parent in child |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
386 (aset newc class-parent (cons SC (aref newc class-parent))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
387 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
388 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
389 ;; turn this into a useable self-pointing symbol |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
390 (set cname cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
391 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
392 ;; Store the new class vector definition into the symbol. We need to |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
393 ;; do this first so that we can call defmethod for the accessor. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
394 ;; The vector will be updated by the following while loop and will not |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
395 ;; need to be stored a second time. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
396 (put cname 'eieio-class-definition newc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
397 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
398 ;; Clear the parent |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
399 (if clear-parent (aset newc class-parent nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
400 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
401 ;; Create an autoload on top of our constructor function. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
402 (autoload cname filename doc nil nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
403 (autoload (intern (concat (symbol-name cname) "-p")) filename "" nil nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
404 (autoload (intern (concat (symbol-name cname) "-child-p")) filename "" nil nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
405 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
406 )))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
407 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
408 (defsubst eieio-class-un-autoload (cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
409 "If class CNAME is in an autoload state, load it's file." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
410 (when (eq (car-safe (symbol-function cname)) 'autoload) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
411 (load-library (car (cdr (symbol-function cname)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
412 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
413 (defun eieio-defclass (cname superclasses slots options-and-doc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
414 "See `defclass' for more information. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
415 Define CNAME as a new subclass of SUPERCLASSES, with SLOTS being the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
416 slots residing in that class definition, and with options or documentation |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
417 OPTIONS-AND-DOC as the toplevel documentation for this class." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
418 ;; Run our eieio-hook each time, and clear it when we are done. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
419 ;; This way people can add hooks safely if they want to modify eieio |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
420 ;; or add definitions when eieio is loaded or something like that. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
421 (run-hooks 'eieio-hook) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
422 (setq eieio-hook nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
423 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
424 (if (not (symbolp cname)) (signal 'wrong-type-argument '(symbolp cname))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
425 (if (not (listp superclasses)) (signal 'wrong-type-argument '(listp superclasses))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
426 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
427 (let* ((pname (if superclasses superclasses nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
428 (newc (make-vector class-num-slots nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
429 (oldc (when (class-p cname) (class-v cname))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
430 (groups nil) ;; list of groups id'd from slots |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
431 (options nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
432 (clearparent nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
433 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
434 (aset newc 0 'defclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
435 (aset newc class-symbol cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
436 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
437 ;; If this class already existed, and we are updating it's structure, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
438 ;; make sure we keep the old child list. This can cause bugs, but |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
439 ;; if no new slots are created, it also saves time, and prevents |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
440 ;; method table breakage, particularly when the users is only |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
441 ;; byte compiling an EIEIO file. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
442 (if oldc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
443 (aset newc class-children (aref oldc class-children)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
444 ;; If the old class did not exist, but did exist in the autoload map, then adopt those children. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
445 ;; This is like the above, but deals with autoloads nicely. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
446 (let ((sym (intern-soft (symbol-name cname) eieio-defclass-autoload-map))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
447 (when sym |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
448 (condition-case nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
449 (aset newc class-children (symbol-value sym)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
450 (error nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
451 (unintern (symbol-name cname) eieio-defclass-autoload-map) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
452 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
453 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
454 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
455 (cond ((and (stringp (car options-and-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
456 (/= 1 (% (length options-and-doc) 2))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
457 (error "Too many arguments to `defclass'")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
458 ((and (symbolp (car options-and-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
459 (/= 0 (% (length options-and-doc) 2))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
460 (error "Too many arguments to `defclass'")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
461 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
462 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
463 (setq options |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
464 (if (stringp (car options-and-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
465 (cons :documentation options-and-doc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
466 options-and-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
467 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
468 (if pname |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
469 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
470 (while pname |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
471 (if (and (car pname) (symbolp (car pname))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
472 (if (not (class-p (car pname))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
473 ;; bad class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
474 (error "Given parent class %s is not a class" (car pname)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
475 ;; good parent class... |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
476 ;; save new child in parent |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
477 (when (not (member cname (aref (class-v (car pname)) class-children))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
478 (aset (class-v (car pname)) class-children |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
479 (cons cname (aref (class-v (car pname)) class-children)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
480 ;; Get custom groups, and store them into our local copy. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
481 (mapc (lambda (g) (add-to-list 'groups g)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
482 (class-option (car pname) :custom-groups)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
483 ;; save parent in child |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
484 (aset newc class-parent (cons (car pname) (aref newc class-parent)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
485 (error "Invalid parent class %s" pname)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
486 (setq pname (cdr pname))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
487 ;; Reverse the list of our parents so that they are prioritized in |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
488 ;; the same order as specified in the code. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
489 (aset newc class-parent (nreverse (aref newc class-parent))) ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
490 ;; If there is nothing to loop over, then inherit from the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
491 ;; default superclass. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
492 (unless (eq cname 'eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
493 ;; adopt the default parent here, but clear it later... |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
494 (setq clearparent t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
495 ;; save new child in parent |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
496 (if (not (member cname (aref (class-v 'eieio-default-superclass) class-children))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
497 (aset (class-v 'eieio-default-superclass) class-children |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
498 (cons cname (aref (class-v 'eieio-default-superclass) class-children)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
499 ;; save parent in child |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
500 (aset newc class-parent (list eieio-default-superclass)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
501 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
502 ;; turn this into a useable self-pointing symbol |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
503 (set cname cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
504 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
505 ;; These two tests must be created right away so we can have self- |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
506 ;; referencing classes. ei, a class whose slot can contain only |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
507 ;; pointers to itself. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
508 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
509 ;; Create the test function |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
510 (let ((csym (intern (concat (symbol-name cname) "-p")))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
511 (fset csym |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
512 (list 'lambda (list 'obj) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
513 (format "Test OBJ to see if it an object of type %s" cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
514 (list 'and '(eieio-object-p obj) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
515 (list 'same-class-p 'obj cname))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
516 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
517 ;; Make sure the method invocation order is a valid value. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
518 (let ((io (class-option-assoc options :method-invocation-order))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
519 (when (and io (not (member io '(:depth-first :breadth-first)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
520 (error "Method invocation order %s is not allowed" io) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
521 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
522 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
523 ;; Create a handy child test too |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
524 (let ((csym (intern (concat (symbol-name cname) "-child-p")))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
525 (fset csym |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
526 `(lambda (obj) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
527 ,(format |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
528 "Test OBJ to see if it an object is a child of type %s" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
529 cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
530 (and (eieio-object-p obj) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
531 (object-of-class-p obj ,cname)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
532 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
533 ;; When using typep, (typep OBJ 'myclass) returns t for objects which |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
534 ;; are subclasses of myclass. For our predicates, however, it is |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
535 ;; important for EIEIO to be backwards compatible, where |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
536 ;; myobject-p, and myobject-child-p are different. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
537 ;; "cl" uses this technique to specify symbols with specific typep |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
538 ;; test, so we can let typep have the CLOS documented behavior |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
539 ;; while keeping our above predicate clean. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
540 (eval `(deftype ,cname () |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
541 '(satisfies |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
542 ,(intern (concat (symbol-name cname) "-child-p"))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
543 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
544 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
545 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
546 ;; before adding new slots, lets add all the methods and classes |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
547 ;; in from the parent class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
548 (eieio-copy-parents-into-subclass newc superclasses) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
549 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
550 ;; Store the new class vector definition into the symbol. We need to |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
551 ;; do this first so that we can call defmethod for the accessor. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
552 ;; The vector will be updated by the following while loop and will not |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
553 ;; need to be stored a second time. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
554 (put cname 'eieio-class-definition newc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
555 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
556 ;; Query each slot in the declaration list and mangle into the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
557 ;; class structure I have defined. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
558 (while slots |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
559 (let* ((slot1 (car slots)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
560 (name (car slot1)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
561 (slot (cdr slot1)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
562 (acces (plist-get slot ':accessor)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
563 (init (or (plist-get slot ':initform) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
564 (if (member ':initform slot) nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
565 eieio-unbound))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
566 (initarg (plist-get slot ':initarg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
567 (docstr (plist-get slot ':documentation)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
568 (prot (plist-get slot ':protection)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
569 (reader (plist-get slot ':reader)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
570 (writer (plist-get slot ':writer)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
571 (alloc (plist-get slot ':allocation)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
572 (type (plist-get slot ':type)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
573 (custom (plist-get slot ':custom)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
574 (label (plist-get slot ':label)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
575 (customg (plist-get slot ':group)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
576 (printer (plist-get slot ':printer)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
577 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
578 (skip-nil (class-option-assoc options :allow-nil-initform)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
579 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
580 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
581 (if eieio-error-unsupported-class-tags |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
582 (let ((tmp slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
583 (while tmp |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
584 (if (not (member (car tmp) '(:accessor |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
585 :initform |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
586 :initarg |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
587 :documentation |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
588 :protection |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
589 :reader |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
590 :writer |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
591 :allocation |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
592 :type |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
593 :custom |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
594 :label |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
595 :group |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
596 :printer |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
597 :allow-nil-initform |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
598 :custom-groups))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
599 (signal 'invalid-slot-type (list (car tmp)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
600 (setq tmp (cdr (cdr tmp)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
601 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
602 ;; Clean up the meaning of protection. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
603 (cond ((or (eq prot 'public) (eq prot :public)) (setq prot nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
604 ((or (eq prot 'protected) (eq prot :protected)) (setq prot 'protected)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
605 ((or (eq prot 'private) (eq prot :private)) (setq prot 'private)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
606 ((eq prot nil) nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
607 (t (signal 'invalid-slot-type (list ':protection prot)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
608 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
609 ;; Make sure the :allocation parameter has a valid value. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
610 (if (not (or (not alloc) (eq alloc :class) (eq alloc :instance))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
611 (signal 'invalid-slot-type (list ':allocation alloc))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
612 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
613 ;; The default type specifier is supposed to be t, meaning anything. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
614 (if (not type) (setq type t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
615 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
616 ;; Label is nil, or a string |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
617 (if (not (or (null label) (stringp label))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
618 (signal 'invalid-slot-type (list ':label label))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
619 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
620 ;; Is there an initarg, but allocation of class? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
621 (if (and initarg (eq alloc :class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
622 (message "Class allocated slots do not need :initarg")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
623 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
624 ;; intern the symbol so we can use it blankly |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
625 (if initarg (set initarg initarg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
626 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
627 ;; The customgroup should be a list of symbols |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
628 (cond ((null customg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
629 (setq customg '(default))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
630 ((not (listp customg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
631 (setq customg (list customg)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
632 ;; The customgroup better be a symbol, or list of symbols. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
633 (mapc (lambda (cg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
634 (if (not (symbolp cg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
635 (signal 'invalid-slot-type (list ':group cg)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
636 customg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
637 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
638 ;; First up, add this slot into our new class. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
639 (eieio-add-new-slot newc name init docstr type custom label customg printer |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
640 prot initarg alloc 'defaultoverride skip-nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
641 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
642 ;; We need to id the group, and store them in a group list attribute. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
643 (mapc (lambda (cg) (add-to-list 'groups cg)) customg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
644 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
645 ;; anyone can have an accessor function. This creates a function |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
646 ;; of the specified name, and also performs a `defsetf' if applicable |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
647 ;; so that users can `setf' the space returned by this function |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
648 (if acces |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
649 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
650 (eieio-defmethod acces |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
651 (list (if (eq alloc :class) :static :primary) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
652 (list (list 'this cname)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
653 (format |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
654 "Retrieves the slot `%s' from an object of class `%s'" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
655 name cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
656 (list 'if (list 'slot-boundp 'this (list 'quote name)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
657 (list 'eieio-oref 'this (list 'quote name)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
658 ;; Else - Some error? nil? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
659 nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
660 ))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
661 ;; Thanks Pascal Bourguignon <pjb@informatimago.com> |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
662 ;; For this complex macro. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
663 (eval (macroexpand |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
664 (list 'defsetf acces '(widget) '(store) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
665 (list 'list ''eieio-oset 'widget |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
666 (list 'quote (list 'quote name)) 'store)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
667 ;;`(defsetf ,acces (widget) (store) (eieio-oset widget ',cname store)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
668 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
669 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
670 ;; If a writer is defined, then create a generic method of that |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
671 ;; name whose purpose is to set the value of the slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
672 (if writer |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
673 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
674 (eieio-defmethod writer |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
675 (list (list (list 'this cname) 'value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
676 (format "Set the slot `%s' of an object of class `%s'" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
677 name cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
678 `(setf (slot-value this ',name) value))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
679 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
680 ;; If a reader is defined, then create a generic method |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
681 ;; of that name whose purpose is to access this slot value. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
682 (if reader |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
683 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
684 (eieio-defmethod reader |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
685 (list (list (list 'this cname)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
686 (format "Access the slot `%s' from object of class `%s'" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
687 name cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
688 `(slot-value this ',name))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
689 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
690 (setq slots (cdr slots))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
691 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
692 ;; Now that everything has been loaded up, all our lists are backwards! Fix that up now. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
693 (aset newc class-public-a (nreverse (aref newc class-public-a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
694 (aset newc class-public-d (nreverse (aref newc class-public-d))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
695 (aset newc class-public-doc (nreverse (aref newc class-public-doc))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
696 (aset newc class-public-type |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
697 (apply 'vector (nreverse (aref newc class-public-type)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
698 (aset newc class-public-custom (nreverse (aref newc class-public-custom))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
699 (aset newc class-public-custom-label (nreverse (aref newc class-public-custom-label))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
700 (aset newc class-public-custom-group (nreverse (aref newc class-public-custom-group))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
701 (aset newc class-public-printer (nreverse (aref newc class-public-printer))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
702 (aset newc class-protection (nreverse (aref newc class-protection))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
703 (aset newc class-initarg-tuples (nreverse (aref newc class-initarg-tuples))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
704 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
705 ;; The storage for class-class-allocation-type needs to be turned into |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
706 ;; a vector now. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
707 (aset newc class-class-allocation-type |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
708 (apply 'vector (aref newc class-class-allocation-type))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
709 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
710 ;; Also, take class allocated values, and vectorize them for speed. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
711 (aset newc class-class-allocation-values |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
712 (apply 'vector (aref newc class-class-allocation-values))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
713 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
714 ;; Attach slot symbols into an obarray, and store the index of |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
715 ;; this slot as the variable slot in this new symbol. We need to |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
716 ;; know about primes, because obarrays are best set in vectors of |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
717 ;; prime number length, and we also need to make our vector small |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
718 ;; to save space, and also optimal for the number of items we have. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
719 (let* ((cnt 0) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
720 (pubsyms (aref newc class-public-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
721 (prots (aref newc class-protection)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
722 (l (length pubsyms)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
723 (vl (let ((primes '( 3 5 7 11 13 17 19 23 29 31 37 41 43 47 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
724 53 59 61 67 71 73 79 83 89 97 101 ))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
725 (while (and primes (< (car primes) l)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
726 (setq primes (cdr primes))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
727 (car primes))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
728 (oa (make-vector vl 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
729 (newsym)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
730 (while pubsyms |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
731 (setq newsym (intern (symbol-name (car pubsyms)) oa)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
732 (set newsym cnt) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
733 (setq cnt (1+ cnt)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
734 (if (car prots) (put newsym 'protection (car prots))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
735 (setq pubsyms (cdr pubsyms) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
736 prots (cdr prots))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
737 (aset newc class-symbol-obarray oa) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
738 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
739 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
740 ;; Create the constructor function |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
741 (if (class-option-assoc options :abstract) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
742 ;; Abstract classes cannot be instantiated. Say so. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
743 (let ((abs (class-option-assoc options :abstract))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
744 (if (not (stringp abs)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
745 (setq abs (format "Class %s is abstract" cname))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
746 (fset cname |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
747 `(lambda (&rest stuff) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
748 ,(format "You cannot create a new object of type %s" cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
749 (error ,abs)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
750 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
751 ;; Non-abstract classes need a constructor. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
752 (fset cname |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
753 `(lambda (newname &rest slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
754 ,(format "Create a new object with name NAME of class type %s" cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
755 (apply 'constructor ,cname newname slots))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
756 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
757 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
758 ;; Set up a specialized doc string. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
759 ;; Use stored value since it is calculated in a non-trivial way |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
760 (put cname 'variable-documentation |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
761 (class-option-assoc options :documentation)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
762 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
763 ;; We have a list of custom groups. Store them into the options. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
764 (let ((g (class-option-assoc options :custom-groups))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
765 (mapc (lambda (cg) (add-to-list 'g cg)) groups) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
766 (if (memq :custom-groups options) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
767 (setcar (cdr (memq :custom-groups options)) g) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
768 (setq options (cons :custom-groups (cons g options))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
769 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
770 ;; Set up the options we have collected. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
771 (aset newc class-options options) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
772 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
773 ;; if this is a superclass, clear out parent (which was set to the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
774 ;; default superclass eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
775 (if clearparent (aset newc class-parent nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
776 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
777 ;; Create the cached default object. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
778 (let ((cache (make-vector (+ (length (aref newc class-public-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
779 3) nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
780 (aset cache 0 'object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
781 (aset cache object-class cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
782 (aset cache object-name 'default-cache-object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
783 (let ((eieio-skip-typecheck t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
784 ;; All type-checking has been done to our satisfaction |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
785 ;; before this call. Don't waste our time in this call.. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
786 (eieio-set-defaults cache t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
787 (aset newc class-default-object-cache cache)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
788 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
789 ;; Return our new class object |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
790 ;; newc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
791 cname |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
792 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
793 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
794 (defun eieio-perform-slot-validation-for-default (slot spec value skipnil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
795 "For SLOT, signal if SPEC does not match VALUE. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
796 If SKIPNIL is non-nil, then if VALUE is nil, return t." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
797 (let ((val (eieio-default-eval-maybe value))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
798 (if (and (not eieio-skip-typecheck) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
799 (not (and skipnil (null val))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
800 (not (eieio-perform-slot-validation spec val))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
801 (signal 'invalid-slot-type (list slot spec val))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
802 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
803 (defun eieio-add-new-slot (newc a d doc type cust label custg print prot init alloc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
804 &optional defaultoverride skipnil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
805 "Add into NEWC attribute A. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
806 If A already exists in NEWC, then do nothing. If it doesn't exist, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
807 then also add in D (defualt), DOC, TYPE, CUST, LABEL, CUSTG, PRINT, PROT, and INIT arg. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
808 Argument ALLOC specifies if the slot is allocated per instance, or per class. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
809 If optional DEFAULTOVERRIDE is non-nil, then if A exists in NEWC, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
810 we must override it's value for a default. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
811 Optional argument SKIPNIL indicates if type checking should be skipped |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
812 if default value is nil." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
813 ;; Make sure we duplicate those items that are sequences. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
814 (condition-case nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
815 (if (sequencep d) (setq d (copy-sequence d))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
816 ;; This copy can fail on a cons cell with a non-cons in the cdr. Lets skip it if it doesn't work. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
817 (error nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
818 (if (sequencep type) (setq type (copy-sequence type))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
819 (if (sequencep cust) (setq cust (copy-sequence cust))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
820 (if (sequencep custg) (setq custg (copy-sequence custg))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
821 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
822 ;; To prevent override information w/out specification of storage, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
823 ;; we need to do this little hack. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
824 (if (member a (aref newc class-class-allocation-a)) (setq alloc ':class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
825 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
826 (if (or (not alloc) (and (symbolp alloc) (eq alloc ':instance))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
827 ;; In this case, we modify the INSTANCE version of a given slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
828 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
829 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
830 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
831 ;; Only add this element if it is so-far unique |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
832 (if (not (member a (aref newc class-public-a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
833 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
834 (eieio-perform-slot-validation-for-default a type d skipnil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
835 (aset newc class-public-a (cons a (aref newc class-public-a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
836 (aset newc class-public-d (cons d (aref newc class-public-d))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
837 (aset newc class-public-doc (cons doc (aref newc class-public-doc))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
838 (aset newc class-public-type (cons type (aref newc class-public-type))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
839 (aset newc class-public-custom (cons cust (aref newc class-public-custom))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
840 (aset newc class-public-custom-label (cons label (aref newc class-public-custom-label))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
841 (aset newc class-public-custom-group (cons custg (aref newc class-public-custom-group))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
842 (aset newc class-public-printer (cons print (aref newc class-public-printer))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
843 (aset newc class-protection (cons prot (aref newc class-protection))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
844 (aset newc class-initarg-tuples (cons (cons init a) (aref newc class-initarg-tuples))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
845 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
846 ;; When defaultoverride is true, we are usually adding new local |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
847 ;; attributes which must override the default value of any slot |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
848 ;; passed in by one of the parent classes. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
849 (when defaultoverride |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
850 ;; There is a match, and we must override the old value. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
851 (let* ((ca (aref newc class-public-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
852 (np (member a ca)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
853 (num (- (length ca) (length np))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
854 (dp (if np (nthcdr num (aref newc class-public-d)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
855 nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
856 (tp (if np (nth num (aref newc class-public-type)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
857 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
858 (if (not np) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
859 (error "Eieio internal error overriding default value for %s" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
860 a) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
861 ;; If type is passed in, is it the same? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
862 (if (not (eq type t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
863 (if (not (equal type tp)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
864 (error |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
865 "Child slot type `%s' does not match inherited type `%s' for `%s'" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
866 type tp a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
867 ;; If we have a repeat, only update the initarg... |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
868 (unless (eq d eieio-unbound) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
869 (eieio-perform-slot-validation-for-default a tp d skipnil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
870 (setcar dp d)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
871 ;; If we have a new initarg, check for it. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
872 (when init |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
873 (let* ((inits (aref newc class-initarg-tuples)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
874 (inita (rassq a inits))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
875 ;; Replace the CAR of the associate INITA. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
876 ;;(message "Initarg: %S replace %s" inita init) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
877 (setcar inita init) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
878 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
879 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
880 ;; PLN Tue Jun 26 11:57:06 2007 : The protection is |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
881 ;; checked and SHOULD match the superclass |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
882 ;; protection. Otherwise an error is thrown. However |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
883 ;; I wonder if a more flexible schedule might be |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
884 ;; implemented. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
885 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
886 ;; EML - We used to have (if prot... here, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
887 ;; but a prot of 'nil means public. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
888 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
889 (let ((super-prot (nth num (aref newc class-protection))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
890 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
891 (if (not (eq prot super-prot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
892 (error "Child slot protection `%s' does not match inherited protection `%s' for `%s'" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
893 prot super-prot a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
894 ;; End original PLN |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
895 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
896 ;; PLN Tue Jun 26 11:57:06 2007 : |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
897 ;; We do a non redundant combination of ancient |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
898 ;; custom groups and new ones using the common lisp |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
899 ;; `union' method. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
900 (when custg |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
901 (let ((where-groups |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
902 (nthcdr num (aref newc class-public-custom-group)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
903 (setcar where-groups |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
904 (union (car where-groups) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
905 (if (listp custg) custg (list custg)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
906 ;; End PLN |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
907 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
908 ;; PLN Mon Jun 25 22:44:34 2007 : If a new cust is |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
909 ;; set, simply replaces the old one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
910 (when cust |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
911 ;; (message "Custom type redefined to %s" cust) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
912 (setcar (nthcdr num (aref newc class-public-custom)) cust)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
913 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
914 ;; If a new label is specified, it simply replaces |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
915 ;; the old one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
916 (when label |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
917 ;; (message "Custom label redefined to %s" label) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
918 (setcar (nthcdr num (aref newc class-public-custom-label)) label)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
919 ;; End PLN |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
920 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
921 ;; PLN Sat Jun 30 17:24:42 2007 : when a new |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
922 ;; doc is specified, simply replaces the old one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
923 (when doc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
924 ;;(message "Documentation redefined to %s" doc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
925 (setcar (nthcdr num (aref newc class-public-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
926 doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
927 ;; End PLN |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
928 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
929 ;; If a new printer is specified, it simply replaces |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
930 ;; the old one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
931 (when print |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
932 ;; (message "printer redefined to %s" print) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
933 (setcar (nthcdr num (aref newc class-public-printer)) print)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
934 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
935 ))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
936 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
937 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
938 ;; CLASS ALLOCATED SLOTS |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
939 (let ((value (eieio-default-eval-maybe d))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
940 (if (not (member a (aref newc class-class-allocation-a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
941 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
942 (eieio-perform-slot-validation-for-default a type value skipnil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
943 ;; Here we have found a :class version of a slot. This |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
944 ;; requires a very different aproach. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
945 (aset newc class-class-allocation-a (cons a (aref newc class-class-allocation-a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
946 (aset newc class-class-allocation-doc (cons doc (aref newc class-class-allocation-doc))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
947 (aset newc class-class-allocation-type (cons type (aref newc class-class-allocation-type))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
948 (aset newc class-class-allocation-custom (cons cust (aref newc class-class-allocation-custom))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
949 (aset newc class-class-allocation-custom-label (cons label (aref newc class-class-allocation-custom-label))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
950 (aset newc class-class-allocation-custom-group (cons custg (aref newc class-class-allocation-custom-group))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
951 (aset newc class-class-allocation-protection (cons prot (aref newc class-class-allocation-protection))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
952 ;; Default value is stored in the 'values section, since new objects |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
953 ;; can't initialize from this element. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
954 (aset newc class-class-allocation-values (cons value (aref newc class-class-allocation-values)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
955 (when defaultoverride |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
956 ;; There is a match, and we must override the old value. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
957 (let* ((ca (aref newc class-class-allocation-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
958 (np (member a ca)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
959 (num (- (length ca) (length np))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
960 (dp (if np |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
961 (nthcdr num |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
962 (aref newc class-class-allocation-values)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
963 nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
964 (tp (if np (nth num (aref newc class-class-allocation-type)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
965 nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
966 (if (not np) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
967 (error "Eieio internal error overriding default value for %s" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
968 a) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
969 ;; If type is passed in, is it the same? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
970 (if (not (eq type t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
971 (if (not (equal type tp)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
972 (error |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
973 "Child slot type `%s' does not match inherited type `%s' for `%s'" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
974 type tp a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
975 ;; EML - Note: the only reason to override a class bound slot |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
976 ;; is to change the default, so allow unbound in. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
977 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
978 ;; If we have a repeat, only update the vlaue... |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
979 (eieio-perform-slot-validation-for-default a tp value skipnil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
980 (setcar dp value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
981 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
982 ;; PLN Tue Jun 26 11:57:06 2007 : The protection is |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
983 ;; checked and SHOULD match the superclass |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
984 ;; protection. Otherwise an error is thrown. However |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
985 ;; I wonder if a more flexible schedule might be |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
986 ;; implemented. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
987 (let ((super-prot |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
988 (car (nthcdr num (aref newc class-class-allocation-protection))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
989 (if (not (eq prot super-prot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
990 (error "Child slot protection `%s' does not match inherited protection `%s' for `%s'" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
991 prot super-prot a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
992 ;; We do a non redundant combination of ancient |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
993 ;; custom groups and new ones using the common lisp |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
994 ;; `union' method. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
995 (when custg |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
996 (let ((where-groups |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
997 (nthcdr num (aref newc class-class-allocation-custom-group)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
998 (setcar where-groups |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
999 (union (car where-groups) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1000 (if (listp custg) custg (list custg)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1001 ;; End PLN |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1002 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1003 ;; PLN Sat Jun 30 17:24:42 2007 : when a new |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1004 ;; doc is specified, simply replaces the old one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1005 (when doc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1006 ;;(message "Documentation redefined to %s" doc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1007 (setcar (nthcdr num (aref newc class-class-allocation-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1008 doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1009 ;; End PLN |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1010 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1011 ;; If a new printer is specified, it simply replaces |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1012 ;; the old one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1013 (when print |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1014 ;; (message "printer redefined to %s" print) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1015 (setcar (nthcdr num (aref newc class-class-allocation-printer)) print)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1016 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1017 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1018 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1019 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1020 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1021 (defun eieio-copy-parents-into-subclass (newc parents) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1022 "Copy into NEWC the slots of PARENTS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1023 Follow the rules of not overwritting early parents when applying to |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1024 the new child class." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1025 (let ((ps (aref newc class-parent)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1026 (sn (class-option-assoc (aref newc class-options) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1027 ':allow-nil-initform))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1028 (while ps |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1029 ;; First, duplicate all the slots of the parent. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1030 (let ((pcv (class-v (car ps)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1031 (let ((pa (aref pcv class-public-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1032 (pd (aref pcv class-public-d)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1033 (pdoc (aref pcv class-public-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1034 (ptype (aref pcv class-public-type)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1035 (pcust (aref pcv class-public-custom)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1036 (plabel (aref pcv class-public-custom-label)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1037 (pcustg (aref pcv class-public-custom-group)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1038 (printer (aref pcv class-public-printer)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1039 (pprot (aref pcv class-protection)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1040 (pinit (aref pcv class-initarg-tuples)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1041 (i 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1042 (while pa |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1043 (eieio-add-new-slot newc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1044 (car pa) (car pd) (car pdoc) (aref ptype i) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1045 (car pcust) (car plabel) (car pcustg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1046 (car printer) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1047 (car pprot) (car-safe (car pinit)) nil nil sn) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1048 ;; Increment each value. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1049 (setq pa (cdr pa) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1050 pd (cdr pd) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1051 pdoc (cdr pdoc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1052 i (1+ i) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1053 pcust (cdr pcust) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1054 plabel (cdr plabel) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1055 pcustg (cdr pcustg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1056 printer (cdr printer) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1057 pprot (cdr pprot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1058 pinit (cdr pinit)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1059 )) ;; while/let |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1060 ;; Now duplicate all the class alloc slots. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1061 (let ((pa (aref pcv class-class-allocation-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1062 (pdoc (aref pcv class-class-allocation-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1063 (ptype (aref pcv class-class-allocation-type)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1064 (pcust (aref pcv class-class-allocation-custom)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1065 (plabel (aref pcv class-class-allocation-custom-label)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1066 (pcustg (aref pcv class-class-allocation-custom-group)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1067 (printer (aref pcv class-class-allocation-printer)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1068 (pprot (aref pcv class-class-allocation-protection)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1069 (pval (aref pcv class-class-allocation-values)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1070 (i 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1071 (while pa |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1072 (eieio-add-new-slot newc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1073 (car pa) (aref pval i) (car pdoc) (aref ptype i) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1074 (car pcust) (car plabel) (car pcustg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1075 (car printer) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1076 (car pprot) nil ':class sn) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1077 ;; Increment each value. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1078 (setq pa (cdr pa) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1079 pdoc (cdr pdoc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1080 pcust (cdr pcust) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1081 plabel (cdr plabel) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1082 pcustg (cdr pcustg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1083 printer (cdr printer) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1084 pprot (cdr pprot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1085 i (1+ i)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1086 ))) ;; while/let |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1087 ;; Loop over each parent class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1088 (setq ps (cdr ps))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1089 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1090 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1091 ;;; CLOS style implementation of object creators. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1092 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1093 (defun make-instance (class &rest initargs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1094 "Make a new instance of CLASS based on INITARGS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1095 CLASS is a class symbol. For example: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1096 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1097 (make-instance 'foo) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1098 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1099 INITARGS is a property list with keywords based on the :initarg |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1100 for each slot. For example: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1101 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1102 (make-instance 'foo :slot1 value1 :slotN valueN) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1103 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1104 Compatability note: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1105 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1106 If the first element of INITARGS is a string, it is used as the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1107 name of the class. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1108 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1109 In EIEIO, the class' constructor requires a name for use when printing. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1110 `make-instance' in CLOS doesn't use names the way Emacs does, so the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1111 class is used as the name slot instead when INITARGS doesn't start with |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1112 a string." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1113 (if (and (car initargs) (stringp (car initargs))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1114 (apply (class-constructor class) initargs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1115 (apply (class-constructor class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1116 (cond ((symbolp class) (symbol-name class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1117 (t (format "%S" class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1118 initargs))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1119 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1120 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1121 ;;; CLOS methods and generics |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1122 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1123 (defmacro defgeneric (method args &optional doc-string) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1124 "Create a generic function METHOD. ARGS is ignored. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1125 DOC-STRING is the base documentation for this class. A generic |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1126 function has no body, as it's purpose is to decide which method body |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1127 is appropriate to use. Use `defmethod' to create methods, and it |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1128 calls defgeneric for you. With this implementation the arguments are |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1129 currently ignored. You can use `defgeneric' to apply specialized |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1130 top level documentation to a method." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1131 `(eieio-defgeneric (quote ,method) ,doc-string)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1132 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1133 (defun eieio-defgeneric-form (method doc-string) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1134 "The lambda form that would be used as the function defined on METHOD. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1135 All methods should call the same EIEIO function for dispatch. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1136 DOC-STRING is the documentation attached to METHOD." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1137 `(lambda (&rest local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1138 ,doc-string |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1139 (eieio-generic-call (quote ,method) local-args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1140 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1141 (defsubst eieio-defgeneric-reset-generic-form (method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1142 "Setup METHOD to call the generic form." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1143 (let ((doc-string (documentation method))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1144 (fset method (eieio-defgeneric-form method doc-string)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1145 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1146 (defun eieio-defgeneric-form-primary-only (method doc-string) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1147 "The lambda form that would be used as the function defined on METHOD. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1148 All methods should call the same EIEIO function for dispatch. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1149 DOC-STRING is the documentation attached to METHOD." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1150 `(lambda (&rest local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1151 ,doc-string |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1152 (eieio-generic-call-primary-only (quote ,method) local-args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1153 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1154 (defsubst eieio-defgeneric-reset-generic-form-primary-only (method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1155 "Setup METHOD to call the generic form." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1156 (let ((doc-string (documentation method))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1157 (fset method (eieio-defgeneric-form-primary-only method doc-string)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1158 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1159 (defun eieio-defgeneric-form-primary-only-one (method doc-string |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1160 class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1161 impl |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1162 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1163 "The lambda form that would be used as the function defined on METHOD. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1164 All methods should call the same EIEIO function for dispatch. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1165 DOC-STRING is the documentation attached to METHOD. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1166 CLASS is the class symbol needed for private method access. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1167 IMPL is the symbol holding the method implementation." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1168 ;; NOTE: I tried out byte compiling this little fcn. Turns out it |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1169 ;; is faster to execute this for not byte-compiled. ie, install this, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1170 ;; then measure calls going through here. I wonder why. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1171 (require 'bytecomp) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1172 (let ((byte-compile-free-references nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1173 (byte-compile-warnings nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1174 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1175 (byte-compile-lambda |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1176 `(lambda (&rest local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1177 ,doc-string |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1178 ;; This is a cool cheat. Usually we need to look up in the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1179 ;; method table to find out if there is a method or not. We can |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1180 ;; instead make that determination at load time when there is |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1181 ;; only one method. If the first arg is not a child of the class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1182 ;; of that one implementation, then clearly, there is no method def. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1183 (if (not (eieio-object-p (car local-args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1184 ;; Not an object. Just signal. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1185 (signal 'no-method-definition (list ,(list 'quote method) local-args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1186 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1187 ;; We do have an object. Make sure it is the right type. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1188 (if ,(if (eq class eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1189 nil ; default superclass means just an obj. Already asked. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1190 `(not (child-of-class-p (aref (car local-args) object-class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1191 ,(list 'quote class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1192 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1193 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1194 ;; If not the right kind of object, call no applicable |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1195 (apply 'no-applicable-method (car local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1196 ,(list 'quote method) local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1197 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1198 ;; It is ok, do the call. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1199 ;; Fill in inter-call variables then evaluate the method. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1200 (let ((scoped-class ,(list 'quote class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1201 (eieio-generic-call-next-method-list nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1202 (eieio-generic-call-key method-primary) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1203 (eieio-generic-call-methodname ,(list 'quote method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1204 (eieio-generic-call-arglst local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1205 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1206 (apply ,(list 'quote impl) local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1207 ;(,impl local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1208 )))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1209 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1210 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1211 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1212 (defsubst eieio-defgeneric-reset-generic-form-primary-only-one (method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1213 "Setup METHOD to call the generic form." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1214 (let* ((doc-string (documentation method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1215 (M (get method 'eieio-method-tree)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1216 (entry (car (aref M method-primary))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1217 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1218 (fset method (eieio-defgeneric-form-primary-only-one |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1219 method doc-string |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1220 (car entry) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1221 (cdr entry) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1222 )))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1223 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1224 (defun eieio-defgeneric (method doc-string) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1225 "Engine part to `defgeneric' macro defining METHOD with DOC-STRING." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1226 (if (and (fboundp method) (not (generic-p method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1227 (or (byte-code-function-p (symbol-function method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1228 (not (eq 'autoload (car (symbol-function method))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1229 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1230 (error "You cannot create a generic/method over an existing symbol: %s" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1231 method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1232 ;; Don't do this over and over. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1233 (unless (fboundp 'method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1234 ;; This defun tells emacs where the first definition of this |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1235 ;; method is defined. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1236 `(defun ,method nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1237 ;; Make sure the method tables are installed. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1238 (eieiomt-install method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1239 ;; Apply the actual body of this function. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1240 (fset method (eieio-defgeneric-form method doc-string)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1241 ;; Return the method |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1242 'method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1243 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1244 (defun eieio-unbind-method-implementations (method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1245 "Make the generic method METHOD have no implementations.. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1246 It will leave the original generic function in place, but remove |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1247 reference to all implementations of METHOD." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1248 (put method 'eieio-method-tree nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1249 (put method 'eieio-method-obarray nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1250 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1251 (defmacro defmethod (method &rest args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1252 "Create a new METHOD through `defgeneric' with ARGS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1253 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1254 The second optional argument KEY is a specifier that |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1255 modifies how the method is called, including: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1256 :before - Method will be called before the :primary |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1257 :primary - The default if not specified. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1258 :after - Method will be called after the :primary |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1259 :static - First arg could be an object or class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1260 The next argument is the ARGLIST. The ARGLIST specifies the arguments |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1261 to the method as with `defun'. The first argument can have a type |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1262 specifier, such as: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1263 ((VARNAME CLASS) ARG2 ...) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1264 where VARNAME is the name of the local variable for the method being |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1265 created. The CLASS is a class symbol for a class made with `defclass'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1266 A DOCSTRING comes after the ARGLIST, and is optional. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1267 All the rest of the args are the BODY of the method. A method will |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1268 return the value of the last form in the BODY. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1269 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1270 Summary: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1271 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1272 (defmethod mymethod [:before | :primary | :after | :static] |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1273 ((typearg class-name) arg2 &optional opt &rest rest) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1274 \"doc-string\" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1275 body)" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1276 `(eieio-defmethod (quote ,method) (quote ,args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1277 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1278 (defun eieio-defmethod (method args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1279 "Work part of the `defmethod' macro defining METHOD with ARGS." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1280 (let ((key nil) (body nil) (firstarg nil) (argfix nil) (argclass nil) loopa) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1281 ;; find optional keys |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1282 (setq key |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1283 (cond ((or (eq ':BEFORE (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1284 (eq ':before (car args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1285 (setq args (cdr args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1286 method-before) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1287 ((or (eq ':AFTER (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1288 (eq ':after (car args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1289 (setq args (cdr args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1290 method-after) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1291 ((or (eq ':PRIMARY (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1292 (eq ':primary (car args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1293 (setq args (cdr args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1294 method-primary) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1295 ((or (eq ':STATIC (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1296 (eq ':static (car args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1297 (setq args (cdr args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1298 method-static) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1299 ;; Primary key |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1300 (t method-primary))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1301 ;; get body, and fix contents of args to be the arguments of the fn. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1302 (setq body (cdr args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1303 args (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1304 (setq loopa args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1305 ;; Create a fixed version of the arguments |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1306 (while loopa |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1307 (setq argfix (cons (if (listp (car loopa)) (car (car loopa)) (car loopa)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1308 argfix)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1309 (setq loopa (cdr loopa))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1310 ;; make sure there is a generic |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1311 (eieio-defgeneric |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1312 method |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1313 (if (stringp (car body)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1314 (car body) (format "Generically created method `%s'" method))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1315 ;; create symbol for property to bind to. If the first arg is of |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1316 ;; the form (varname vartype) and `vartype' is a class, then |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1317 ;; that class will be the type symbol. If not, then it will fall |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1318 ;; under the type `primary' which is a non-specific calling of the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1319 ;; function. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1320 (setq firstarg (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1321 (if (listp firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1322 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1323 (setq argclass (nth 1 firstarg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1324 (if (not (class-p argclass)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1325 (error "Unknown class type %s in method parameters" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1326 (nth 1 firstarg)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1327 (if (= key -1) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1328 (signal 'wrong-type-argument (list :static 'non-class-arg))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1329 ;; generics are higher |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1330 (setq key (+ key 3))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1331 ;; Put this lambda into the symbol so we can find it |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1332 (if (byte-code-function-p (car-safe body)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1333 (eieiomt-add method (car-safe body) key argclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1334 (eieiomt-add method (append (list 'lambda (reverse argfix)) body) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1335 key argclass)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1336 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1337 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1338 (when eieio-optimize-primary-methods-flag |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1339 ;; Optimizing step: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1340 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1341 ;; If this method, after this setup, only has primary methods, then |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1342 ;; we can setup the generic that way. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1343 (if (generic-primary-only-p method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1344 ;; If there is only one primary method, then we can go one more |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1345 ;; optimization step. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1346 (if (generic-primary-only-one-p method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1347 (eieio-defgeneric-reset-generic-form-primary-only-one method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1348 (eieio-defgeneric-reset-generic-form-primary-only method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1349 (eieio-defgeneric-reset-generic-form method))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1350 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1351 method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1352 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1353 ;;; Slot type validation |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1354 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1355 (defun eieio-perform-slot-validation (spec value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1356 "Return non-nil if SPEC does not match VALUE." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1357 ;; typep is in cl-macs |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1358 (or (eq spec t) ; t always passes |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1359 (eq value eieio-unbound) ; unbound always passes |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1360 (typep value spec))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1361 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1362 (defun eieio-validate-slot-value (class slot-idx value slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1363 "Make sure that for CLASS referencing SLOT-IDX, that VALUE is valid. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1364 Checks the :type specifier. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1365 SLOT is the slot that is being checked, and is only used when throwing |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1366 and error." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1367 (if eieio-skip-typecheck |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1368 nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1369 ;; Trim off object IDX junk added in for the object index. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1370 (setq slot-idx (- slot-idx 3)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1371 (let ((st (aref (aref (class-v class) class-public-type) slot-idx))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1372 (if (not (eieio-perform-slot-validation st value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1373 (signal 'invalid-slot-type (list class slot st value)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1374 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1375 (defun eieio-validate-class-slot-value (class slot-idx value slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1376 "Make sure that for CLASS referencing SLOT-IDX, that VALUE is valid. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1377 Checks the :type specifier. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1378 SLOT is the slot that is being checked, and is only used when throwing |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1379 and error." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1380 (if eieio-skip-typecheck |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1381 nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1382 (let ((st (aref (aref (class-v class) class-class-allocation-type) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1383 slot-idx))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1384 (if (not (eieio-perform-slot-validation st value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1385 (signal 'invalid-slot-type (list class slot st value)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1386 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1387 (defun eieio-barf-if-slot-unbound (value instance slotname fn) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1388 "Throw a signal if VALUE is a representation of an UNBOUND slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1389 INSTANCE is the object being referenced. SLOTNAME is the offending |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1390 slot. If the slot is ok, return VALUE. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1391 Argument FN is the function calling this verifier." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1392 (if (and (eq value eieio-unbound) (not eieio-skip-typecheck)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1393 (slot-unbound instance (object-class instance) slotname fn) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1394 value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1395 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1396 ;;; Missing types that are useful to me. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1397 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1398 (defun boolean-p (bool) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1399 "Return non-nil if BOOL is nil or t." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1400 (or (null bool) (eq bool t))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1401 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1402 ;;; Get/Set slots in an object. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1403 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1404 (defmacro oref (obj slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1405 "Retrieve the value stored in OBJ in the slot named by SLOT. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1406 Slot is the name of the slot when created by `defclass' or the label |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1407 created by the :initarg tag." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1408 `(eieio-oref ,obj (quote ,slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1409 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1410 (defun eieio-oref (obj slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1411 "Return the value in OBJ at SLOT in the object vector." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1412 (if (not (or (eieio-object-p obj) (class-p obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1413 (signal 'wrong-type-argument (list '(or eieio-object-p class-p) obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1414 (if (not (symbolp slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1415 (signal 'wrong-type-argument (list 'symbolp slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1416 (if (class-p obj) (eieio-class-un-autoload obj)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1417 (let* ((class (if (class-p obj) obj (aref obj object-class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1418 (c (eieio-slot-name-index class obj slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1419 (if (not c) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1420 ;; It might be missing because it is a :class allocated slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1421 ;; Lets check that info out. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1422 (if (setq c (eieio-class-slot-name-index class slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1423 ;; Oref that slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1424 (aref (aref (class-v class) class-class-allocation-values) c) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1425 ;; The slot-missing method is a cool way of allowing an object author |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1426 ;; to intercept missing slot definitions. Since it is also the LAST |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1427 ;; thing called in this fn, it's return value would be retrieved. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1428 (slot-missing obj slot 'oref) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1429 ;;(signal 'invalid-slot-name (list (object-name obj) slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1430 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1431 (if (not (eieio-object-p obj)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1432 (signal 'wrong-type-argument (list 'eieio-object-p obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1433 (eieio-barf-if-slot-unbound (aref obj c) obj slot 'oref)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1434 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1435 (defalias 'slot-value 'eieio-oref) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1436 (defalias 'set-slot-value 'eieio-oset) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1437 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1438 ;; @TODO - DELETE THIS AFTER FAIR WARNING |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1439 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1440 ;; This alias is needed so that functions can be written |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1441 ;; for defaults, but still behave like lambdas. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1442 (defmacro lambda-default (&rest cdr) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1443 "The same as `lambda' but is used as a default value in `defclass'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1444 As such, the form (lambda-default ARGS DOCSTRING INTERACTIVE BODY) is |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1445 self quoting. This macro is meant for the sole purpose of quoting |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1446 lambda expressions into class defaults. Any `lambda-default' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1447 expression is automatically transformed into a `lambda' expression |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1448 when copied from the defaults into a new object. The use of |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1449 `oref-default', however, will return a `lambda-default' expression. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1450 CDR is function definition and body." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1451 (message "Warning: Use of `labda-default' will be obsoleted in the next version of EIEIO.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1452 ;; This definition is copied directly from subr.el for lambda |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1453 (list 'function (cons 'lambda-default cdr))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1454 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1455 (put 'lambda-default 'lisp-indent-function 'defun) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1456 (put 'lambda-default 'byte-compile 'byte-compile-lambda-form) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1457 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1458 (defmacro oref-default (obj slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1459 "Gets the default value of OBJ (maybe a class) for SLOT. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1460 The default value is the value installed in a class with the :initform |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1461 tag. SLOT can be the slot name, or the tag specified by the :initarg |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1462 tag in the `defclass' call." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1463 `(eieio-oref-default ,obj (quote ,slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1464 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1465 (defun eieio-oref-default (obj slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1466 "Does the work for the macro `oref-default' with similar parameters. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1467 Fills in OBJ's SLOT with it's default value." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1468 (if (not (or (eieio-object-p obj) (class-p obj))) (signal 'wrong-type-argument (list 'eieio-object-p obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1469 (if (not (symbolp slot)) (signal 'wrong-type-argument (list 'symbolp slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1470 (let* ((cl (if (eieio-object-p obj) (aref obj object-class) obj)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1471 (c (eieio-slot-name-index cl obj slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1472 (if (not c) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1473 ;; It might be missing because it is a :class allocated slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1474 ;; Lets check that info out. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1475 (if (setq c |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1476 (eieio-class-slot-name-index cl slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1477 ;; Oref that slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1478 (aref (aref (class-v cl) class-class-allocation-values) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1479 c) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1480 (slot-missing obj slot 'oref-default) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1481 ;;(signal 'invalid-slot-name (list (class-name cl) slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1482 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1483 (eieio-barf-if-slot-unbound |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1484 (let ((val (nth (- c 3) (aref (class-v cl) class-public-d)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1485 (eieio-default-eval-maybe val)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1486 obj cl 'oref-default)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1487 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1488 (defun eieio-default-eval-maybe (val) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1489 "Check VAL, and return what `oref-default' would provide." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1490 ;; check for functions to evaluate |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1491 (if (and (listp val) (equal (car val) 'lambda)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1492 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1493 (message "Warning: Evaluation of `lambda' initform will be obsoleted in the next version of EIEIO.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1494 (funcall val) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1495 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1496 ;; check for quoted things, and unquote them |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1497 (if (and (listp val) (eq (car val) 'quote)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1498 (car (cdr val)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1499 ;; return it verbatim |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1500 (if (and (listp val) (eq (car val) 'lambda-default)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1501 (let ((s (copy-sequence val))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1502 (setcar s 'lambda) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1503 s) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1504 val)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1505 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1506 ;;; Object Set macros |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1507 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1508 (defmacro oset (obj slot value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1509 "Set the value in OBJ for slot SLOT to VALUE. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1510 SLOT is the slot name as specified in `defclass' or the tag created |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1511 with in the :initarg slot. VALUE can be any Lisp object." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1512 `(eieio-oset ,obj (quote ,slot) ,value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1513 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1514 (defun eieio-oset (obj slot value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1515 "Does the work for the macro `oset'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1516 Fills in OBJ's SLOT with VALUE." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1517 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1518 (if (not (symbolp slot)) (signal 'wrong-type-argument (list 'symbolp slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1519 (let ((c (eieio-slot-name-index (object-class-fast obj) obj slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1520 (if (not c) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1521 ;; It might be missing because it is a :class allocated slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1522 ;; Lets check that info out. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1523 (if (setq c |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1524 (eieio-class-slot-name-index (aref obj object-class) slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1525 ;; Oset that slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1526 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1527 (eieio-validate-class-slot-value (object-class-fast obj) c value slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1528 (aset (aref (class-v (aref obj object-class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1529 class-class-allocation-values) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1530 c value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1531 ;; See oref for comment on `slot-missing' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1532 (slot-missing obj slot 'oset value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1533 ;;(signal 'invalid-slot-name (list (object-name obj) slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1534 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1535 (eieio-validate-slot-value (object-class-fast obj) c value slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1536 (aset obj c value)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1537 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1538 (defmacro oset-default (class slot value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1539 "Set the default slot in CLASS for SLOT to VALUE. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1540 The default value is usually set with the :initform tag during class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1541 creation. This allows users to change the default behavior of classes |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1542 after they are created." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1543 `(eieio-oset-default ,class (quote ,slot) ,value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1544 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1545 (defun eieio-oset-default (class slot value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1546 "Does the work for the macro `oset-default'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1547 Fills in the default value in CLASS' in SLOT with VALUE." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1548 (if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1549 (if (not (symbolp slot)) (signal 'wrong-type-argument (list 'symbolp slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1550 (let* ((scoped-class class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1551 (c (eieio-slot-name-index class nil slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1552 (if (not c) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1553 ;; It might be missing because it is a :class allocated slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1554 ;; Lets check that info out. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1555 (if (setq c (eieio-class-slot-name-index class slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1556 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1557 ;; Oref that slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1558 (eieio-validate-class-slot-value class c value slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1559 (aset (aref (class-v class) class-class-allocation-values) c |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1560 value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1561 (signal 'invalid-slot-name (list (class-name class) slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1562 (eieio-validate-slot-value class c value slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1563 ;; Set this into the storage for defaults. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1564 (setcar (nthcdr (- c 3) (aref (class-v class) class-public-d)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1565 value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1566 ;; Take the value, and put it into our cache object. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1567 (eieio-oset (aref (class-v class) class-default-object-cache) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1568 slot value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1569 ))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1570 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1571 ;;; Handy CLOS macros |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1572 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1573 (defmacro with-slots (spec-list object &rest body) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1574 "Bind SPEC-LIST lexically to slot values in OBJECT, and execute BODY. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1575 This establishes a lexical environment for referring to the slots in |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1576 the instance named by the given slot-names as though they were |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1577 variables. Within such a context the value of the slot can be |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1578 specified by using its slot name, as if it were a lexically bound |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1579 variable. Both setf and setq can be used to set the value of the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1580 slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1581 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1582 SPEC-LIST is of a form similar to `let'. For example: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1583 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1584 ((VAR1 SLOT1) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1585 SLOT2 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1586 SLOTN |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1587 (VARN+1 SLOTN+1)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1588 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1589 Where each VAR is the local variable given to the associated |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1590 SLOT. A Slot specified without a variable name is given a |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1591 variable name of the same name as the slot." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1592 ;; Transform the spec-list into a symbol-macrolet spec-list. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1593 (let ((mappings (mapcar (lambda (entry) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1594 (let ((var (if (listp entry) (car entry) entry)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1595 (slot (if (listp entry) (cadr entry) entry))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1596 (list var `(slot-value ,object ',slot)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1597 spec-list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1598 (append (list 'symbol-macrolet mappings) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1599 body))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1600 (put 'with-slots 'lisp-indent-function 2) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1601 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1602 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1603 ;;; Simple generators, and query functions. None of these would do |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1604 ;; well embedded into an object. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1605 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1606 (defmacro object-class-fast (obj) "Return the class struct defining OBJ with no check." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1607 `(aref ,obj object-class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1608 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1609 (defun class-name (class) "Return a Lisp like symbol name for CLASS." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1610 (if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1611 ;; I think this is supposed to return a symbol, but to me CLASS is a symbol, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1612 ;; and I wanted a string. Arg! |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1613 (format "#<class %s>" (symbol-name class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1614 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1615 (defun object-name (obj &optional extra) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1616 "Return a Lisp like symbol string for object OBJ. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1617 If EXTRA, include that in the string returned to represent the symbol." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1618 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1619 (format "#<%s %s%s>" (symbol-name (object-class-fast obj)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1620 (aref obj object-name) (or extra ""))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1621 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1622 (defun object-name-string (obj) "Return a string which is OBJ's name." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1623 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1624 (aref obj object-name)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1625 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1626 (defun object-set-name-string (obj name) "Set the string which is OBJ's NAME." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1627 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1628 (if (not (stringp name)) (signal 'wrong-type-argument (list 'stringp name))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1629 (aset obj object-name name)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1630 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1631 (defun object-class (obj) "Return the class struct defining OBJ." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1632 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1633 (object-class-fast obj)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1634 (defalias 'class-of 'object-class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1635 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1636 (defun object-class-name (obj) "Return a Lisp like symbol name for OBJ's class." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1637 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1638 (class-name (object-class-fast obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1639 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1640 (defmacro class-parents-fast (class) "Return parent classes to CLASS with no check." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1641 `(aref (class-v ,class) class-parent)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1642 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1643 (defun class-parents (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1644 "Return parent classes to CLASS. (overload of variable). |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1645 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1646 The CLOS function `class-direct-superclasses' is aliased to this function." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1647 (if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1648 (class-parents-fast class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1649 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1650 (defmacro class-children-fast (class) "Return child classes to CLASS with no check." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1651 `(aref (class-v ,class) class-children)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1652 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1653 (defun class-children (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1654 "Return child classses to CLASS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1655 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1656 The CLOS function `class-direct-subclasses' is aliased to this function." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1657 (if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1658 (class-children-fast class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1659 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1660 ;; Official CLOS functions. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1661 (defalias 'class-direct-superclasses 'class-parents) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1662 (defalias 'class-direct-subclasses 'class-children) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1663 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1664 (defmacro class-parent-fast (class) "Return first parent class to CLASS with no check." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1665 `(car (class-parents-fast ,class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1666 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1667 (defmacro class-parent (class) "Return first parent class to CLASS. (overload of variable)." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1668 `(car (class-parents ,class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1669 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1670 (defmacro same-class-fast-p (obj class) "Return t if OBJ is of class-type CLASS with no error checking." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1671 `(eq (aref ,obj object-class) ,class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1672 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1673 (defun same-class-p (obj class) "Return t if OBJ is of class-type CLASS." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1674 (if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1675 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1676 (same-class-fast-p obj class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1677 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1678 (defun object-of-class-p (obj class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1679 "Return non-nil if OBJ is an instance of CLASS or CLASS' subclasses." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1680 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1681 ;; class will be checked one layer down |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1682 (child-of-class-p (aref obj object-class) class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1683 ;; Backwards compatibility |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1684 (defalias 'obj-of-class-p 'object-of-class-p) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1685 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1686 (defun child-of-class-p (child class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1687 "If CHILD class is a subclass of CLASS." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1688 (if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1689 (if (not (class-p child)) (signal 'wrong-type-argument (list 'class-p child))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1690 (let ((p nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1691 (while (and child (not (eq child class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1692 (setq p (append p (aref (class-v child) class-parent)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1693 child (car p) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1694 p (cdr p))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1695 (if child t))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1696 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1697 (defun object-slots (obj) "List of slots available in OBJ." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1698 (if (not (eieio-object-p obj)) (signal 'wrong-type-argument (list 'eieio-object-p obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1699 (aref (class-v (object-class-fast obj)) class-public-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1700 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1701 (defun class-slot-initarg (class slot) "Fetch from CLASS, SLOT's :initarg." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1702 (if (not (class-p class)) (signal 'wrong-type-argument (list 'class-p class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1703 (let ((ia (aref (class-v class) class-initarg-tuples)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1704 (f nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1705 (while (and ia (not f)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1706 (if (eq (cdr (car ia)) slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1707 (setq f (car (car ia)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1708 (setq ia (cdr ia))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1709 f)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1710 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1711 ;;; CLOS queries into classes and slots |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1712 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1713 (defun slot-boundp (object slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1714 "Non-nil if OBJECT's SLOT is bound. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1715 Setting a slot's value makes it bound. Calling `slot-makeunbound' will |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1716 make a slot unbound. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1717 OBJECT can be an instance or a class." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1718 ;; Skip typechecking while retrieving this value. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1719 (let ((eieio-skip-typecheck t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1720 ;; Return nil if the magic symbol is in there. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1721 (if (eieio-object-p object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1722 (if (eq (eieio-oref object slot) eieio-unbound) nil t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1723 (if (class-p object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1724 (if (eq (eieio-oref-default object slot) eieio-unbound) nil t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1725 (signal 'wrong-type-argument (list 'eieio-object-p object)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1726 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1727 (defun slot-makeunbound (object slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1728 "In OBJECT, make SLOT unbound." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1729 (eieio-oset object slot eieio-unbound)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1730 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1731 (defun slot-exists-p (object-or-class slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1732 "Non-nil if OBJECT-OR-CLASS has SLOT." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1733 (let ((cv (class-v (cond ((eieio-object-p object-or-class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1734 (object-class object-or-class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1735 ((class-p object-or-class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1736 object-or-class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1737 ))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1738 (or (memq slot (aref cv class-public-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1739 (memq slot (aref cv class-class-allocation-a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1740 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1741 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1742 (defun find-class (symbol &optional errorp) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1743 "Return the class that SYMBOL represents. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1744 If there is no class, nil is returned if ERRORP is nil. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1745 If ERRORP is non-nil, `wrong-argument-type' is signaled." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1746 (if (not (class-p symbol)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1747 (if errorp (signal 'wrong-type-argument (list 'class-p symbol)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1748 nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1749 (class-v symbol))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1750 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1751 ;;; Slightly more complex utility functions for objects |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1752 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1753 (defun object-assoc (key slot list) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1754 "Return an object if KEY is `equal' to SLOT's value of an object in LIST. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1755 LIST is a list of objects who's slots are searched. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1756 Objects in LIST do not need to have a slot named SLOT, nor does |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1757 SLOT need to be bound. If these errors occur, those objects will |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1758 be ignored." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1759 (if (not (listp list)) (signal 'wrong-type-argument (list 'listp list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1760 (while (and list (not (condition-case nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1761 ;; This prevents errors for missing slots. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1762 (equal key (eieio-oref (car list) slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1763 (error nil)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1764 (setq list (cdr list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1765 (car list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1766 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1767 (defun object-assoc-list (slot list) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1768 "Return an association list with the contents of SLOT as the key element. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1769 LIST must be a list of objects with SLOT in it. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1770 This is useful when you need to do completing read on an object group." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1771 (if (not (listp list)) (signal 'wrong-type-argument (list 'listp list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1772 (let ((assoclist nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1773 (while list |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1774 (setq assoclist (cons (cons (eieio-oref (car list) slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1775 (car list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1776 assoclist)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1777 (setq list (cdr list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1778 (nreverse assoclist))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1779 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1780 (defun object-assoc-list-safe (slot list) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1781 "Return an association list with the contents of SLOT as the key element. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1782 LIST must be a list of objects, but those objects do not need to have |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1783 SLOT in it. If it does not, then that element is left out of the association |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1784 list." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1785 (if (not (listp list)) (signal 'wrong-type-argument (list 'listp list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1786 (let ((assoclist nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1787 (while list |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1788 (if (slot-exists-p (car list) slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1789 (setq assoclist (cons (cons (eieio-oref (car list) slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1790 (car list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1791 assoclist))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1792 (setq list (cdr list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1793 (nreverse assoclist))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1794 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1795 (defun object-add-to-list (object slot item &optional append) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1796 "In OBJECT's SLOT, add ITEM to the list of elements. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1797 Optional argument APPEND indicates we need to append to the list. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1798 If ITEM already exists in the list in SLOT, then it is not added. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1799 Comparison is done with `equal' through the `member' function call. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1800 If SLOT is unbound, bind it to the list containing ITEM." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1801 (let (ov) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1802 ;; Find the originating list. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1803 (if (not (slot-boundp object slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1804 (setq ov (list item)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1805 (setq ov (eieio-oref object slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1806 ;; turn it into a list. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1807 (unless (listp ov) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1808 (setq ov (list ov))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1809 ;; Do the combination |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1810 (if (not (member item ov)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1811 (setq ov |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1812 (if append |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1813 (append ov (list item)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1814 (cons item ov))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1815 ;; Set back into the slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1816 (eieio-oset object slot ov))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1817 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1818 (defun object-remove-from-list (object slot item) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1819 "In OBJECT's SLOT, remove occurrences of ITEM. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1820 Deletion is done with `delete', which deletes by side effect |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1821 and comparisons are done with `equal'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1822 If SLOT is unbound, do nothing." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1823 (if (not (slot-boundp object slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1824 nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1825 (eieio-oset object slot (delete item (eieio-oref object slot))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1826 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1827 ;;; EIEIO internal search functions |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1828 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1829 (defun eieio-slot-originating-class-p (start-class slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1830 "Return Non-nil if START-CLASS is the first class to define SLOT. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1831 This is for testing if `scoped-class' is the class that defines SLOT |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1832 so that we can protect private slots." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1833 (let ((par (class-parents start-class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1834 (ret t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1835 (if (not par) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1836 t |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1837 (while (and par ret) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1838 (if (intern-soft (symbol-name slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1839 (aref (class-v (car par)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1840 class-symbol-obarray)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1841 (setq ret nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1842 (setq par (cdr par))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1843 ret))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1844 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1845 (defun eieio-slot-name-index (class obj slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1846 "In CLASS for OBJ find the index of the named SLOT. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1847 The slot is a symbol which is installed in CLASS by the `defclass' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1848 call. OBJ can be nil, but if it is an object, and the slot in question |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1849 is protected, access will be allowed if obj is a child of the currently |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1850 `scoped-class'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1851 If SLOT is the value created with :initarg instead, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1852 reverse-lookup that name, and recurse with the associated slot value." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1853 ;; Removed checks to outside this call |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1854 (let* ((fsym (intern-soft (symbol-name slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1855 (aref (class-v class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1856 class-symbol-obarray))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1857 (fsi (if (symbolp fsym) (symbol-value fsym) nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1858 (if (integerp fsi) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1859 (cond |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1860 ((not (get fsym 'protection)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1861 (+ 3 fsi)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1862 ((and (eq (get fsym 'protection) 'protected) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1863 scoped-class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1864 (or (child-of-class-p class scoped-class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1865 (and (eieio-object-p obj) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1866 (child-of-class-p class (object-class obj))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1867 (+ 3 fsi)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1868 ((and (eq (get fsym 'protection) 'private) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1869 (or (and scoped-class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1870 (eieio-slot-originating-class-p scoped-class slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1871 eieio-initializing-object)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1872 (+ 3 fsi)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1873 (t nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1874 (let ((fn (eieio-initarg-to-attribute class slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1875 (if fn (eieio-slot-name-index class obj fn) nil))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1876 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1877 (defun eieio-class-slot-name-index (class slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1878 "In CLASS find the index of the named SLOT. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1879 The slot is a symbol which is installed in CLASS by the `defclass' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1880 call. If SLOT is the value created with :initarg instead, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1881 reverse-lookup that name, and recurse with the associated slot value." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1882 ;; This will happen less often, and with fewer slots. Do this the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1883 ;; storage cheap way. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1884 (let* ((a (aref (class-v class) class-class-allocation-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1885 (l1 (length a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1886 (af (memq slot a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1887 (l2 (length af))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1888 ;; Slot # is length of the total list, minus the remaining list of |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1889 ;; the found slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1890 (if af (- l1 l2)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1891 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1892 ;;; CLOS generics internal function handling |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1893 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1894 (defvar eieio-generic-call-methodname nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1895 "When using `call-next-method', provides a context on how to do it.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1896 (defvar eieio-generic-call-arglst nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1897 "When using `call-next-method', provides a context for parameters.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1898 (defvar eieio-generic-call-key nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1899 "When using `call-next-method', provides a context for the current key. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1900 Keys are a number representing :before, :primary, and :after methods.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1901 (defvar eieio-generic-call-next-method-list nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1902 "When executing a PRIMARY or STATIC method, track the 'next-method'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1903 During executions, the list is first generated, then as each next method |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1904 is called, the next method is popped off the stack.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1905 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1906 (defvar eieio-pre-method-execution-hooks nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1907 "*Hooks run just before a method is executed. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1908 The hook function must accept on argument, this list of forms |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1909 about to be executed.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1910 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1911 (defun eieio-generic-call (method args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1912 "Call METHOD with ARGS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1913 ARGS provides the context on which implementation to use. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1914 This should only be called from a generic function." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1915 ;; We must expand our arguments first as they are always |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1916 ;; passed in as quoted symbols |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1917 (let ((newargs nil) (mclass nil) (lambdas nil) (tlambdas nil) (keys nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1918 (eieio-generic-call-methodname method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1919 (eieio-generic-call-arglst args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1920 (firstarg nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1921 (primarymethodlist nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1922 ;; get a copy |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1923 (setq newargs args |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1924 firstarg (car newargs)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1925 ;; Is the class passed in autoloaded? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1926 ;; Since class names are also constructors, they can be autoloaded |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1927 ;; via the autoload command. Check for this, and load them in. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1928 ;; It's ok if it doesn't turn out to be a class. Probably want that |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1929 ;; function loaded anyway. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1930 (if (and (symbolp firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1931 (fboundp firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1932 (listp (symbol-function firstarg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1933 (eq 'autoload (car (symbol-function firstarg)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1934 (load (nth 1 (symbol-function firstarg)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1935 ;; Determine the class to use. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1936 (cond ((eieio-object-p firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1937 (setq mclass (object-class-fast firstarg))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1938 ((class-p firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1939 (setq mclass firstarg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1940 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1941 ;; Make sure the class is a valid class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1942 ;; mclass can be nil (meaning a generic for should be used. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1943 ;; mclass cannot have a value that is not a class, however. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1944 (when (and (not (null mclass)) (not (class-p mclass))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1945 (error "Cannot dispatch method %S on class %S" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1946 method mclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1947 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1948 ;; Now create a list in reverse order of all the calls we have |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1949 ;; make in order to successfully do this right. Rules: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1950 ;; 1) Only call generics if scoped-class is not defined |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1951 ;; This prevents multiple calls in the case of recursion |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1952 ;; 2) Only call static if this is a static method. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1953 ;; 3) Only call specifics if the definition allows for them. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1954 ;; 4) Call in order based on :before, :primary, and :after |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1955 (when (eieio-object-p firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1956 ;; Non-static calls do all this stuff. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1957 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1958 ;; :after methods |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1959 (setq tlambdas |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1960 (if mclass |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1961 (eieiomt-method-list method method-after mclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1962 (list (eieio-generic-form method method-after nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1963 ;;(or (and mclass (eieio-generic-form method method-after mclass)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1964 ;; (eieio-generic-form method method-after nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1965 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1966 (setq lambdas (append tlambdas lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1967 keys (append (make-list (length tlambdas) method-after) keys)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1968 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1969 ;; :primary methods |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1970 (setq tlambdas |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1971 (or (and mclass (eieio-generic-form method method-primary mclass)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1972 (eieio-generic-form method method-primary nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1973 (when tlambdas |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1974 (setq lambdas (cons tlambdas lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1975 keys (cons method-primary keys) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1976 primarymethodlist |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1977 (eieiomt-method-list method method-primary mclass))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1978 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1979 ;; :before methods |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1980 (setq tlambdas |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1981 (if mclass |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1982 (eieiomt-method-list method method-before mclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1983 (list (eieio-generic-form method method-before nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1984 ;;(or (and mclass (eieio-generic-form method method-before mclass)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1985 ;; (eieio-generic-form method method-before nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1986 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1987 (setq lambdas (append tlambdas lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1988 keys (append (make-list (length tlambdas) method-before) keys)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1989 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1990 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1991 ;; If there were no methods found, then there could be :static methods. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1992 (when (not lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1993 (setq tlambdas |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1994 (eieio-generic-form method method-static mclass)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1995 (setq lambdas (cons tlambdas lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1996 keys (cons method-static keys) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1997 primarymethodlist ;; Re-use even with bad name here |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1998 (eieiomt-method-list method method-static mclass))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1999 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2000 (run-hook-with-args 'eieio-pre-method-execution-hooks |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2001 primarymethodlist) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2002 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2003 ;; Now loop through all occurances forms which we must execute |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2004 ;; (which are happily sorted now) and execute them all! |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2005 (let ((rval nil) (lastval nil) (rvalever nil) (found nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2006 (while lambdas |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2007 (if (car lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2008 (let* ((scoped-class (cdr (car lambdas))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2009 (eieio-generic-call-key (car keys)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2010 (has-return-val |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2011 (or (= eieio-generic-call-key method-primary) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2012 (= eieio-generic-call-key method-static))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2013 (eieio-generic-call-next-method-list |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2014 ;; Use the cdr, as the first element is the fcn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2015 ;; we are calling right now. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2016 (when has-return-val (cdr primarymethodlist))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2017 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2018 (setq found t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2019 ;;(setq rval (apply (car (car lambdas)) newargs)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2020 (setq lastval (apply (car (car lambdas)) newargs)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2021 (when has-return-val |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2022 (setq rval lastval |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2023 rvalever t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2024 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2025 (setq lambdas (cdr lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2026 keys (cdr keys))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2027 (if (not found) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2028 (if (eieio-object-p (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2029 (setq rval (apply 'no-applicable-method (car args) method args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2030 rvalever t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2031 (signal |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2032 'no-method-definition |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2033 (list method args)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2034 ;; Right Here... it could be that lastval is returned when |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2035 ;; rvalever is nil. Is that right? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2036 rval))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2037 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2038 (defun eieio-generic-call-primary-only (method args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2039 "Call METHOD with ARGS for methods with only :PRIMARY implementations. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2040 ARGS provides the context on which implementation to use. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2041 This should only be called from a generic function. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2042 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2043 This method is like `eieio-generic-call', but only |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2044 implementations in the :PRIMARY slot are queried. After many |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2045 years of use, it appears that over 90% of methods in use |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2046 have :PRIMARY implementations only. We can therefore optimize |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2047 for this common case to improve performance." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2048 ;; We must expand our arguments first as they are always |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2049 ;; passed in as quoted symbols |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2050 (let ((newargs nil) (mclass nil) (lambdas nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2051 (eieio-generic-call-methodname method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2052 (eieio-generic-call-arglst args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2053 (firstarg nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2054 (primarymethodlist nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2055 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2056 ;; get a copy |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2057 (setq newargs args |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2058 firstarg (car newargs)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2059 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2060 ;; Determine the class to use. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2061 (cond ((eieio-object-p firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2062 (setq mclass (object-class-fast firstarg))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2063 ((not firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2064 (error "Method %s called on nil" method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2065 ((not (eieio-object-p firstarg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2066 (error "Primary-only method %s called on something not an object" method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2067 (t |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2068 (error "EIEIO Error: Improperly classified method %s as primary only" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2069 method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2070 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2071 ;; Make sure the class is a valid class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2072 ;; mclass can be nil (meaning a generic for should be used. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2073 ;; mclass cannot have a value that is not a class, however. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2074 (when (null mclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2075 (error "Cannot dispatch method %S on class %S" method mclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2076 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2077 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2078 ;; :primary methods |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2079 (setq lambdas (eieio-generic-form method method-primary mclass)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2080 (setq primarymethodlist ;; Re-use even with bad name here |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2081 (eieiomt-method-list method method-primary mclass)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2082 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2083 ;; Now loop through all occurances forms which we must execute |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2084 ;; (which are happily sorted now) and execute them all! |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2085 (let* ((rval nil) (lastval nil) (rvalever nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2086 (scoped-class (cdr lambdas)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2087 (eieio-generic-call-key method-primary) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2088 ;; Use the cdr, as the first element is the fcn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2089 ;; we are calling right now. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2090 (eieio-generic-call-next-method-list (cdr primarymethodlist)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2091 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2092 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2093 (if (or (not lambdas) (not (car lambdas))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2094 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2095 ;; No methods found for this impl... |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2096 (if (eieio-object-p (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2097 (setq rval (apply 'no-applicable-method (car args) method args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2098 rvalever t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2099 (signal |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2100 'no-method-definition |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2101 (list method args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2102 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2103 ;; Do the regular implementation here. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2104 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2105 (run-hook-with-args 'eieio-pre-method-execution-hooks |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2106 lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2107 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2108 (setq lastval (apply (car lambdas) newargs)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2109 (setq rval lastval |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2110 rvalever t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2111 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2112 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2113 ;; Right Here... it could be that lastval is returned when |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2114 ;; rvalever is nil. Is that right? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2115 rval))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2116 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2117 (defun eieiomt-method-list (method key class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2118 "Return an alist list of methods lambdas. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2119 METHOD is the method name. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2120 KEY represents either :before, or :after methods. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2121 CLASS is the starting class to search from in the method tree. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2122 If CLASS is nil, then an empty list of methods should be returned." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2123 ;; Note: eieiomt - the MT means MethodTree. See more comments below |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2124 ;; for the rest of the eieiomt methods. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2125 (let ((lambdas nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2126 (mclass (list class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2127 (while mclass |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2128 ;; Note: a nil can show up in the class list once we start |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2129 ;; searching through the method tree. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2130 (when (car mclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2131 ;; lookup the form to use for the PRIMARY object for the next level |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2132 (let ((tmpl (eieio-generic-form method key (car mclass)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2133 (when (or (not lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2134 ;; This prevents duplicates coming out of the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2135 ;; class method optimizer. Perhaps we should |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2136 ;; just not optimize before/afters? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2137 (not (eq (car tmpl) (car (car lambdas))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2138 (setq lambdas (cons tmpl lambdas)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2139 (if (null (car lambdas)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2140 (setq lambdas (cdr lambdas)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2141 ;; Add new classes to mclass. Since our input might not be a class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2142 ;; protect against that. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2143 (if (car mclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2144 ;; If there is a class, append any methods it may provide |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2145 ;; to the remainder of the class list. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2146 (let ((io (class-method-invocation-order (car mclass)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2147 (if (eq io :depth-first) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2148 ;; Depth first. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2149 (setq mclass (append (eieiomt-next (car mclass)) (cdr mclass))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2150 ;; Breadth first. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2151 (setq mclass (append (cdr mclass) (eieiomt-next (car mclass))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2152 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2153 ;; Advance to next entry in mclass if it is nil. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2154 (setq mclass (cdr mclass))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2155 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2156 (if (eq key method-after) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2157 lambdas |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2158 (nreverse lambdas)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2159 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2160 (defun next-method-p () |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2161 "Non-nil if there is a next method. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2162 Returns a list of lambda expressions which is the `next-method' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2163 order." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2164 eieio-generic-call-next-method-list) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2165 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2166 (defun call-next-method (&rest replacement-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2167 "Call the superclass method from a subclass method. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2168 The superclass method is specified in the current method list, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2169 and is called the next method. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2170 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2171 If REPLACEMENT-ARGS is non-nil, then use them instead of |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2172 `eieio-generic-call-arglst'. The generic arg list are the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2173 arguments passed in at the top level. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2174 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2175 Use `next-method-p' to find out if there is a next method to call." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2176 (if (not scoped-class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2177 (error "Call-next-method not called within a class specific method")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2178 (if (and (/= eieio-generic-call-key method-primary) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2179 (/= eieio-generic-call-key method-static)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2180 (error "Cannot `call-next-method' except in :primary or :static methods") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2181 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2182 (let ((newargs (or replacement-args eieio-generic-call-arglst)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2183 (next (car eieio-generic-call-next-method-list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2184 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2185 (if (or (not next) (not (car next))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2186 (apply 'no-next-method (car newargs) (cdr newargs)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2187 (let* ((eieio-generic-call-next-method-list |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2188 (cdr eieio-generic-call-next-method-list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2189 (scoped-class (cdr next)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2190 (fcn (car next)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2191 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2192 (apply fcn newargs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2193 )))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2194 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2195 ;;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2196 ;; eieio-method-tree : eieiomt- |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2197 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2198 ;; Stored as eieio-method-tree in property list of a generic method |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2199 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2200 ;; (eieio-method-tree . [BEFORE PRIMARY AFTER |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2201 ;; genericBEFORE genericPRIMARY genericAFTER]) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2202 ;; and |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2203 ;; (eieio-method-obarray . [BEFORE PRIMARY AFTER |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2204 ;; genericBEFORE genericPRIMARY genericAFTER]) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2205 ;; where the association is a vector. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2206 ;; (aref 0 -- all static methods. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2207 ;; (aref 1 -- all methods classified as :before |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2208 ;; (aref 2 -- all methods classified as :primary |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2209 ;; (aref 3 -- all methods classified as :after |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2210 ;; (aref 4 -- a generic classified as :before |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2211 ;; (aref 5 -- a generic classified as :primary |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2212 ;; (aref 6 -- a generic classified as :after |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2213 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2214 (defvar eieiomt-optimizing-obarray nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2215 "While mapping atoms, this contain the obarray being optimized.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2216 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2217 (defun eieiomt-install (method-name) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2218 "Install the method tree, and obarray onto METHOD-NAME. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2219 Do not do the work if they already exist." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2220 (let ((emtv (get method-name 'eieio-method-tree)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2221 (emto (get method-name 'eieio-method-obarray))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2222 (if (or (not emtv) (not emto)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2223 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2224 (setq emtv (put method-name 'eieio-method-tree |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2225 (make-vector method-num-slots nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2226 emto (put method-name 'eieio-method-obarray |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2227 (make-vector method-num-slots nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2228 (aset emto 0 (make-vector 11 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2229 (aset emto 1 (make-vector 11 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2230 (aset emto 2 (make-vector 41 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2231 (aset emto 3 (make-vector 11 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2232 )))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2233 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2234 (defun eieiomt-add (method-name method key class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2235 "Add to METHOD-NAME the forms METHOD in a call position KEY for CLASS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2236 METHOD-NAME is the name created by a call to `defgeneric'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2237 METHOD are the forms for a given implementation. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2238 KEY is an integer (see comment in eieio.el near this function) which |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2239 is associated with the :static :before :primary and :after tags. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2240 It also indicates if CLASS is defined or not. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2241 CLASS is the class this method is associated with." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2242 (if (or (> key method-num-slots) (< key 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2243 (error "Eieiomt-add: method key error!")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2244 (let ((emtv (get method-name 'eieio-method-tree)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2245 (emto (get method-name 'eieio-method-obarray))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2246 ;; Make sure the method tables are available. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2247 (if (or (not emtv) (not emto)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2248 (error "Programmer error: eieiomt-add")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2249 ;; only add new cells on if it doesn't already exist! |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2250 (if (assq class (aref emtv key)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2251 (setcdr (assq class (aref emtv key)) method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2252 (aset emtv key (cons (cons class method) (aref emtv key)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2253 ;; Add function definition into newly created symbol, and store |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2254 ;; said symbol in the correct obarray, otherwise use the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2255 ;; other array to keep this stuff |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2256 (if (< key method-num-lists) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2257 (let ((nsym (intern (symbol-name class) (aref emto key)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2258 (fset nsym method))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2259 ;; Now optimize the entire obarray |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2260 (if (< key method-num-lists) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2261 (let ((eieiomt-optimizing-obarray (aref emto key))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2262 ;; @todo - Is this overkill? Should we just clear the symbol? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2263 (mapatoms 'eieiomt-sym-optimize eieiomt-optimizing-obarray))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2264 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2265 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2266 (defun eieiomt-next (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2267 "Return the next parent class for CLASS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2268 If CLASS is a superclass, return variable `eieio-default-superclass'. If CLASS |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2269 is variable `eieio-default-superclass' then return nil. This is different from |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2270 function `class-parent' as class parent returns nil for superclasses. This |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2271 function performs no type checking!" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2272 ;; No type-checking because all calls are made from functions which |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2273 ;; are safe and do checking for us. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2274 (or (class-parents-fast class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2275 (if (eq class 'eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2276 nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2277 '(eieio-default-superclass)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2278 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2279 (defun eieiomt-sym-optimize (s) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2280 "Find the next class above S which has a function body for the optimizer." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2281 ;; (message "Optimizing %S" s) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2282 (let* ((es (intern-soft (symbol-name s))) ;external symbol of class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2283 (io (class-method-invocation-order es)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2284 (ov nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2285 (cont t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2286 ;; This converts ES from a single symbol to a list of parent classes. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2287 (setq es (eieiomt-next es)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2288 ;; Loop over ES, then it's children individually. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2289 ;; We can have multiple hits only at one level of the parent tree. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2290 (while (and es cont) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2291 (setq ov (intern-soft (symbol-name (car es)) eieiomt-optimizing-obarray)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2292 (if (fboundp ov) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2293 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2294 (set s ov) ;store ov as our next symbol |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2295 (setq cont nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2296 (if (eq io :depth-first) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2297 ;; Pre-pend the subclasses of (car es) so we get |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2298 ;; DEPTH FIRST optimization. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2299 (setq es (append (eieiomt-next (car es)) (cdr es))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2300 ;; Else, we are breadth first. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2301 ;; (message "Class %s is breadth first" es) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2302 (setq es (append (cdr es) (eieiomt-next (car es)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2303 ))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2304 ;; If there is no nearest call, then set our value to nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2305 (if (not es) (set s nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2306 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2307 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2308 (defun eieio-generic-form (method key class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2309 "Return the lambda form belonging to METHOD using KEY based upon CLASS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2310 If CLASS is not a class then use `generic' instead. If class has no |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2311 form, but has a parent class, then trace to that parent class. The |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2312 first time a form is requested from a symbol, an optimized path is |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2313 memoized for future faster use." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2314 (let ((emto (aref (get method 'eieio-method-obarray) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2315 (if class key (+ key 3))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2316 (if (class-p class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2317 ;; 1) find our symbol |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2318 (let ((cs (intern-soft (symbol-name class) emto))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2319 (if (not cs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2320 ;; 2) If there isn't one, then make one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2321 ;; This can be slow since it only occurs once |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2322 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2323 (setq cs (intern (symbol-name class) emto)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2324 ;; 2.1) Cache it's nearest neighbor with a quick optimize |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2325 ;; which should only occur once for this call ever |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2326 (let ((eieiomt-optimizing-obarray emto)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2327 (eieiomt-sym-optimize cs)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2328 ;; 3) If it's bound return this one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2329 (if (fboundp cs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2330 (cons cs (aref (class-v class) class-symbol)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2331 ;; 4) If it's not bound then this variable knows something |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2332 (if (symbol-value cs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2333 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2334 ;; 4.1) This symbol holds the next class in it's value |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2335 (setq class (symbol-value cs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2336 cs (intern-soft (symbol-name class) emto)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2337 ;; 4.2) The optimizer should always have chosen a |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2338 ;; function-symbol |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2339 ;;(if (fboundp cs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2340 (cons cs (aref (class-v (intern (symbol-name class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2341 class-symbol)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2342 ;;(error "EIEIO optimizer: erratic data loss!")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2343 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2344 ;; There never will be a funcall... |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2345 nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2346 ;; for a generic call, what is a list, is the function body we want. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2347 (let ((emtl (aref (get method 'eieio-method-tree) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2348 (if class key (+ key 3))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2349 (if emtl |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2350 ;; The car of EMTL is supposed to be a class, which in this |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2351 ;; case is nil, so skip it. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2352 (cons (cdr (car emtl)) nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2353 nil))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2354 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2355 ;;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2356 ;; Way to assign slots based on a list. Used for constructors, or |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2357 ;; even resetting an object at run-time |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2358 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2359 (defun eieio-set-defaults (obj &optional set-all) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2360 "Take object OBJ, and reset all slots to their defaults. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2361 If SET-ALL is non-nil, then when a default is nil, that value is |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2362 reset. If SET-ALL is nil, the slots are only reset if the default is |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2363 not nil." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2364 (let ((scoped-class (aref obj object-class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2365 (eieio-initializing-object t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2366 (pub (aref (class-v (aref obj object-class)) class-public-a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2367 (while pub |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2368 (let ((df (eieio-oref-default obj (car pub)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2369 (if (and (listp df) (eq (car df) 'lambda-default)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2370 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2371 (setq df (copy-sequence df)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2372 (setcar df 'lambda))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2373 (if (or df set-all) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2374 (eieio-oset obj (car pub) df))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2375 (setq pub (cdr pub))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2376 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2377 (defun eieio-initarg-to-attribute (class initarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2378 "For CLASS, convert INITARG to the actual attribute name. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2379 If there is no translation, pass it in directly (so we can cheat if |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2380 need be.. May remove that later...)" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2381 (let ((tuple (assoc initarg (aref (class-v class) class-initarg-tuples)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2382 (if tuple |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2383 (cdr tuple) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2384 nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2385 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2386 (defun eieio-attribute-to-initarg (class attribute) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2387 "In CLASS, convert the ATTRIBUTE into the corresponding init argument tag. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2388 This is usually a symbol that starts with `:'." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2389 (let ((tuple (rassoc attribute (aref (class-v class) class-initarg-tuples)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2390 (if tuple |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2391 (car tuple) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2392 nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2393 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2394 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2395 ;;; Here are some special types of errors |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2396 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2397 (intern "no-method-definition") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2398 (put 'no-method-definition 'error-conditions '(no-method-definition error)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2399 (put 'no-method-definition 'error-message "No method definition") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2400 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2401 (intern "no-next-method") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2402 (put 'no-next-method 'error-conditions '(no-next-method error)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2403 (put 'no-next-method 'error-message "No next method") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2404 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2405 (intern "invalid-slot-name") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2406 (put 'invalid-slot-name 'error-conditions '(invalid-slot-name error)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2407 (put 'invalid-slot-name 'error-message "Invalid slot name") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2408 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2409 (intern "invalid-slot-type") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2410 (put 'invalid-slot-type 'error-conditions '(invalid-slot-type error nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2411 (put 'invalid-slot-type 'error-message "Invalid slot type") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2412 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2413 (intern "unbound-slot") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2414 (put 'unbound-slot 'error-conditions '(unbound-slot error nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2415 (put 'unbound-slot 'error-message "Unbound slot") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2416 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2417 ;;; Here are some CLOS items that need the CL package |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2418 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2419 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2420 (defsetf slot-value (obj slot) (store) (list 'eieio-oset obj slot store)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2421 (defsetf eieio-oref (obj slot) (store) (list 'eieio-oset obj slot store)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2422 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2423 ;; The below setf method was written by Arnd Kohrs <kohrs@acm.org> |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2424 (define-setf-method oref (obj slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2425 (let ((obj-temp (gensym)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2426 (slot-temp (gensym)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2427 (store-temp (gensym))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2428 (list (list obj-temp slot-temp) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2429 (list obj `(quote ,slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2430 (list store-temp) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2431 (list 'set-slot-value obj-temp slot-temp |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2432 store-temp) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2433 (list 'slot-value obj-temp slot-temp)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2434 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2435 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2436 ;;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2437 ;; We want all objects created by EIEIO to have some default set of |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2438 ;; behaviours so we can create object utilities, and allow various |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2439 ;; types of error checking. To do this, create the default EIEIO |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2440 ;; class, and when no parent class is specified, use this as the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2441 ;; default. (But don't store it in the other classes as the default, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2442 ;; allowing for transparent support.) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2443 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2444 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2445 (defclass eieio-default-superclass nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2446 nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2447 "Default parent class for classes with no specified parent class. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2448 Its slots are automatically adopted by classes with no specified |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2449 parents. This class is not stored in the `parent' slot of a class vector." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2450 :abstract t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2451 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2452 (defalias 'standard-class 'eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2453 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2454 (defgeneric constructor (class newname &rest slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2455 "Default constructor for CLASS `eieio-defualt-superclass'.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2456 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2457 (defmethod constructor :static |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2458 ((class eieio-default-superclass) newname &rest slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2459 "Default constructor for CLASS `eieio-defualt-superclass'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2460 NEWNAME is the name to be given to the constructed object. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2461 SLOTS are the initialization slots used by `shared-initialize'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2462 This static method is called when an object is constructed. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2463 It allocates the vector used to represent an EIEIO object, and then |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2464 calls `shared-initialize' on that object." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2465 (let* ((new-object (copy-sequence (aref (class-v class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2466 class-default-object-cache)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2467 ;; Update the name for the newly created object. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2468 (aset new-object object-name newname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2469 ;; Call the initialize method on the new object with the slots |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2470 ;; that were passed down to us. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2471 (initialize-instance new-object slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2472 ;; Return the created object. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2473 new-object)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2474 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2475 (defgeneric shared-initialize (obj slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2476 "Set slots of OBJ with SLOTS which is a list of name/value pairs. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2477 Called from the constructor routine.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2478 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2479 (defmethod shared-initialize ((obj eieio-default-superclass) slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2480 "Set slots of OBJ with SLOTS which is a list of name/value pairs. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2481 Called from the constructor routine." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2482 (let ((scoped-class (aref obj object-class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2483 (while slots |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2484 (let ((rn (eieio-initarg-to-attribute (object-class-fast obj) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2485 (car slots)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2486 (if (not rn) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2487 (slot-missing obj (car slots) 'oset (car (cdr slots))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2488 (eieio-oset obj rn (car (cdr slots))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2489 (setq slots (cdr (cdr slots)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2490 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2491 (defgeneric initialize-instance (this &optional slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2492 "Constructs the new object THIS based on SLOTS.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2493 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2494 (defmethod initialize-instance ((this eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2495 &optional slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2496 "Constructs the new object THIS based on SLOTS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2497 SLOTS is a tagged list where odd numbered elements are tags, and |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2498 even numbered elements are the values to store in the tagged slot. If |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2499 you overload the `initialize-instance', there you will need to call |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2500 `shared-initialize' yourself, or you can call `call-next-method' to |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2501 have this constructor called automatically. If these steps are not |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2502 taken, then new objects of your class will not have their values |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2503 dynamically set from SLOTS." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2504 ;; First, see if any of our defaults are `lambda', and |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2505 ;; re-evaluate them and apply the value to our slots. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2506 (let* ((scoped-class (class-v (aref this object-class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2507 (slot (aref scoped-class class-public-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2508 (defaults (aref scoped-class class-public-d))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2509 (while slot |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2510 (if (and (listp (car defaults)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2511 (eq 'lambda (car (car defaults)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2512 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2513 (message "Warning: Evaluation of `lambda' initform will be obsoleted in the next version of EIEIO.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2514 (eieio-oset this (car slot) (funcall (car defaults))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2515 (setq slot (cdr slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2516 defaults (cdr defaults)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2517 ;; Shared initialize will parse our slots for us. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2518 (shared-initialize this slots)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2519 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2520 (defgeneric slot-missing (object slot-name operation &optional new-value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2521 "Method invoked when an attempt to access a slot in OBJECT fails.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2522 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2523 (defmethod slot-missing ((object eieio-default-superclass) slot-name |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2524 operation &optional new-value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2525 "Method invoked when an attempt to access a slot in OBJECT fails. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2526 SLOT-NAME is the name of the failed slot, OPERATION is the type of access |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2527 that was requested, and optional NEW-VALUE is the value that was desired |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2528 to be set. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2529 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2530 This method is called from `oref', `oset', and other functions which |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2531 directly reference slots in EIEIO objects." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2532 (signal 'invalid-slot-name (list (object-name object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2533 slot-name))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2534 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2535 (defgeneric slot-unbound (object class slot-name fn) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2536 "Slot unbound is invoked during an attempt to reference an unbound slot.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2537 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2538 (defmethod slot-unbound ((object eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2539 class slot-name fn) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2540 "Slot unbound is invoked during an attempt to reference an unbound slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2541 OBJECT is the instance of the object being reference. CLASS is the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2542 class of OBJECT, and SLOT-NAME is the offending slot. This function |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2543 throws the signal `unbound-slot'. You can overload this function and |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2544 return the value to use in place of the unbound value. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2545 Argument FN is the function signaling this error. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2546 Use `slot-boundp' to determine if a slot is bound or not. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2547 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2548 In CLOS, the argument list is (CLASS OBJECT SLOT-NAME), but |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2549 EIEIO can only dispatch on the first argument, so the first two are swapped." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2550 (signal 'unbound-slot (list (class-name class) (object-name object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2551 slot-name fn))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2552 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2553 (defgeneric no-applicable-method (object method &rest args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2554 "Called if there are no implementations for OBJECT in METHOD.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2555 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2556 (defmethod no-applicable-method ((object eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2557 method &rest args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2558 "Called if there are no implementations for OBJECT in METHOD. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2559 OBJECT is the object which has no method implementation. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2560 ARGS are the arguments that were passed to METHOD. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2561 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2562 Implement this for a class to block this signal. The return |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2563 value becomes the return value of the original method call." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2564 (signal 'no-method-definition (list method (object-name object))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2565 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2566 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2567 (defgeneric no-next-method (object &rest args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2568 "Called from `call-next-method' when no additional methods are available.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2569 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2570 (defmethod no-next-method ((object eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2571 &rest args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2572 "Called from `call-next-method' when no additional methods are available. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2573 OBJECT is othe object being called on `call-next-method'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2574 ARGS are the arguments it is called by. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2575 This method signals `no-next-method' by default. Override this |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2576 method to not throw an error, and it's return value becomes the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2577 return value of `call-next-method'." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2578 (signal 'no-next-method (list (object-name object) args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2579 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2580 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2581 (defgeneric clone (obj &rest params) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2582 "Make a copy of OBJ, and then supply PARAMS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2583 PARAMS is a parameter list of the same form used by `initialize-instance'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2584 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2585 When overloading `clone', be sure to call `call-next-method' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2586 first and modify the returned object.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2587 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2588 (defmethod clone ((obj eieio-default-superclass) &rest params) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2589 "Make a copy of OBJ, and then apply PARAMS." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2590 (let ((nobj (copy-sequence obj)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2591 (nm (aref obj object-name)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2592 (passname (and params (stringp (car params)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2593 (num 1)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2594 (if params (shared-initialize nobj (if passname (cdr params) params))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2595 (if (not passname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2596 (save-match-data |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2597 (if (string-match "-\\([0-9]+\\)" nm) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2598 (setq num (1+ (string-to-number (match-string 1 nm))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2599 nm (substring nm 0 (match-beginning 0)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2600 (aset nobj object-name (concat nm "-" (int-to-string num)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2601 (aset nobj object-name (car params))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2602 nobj)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2603 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2604 (defgeneric destructor (this &rest params) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2605 "Destructor for cleaning up any dynamic links to our object.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2606 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2607 (defmethod destructor ((this eieio-default-superclass) &rest params) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2608 "Destructor for cleaning up any dynamic links to our object. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2609 Argument THIS is the object being destroyed. PARAMS are additional |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2610 ignored parameters." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2611 ;; No cleanup... yet. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2612 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2613 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2614 (defgeneric object-print (this &rest strings) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2615 "Pretty printer for object THIS. Call function `object-name' with STRINGS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2616 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2617 It is sometimes useful to put a summary of the object into the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2618 default #<notation> string when using eieio browsing tools. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2619 Implement this method to customize the summary.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2620 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2621 (defmethod object-print ((this eieio-default-superclass) &rest strings) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2622 "Pretty printer for object THIS. Call function `object-name' with STRINGS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2623 The default method for printing object THIS is to use the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2624 function `object-name'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2625 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2626 It is sometimes useful to put a summary of the object into the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2627 default #<notation> string when using eieio browsing tools. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2628 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2629 Implement this function and specify STRINGS in a call to |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2630 `call-next-method' to provide additional summary information. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2631 When passing in extra strings from child classes, always remember |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2632 to prepend a space." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2633 (object-name this (apply 'concat strings))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2634 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2635 (defvar eieio-print-depth 0 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2636 "When printing, keep track of the current indentation depth.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2637 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2638 (defgeneric object-write (this &optional comment) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2639 "Write out object THIS to the current stream. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2640 Optional COMMENDS will add comments to the beginning of the output.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2641 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2642 (defmethod object-write ((this eieio-default-superclass) &optional comment) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2643 "Write object THIS out to the current stream. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2644 This writes out the vector version of this object. Complex and recursive |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2645 object are discouraged from being written. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2646 If optional COMMENT is non-nil, include comments when outputting |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2647 this object." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2648 (when comment |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2649 (princ ";; Object ") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2650 (princ (object-name-string this)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2651 (princ "\n") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2652 (princ comment) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2653 (princ "\n")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2654 (let* ((cl (object-class this)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2655 (cv (class-v cl))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2656 ;; Now output readable lisp to recreate this object |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2657 ;; It should look like this: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2658 ;; (<constructor> <name> <slot> <slot> ... ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2659 ;; Each slot's slot is writen using its :writer. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2660 (princ (make-string (* eieio-print-depth 2) ? )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2661 (princ "(") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2662 (princ (symbol-name (class-constructor (object-class this)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2663 (princ " \"") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2664 (princ (object-name-string this)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2665 (princ "\"\n") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2666 ;; Loop over all the public slots |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2667 (let ((publa (aref cv class-public-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2668 (publd (aref cv class-public-d)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2669 (publp (aref cv class-public-printer)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2670 (eieio-print-depth (1+ eieio-print-depth))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2671 (while publa |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2672 (when (slot-boundp this (car publa)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2673 (let ((i (class-slot-initarg cl (car publa))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2674 (v (eieio-oref this (car publa))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2675 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2676 (unless (or (not i) (equal v (car publd))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2677 (princ (make-string (* eieio-print-depth 2) ? )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2678 (princ (symbol-name i)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2679 (princ " ") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2680 (if (car publp) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2681 ;; Use our public printer |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2682 (funcall (car publp) v) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2683 ;; Use our generic override prin1 function. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2684 (eieio-override-prin1 v)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2685 (princ "\n")))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2686 (setq publa (cdr publa) publd (cdr publd) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2687 publp (cdr publp))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2688 (princ (make-string (* eieio-print-depth 2) ? ))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2689 (princ ")\n"))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2690 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2691 (defun eieio-override-prin1 (thing) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2692 "Perform a prin1 on THING taking advantage of object knowledge." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2693 (cond ((eieio-object-p thing) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2694 (object-write thing)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2695 ((listp thing) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2696 (eieio-list-prin1 thing)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2697 ((class-p thing) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2698 (princ (class-name thing))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2699 ((symbolp thing) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2700 (princ (concat "'" (symbol-name thing)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2701 (t (prin1 thing)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2702 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2703 (defun eieio-list-prin1 (list) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2704 "Display LIST where list may contain objects." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2705 (if (not (eieio-object-p (car list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2706 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2707 (princ "'") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2708 (prin1 list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2709 (princ "(list ") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2710 (if (eieio-object-p (car list)) (princ "\n ")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2711 (while list |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2712 (if (eieio-object-p (car list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2713 (object-write (car list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2714 (princ "'") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2715 (prin1 (car list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2716 (princ " ") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2717 (setq list (cdr list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2718 (princ (make-string (* eieio-print-depth 2) ? )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2719 (princ ")"))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2720 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2721 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2722 ;;; Unimplemented functions from CLOS |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2723 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2724 (defun change-class (obj class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2725 "Change the class of OBJ to type CLASS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2726 This may create or delete slots, but does not affect the return value |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2727 of `eq'." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2728 (error "Eieio: `change-class' is unimplemented")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2729 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2730 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2731 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2732 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2733 ;;; Interfacing with edebug |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2734 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2735 (defun eieio-edebug-prin1-to-string (object &optional noescape) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2736 "Display eieio OBJECT in fancy format. Overrides the edebug default. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2737 Optional argument NOESCAPE is passed to `prin1-to-string' when appropriate." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2738 (cond ((class-p object) (class-name object)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2739 ((eieio-object-p object) (object-print object)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2740 ((and (listp object) (or (class-p (car object)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2741 (eieio-object-p (car object)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2742 (concat "(" (mapconcat 'eieio-edebug-prin1-to-string object " ") ")")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2743 (t (prin1-to-string object noescape)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2744 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2745 (add-hook 'edebug-setup-hook |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2746 (lambda () |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2747 (def-edebug-spec defmethod |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2748 (&define ; this means we are defining something |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2749 [&or name ("setf" :name setf name)] |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2750 ;; ^^ This is the methods symbol |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2751 [ &optional symbolp ] ; this is key :before etc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2752 list ; arguments |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2753 [ &optional stringp ] ; documentation string |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2754 def-body ; part to be debugged |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2755 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2756 ;; The rest of the macros |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2757 (def-edebug-spec oref (form quote)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2758 (def-edebug-spec oref-default (form quote)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2759 (def-edebug-spec oset (form quote form)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2760 (def-edebug-spec oset-default (form quote form)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2761 (def-edebug-spec class-v form) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2762 (def-edebug-spec class-p form) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2763 (def-edebug-spec eieio-object-p form) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2764 (def-edebug-spec class-constructor form) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2765 (def-edebug-spec generic-p form) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2766 (def-edebug-spec with-slots (list list def-body)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2767 ;; I suspect this isn't the best way to do this, but when |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2768 ;; cust-print was used on my system all my objects |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2769 ;; appeared as "#1 =" which was not useful. This allows |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2770 ;; edebug to print my objects in the nice way they were |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2771 ;; meant to with `object-print' and `class-name' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2772 ;; (defalias 'edebug-prin1-to-string 'eieio-edebug-prin1-to-string) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2773 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2774 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2775 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2776 (eval-after-load "cedet-edebug" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2777 '(progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2778 (cedet-edebug-add-print-override '(class-p object) '(class-name object) ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2779 (cedet-edebug-add-print-override '(eieio-object-p object) '(object-print object) ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2780 (cedet-edebug-add-print-override '(and (listp object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2781 (or (class-p (car object)) (eieio-object-p (car object)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2782 '(cedet-edebug-prin1-recurse object) ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2783 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2784 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2785 ;;; Interfacing with imenu in emacs lisp mode |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2786 ;; (Only if the expression is defined) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2787 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2788 (if (eval-when-compile (boundp 'list-imenu-generic-expression)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2789 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2790 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2791 (defun eieio-update-lisp-imenu-expression () |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2792 "Examine `lisp-imenu-generic-expression' and modify it to find `defmethod'." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2793 (let ((exp lisp-imenu-generic-expression)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2794 (while exp |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2795 ;; it's of the form '( ( title expr indx ) ... ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2796 (let* ((subcar (cdr (car exp))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2797 (substr (car subcar))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2798 (if (and (not (string-match "|method\\\\" substr)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2799 (string-match "|advice\\\\" substr)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2800 (setcar subcar |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2801 (replace-match "|advice\\|method\\" t t substr 0)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2802 (setq exp (cdr exp))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2803 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2804 (eieio-update-lisp-imenu-expression) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2805 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2806 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2807 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2808 ;;; Autoloading some external symbols, and hooking into the help system |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2809 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2810 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2811 (autoload 'eieio-help-mode-augmentation-maybee "eieio-opt" "For buffers thrown into help mode, augment for eieio.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2812 (autoload 'eieio-browse "eieio-opt" "Create an object browser window" t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2813 (autoload 'eieio-describe-class "eieio-opt" "Describe CLASS defined by a string or symbol" t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2814 (autoload 'eieio-describe-constructor "eieio-opt" "Describe the constructor function FCN." t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2815 (autoload 'describe-class "eieio-opt" "Describe CLASS defined by a string or symbol" t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2816 (autoload 'eieio-describe-generic "eieio-opt" "Describe GENERIC defined by a string or symbol" t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2817 (autoload 'describe-generic "eieio-opt" "Describe GENERIC defined by a string or symbol" t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2818 (autoload 'eieiodoc-class "eieio-doc" "Create texinfo documentation about a class hierarchy." t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2819 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2820 (autoload 'customize-object "eieio-custom" "Create a custom buffer editing OBJ.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2821 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2822 ;; make sure this shows up after the help mode hook. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2823 (add-hook 'temp-buffer-show-hook 'eieio-help-mode-augmentation-maybee t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2824 ;; (require 'advice) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2825 ;; (defadvice describe-variable (around eieio-describe activate) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2826 ;; "Display the full documentation of FUNCTION (a symbol). |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2827 ;; Returns the documentation as a string, also." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2828 ;; (if (class-p (ad-get-arg 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2829 ;; (eieio-describe-class (ad-get-arg 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2830 ;; ad-do-it)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2831 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2832 ;; (defadvice describe-function (around eieio-describe activate) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2833 ;; "Display the full documentation of VARIABLE (a symbol). |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2834 ;; Returns the documentation as a string, also." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2835 ;; (if (generic-p (ad-get-arg 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2836 ;; (eieio-describe-generic (ad-get-arg 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2837 ;; (if (class-p (ad-get-arg 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2838 ;; (eieio-describe-constructor (ad-get-arg 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2839 ;; ad-do-it))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2840 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2841 (provide 'eieio) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2842 ;;; eieio ends here |