Mercurial > emacs
annotate lisp/eieio/eieio.el @ 104401:2efe3dc24373
Add files for the EIEIO library.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sat, 22 Aug 2009 04:12:52 +0000 |
parents | |
children | 5df6945a3eaa |
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 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
48 (when (featurep 'eieio) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
49 (error "Do not load EIEIO twice.")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
50 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
51 (eval-when-compile |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
52 (when (featurep 'eieio) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
53 (error "Do not byte-compile EIEIO if EIEIO is already loaded."))) |
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 (require 'cl) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
56 ;;(load "cl-macs" nil t) ; No provide in this file. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
57 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
58 ;;; Code: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
59 (defun eieio-version () |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
60 "Display the current version of EIEIO." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
61 (interactive) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
62 (message eieio-version)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
63 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
64 (eval-and-compile |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
65 ;; 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
|
66 ;; 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
|
67 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
68 ;; Compatibility |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
69 (if (fboundp 'compiled-function-arglist) |
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 ;; 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
|
72 (defalias 'eieio-compiled-function-arglist 'compiled-function-arglist) |
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 ;; 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
|
75 ;; grab the appropriate element. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
76 (defun eieio-compiled-function-arglist (func) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
77 "Return the argument list for the compiled function FUNC." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
78 (aref func 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
79 |
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 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
82 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
83 ;;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
84 ;; Variable declarations. |
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 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
87 (defvar eieio-hook nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
88 "*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
|
89 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
90 (defvar eieio-error-unsupported-class-tags nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
91 "*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
|
92 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
|
93 since EIEIO does not support all CLOS tags.") |
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 (defvar eieio-skip-typecheck nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
96 "*If non-nil, skip all slot typechecking. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
97 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
|
98 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
|
99 default setting for optimization purposes.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
100 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
101 (defvar eieio-optimize-primary-methods-flag t |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
102 "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
|
103 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
104 ;; State Variables |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
105 (defvar this nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
106 "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
|
107 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
|
108 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
109 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
|
110 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
|
111 `call-next-method'") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
112 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
113 (defvar scoped-class nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
114 "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
|
115 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
|
116 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
|
117 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
118 (defvar eieio-initializing-object nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
119 "Set to non-nil while initializing an object.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
120 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
121 (defconst eieio-unbound (make-symbol "unbound") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
122 "Uninterned symbol representing an unbound slot in an object.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
123 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
124 ;; 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
|
125 ;; while it is being built itself. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
126 (defvar eieio-default-superclass nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
127 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
128 (defconst class-symbol 1 "Class's symbol (self-referencing.).") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
129 (defconst class-parent 2 "Class parent slot.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
130 (defconst class-children 3 "Class children class slot.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
131 (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
|
132 ;; @todo |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
133 ;; 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
|
134 ;; Get rid of it! |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
135 (defconst class-public-a 5 "Class attribute index.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
136 (defconst class-public-d 6 "Class attribute defaults index.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
137 (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
|
138 (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
|
139 (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
|
140 (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
|
141 (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
|
142 (defconst class-public-printer 12 "Printer for a slot.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
143 (defconst class-protection 13 "Class protection for a slot.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
144 (defconst class-initarg-tuples 14 "Class initarg tuples list.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
145 (defconst class-class-allocation-a 15 "Class allocated attributes.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
146 (defconst class-class-allocation-doc 16 "Class allocated documentation.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
147 (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
|
148 (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
|
149 (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
|
150 (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
|
151 (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
|
152 (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
|
153 (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
|
154 (defconst class-default-object-cache 24 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
155 "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
|
156 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
|
157 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
|
158 from the default.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
159 (defconst class-options 25 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
160 "Storage location of tagged class options. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
161 Stored outright without modifications or stripping.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
162 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
163 (defconst class-num-slots 26 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
164 "Number of slots in the class definition object.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
165 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
166 (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
|
167 (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
|
168 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
169 (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
|
170 (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
|
171 (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
|
172 (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
|
173 (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
|
174 (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
|
175 (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
|
176 (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
|
177 (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
|
178 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
179 ;; How to specialty compile stuff. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
180 (autoload 'byte-compile-file-form-defmethod "eieio-comp" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
181 "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
|
182 (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
|
183 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
184 (eval-when-compile (require 'eieio-comp)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
185 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
186 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
187 ;;; Important macros used in eieio. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
188 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
189 (defmacro class-v (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
190 "Internal: Return the class vector from the CLASS symbol." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
191 ;; 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
|
192 `(get ,class 'eieio-class-definition)) |
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 (defmacro class-p (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
195 "Return t if CLASS is a valid class vector. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
196 CLASS is a symbol." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
197 ;; 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
|
198 ;; things. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
199 `(condition-case nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
200 (eq (aref (class-v ,class) 0) 'defclass) |
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 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
203 ;;;###autoload |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
204 (defmacro eieio-object-p (obj) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
205 "Return non-nil if OBJ is an EIEIO object." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
206 `(condition-case nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
207 (let ((tobj ,obj)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
208 (and (eq (aref tobj 0) 'object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
209 (class-p (aref tobj object-class)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
210 (error nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
211 (defalias 'object-p 'eieio-object-p) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
212 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
213 (defmacro class-constructor (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
214 "Return the symbol representing the constructor of CLASS." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
215 `(aref (class-v ,class) class-symbol)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
216 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
217 (defmacro generic-p (method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
218 "Return t if symbol METHOD is a generic function. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
219 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
|
220 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
|
221 `(and (fboundp ,method) (get ,method 'eieio-method-obarray))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
222 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
223 (defun generic-primary-only-p (method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
224 "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
|
225 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
|
226 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
|
227 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
|
228 (and (generic-p method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
229 (let ((M (get method 'eieio-method-tree))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
230 (and (< 0 (length (aref M method-primary))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
231 (not (aref M method-static)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
232 (not (aref M method-before)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
233 (not (aref M method-after)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
234 (not (aref M method-generic-before)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
235 (not (aref M method-generic-primary)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
236 (not (aref M method-generic-after)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
237 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
238 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
239 (defun generic-primary-only-one-p (method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
240 "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
|
241 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
|
242 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
|
243 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
|
244 (and (generic-p method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
245 (let ((M (get method 'eieio-method-tree))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
246 (and (= 1 (length (aref M method-primary))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
247 (not (aref M method-static)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
248 (not (aref M method-before)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
249 (not (aref M method-after)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
250 (not (aref M method-generic-before)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
251 (not (aref M method-generic-primary)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
252 (not (aref M method-generic-after)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
253 )) |
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-option-assoc (list option) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
256 "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
|
257 `(car-safe (cdr (memq ,option ,list)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
258 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
259 (defmacro class-option (class option) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
260 "Return the value stored for CLASS' OPTION. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
261 Return nil if that option doesn't exist." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
262 `(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
|
263 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
264 (defmacro class-abstract-p (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
265 "Return non-nil if CLASS is abstract. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
266 Abstract classes cannot be instantiated." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
267 `(class-option ,class :abstract)) |
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 class-method-invocation-order (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
270 "Return the invocation order of CLASS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
271 Abstract classes cannot be instantiated." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
272 `(or (class-option ,class :method-invocation-order) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
273 :breadth-first)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
274 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
275 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
276 ;;; Defining a new class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
277 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
278 (defmacro defclass (name superclass slots &rest options-and-doc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
279 "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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 yet supported. Supported tags are: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
285 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
286 :initform - initializing form |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
287 :initarg - tag used during initialization |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
288 :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
|
289 :allocation - specify where the value is stored. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
290 defaults to `:instance', but could also be `:class' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
291 :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
|
292 :reader - a function symbol which will `read' an object |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
293 :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
|
294 :documentation |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
295 - A string documenting use of this slot. |
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 The following are extensions on CLOS: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
298 :protection - Specify protection for this slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
299 Defaults to `:public'. Also use `:protected', or `:private' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
300 :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
|
301 :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
|
302 :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
|
303 :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
|
304 See `eieio-override-prin1' as an example. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
305 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
306 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
|
307 of documentation, (including a :documentation tag) in addition to |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
308 documentation, or not at all. Supported options are: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
309 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
310 :documentation - The doc-string used for this class. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
311 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
312 Options added to EIEIO: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
313 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
314 :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
|
315 :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
|
316 reasonable groups for customizations. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
317 :abstract - Non-nil to prevent instances of this class. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
318 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
|
319 try to make an instance. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
320 :method-invocation-order |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
321 - Control the method invokation order if there is |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
322 multiple inheritance. Valid values are: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
323 :breadth-first - The default. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
324 :depth-first |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
325 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
326 Options in CLOS not supported in EIEIO: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
327 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
328 :metaclass - Class to use in place of `standard-class' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
329 :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
|
330 this class. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
331 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
332 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
|
333 wish, and reference them using the function `class-option'." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
334 ;; 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
|
335 ;; 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
|
336 ;; 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
|
337 `(eval-and-compile |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
338 (eieio-defclass ',name ',superclass ',slots ',options-and-doc))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
339 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
340 (defvar eieio-defclass-autoload-map (make-vector 7 nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
341 "Symbol map of superclasses we find in autoloads.") |
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 (defun eieio-defclass-autoload (cname superclasses filename doc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
344 "Create autoload symbols for the EIEIO class CNAME. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
345 SUPERCLASSES are the superclasses that CNAME inherites from. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
346 DOC is the docstring for CNAME. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
347 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
|
348 SUPERCLASSES as children. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
349 It creates an autoload function for CNAME's constructor." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
350 ;; Assume we've already debugged inputs. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
351 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
352 (let* ((oldc (when (class-p cname) (class-v cname))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
353 (newc (make-vector class-num-slots nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
354 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
355 (if oldc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
356 nil ;; Do nothing if we already have this class. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
357 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
358 ;; 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
|
359 (aset newc 0 'defclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
360 (aset newc class-symbol cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
361 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
362 (let ((clear-parent nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
363 ;; No parents? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
364 (when (not superclasses) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
365 (setq superclasses '(eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
366 clear-parent t) |
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 ;; 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
|
370 ;; autoload it later. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
371 (dolist (SC superclasses) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
372 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
373 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
374 ;; 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
|
375 ;; map needs to be cleared! |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
376 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
377 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
378 ;; Does our parent exist? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
379 (if (not (class-p SC)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
380 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
381 ;; 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
|
382 ;; parent on that symbol. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
383 (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
|
384 (if (not (boundp sym)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
385 (set sym (list cname)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
386 (add-to-list sym cname)) |
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 ;; We have a parent, save the child in there. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
390 (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
|
391 (aset (class-v SC) class-children |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
392 (cons cname (aref (class-v SC) class-children))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
393 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
394 ;; save parent in child |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
395 (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
|
396 ) |
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 ;; turn this into a useable self-pointing symbol |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
399 (set cname cname) |
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 ;; 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
|
402 ;; 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
|
403 ;; 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
|
404 ;; need to be stored a second time. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
405 (put cname 'eieio-class-definition newc) |
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 ;; Clear the parent |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
408 (if clear-parent (aset newc class-parent nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
409 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
410 ;; Create an autoload on top of our constructor function. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
411 (autoload cname filename doc nil nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
412 (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
|
413 (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
|
414 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
415 )))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
416 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
417 (defsubst eieio-class-un-autoload (cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
418 "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
|
419 (when (eq (car-safe (symbol-function cname)) 'autoload) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
420 (load-library (car (cdr (symbol-function cname)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
421 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
422 (defun eieio-defclass (cname superclasses slots options-and-doc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
423 "See `defclass' for more information. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
424 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
|
425 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
|
426 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
|
427 ;; 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
|
428 ;; 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
|
429 ;; 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
|
430 (run-hooks 'eieio-hook) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
431 (setq eieio-hook nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
432 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
433 (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
|
434 (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
|
435 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
436 (let* ((pname (if superclasses superclasses nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
437 (newc (make-vector class-num-slots nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
438 (oldc (when (class-p cname) (class-v cname))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
439 (groups nil) ;; list of groups id'd from slots |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
440 (options nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
441 (clearparent nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
442 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
443 (aset newc 0 'defclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
444 (aset newc class-symbol cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
445 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
446 ;; 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
|
447 ;; 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
|
448 ;; 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
|
449 ;; method table breakage, particularly when the users is only |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
450 ;; byte compiling an EIEIO file. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
451 (if oldc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
452 (aset newc class-children (aref oldc class-children)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
453 ;; 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
|
454 ;; 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
|
455 (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
|
456 (when sym |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
457 (condition-case nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
458 (aset newc class-children (symbol-value sym)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
459 (error nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
460 (unintern (symbol-name cname) eieio-defclass-autoload-map) |
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 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
464 (cond ((and (stringp (car options-and-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
465 (/= 1 (% (length options-and-doc) 2))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
466 (error "Too many arguments to `defclass'")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
467 ((and (symbolp (car options-and-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
468 (/= 0 (% (length options-and-doc) 2))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
469 (error "Too many arguments to `defclass'")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
470 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
471 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
472 (setq options |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
473 (if (stringp (car options-and-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
474 (cons :documentation options-and-doc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
475 options-and-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
476 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
477 (if pname |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
478 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
479 (while pname |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
480 (if (and (car pname) (symbolp (car pname))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
481 (if (not (class-p (car pname))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
482 ;; bad class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
483 (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
|
484 ;; good parent class... |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
485 ;; save new child in parent |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
486 (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
|
487 (aset (class-v (car pname)) class-children |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
488 (cons cname (aref (class-v (car pname)) class-children)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
489 ;; 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
|
490 (mapc (lambda (g) (add-to-list 'groups g)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
491 (class-option (car pname) :custom-groups)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
492 ;; save parent in child |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
493 (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
|
494 (error "Invalid parent class %s" pname)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
495 (setq pname (cdr pname))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
496 ;; 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
|
497 ;; the same order as specified in the code. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
498 (aset newc class-parent (nreverse (aref newc class-parent))) ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
499 ;; 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
|
500 ;; default superclass. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
501 (unless (eq cname 'eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
502 ;; adopt the default parent here, but clear it later... |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
503 (setq clearparent t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
504 ;; save new child in parent |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
505 (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
|
506 (aset (class-v 'eieio-default-superclass) class-children |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
507 (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
|
508 ;; save parent in child |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
509 (aset newc class-parent (list eieio-default-superclass)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
510 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
511 ;; turn this into a useable self-pointing symbol |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
512 (set cname cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
513 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
514 ;; 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
|
515 ;; 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
|
516 ;; pointers to itself. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
517 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
518 ;; Create the test function |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
519 (let ((csym (intern (concat (symbol-name cname) "-p")))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
520 (fset csym |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
521 (list 'lambda (list 'obj) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
522 (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
|
523 (list 'and '(eieio-object-p obj) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
524 (list 'same-class-p 'obj cname))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
525 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
526 ;; 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
|
527 (let ((io (class-option-assoc options :method-invocation-order))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
528 (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
|
529 (error "Method invocation order %s is not allowed" io) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
530 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
531 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
532 ;; Create a handy child test too |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
533 (let ((csym (intern (concat (symbol-name cname) "-child-p")))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
534 (fset csym |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
535 `(lambda (obj) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
536 ,(format |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
537 "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
|
538 cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
539 (and (eieio-object-p obj) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
540 (object-of-class-p obj ,cname)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
541 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
542 ;; 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
|
543 ;; 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
|
544 ;; important for EIEIO to be backwards compatible, where |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
545 ;; myobject-p, and myobject-child-p are different. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
546 ;; "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
|
547 ;; 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
|
548 ;; while keeping our above predicate clean. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
549 (eval `(deftype ,cname () |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
550 '(satisfies |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
551 ,(intern (concat (symbol-name cname) "-child-p"))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
552 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
553 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
554 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
555 ;; 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
|
556 ;; in from the parent class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
557 (eieio-copy-parents-into-subclass newc superclasses) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
558 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
559 ;; 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
|
560 ;; 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
|
561 ;; 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
|
562 ;; need to be stored a second time. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
563 (put cname 'eieio-class-definition newc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
564 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
565 ;; 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
|
566 ;; class structure I have defined. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
567 (while slots |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
568 (let* ((slot1 (car slots)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
569 (name (car slot1)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
570 (slot (cdr slot1)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
571 (acces (plist-get slot ':accessor)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
572 (init (or (plist-get slot ':initform) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
573 (if (member ':initform slot) nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
574 eieio-unbound))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
575 (initarg (plist-get slot ':initarg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
576 (docstr (plist-get slot ':documentation)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
577 (prot (plist-get slot ':protection)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
578 (reader (plist-get slot ':reader)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
579 (writer (plist-get slot ':writer)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
580 (alloc (plist-get slot ':allocation)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
581 (type (plist-get slot ':type)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
582 (custom (plist-get slot ':custom)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
583 (label (plist-get slot ':label)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
584 (customg (plist-get slot ':group)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
585 (printer (plist-get slot ':printer)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
586 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
587 (skip-nil (class-option-assoc options :allow-nil-initform)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
588 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
589 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
590 (if eieio-error-unsupported-class-tags |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
591 (let ((tmp slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
592 (while tmp |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
593 (if (not (member (car tmp) '(:accessor |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
594 :initform |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
595 :initarg |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
596 :documentation |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
597 :protection |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
598 :reader |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
599 :writer |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
600 :allocation |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
601 :type |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
602 :custom |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
603 :label |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
604 :group |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
605 :printer |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
606 :allow-nil-initform |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
607 :custom-groups))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
608 (signal 'invalid-slot-type (list (car tmp)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
609 (setq tmp (cdr (cdr tmp)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
610 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
611 ;; Clean up the meaning of protection. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
612 (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
|
613 ((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
|
614 ((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
|
615 ((eq prot nil) nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
616 (t (signal 'invalid-slot-type (list ':protection prot)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
617 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
618 ;; Make sure the :allocation parameter has a valid value. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
619 (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
|
620 (signal 'invalid-slot-type (list ':allocation alloc))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
621 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
622 ;; 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
|
623 (if (not type) (setq type t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
624 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
625 ;; Label is nil, or a string |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
626 (if (not (or (null label) (stringp label))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
627 (signal 'invalid-slot-type (list ':label label))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
628 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
629 ;; Is there an initarg, but allocation of class? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
630 (if (and initarg (eq alloc :class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
631 (message "Class allocated slots do not need :initarg")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
632 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
633 ;; intern the symbol so we can use it blankly |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
634 (if initarg (set initarg initarg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
635 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
636 ;; The customgroup should be a list of symbols |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
637 (cond ((null customg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
638 (setq customg '(default))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
639 ((not (listp customg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
640 (setq customg (list customg)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
641 ;; 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
|
642 (mapc (lambda (cg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
643 (if (not (symbolp cg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
644 (signal 'invalid-slot-type (list ':group cg)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
645 customg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
646 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
647 ;; First up, add this slot into our new class. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
648 (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
|
649 prot initarg alloc 'defaultoverride skip-nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
650 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
651 ;; 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
|
652 (mapc (lambda (cg) (add-to-list 'groups cg)) customg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
653 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
654 ;; 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
|
655 ;; 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
|
656 ;; 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
|
657 (if acces |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
658 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
659 (eieio-defmethod acces |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
660 (list (if (eq alloc :class) :static :primary) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
661 (list (list 'this cname)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
662 (format |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
663 "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
|
664 name cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
665 (list 'if (list 'slot-boundp 'this (list 'quote name)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
666 (list 'eieio-oref 'this (list 'quote name)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
667 ;; Else - Some error? nil? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
668 nil |
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 ;; Thanks Pascal Bourguignon <pjb@informatimago.com> |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
671 ;; For this complex macro. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
672 (eval (macroexpand |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
673 (list 'defsetf acces '(widget) '(store) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
674 (list 'list ''eieio-oset 'widget |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
675 (list 'quote (list 'quote name)) 'store)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
676 ;;`(defsetf ,acces (widget) (store) (eieio-oset widget ',cname store)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
677 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
678 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
679 ;; 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
|
680 ;; 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
|
681 (if writer |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
682 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
683 (eieio-defmethod writer |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
684 (list (list (list 'this cname) 'value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
685 (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
|
686 name cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
687 `(setf (slot-value this ',name) value))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
688 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
689 ;; 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
|
690 ;; 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
|
691 (if reader |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
692 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
693 (eieio-defmethod reader |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
694 (list (list (list 'this cname)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
695 (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
|
696 name cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
697 `(slot-value this ',name))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
698 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
699 (setq slots (cdr slots))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
700 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
701 ;; 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
|
702 (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
|
703 (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
|
704 (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
|
705 (aset newc class-public-type |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
706 (apply 'vector (nreverse (aref newc class-public-type)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
707 (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
|
708 (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
|
709 (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
|
710 (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
|
711 (aset newc class-protection (nreverse (aref newc class-protection))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
712 (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
|
713 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
714 ;; 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
|
715 ;; a vector now. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
716 (aset newc class-class-allocation-type |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
717 (apply 'vector (aref newc class-class-allocation-type))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
718 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
719 ;; 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
|
720 (aset newc class-class-allocation-values |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
721 (apply 'vector (aref newc class-class-allocation-values))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
722 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
723 ;; 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
|
724 ;; 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
|
725 ;; 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
|
726 ;; 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
|
727 ;; 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
|
728 (let* ((cnt 0) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
729 (pubsyms (aref newc class-public-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
730 (prots (aref newc class-protection)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
731 (l (length pubsyms)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
732 (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
|
733 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
|
734 (while (and primes (< (car primes) l)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
735 (setq primes (cdr primes))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
736 (car primes))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
737 (oa (make-vector vl 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
738 (newsym)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
739 (while pubsyms |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
740 (setq newsym (intern (symbol-name (car pubsyms)) oa)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
741 (set newsym cnt) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
742 (setq cnt (1+ cnt)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
743 (if (car prots) (put newsym 'protection (car prots))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
744 (setq pubsyms (cdr pubsyms) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
745 prots (cdr prots))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
746 (aset newc class-symbol-obarray oa) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
747 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
748 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
749 ;; Create the constructor function |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
750 (if (class-option-assoc options :abstract) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
751 ;; Abstract classes cannot be instantiated. Say so. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
752 (let ((abs (class-option-assoc options :abstract))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
753 (if (not (stringp abs)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
754 (setq abs (format "Class %s is abstract" cname))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
755 (fset cname |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
756 `(lambda (&rest stuff) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
757 ,(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
|
758 (error ,abs)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
759 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
760 ;; Non-abstract classes need a constructor. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
761 (fset cname |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
762 `(lambda (newname &rest slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
763 ,(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
|
764 (apply 'constructor ,cname newname slots))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
765 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
766 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
767 ;; Set up a specialized doc string. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
768 ;; 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
|
769 (put cname 'variable-documentation |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
770 (class-option-assoc options :documentation)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
771 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
772 ;; 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
|
773 (let ((g (class-option-assoc options :custom-groups))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
774 (mapc (lambda (cg) (add-to-list 'g cg)) groups) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
775 (if (memq :custom-groups options) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
776 (setcar (cdr (memq :custom-groups options)) g) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
777 (setq options (cons :custom-groups (cons g options))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
778 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
779 ;; Set up the options we have collected. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
780 (aset newc class-options options) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
781 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
782 ;; 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
|
783 ;; default superclass eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
784 (if clearparent (aset newc class-parent nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
785 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
786 ;; Create the cached default object. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
787 (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
|
788 3) nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
789 (aset cache 0 'object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
790 (aset cache object-class cname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
791 (aset cache object-name 'default-cache-object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
792 (let ((eieio-skip-typecheck t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
793 ;; All type-checking has been done to our satisfaction |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
794 ;; 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
|
795 (eieio-set-defaults cache t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
796 (aset newc class-default-object-cache cache)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
797 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
798 ;; Return our new class object |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
799 ;; newc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
800 cname |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
801 )) |
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-perform-slot-validation-for-default (slot spec value skipnil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
804 "For SLOT, signal if SPEC does not match VALUE. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
805 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
|
806 (let ((val (eieio-default-eval-maybe value))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
807 (if (and (not eieio-skip-typecheck) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
808 (not (and skipnil (null val))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
809 (not (eieio-perform-slot-validation spec val))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
810 (signal 'invalid-slot-type (list slot spec val))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
811 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
812 (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
|
813 &optional defaultoverride skipnil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
814 "Add into NEWC attribute A. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
815 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
|
816 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
|
817 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
|
818 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
|
819 we must override it's value for a default. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
820 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
|
821 if default value is nil." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
822 ;; Make sure we duplicate those items that are sequences. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
823 (condition-case nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
824 (if (sequencep d) (setq d (copy-sequence d))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
825 ;; 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
|
826 (error nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
827 (if (sequencep type) (setq type (copy-sequence type))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
828 (if (sequencep cust) (setq cust (copy-sequence cust))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
829 (if (sequencep custg) (setq custg (copy-sequence custg))) |
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 ;; To prevent override information w/out specification of storage, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
832 ;; we need to do this little hack. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
833 (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
|
834 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
835 (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
|
836 ;; 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
|
837 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
838 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
839 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
840 ;; 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
|
841 (if (not (member a (aref newc class-public-a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
842 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
843 (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
|
844 (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
|
845 (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
|
846 (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
|
847 (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
|
848 (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
|
849 (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
|
850 (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
|
851 (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
|
852 (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
|
853 (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
|
854 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
855 ;; 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
|
856 ;; 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
|
857 ;; passed in by one of the parent classes. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
858 (when defaultoverride |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
859 ;; 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
|
860 (let* ((ca (aref newc class-public-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
861 (np (member a ca)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
862 (num (- (length ca) (length np))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
863 (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
|
864 nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
865 (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
|
866 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
867 (if (not np) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
868 (error "Eieio internal error overriding default value for %s" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
869 a) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
870 ;; If type is passed in, is it the same? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
871 (if (not (eq type t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
872 (if (not (equal type tp)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
873 (error |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
874 "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
|
875 type tp a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
876 ;; If we have a repeat, only update the initarg... |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
877 (unless (eq d eieio-unbound) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
878 (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
|
879 (setcar dp d)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
880 ;; If we have a new initarg, check for it. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
881 (when init |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
882 (let* ((inits (aref newc class-initarg-tuples)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
883 (inita (rassq a inits))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
884 ;; Replace the CAR of the associate INITA. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
885 ;;(message "Initarg: %S replace %s" inita init) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
886 (setcar inita init) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
887 )) |
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 ;; 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
|
890 ;; checked and SHOULD match the superclass |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
891 ;; protection. Otherwise an error is thrown. However |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
892 ;; I wonder if a more flexible schedule might be |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
893 ;; implemented. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
894 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
895 ;; EML - We used to have (if prot... here, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
896 ;; but a prot of 'nil means public. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
897 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
898 (let ((super-prot (nth num (aref newc class-protection))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
899 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
900 (if (not (eq prot super-prot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
901 (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
|
902 prot super-prot a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
903 ;; End original PLN |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
904 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
905 ;; PLN Tue Jun 26 11:57:06 2007 : |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
906 ;; We do a non redundant combination of ancient |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
907 ;; custom groups and new ones using the common lisp |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
908 ;; `union' method. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
909 (when custg |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
910 (let ((where-groups |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
911 (nthcdr num (aref newc class-public-custom-group)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
912 (setcar where-groups |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
913 (union (car where-groups) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
914 (if (listp custg) custg (list custg)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
915 ;; End PLN |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
916 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
917 ;; 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
|
918 ;; set, simply replaces the old one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
919 (when cust |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
920 ;; (message "Custom type redefined to %s" cust) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
921 (setcar (nthcdr num (aref newc class-public-custom)) cust)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
922 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
923 ;; If a new label is specified, it simply replaces |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
924 ;; the old one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
925 (when label |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
926 ;; (message "Custom label redefined to %s" label) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
927 (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
|
928 ;; End PLN |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
929 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
930 ;; 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
|
931 ;; doc is specified, simply replaces the old one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
932 (when doc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
933 ;;(message "Documentation redefined to %s" doc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
934 (setcar (nthcdr num (aref newc class-public-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
935 doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
936 ;; End PLN |
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 ;; If a new printer is specified, it simply replaces |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
939 ;; the old one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
940 (when print |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
941 ;; (message "printer redefined to %s" print) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
942 (setcar (nthcdr num (aref newc class-public-printer)) print)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
943 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
944 ))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
945 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
946 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
947 ;; CLASS ALLOCATED SLOTS |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
948 (let ((value (eieio-default-eval-maybe d))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
949 (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
|
950 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
951 (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
|
952 ;; 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
|
953 ;; requires a very different aproach. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
954 (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
|
955 (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
|
956 (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
|
957 (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
|
958 (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
|
959 (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
|
960 (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
|
961 ;; 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
|
962 ;; can't initialize from this element. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
963 (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
|
964 (when defaultoverride |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
965 ;; 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
|
966 (let* ((ca (aref newc class-class-allocation-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
967 (np (member a ca)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
968 (num (- (length ca) (length np))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
969 (dp (if np |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
970 (nthcdr num |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
971 (aref newc class-class-allocation-values)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
972 nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
973 (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
|
974 nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
975 (if (not np) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
976 (error "Eieio internal error overriding default value for %s" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
977 a) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
978 ;; If type is passed in, is it the same? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
979 (if (not (eq type t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
980 (if (not (equal type tp)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
981 (error |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
982 "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
|
983 type tp a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
984 ;; 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
|
985 ;; is to change the default, so allow unbound in. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
986 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
987 ;; If we have a repeat, only update the vlaue... |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
988 (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
|
989 (setcar dp value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
990 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
991 ;; 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
|
992 ;; checked and SHOULD match the superclass |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
993 ;; protection. Otherwise an error is thrown. However |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
994 ;; I wonder if a more flexible schedule might be |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
995 ;; implemented. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
996 (let ((super-prot |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
997 (car (nthcdr num (aref newc class-class-allocation-protection))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
998 (if (not (eq prot super-prot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
999 (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
|
1000 prot super-prot a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1001 ;; We do a non redundant combination of ancient |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1002 ;; custom groups and new ones using the common lisp |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1003 ;; `union' method. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1004 (when custg |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1005 (let ((where-groups |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1006 (nthcdr num (aref newc class-class-allocation-custom-group)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1007 (setcar where-groups |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1008 (union (car where-groups) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1009 (if (listp custg) custg (list custg)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1010 ;; End PLN |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1011 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1012 ;; 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
|
1013 ;; doc is specified, simply replaces the old one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1014 (when doc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1015 ;;(message "Documentation redefined to %s" doc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1016 (setcar (nthcdr num (aref newc class-class-allocation-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1017 doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1018 ;; End PLN |
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 ;; If a new printer is specified, it simply replaces |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1021 ;; the old one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1022 (when print |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1023 ;; (message "printer redefined to %s" print) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1024 (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
|
1025 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1026 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1027 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1028 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1029 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1030 (defun eieio-copy-parents-into-subclass (newc parents) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1031 "Copy into NEWC the slots of PARENTS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1032 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
|
1033 the new child class." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1034 (let ((ps (aref newc class-parent)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1035 (sn (class-option-assoc (aref newc class-options) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1036 ':allow-nil-initform))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1037 (while ps |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1038 ;; First, duplicate all the slots of the parent. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1039 (let ((pcv (class-v (car ps)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1040 (let ((pa (aref pcv class-public-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1041 (pd (aref pcv class-public-d)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1042 (pdoc (aref pcv class-public-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1043 (ptype (aref pcv class-public-type)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1044 (pcust (aref pcv class-public-custom)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1045 (plabel (aref pcv class-public-custom-label)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1046 (pcustg (aref pcv class-public-custom-group)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1047 (printer (aref pcv class-public-printer)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1048 (pprot (aref pcv class-protection)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1049 (pinit (aref pcv class-initarg-tuples)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1050 (i 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1051 (while pa |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1052 (eieio-add-new-slot newc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1053 (car pa) (car pd) (car pdoc) (aref ptype i) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1054 (car pcust) (car plabel) (car pcustg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1055 (car printer) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1056 (car pprot) (car-safe (car pinit)) nil nil sn) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1057 ;; Increment each value. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1058 (setq pa (cdr pa) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1059 pd (cdr pd) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1060 pdoc (cdr pdoc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1061 i (1+ i) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1062 pcust (cdr pcust) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1063 plabel (cdr plabel) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1064 pcustg (cdr pcustg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1065 printer (cdr printer) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1066 pprot (cdr pprot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1067 pinit (cdr pinit)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1068 )) ;; while/let |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1069 ;; Now duplicate all the class alloc slots. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1070 (let ((pa (aref pcv class-class-allocation-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1071 (pdoc (aref pcv class-class-allocation-doc)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1072 (ptype (aref pcv class-class-allocation-type)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1073 (pcust (aref pcv class-class-allocation-custom)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1074 (plabel (aref pcv class-class-allocation-custom-label)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1075 (pcustg (aref pcv class-class-allocation-custom-group)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1076 (printer (aref pcv class-class-allocation-printer)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1077 (pprot (aref pcv class-class-allocation-protection)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1078 (pval (aref pcv class-class-allocation-values)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1079 (i 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1080 (while pa |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1081 (eieio-add-new-slot newc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1082 (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
|
1083 (car pcust) (car plabel) (car pcustg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1084 (car printer) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1085 (car pprot) nil ':class sn) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1086 ;; Increment each value. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1087 (setq pa (cdr pa) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1088 pdoc (cdr pdoc) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1089 pcust (cdr pcust) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1090 plabel (cdr plabel) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1091 pcustg (cdr pcustg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1092 printer (cdr printer) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1093 pprot (cdr pprot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1094 i (1+ i)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1095 ))) ;; while/let |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1096 ;; Loop over each parent class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1097 (setq ps (cdr ps))) |
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 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1100 ;;; CLOS style implementation of object creators. |
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 (defun make-instance (class &rest initargs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1103 "Make a new instance of CLASS based on INITARGS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1104 CLASS is a class symbol. For example: |
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 (make-instance 'foo) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1107 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1108 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
|
1109 for each slot. For example: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1110 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1111 (make-instance 'foo :slot1 value1 :slotN valueN) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1112 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1113 Compatability note: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1114 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1115 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
|
1116 name of the class. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1117 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1118 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
|
1119 `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
|
1120 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
|
1121 a string." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1122 (if (and (car initargs) (stringp (car initargs))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1123 (apply (class-constructor class) initargs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1124 (apply (class-constructor class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1125 (cond ((symbolp class) (symbol-name class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1126 (t (format "%S" class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1127 initargs))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1128 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1129 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1130 ;;; CLOS methods and generics |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1131 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1132 (defmacro defgeneric (method args &optional doc-string) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1133 "Create a generic function METHOD. ARGS is ignored. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1134 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
|
1135 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
|
1136 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
|
1137 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
|
1138 currently ignored. You can use `defgeneric' to apply specialized |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1139 top level documentation to a method." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1140 `(eieio-defgeneric (quote ,method) ,doc-string)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1141 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1142 (defun eieio-defgeneric-form (method doc-string) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1143 "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
|
1144 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
|
1145 DOC-STRING is the documentation attached to METHOD." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1146 `(lambda (&rest local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1147 ,doc-string |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1148 (eieio-generic-call (quote ,method) local-args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1149 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1150 (defsubst eieio-defgeneric-reset-generic-form (method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1151 "Setup METHOD to call the generic form." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1152 (let ((doc-string (documentation method))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1153 (fset method (eieio-defgeneric-form method doc-string)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1154 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1155 (defun eieio-defgeneric-form-primary-only (method doc-string) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1156 "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
|
1157 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
|
1158 DOC-STRING is the documentation attached to METHOD." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1159 `(lambda (&rest local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1160 ,doc-string |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1161 (eieio-generic-call-primary-only (quote ,method) local-args))) |
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 (defsubst eieio-defgeneric-reset-generic-form-primary-only (method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1164 "Setup METHOD to call the generic form." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1165 (let ((doc-string (documentation method))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1166 (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
|
1167 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1168 (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
|
1169 class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1170 impl |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1171 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1172 "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
|
1173 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
|
1174 DOC-STRING is the documentation attached to METHOD. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1175 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
|
1176 IMPL is the symbol holding the method implementation." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1177 ;; 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
|
1178 ;; 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
|
1179 ;; then measure calls going through here. I wonder why. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1180 (require 'bytecomp) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1181 (let ((byte-compile-free-references nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1182 (byte-compile-warnings nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1183 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1184 (byte-compile-lambda |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1185 `(lambda (&rest local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1186 ,doc-string |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1187 ;; 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
|
1188 ;; 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
|
1189 ;; 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
|
1190 ;; 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
|
1191 ;; 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
|
1192 (if (not (eieio-object-p (car local-args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1193 ;; Not an object. Just signal. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1194 (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
|
1195 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1196 ;; 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
|
1197 (if ,(if (eq class eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1198 nil ; default superclass means just an obj. Already asked. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1199 `(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
|
1200 ,(list 'quote class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1201 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1202 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1203 ;; 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
|
1204 (apply 'no-applicable-method (car local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1205 ,(list 'quote method) local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1206 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1207 ;; It is ok, do the call. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1208 ;; Fill in inter-call variables then evaluate the method. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1209 (let ((scoped-class ,(list 'quote class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1210 (eieio-generic-call-next-method-list nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1211 (eieio-generic-call-key method-primary) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1212 (eieio-generic-call-methodname ,(list 'quote method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1213 (eieio-generic-call-arglst local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1214 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1215 (apply ,(list 'quote impl) local-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1216 ;(,impl local-args) |
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 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1219 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1220 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1221 (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
|
1222 "Setup METHOD to call the generic form." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1223 (let* ((doc-string (documentation method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1224 (M (get method 'eieio-method-tree)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1225 (entry (car (aref M method-primary))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1226 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1227 (fset method (eieio-defgeneric-form-primary-only-one |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1228 method doc-string |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1229 (car entry) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1230 (cdr entry) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1231 )))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1232 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1233 (defun eieio-defgeneric (method doc-string) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1234 "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
|
1235 (if (and (fboundp method) (not (generic-p method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1236 (or (byte-code-function-p (symbol-function method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1237 (not (eq 'autoload (car (symbol-function method))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1238 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1239 (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
|
1240 method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1241 ;; Don't do this over and over. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1242 (unless (fboundp 'method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1243 ;; 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
|
1244 ;; method is defined. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1245 `(defun ,method nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1246 ;; Make sure the method tables are installed. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1247 (eieiomt-install method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1248 ;; Apply the actual body of this function. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1249 (fset method (eieio-defgeneric-form method doc-string)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1250 ;; Return the method |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1251 'method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1252 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1253 (defun eieio-unbind-method-implementations (method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1254 "Make the generic method METHOD have no implementations.. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1255 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
|
1256 reference to all implementations of METHOD." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1257 (put method 'eieio-method-tree nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1258 (put method 'eieio-method-obarray nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1259 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1260 (defmacro defmethod (method &rest args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1261 "Create a new METHOD through `defgeneric' with ARGS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1262 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1263 The second optional argument KEY is a specifier that |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1264 modifies how the method is called, including: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1265 :before - Method will be called before the :primary |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1266 :primary - The default if not specified. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1267 :after - Method will be called after the :primary |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1268 :static - First arg could be an object or class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1269 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
|
1270 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
|
1271 specifier, such as: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1272 ((VARNAME CLASS) ARG2 ...) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1273 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
|
1274 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
|
1275 A DOCSTRING comes after the ARGLIST, and is optional. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1276 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
|
1277 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
|
1278 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1279 Summary: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1280 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1281 (defmethod mymethod [:before | :primary | :after | :static] |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1282 ((typearg class-name) arg2 &optional opt &rest rest) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1283 \"doc-string\" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1284 body)" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1285 `(eieio-defmethod (quote ,method) (quote ,args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1286 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1287 (defun eieio-defmethod (method args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1288 "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
|
1289 (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
|
1290 ;; find optional keys |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1291 (setq key |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1292 (cond ((or (eq ':BEFORE (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1293 (eq ':before (car args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1294 (setq args (cdr args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1295 method-before) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1296 ((or (eq ':AFTER (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1297 (eq ':after (car args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1298 (setq args (cdr args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1299 method-after) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1300 ((or (eq ':PRIMARY (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1301 (eq ':primary (car args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1302 (setq args (cdr args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1303 method-primary) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1304 ((or (eq ':STATIC (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1305 (eq ':static (car args))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1306 (setq args (cdr args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1307 method-static) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1308 ;; Primary key |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1309 (t method-primary))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1310 ;; 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
|
1311 (setq body (cdr args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1312 args (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1313 (setq loopa args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1314 ;; Create a fixed version of the arguments |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1315 (while loopa |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1316 (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
|
1317 argfix)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1318 (setq loopa (cdr loopa))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1319 ;; make sure there is a generic |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1320 (eieio-defgeneric |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1321 method |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1322 (if (stringp (car body)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1323 (car body) (format "Generically created method `%s'" method))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1324 ;; 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
|
1325 ;; 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
|
1326 ;; 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
|
1327 ;; 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
|
1328 ;; function. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1329 (setq firstarg (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1330 (if (listp firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1331 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1332 (setq argclass (nth 1 firstarg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1333 (if (not (class-p argclass)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1334 (error "Unknown class type %s in method parameters" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1335 (nth 1 firstarg)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1336 (if (= key -1) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1337 (signal 'wrong-type-argument (list :static 'non-class-arg))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1338 ;; generics are higher |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1339 (setq key (+ key 3))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1340 ;; 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
|
1341 (if (byte-code-function-p (car-safe body)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1342 (eieiomt-add method (car-safe body) key argclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1343 (eieiomt-add method (append (list 'lambda (reverse argfix)) body) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1344 key argclass)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1345 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1346 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1347 (when eieio-optimize-primary-methods-flag |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1348 ;; Optimizing step: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1349 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1350 ;; 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
|
1351 ;; we can setup the generic that way. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1352 (if (generic-primary-only-p method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1353 ;; 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
|
1354 ;; optimization step. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1355 (if (generic-primary-only-one-p method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1356 (eieio-defgeneric-reset-generic-form-primary-only-one method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1357 (eieio-defgeneric-reset-generic-form-primary-only method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1358 (eieio-defgeneric-reset-generic-form method))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1359 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1360 method) |
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 ;;; Slot type validation |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1363 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1364 (defun eieio-perform-slot-validation (spec value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1365 "Return non-nil if SPEC does not match VALUE." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1366 ;; typep is in cl-macs |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1367 (or (eq spec t) ; t always passes |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1368 (eq value eieio-unbound) ; unbound always passes |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1369 (typep value spec))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1370 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1371 (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
|
1372 "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
|
1373 Checks the :type specifier. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1374 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
|
1375 and error." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1376 (if eieio-skip-typecheck |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1377 nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1378 ;; 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
|
1379 (setq slot-idx (- slot-idx 3)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1380 (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
|
1381 (if (not (eieio-perform-slot-validation st value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1382 (signal 'invalid-slot-type (list class slot st value)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1383 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1384 (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
|
1385 "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
|
1386 Checks the :type specifier. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1387 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
|
1388 and error." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1389 (if eieio-skip-typecheck |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1390 nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1391 (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
|
1392 slot-idx))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1393 (if (not (eieio-perform-slot-validation st value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1394 (signal 'invalid-slot-type (list class slot st 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 (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
|
1397 "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
|
1398 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
|
1399 slot. If the slot is ok, return VALUE. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1400 Argument FN is the function calling this verifier." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1401 (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
|
1402 (slot-unbound instance (object-class instance) slotname fn) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1403 value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1404 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1405 ;;; Missing types that are useful to me. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1406 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1407 (defun boolean-p (bool) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1408 "Return non-nil if BOOL is nil or t." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1409 (or (null bool) (eq bool t))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1410 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1411 ;;; Get/Set slots in an object. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1412 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1413 (defmacro oref (obj slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1414 "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
|
1415 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
|
1416 created by the :initarg tag." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1417 `(eieio-oref ,obj (quote ,slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1418 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1419 (defun eieio-oref (obj slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1420 "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
|
1421 (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
|
1422 (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
|
1423 (if (not (symbolp slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1424 (signal 'wrong-type-argument (list 'symbolp slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1425 (if (class-p obj) (eieio-class-un-autoload obj)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1426 (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
|
1427 (c (eieio-slot-name-index class obj slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1428 (if (not c) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1429 ;; 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
|
1430 ;; Lets check that info out. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1431 (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
|
1432 ;; Oref that slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1433 (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
|
1434 ;; 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
|
1435 ;; 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
|
1436 ;; 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
|
1437 (slot-missing obj slot 'oref) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1438 ;;(signal 'invalid-slot-name (list (object-name obj) slot)) |
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 (if (not (eieio-object-p obj)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1441 (signal 'wrong-type-argument (list 'eieio-object-p obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1442 (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
|
1443 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1444 (defalias 'slot-value 'eieio-oref) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1445 (defalias 'set-slot-value 'eieio-oset) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1446 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1447 ;; @TODO - DELETE THIS AFTER FAIR WARNING |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1448 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1449 ;; 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
|
1450 ;; for defaults, but still behave like lambdas. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1451 (defmacro lambda-default (&rest cdr) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1452 "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
|
1453 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
|
1454 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
|
1455 lambda expressions into class defaults. Any `lambda-default' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1456 expression is automatically transformed into a `lambda' expression |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1457 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
|
1458 `oref-default', however, will return a `lambda-default' expression. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1459 CDR is function definition and body." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1460 (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
|
1461 ;; 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
|
1462 (list 'function (cons 'lambda-default cdr))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1463 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1464 (put 'lambda-default 'lisp-indent-function 'defun) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1465 (put 'lambda-default 'byte-compile 'byte-compile-lambda-form) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1466 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1467 (defmacro oref-default (obj slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1468 "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
|
1469 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
|
1470 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
|
1471 tag in the `defclass' call." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1472 `(eieio-oref-default ,obj (quote ,slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1473 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1474 (defun eieio-oref-default (obj slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1475 "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
|
1476 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
|
1477 (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
|
1478 (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
|
1479 (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
|
1480 (c (eieio-slot-name-index cl obj slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1481 (if (not c) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1482 ;; 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
|
1483 ;; Lets check that info out. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1484 (if (setq c |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1485 (eieio-class-slot-name-index cl slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1486 ;; Oref that slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1487 (aref (aref (class-v cl) class-class-allocation-values) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1488 c) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1489 (slot-missing obj slot 'oref-default) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1490 ;;(signal 'invalid-slot-name (list (class-name cl) slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1491 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1492 (eieio-barf-if-slot-unbound |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1493 (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
|
1494 (eieio-default-eval-maybe val)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1495 obj cl 'oref-default)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1496 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1497 (defun eieio-default-eval-maybe (val) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1498 "Check VAL, and return what `oref-default' would provide." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1499 ;; check for functions to evaluate |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1500 (if (and (listp val) (equal (car val) 'lambda)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1501 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1502 (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
|
1503 (funcall val) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1504 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1505 ;; check for quoted things, and unquote them |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1506 (if (and (listp val) (eq (car val) 'quote)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1507 (car (cdr val)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1508 ;; return it verbatim |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1509 (if (and (listp val) (eq (car val) 'lambda-default)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1510 (let ((s (copy-sequence val))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1511 (setcar s 'lambda) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1512 s) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1513 val)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1514 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1515 ;;; Object Set macros |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1516 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1517 (defmacro oset (obj slot value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1518 "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
|
1519 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
|
1520 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
|
1521 `(eieio-oset ,obj (quote ,slot) ,value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1522 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1523 (defun eieio-oset (obj slot value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1524 "Does the work for the macro `oset'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1525 Fills in OBJ's SLOT with VALUE." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1526 (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
|
1527 (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
|
1528 (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
|
1529 (if (not c) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1530 ;; 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
|
1531 ;; Lets check that info out. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1532 (if (setq c |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1533 (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
|
1534 ;; Oset that slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1535 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1536 (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
|
1537 (aset (aref (class-v (aref obj object-class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1538 class-class-allocation-values) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1539 c value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1540 ;; See oref for comment on `slot-missing' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1541 (slot-missing obj slot 'oset value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1542 ;;(signal 'invalid-slot-name (list (object-name obj) slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1543 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1544 (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
|
1545 (aset obj c value)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1546 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1547 (defmacro oset-default (class slot value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1548 "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
|
1549 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
|
1550 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
|
1551 after they are created." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1552 `(eieio-oset-default ,class (quote ,slot) ,value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1553 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1554 (defun eieio-oset-default (class slot value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1555 "Does the work for the macro `oset-default'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1556 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
|
1557 (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
|
1558 (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
|
1559 (let* ((scoped-class class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1560 (c (eieio-slot-name-index class nil slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1561 (if (not c) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1562 ;; 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
|
1563 ;; Lets check that info out. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1564 (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
|
1565 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1566 ;; Oref that slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1567 (eieio-validate-class-slot-value class c value slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1568 (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
|
1569 value)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1570 (signal 'invalid-slot-name (list (class-name class) slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1571 (eieio-validate-slot-value class c value slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1572 ;; Set this into the storage for defaults. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1573 (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
|
1574 value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1575 ;; 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
|
1576 (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
|
1577 slot value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1578 ))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1579 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1580 ;;; Handy CLOS macros |
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 (defmacro with-slots (spec-list object &rest body) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1583 "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
|
1584 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
|
1585 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
|
1586 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
|
1587 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
|
1588 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
|
1589 slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1590 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1591 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
|
1592 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1593 ((VAR1 SLOT1) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1594 SLOT2 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1595 SLOTN |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1596 (VARN+1 SLOTN+1)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1597 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1598 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
|
1599 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
|
1600 variable name of the same name as the slot." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1601 ;; 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
|
1602 (let ((mappings (mapcar (lambda (entry) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1603 (let ((var (if (listp entry) (car entry) entry)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1604 (slot (if (listp entry) (cadr entry) entry))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1605 (list var `(slot-value ,object ',slot)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1606 spec-list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1607 (append (list 'symbol-macrolet mappings) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1608 body))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1609 (put 'with-slots 'lisp-indent-function 2) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1610 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1611 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1612 ;;; 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
|
1613 ;; well embedded into an object. |
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 (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
|
1616 `(aref ,obj object-class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1617 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1618 (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
|
1619 (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
|
1620 ;; 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
|
1621 ;; and I wanted a string. Arg! |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1622 (format "#<class %s>" (symbol-name class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1623 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1624 (defun object-name (obj &optional extra) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1625 "Return a Lisp like symbol string for object OBJ. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1626 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
|
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 (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
|
1629 (aref obj object-name) (or extra ""))) |
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-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
|
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 (aref obj object-name)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1634 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1635 (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
|
1636 (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
|
1637 (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
|
1638 (aset obj object-name name)) |
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 (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
|
1641 (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
|
1642 (object-class-fast obj)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1643 (defalias 'class-of 'object-class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1644 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1645 (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
|
1646 (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
|
1647 (class-name (object-class-fast obj))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1648 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1649 (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
|
1650 `(aref (class-v ,class) class-parent)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1651 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1652 (defun class-parents (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1653 "Return parent classes to CLASS. (overload of variable). |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1654 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1655 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
|
1656 (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
|
1657 (class-parents-fast class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1658 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1659 (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
|
1660 `(aref (class-v ,class) class-children)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1661 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1662 (defun class-children (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1663 "Return child classses to CLASS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1664 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1665 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
|
1666 (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
|
1667 (class-children-fast class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1668 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1669 ;; Official CLOS functions. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1670 (defalias 'class-direct-superclasses 'class-parents) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1671 (defalias 'class-direct-subclasses 'class-children) |
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 (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
|
1674 `(car (class-parents-fast ,class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1675 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1676 (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
|
1677 `(car (class-parents ,class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1678 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1679 (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
|
1680 `(eq (aref ,obj object-class) ,class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1681 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1682 (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
|
1683 (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
|
1684 (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
|
1685 (same-class-fast-p obj class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1686 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1687 (defun object-of-class-p (obj class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1688 "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
|
1689 (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
|
1690 ;; class will be checked one layer down |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1691 (child-of-class-p (aref obj object-class) class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1692 ;; Backwards compatibility |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1693 (defalias 'obj-of-class-p 'object-of-class-p) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1694 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1695 (defun child-of-class-p (child class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1696 "If CHILD class is a subclass of CLASS." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1697 (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
|
1698 (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
|
1699 (let ((p nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1700 (while (and child (not (eq child class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1701 (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
|
1702 child (car p) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1703 p (cdr p))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1704 (if child t))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1705 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1706 (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
|
1707 (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
|
1708 (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
|
1709 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1710 (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
|
1711 (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
|
1712 (let ((ia (aref (class-v class) class-initarg-tuples)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1713 (f nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1714 (while (and ia (not f)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1715 (if (eq (cdr (car ia)) slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1716 (setq f (car (car ia)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1717 (setq ia (cdr ia))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1718 f)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1719 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1720 ;;; CLOS queries into classes and slots |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1721 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1722 (defun slot-boundp (object slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1723 "Non-nil if OBJECT's SLOT is bound. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1724 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
|
1725 make a slot unbound. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1726 OBJECT can be an instance or a class." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1727 ;; Skip typechecking while retrieving this value. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1728 (let ((eieio-skip-typecheck t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1729 ;; Return nil if the magic symbol is in there. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1730 (if (eieio-object-p object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1731 (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
|
1732 (if (class-p object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1733 (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
|
1734 (signal 'wrong-type-argument (list 'eieio-object-p object)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1735 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1736 (defun slot-makeunbound (object slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1737 "In OBJECT, make SLOT unbound." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1738 (eieio-oset object slot eieio-unbound)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1739 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1740 (defun slot-exists-p (object-or-class slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1741 "Non-nil if OBJECT-OR-CLASS has SLOT." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1742 (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
|
1743 (object-class object-or-class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1744 ((class-p object-or-class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1745 object-or-class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1746 ))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1747 (or (memq slot (aref cv class-public-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1748 (memq slot (aref cv class-class-allocation-a))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1749 )) |
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 (defun find-class (symbol &optional errorp) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1752 "Return the class that SYMBOL represents. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1753 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
|
1754 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
|
1755 (if (not (class-p symbol)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1756 (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
|
1757 nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1758 (class-v symbol))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1759 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1760 ;;; Slightly more complex utility functions for objects |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1761 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1762 (defun object-assoc (key slot list) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1763 "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
|
1764 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
|
1765 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
|
1766 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
|
1767 be ignored." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1768 (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
|
1769 (while (and list (not (condition-case nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1770 ;; This prevents errors for missing slots. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1771 (equal key (eieio-oref (car list) slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1772 (error nil)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1773 (setq list (cdr list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1774 (car list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1775 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1776 (defun object-assoc-list (slot list) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1777 "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
|
1778 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
|
1779 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
|
1780 (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
|
1781 (let ((assoclist nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1782 (while list |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1783 (setq assoclist (cons (cons (eieio-oref (car list) slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1784 (car list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1785 assoclist)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1786 (setq list (cdr list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1787 (nreverse assoclist))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1788 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1789 (defun object-assoc-list-safe (slot list) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1790 "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
|
1791 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
|
1792 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
|
1793 list." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1794 (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
|
1795 (let ((assoclist nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1796 (while list |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1797 (if (slot-exists-p (car list) slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1798 (setq assoclist (cons (cons (eieio-oref (car list) slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1799 (car list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1800 assoclist))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1801 (setq list (cdr list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1802 (nreverse assoclist))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1803 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1804 (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
|
1805 "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
|
1806 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
|
1807 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
|
1808 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
|
1809 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
|
1810 (let (ov) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1811 ;; Find the originating list. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1812 (if (not (slot-boundp object slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1813 (setq ov (list item)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1814 (setq ov (eieio-oref object slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1815 ;; turn it into a list. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1816 (unless (listp ov) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1817 (setq ov (list ov))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1818 ;; Do the combination |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1819 (if (not (member item ov)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1820 (setq ov |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1821 (if append |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1822 (append ov (list item)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1823 (cons item ov))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1824 ;; Set back into the slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1825 (eieio-oset object slot ov))) |
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 (defun object-remove-from-list (object slot item) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1828 "In OBJECT's SLOT, remove occurrences of ITEM. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1829 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
|
1830 and comparisons are done with `equal'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1831 If SLOT is unbound, do nothing." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1832 (if (not (slot-boundp object slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1833 nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1834 (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
|
1835 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1836 ;;; EIEIO internal search functions |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1837 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1838 (defun eieio-slot-originating-class-p (start-class slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1839 "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
|
1840 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
|
1841 so that we can protect private slots." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1842 (let ((par (class-parents start-class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1843 (ret t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1844 (if (not par) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1845 t |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1846 (while (and par ret) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1847 (if (intern-soft (symbol-name slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1848 (aref (class-v (car par)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1849 class-symbol-obarray)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1850 (setq ret nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1851 (setq par (cdr par))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1852 ret))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1853 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1854 (defun eieio-slot-name-index (class obj slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1855 "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
|
1856 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
|
1857 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
|
1858 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
|
1859 `scoped-class'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1860 If SLOT is the value created with :initarg instead, |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1861 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
|
1862 ;; Removed checks to outside this call |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1863 (let* ((fsym (intern-soft (symbol-name slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1864 (aref (class-v class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1865 class-symbol-obarray))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1866 (fsi (if (symbolp fsym) (symbol-value fsym) nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1867 (if (integerp fsi) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1868 (cond |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1869 ((not (get fsym 'protection)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1870 (+ 3 fsi)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1871 ((and (eq (get fsym 'protection) 'protected) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1872 scoped-class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1873 (or (child-of-class-p class scoped-class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1874 (and (eieio-object-p obj) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1875 (child-of-class-p class (object-class obj))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1876 (+ 3 fsi)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1877 ((and (eq (get fsym 'protection) 'private) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1878 (or (and scoped-class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1879 (eieio-slot-originating-class-p scoped-class slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1880 eieio-initializing-object)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1881 (+ 3 fsi)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1882 (t nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1883 (let ((fn (eieio-initarg-to-attribute class slot))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1884 (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
|
1885 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1886 (defun eieio-class-slot-name-index (class slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1887 "In CLASS find the index of the named SLOT. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1888 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
|
1889 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
|
1890 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
|
1891 ;; 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
|
1892 ;; storage cheap way. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1893 (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
|
1894 (l1 (length a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1895 (af (memq slot a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1896 (l2 (length af))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1897 ;; 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
|
1898 ;; the found slot. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1899 (if af (- l1 l2)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1900 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1901 ;;; CLOS generics internal function handling |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1902 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1903 (defvar eieio-generic-call-methodname nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1904 "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
|
1905 (defvar eieio-generic-call-arglst nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1906 "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
|
1907 (defvar eieio-generic-call-key nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1908 "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
|
1909 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
|
1910 (defvar eieio-generic-call-next-method-list nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1911 "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
|
1912 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
|
1913 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
|
1914 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1915 (defvar eieio-pre-method-execution-hooks nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1916 "*Hooks run just before a method is executed. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1917 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
|
1918 about to be executed.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1919 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1920 (defun eieio-generic-call (method args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1921 "Call METHOD with ARGS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1922 ARGS provides the context on which implementation to use. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1923 This should only be called from a generic function." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1924 ;; 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
|
1925 ;; passed in as quoted symbols |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1926 (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
|
1927 (eieio-generic-call-methodname method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1928 (eieio-generic-call-arglst args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1929 (firstarg nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1930 (primarymethodlist nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1931 ;; get a copy |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1932 (setq newargs args |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1933 firstarg (car newargs)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1934 ;; Is the class passed in autoloaded? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1935 ;; 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
|
1936 ;; 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
|
1937 ;; 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
|
1938 ;; function loaded anyway. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1939 (if (and (symbolp firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1940 (fboundp firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1941 (listp (symbol-function firstarg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1942 (eq 'autoload (car (symbol-function firstarg)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1943 (load (nth 1 (symbol-function firstarg)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1944 ;; Determine the class to use. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1945 (cond ((eieio-object-p firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1946 (setq mclass (object-class-fast firstarg))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1947 ((class-p firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1948 (setq mclass firstarg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1949 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1950 ;; Make sure the class is a valid class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1951 ;; 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
|
1952 ;; 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
|
1953 (when (and (not (null mclass)) (not (class-p mclass))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1954 (error "Cannot dispatch method %S on class %S" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1955 method mclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1956 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1957 ;; 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
|
1958 ;; make in order to successfully do this right. Rules: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1959 ;; 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
|
1960 ;; This prevents multiple calls in the case of recursion |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1961 ;; 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
|
1962 ;; 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
|
1963 ;; 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
|
1964 (when (eieio-object-p firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1965 ;; Non-static calls do all this stuff. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1966 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1967 ;; :after methods |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1968 (setq tlambdas |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1969 (if mclass |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1970 (eieiomt-method-list method method-after mclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1971 (list (eieio-generic-form method method-after nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1972 ;;(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
|
1973 ;; (eieio-generic-form method method-after nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1974 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1975 (setq lambdas (append tlambdas lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1976 keys (append (make-list (length tlambdas) method-after) keys)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1977 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1978 ;; :primary methods |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1979 (setq tlambdas |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1980 (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
|
1981 (eieio-generic-form method method-primary nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1982 (when tlambdas |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1983 (setq lambdas (cons tlambdas lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1984 keys (cons method-primary keys) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1985 primarymethodlist |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1986 (eieiomt-method-list method method-primary mclass))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1987 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1988 ;; :before methods |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1989 (setq tlambdas |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1990 (if mclass |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1991 (eieiomt-method-list method method-before mclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1992 (list (eieio-generic-form method method-before nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1993 ;;(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
|
1994 ;; (eieio-generic-form method method-before nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1995 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1996 (setq lambdas (append tlambdas lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1997 keys (append (make-list (length tlambdas) method-before) keys)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1998 ) |
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 ;; 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
|
2001 (when (not lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2002 (setq tlambdas |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2003 (eieio-generic-form method method-static mclass)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2004 (setq lambdas (cons tlambdas lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2005 keys (cons method-static keys) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2006 primarymethodlist ;; Re-use even with bad name here |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2007 (eieiomt-method-list method method-static mclass))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2008 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2009 (run-hook-with-args 'eieio-pre-method-execution-hooks |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2010 primarymethodlist) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2011 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2012 ;; 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
|
2013 ;; (which are happily sorted now) and execute them all! |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2014 (let ((rval nil) (lastval nil) (rvalever nil) (found nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2015 (while lambdas |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2016 (if (car lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2017 (let* ((scoped-class (cdr (car lambdas))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2018 (eieio-generic-call-key (car keys)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2019 (has-return-val |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2020 (or (= eieio-generic-call-key method-primary) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2021 (= eieio-generic-call-key method-static))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2022 (eieio-generic-call-next-method-list |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2023 ;; 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
|
2024 ;; we are calling right now. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2025 (when has-return-val (cdr primarymethodlist))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2026 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2027 (setq found t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2028 ;;(setq rval (apply (car (car lambdas)) newargs)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2029 (setq lastval (apply (car (car lambdas)) newargs)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2030 (when has-return-val |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2031 (setq rval lastval |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2032 rvalever t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2033 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2034 (setq lambdas (cdr lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2035 keys (cdr keys))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2036 (if (not found) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2037 (if (eieio-object-p (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2038 (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
|
2039 rvalever t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2040 (signal |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2041 'no-method-definition |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2042 (list method args)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2043 ;; 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
|
2044 ;; rvalever is nil. Is that right? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2045 rval))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2046 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2047 (defun eieio-generic-call-primary-only (method args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2048 "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
|
2049 ARGS provides the context on which implementation to use. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2050 This should only be called from a generic function. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2051 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2052 This method is like `eieio-generic-call', but only |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2053 implementations in the :PRIMARY slot are queried. After many |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2054 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
|
2055 have :PRIMARY implementations only. We can therefore optimize |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2056 for this common case to improve performance." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2057 ;; 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
|
2058 ;; passed in as quoted symbols |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2059 (let ((newargs nil) (mclass nil) (lambdas nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2060 (eieio-generic-call-methodname method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2061 (eieio-generic-call-arglst args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2062 (firstarg nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2063 (primarymethodlist nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2064 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2065 ;; get a copy |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2066 (setq newargs args |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2067 firstarg (car newargs)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2068 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2069 ;; Determine the class to use. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2070 (cond ((eieio-object-p firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2071 (setq mclass (object-class-fast firstarg))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2072 ((not firstarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2073 (error "Method %s called on nil" method)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2074 ((not (eieio-object-p firstarg)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2075 (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
|
2076 (t |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2077 (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
|
2078 method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2079 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2080 ;; Make sure the class is a valid class |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2081 ;; 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
|
2082 ;; 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
|
2083 (when (null mclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2084 (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
|
2085 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2086 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2087 ;; :primary methods |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2088 (setq lambdas (eieio-generic-form method method-primary mclass)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2089 (setq primarymethodlist ;; Re-use even with bad name here |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2090 (eieiomt-method-list method method-primary mclass)) |
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 ;; 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
|
2093 ;; (which are happily sorted now) and execute them all! |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2094 (let* ((rval nil) (lastval nil) (rvalever nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2095 (scoped-class (cdr lambdas)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2096 (eieio-generic-call-key method-primary) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2097 ;; 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
|
2098 ;; we are calling right now. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2099 (eieio-generic-call-next-method-list (cdr primarymethodlist)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2100 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2101 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2102 (if (or (not lambdas) (not (car lambdas))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2103 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2104 ;; No methods found for this impl... |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2105 (if (eieio-object-p (car args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2106 (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
|
2107 rvalever t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2108 (signal |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2109 'no-method-definition |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2110 (list method args))) |
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 ;; Do the regular implementation here. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2113 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2114 (run-hook-with-args 'eieio-pre-method-execution-hooks |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2115 lambdas) |
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 (setq lastval (apply (car lambdas) newargs)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2118 (setq rval lastval |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2119 rvalever t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2120 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2121 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2122 ;; 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
|
2123 ;; rvalever is nil. Is that right? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2124 rval))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2125 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2126 (defun eieiomt-method-list (method key class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2127 "Return an alist list of methods lambdas. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2128 METHOD is the method name. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2129 KEY represents either :before, or :after methods. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2130 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
|
2131 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
|
2132 ;; 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
|
2133 ;; for the rest of the eieiomt methods. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2134 (let ((lambdas nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2135 (mclass (list class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2136 (while mclass |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2137 ;; 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
|
2138 ;; searching through the method tree. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2139 (when (car mclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2140 ;; 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
|
2141 (let ((tmpl (eieio-generic-form method key (car mclass)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2142 (when (or (not lambdas) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2143 ;; This prevents duplicates coming out of the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2144 ;; class method optimizer. Perhaps we should |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2145 ;; just not optimize before/afters? |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2146 (not (eq (car tmpl) (car (car lambdas))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2147 (setq lambdas (cons tmpl lambdas)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2148 (if (null (car lambdas)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2149 (setq lambdas (cdr lambdas)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2150 ;; 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
|
2151 ;; protect against that. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2152 (if (car mclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2153 ;; 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
|
2154 ;; to the remainder of the class list. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2155 (let ((io (class-method-invocation-order (car mclass)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2156 (if (eq io :depth-first) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2157 ;; Depth first. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2158 (setq mclass (append (eieiomt-next (car mclass)) (cdr mclass))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2159 ;; Breadth first. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2160 (setq mclass (append (cdr mclass) (eieiomt-next (car mclass))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2161 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2162 ;; 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
|
2163 (setq mclass (cdr mclass))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2164 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2165 (if (eq key method-after) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2166 lambdas |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2167 (nreverse lambdas)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2168 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2169 (defun next-method-p () |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2170 "Non-nil if there is a next method. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2171 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
|
2172 order." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2173 eieio-generic-call-next-method-list) |
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 (defun call-next-method (&rest replacement-args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2176 "Call the superclass method from a subclass method. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2177 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
|
2178 and is called the next method. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2179 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2180 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
|
2181 `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
|
2182 arguments passed in at the top level. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2183 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2184 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
|
2185 (if (not scoped-class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2186 (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
|
2187 (if (and (/= eieio-generic-call-key method-primary) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2188 (/= eieio-generic-call-key method-static)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2189 (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
|
2190 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2191 (let ((newargs (or replacement-args eieio-generic-call-arglst)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2192 (next (car eieio-generic-call-next-method-list)) |
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 (if (or (not next) (not (car next))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2195 (apply 'no-next-method (car newargs) (cdr newargs)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2196 (let* ((eieio-generic-call-next-method-list |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2197 (cdr eieio-generic-call-next-method-list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2198 (scoped-class (cdr next)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2199 (fcn (car next)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2200 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2201 (apply fcn newargs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2202 )))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2203 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2204 ;;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2205 ;; eieio-method-tree : eieiomt- |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2206 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2207 ;; 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
|
2208 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2209 ;; (eieio-method-tree . [BEFORE PRIMARY AFTER |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2210 ;; genericBEFORE genericPRIMARY genericAFTER]) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2211 ;; and |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2212 ;; (eieio-method-obarray . [BEFORE PRIMARY AFTER |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2213 ;; genericBEFORE genericPRIMARY genericAFTER]) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2214 ;; where the association is a vector. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2215 ;; (aref 0 -- all static methods. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2216 ;; (aref 1 -- all methods classified as :before |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2217 ;; (aref 2 -- all methods classified as :primary |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2218 ;; (aref 3 -- all methods classified as :after |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2219 ;; (aref 4 -- a generic classified as :before |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2220 ;; (aref 5 -- a generic classified as :primary |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2221 ;; (aref 6 -- a generic classified as :after |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2222 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2223 (defvar eieiomt-optimizing-obarray nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2224 "While mapping atoms, this contain the obarray being optimized.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2225 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2226 (defun eieiomt-install (method-name) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2227 "Install the method tree, and obarray onto METHOD-NAME. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2228 Do not do the work if they already exist." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2229 (let ((emtv (get method-name 'eieio-method-tree)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2230 (emto (get method-name 'eieio-method-obarray))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2231 (if (or (not emtv) (not emto)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2232 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2233 (setq emtv (put method-name 'eieio-method-tree |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2234 (make-vector method-num-slots nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2235 emto (put method-name 'eieio-method-obarray |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2236 (make-vector method-num-slots nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2237 (aset emto 0 (make-vector 11 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2238 (aset emto 1 (make-vector 11 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2239 (aset emto 2 (make-vector 41 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2240 (aset emto 3 (make-vector 11 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2241 )))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2242 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2243 (defun eieiomt-add (method-name method key class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2244 "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
|
2245 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
|
2246 METHOD are the forms for a given implementation. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2247 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
|
2248 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
|
2249 It also indicates if CLASS is defined or not. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2250 CLASS is the class this method is associated with." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2251 (if (or (> key method-num-slots) (< key 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2252 (error "Eieiomt-add: method key error!")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2253 (let ((emtv (get method-name 'eieio-method-tree)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2254 (emto (get method-name 'eieio-method-obarray))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2255 ;; Make sure the method tables are available. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2256 (if (or (not emtv) (not emto)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2257 (error "Programmer error: eieiomt-add")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2258 ;; 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
|
2259 (if (assq class (aref emtv key)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2260 (setcdr (assq class (aref emtv key)) method) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2261 (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
|
2262 ;; Add function definition into newly created symbol, and store |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2263 ;; said symbol in the correct obarray, otherwise use the |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2264 ;; other array to keep this stuff |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2265 (if (< key method-num-lists) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2266 (let ((nsym (intern (symbol-name class) (aref emto key)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2267 (fset nsym method))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2268 ;; Now optimize the entire obarray |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2269 (if (< key method-num-lists) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2270 (let ((eieiomt-optimizing-obarray (aref emto key))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2271 ;; @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
|
2272 (mapatoms 'eieiomt-sym-optimize eieiomt-optimizing-obarray))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2273 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2274 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2275 (defun eieiomt-next (class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2276 "Return the next parent class for CLASS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2277 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
|
2278 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
|
2279 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
|
2280 function performs no type checking!" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2281 ;; 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
|
2282 ;; are safe and do checking for us. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2283 (or (class-parents-fast class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2284 (if (eq class 'eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2285 nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2286 '(eieio-default-superclass)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2287 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2288 (defun eieiomt-sym-optimize (s) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2289 "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
|
2290 ;; (message "Optimizing %S" s) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2291 (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
|
2292 (io (class-method-invocation-order es)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2293 (ov nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2294 (cont t)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2295 ;; 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
|
2296 (setq es (eieiomt-next es)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2297 ;; Loop over ES, then it's children individually. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2298 ;; 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
|
2299 (while (and es cont) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2300 (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
|
2301 (if (fboundp ov) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2302 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2303 (set s ov) ;store ov as our next symbol |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2304 (setq cont nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2305 (if (eq io :depth-first) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2306 ;; 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
|
2307 ;; DEPTH FIRST optimization. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2308 (setq es (append (eieiomt-next (car es)) (cdr es))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2309 ;; Else, we are breadth first. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2310 ;; (message "Class %s is breadth first" es) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2311 (setq es (append (cdr es) (eieiomt-next (car es)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2312 ))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2313 ;; 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
|
2314 (if (not es) (set s nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2315 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2316 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2317 (defun eieio-generic-form (method key class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2318 "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
|
2319 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
|
2320 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
|
2321 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
|
2322 memoized for future faster use." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2323 (let ((emto (aref (get method 'eieio-method-obarray) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2324 (if class key (+ key 3))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2325 (if (class-p class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2326 ;; 1) find our symbol |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2327 (let ((cs (intern-soft (symbol-name class) emto))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2328 (if (not cs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2329 ;; 2) If there isn't one, then make one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2330 ;; This can be slow since it only occurs once |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2331 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2332 (setq cs (intern (symbol-name class) emto)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2333 ;; 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
|
2334 ;; which should only occur once for this call ever |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2335 (let ((eieiomt-optimizing-obarray emto)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2336 (eieiomt-sym-optimize cs)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2337 ;; 3) If it's bound return this one. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2338 (if (fboundp cs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2339 (cons cs (aref (class-v class) class-symbol)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2340 ;; 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
|
2341 (if (symbol-value cs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2342 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2343 ;; 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
|
2344 (setq class (symbol-value cs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2345 cs (intern-soft (symbol-name class) emto)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2346 ;; 4.2) The optimizer should always have chosen a |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2347 ;; function-symbol |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2348 ;;(if (fboundp cs) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2349 (cons cs (aref (class-v (intern (symbol-name class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2350 class-symbol)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2351 ;;(error "EIEIO optimizer: erratic data loss!")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2352 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2353 ;; There never will be a funcall... |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2354 nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2355 ;; 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
|
2356 (let ((emtl (aref (get method 'eieio-method-tree) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2357 (if class key (+ key 3))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2358 (if emtl |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2359 ;; 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
|
2360 ;; case is nil, so skip it. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2361 (cons (cdr (car emtl)) nil) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2362 nil))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2363 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2364 ;;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2365 ;; 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
|
2366 ;; even resetting an object at run-time |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2367 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2368 (defun eieio-set-defaults (obj &optional set-all) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2369 "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
|
2370 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
|
2371 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
|
2372 not nil." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2373 (let ((scoped-class (aref obj object-class)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2374 (eieio-initializing-object t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2375 (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
|
2376 (while pub |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2377 (let ((df (eieio-oref-default obj (car pub)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2378 (if (and (listp df) (eq (car df) 'lambda-default)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2379 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2380 (setq df (copy-sequence df)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2381 (setcar df 'lambda))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2382 (if (or df set-all) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2383 (eieio-oset obj (car pub) df))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2384 (setq pub (cdr pub))))) |
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-initarg-to-attribute (class initarg) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2387 "For CLASS, convert INITARG to the actual attribute name. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2388 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
|
2389 need be.. May remove that later...)" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2390 (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
|
2391 (if tuple |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2392 (cdr tuple) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2393 nil))) |
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 (defun eieio-attribute-to-initarg (class attribute) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2396 "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
|
2397 This is usually a symbol that starts with `:'." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2398 (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
|
2399 (if tuple |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2400 (car tuple) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2401 nil))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2402 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2403 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2404 ;;; Here are some special types of errors |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2405 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2406 (intern "no-method-definition") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2407 (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
|
2408 (put 'no-method-definition 'error-message "No method definition") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2409 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2410 (intern "no-next-method") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2411 (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
|
2412 (put 'no-next-method 'error-message "No next method") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2413 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2414 (intern "invalid-slot-name") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2415 (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
|
2416 (put 'invalid-slot-name 'error-message "Invalid slot name") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2417 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2418 (intern "invalid-slot-type") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2419 (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
|
2420 (put 'invalid-slot-type 'error-message "Invalid slot type") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2421 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2422 (intern "unbound-slot") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2423 (put 'unbound-slot 'error-conditions '(unbound-slot error nil)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2424 (put 'unbound-slot 'error-message "Unbound slot") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2425 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2426 ;;; 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
|
2427 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2428 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2429 (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
|
2430 (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
|
2431 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2432 ;; 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
|
2433 (define-setf-method oref (obj slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2434 (let ((obj-temp (gensym)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2435 (slot-temp (gensym)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2436 (store-temp (gensym))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2437 (list (list obj-temp slot-temp) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2438 (list obj `(quote ,slot)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2439 (list store-temp) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2440 (list 'set-slot-value obj-temp slot-temp |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2441 store-temp) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2442 (list 'slot-value obj-temp slot-temp)))) |
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 ;;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2446 ;; 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
|
2447 ;; 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
|
2448 ;; 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
|
2449 ;; 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
|
2450 ;; 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
|
2451 ;; allowing for transparent support.) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2452 ;; |
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 (defclass eieio-default-superclass nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2455 nil |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2456 "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
|
2457 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
|
2458 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
|
2459 :abstract t) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2460 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2461 (defalias 'standard-class 'eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2462 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2463 (defgeneric constructor (class newname &rest slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2464 "Default constructor for CLASS `eieio-defualt-superclass'.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2465 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2466 (defmethod constructor :static |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2467 ((class eieio-default-superclass) newname &rest slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2468 "Default constructor for CLASS `eieio-defualt-superclass'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2469 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
|
2470 SLOTS are the initialization slots used by `shared-initialize'. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2471 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
|
2472 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
|
2473 calls `shared-initialize' on that object." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2474 (let* ((new-object (copy-sequence (aref (class-v class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2475 class-default-object-cache)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2476 ;; Update the name for the newly created object. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2477 (aset new-object object-name newname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2478 ;; 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
|
2479 ;; that were passed down to us. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2480 (initialize-instance new-object slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2481 ;; Return the created object. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2482 new-object)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2483 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2484 (defgeneric shared-initialize (obj slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2485 "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
|
2486 Called from the constructor routine.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2487 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2488 (defmethod shared-initialize ((obj eieio-default-superclass) slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2489 "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
|
2490 Called from the constructor routine." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2491 (let ((scoped-class (aref obj object-class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2492 (while slots |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2493 (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
|
2494 (car slots)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2495 (if (not rn) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2496 (slot-missing obj (car slots) 'oset (car (cdr slots))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2497 (eieio-oset obj rn (car (cdr slots))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2498 (setq slots (cdr (cdr slots)))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2499 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2500 (defgeneric initialize-instance (this &optional slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2501 "Constructs the new object THIS based on SLOTS.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2502 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2503 (defmethod initialize-instance ((this eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2504 &optional slots) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2505 "Constructs the new object THIS based on SLOTS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2506 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
|
2507 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
|
2508 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
|
2509 `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
|
2510 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
|
2511 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
|
2512 dynamically set from SLOTS." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2513 ;; 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
|
2514 ;; 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
|
2515 (let* ((scoped-class (class-v (aref this object-class))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2516 (slot (aref scoped-class class-public-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2517 (defaults (aref scoped-class class-public-d))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2518 (while slot |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2519 (if (and (listp (car defaults)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2520 (eq 'lambda (car (car defaults)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2521 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2522 (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
|
2523 (eieio-oset this (car slot) (funcall (car defaults))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2524 (setq slot (cdr slot) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2525 defaults (cdr defaults)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2526 ;; Shared initialize will parse our slots for us. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2527 (shared-initialize this slots)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2528 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2529 (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
|
2530 "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
|
2531 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2532 (defmethod slot-missing ((object eieio-default-superclass) slot-name |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2533 operation &optional new-value) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2534 "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
|
2535 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
|
2536 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
|
2537 to be set. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2538 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2539 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
|
2540 directly reference slots in EIEIO objects." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2541 (signal 'invalid-slot-name (list (object-name object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2542 slot-name))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2543 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2544 (defgeneric slot-unbound (object class slot-name fn) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2545 "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
|
2546 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2547 (defmethod slot-unbound ((object eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2548 class slot-name fn) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2549 "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
|
2550 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
|
2551 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
|
2552 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
|
2553 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
|
2554 Argument FN is the function signaling this error. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2555 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
|
2556 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2557 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
|
2558 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
|
2559 (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
|
2560 slot-name fn))) |
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 (defgeneric no-applicable-method (object method &rest args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2563 "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
|
2564 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2565 (defmethod no-applicable-method ((object eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2566 method &rest args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2567 "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
|
2568 OBJECT is the object which has no method implementation. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2569 ARGS are the arguments that were passed to METHOD. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2570 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2571 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
|
2572 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
|
2573 (signal 'no-method-definition (list method (object-name object))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2574 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2575 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2576 (defgeneric no-next-method (object &rest args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2577 "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
|
2578 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2579 (defmethod no-next-method ((object eieio-default-superclass) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2580 &rest args) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2581 "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
|
2582 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
|
2583 ARGS are the arguments it is called by. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2584 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
|
2585 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
|
2586 return value of `call-next-method'." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2587 (signal 'no-next-method (list (object-name object) args)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2588 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2589 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2590 (defgeneric clone (obj &rest params) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2591 "Make a copy of OBJ, and then supply PARAMS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2592 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
|
2593 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2594 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
|
2595 first and modify the returned object.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2596 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2597 (defmethod clone ((obj eieio-default-superclass) &rest params) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2598 "Make a copy of OBJ, and then apply PARAMS." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2599 (let ((nobj (copy-sequence obj)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2600 (nm (aref obj object-name)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2601 (passname (and params (stringp (car params)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2602 (num 1)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2603 (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
|
2604 (if (not passname) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2605 (save-match-data |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2606 (if (string-match "-\\([0-9]+\\)" nm) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2607 (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
|
2608 nm (substring nm 0 (match-beginning 0)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2609 (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
|
2610 (aset nobj object-name (car params))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2611 nobj)) |
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 (defgeneric destructor (this &rest params) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2614 "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
|
2615 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2616 (defmethod destructor ((this eieio-default-superclass) &rest params) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2617 "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
|
2618 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
|
2619 ignored parameters." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2620 ;; No cleanup... yet. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2621 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2622 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2623 (defgeneric object-print (this &rest strings) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2624 "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
|
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 Implement this method to customize the summary.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2629 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2630 (defmethod object-print ((this eieio-default-superclass) &rest strings) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2631 "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
|
2632 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
|
2633 function `object-name'. |
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 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
|
2636 default #<notation> string when using eieio browsing tools. |
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 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
|
2639 `call-next-method' to provide additional summary information. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2640 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
|
2641 to prepend a space." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2642 (object-name this (apply 'concat strings))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2643 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2644 (defvar eieio-print-depth 0 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2645 "When printing, keep track of the current indentation depth.") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2646 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2647 (defgeneric object-write (this &optional comment) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2648 "Write out object THIS to the current stream. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2649 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
|
2650 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2651 (defmethod object-write ((this eieio-default-superclass) &optional comment) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2652 "Write object THIS out to the current stream. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2653 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
|
2654 object are discouraged from being written. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2655 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
|
2656 this object." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2657 (when comment |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2658 (princ ";; Object ") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2659 (princ (object-name-string this)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2660 (princ "\n") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2661 (princ comment) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2662 (princ "\n")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2663 (let* ((cl (object-class this)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2664 (cv (class-v cl))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2665 ;; Now output readable lisp to recreate this object |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2666 ;; It should look like this: |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2667 ;; (<constructor> <name> <slot> <slot> ... ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2668 ;; Each slot's slot is writen using its :writer. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2669 (princ (make-string (* eieio-print-depth 2) ? )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2670 (princ "(") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2671 (princ (symbol-name (class-constructor (object-class this)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2672 (princ " \"") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2673 (princ (object-name-string this)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2674 (princ "\"\n") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2675 ;; Loop over all the public slots |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2676 (let ((publa (aref cv class-public-a)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2677 (publd (aref cv class-public-d)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2678 (publp (aref cv class-public-printer)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2679 (eieio-print-depth (1+ eieio-print-depth))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2680 (while publa |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2681 (when (slot-boundp this (car publa)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2682 (let ((i (class-slot-initarg cl (car publa))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2683 (v (eieio-oref this (car publa))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2684 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2685 (unless (or (not i) (equal v (car publd))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2686 (princ (make-string (* eieio-print-depth 2) ? )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2687 (princ (symbol-name i)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2688 (princ " ") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2689 (if (car publp) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2690 ;; Use our public printer |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2691 (funcall (car publp) v) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2692 ;; Use our generic override prin1 function. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2693 (eieio-override-prin1 v)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2694 (princ "\n")))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2695 (setq publa (cdr publa) publd (cdr publd) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2696 publp (cdr publp))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2697 (princ (make-string (* eieio-print-depth 2) ? ))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2698 (princ ")\n"))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2699 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2700 (defun eieio-override-prin1 (thing) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2701 "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
|
2702 (cond ((eieio-object-p thing) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2703 (object-write thing)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2704 ((listp thing) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2705 (eieio-list-prin1 thing)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2706 ((class-p thing) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2707 (princ (class-name thing))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2708 ((symbolp thing) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2709 (princ (concat "'" (symbol-name thing)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2710 (t (prin1 thing)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2711 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2712 (defun eieio-list-prin1 (list) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2713 "Display LIST where list may contain objects." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2714 (if (not (eieio-object-p (car list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2715 (progn |
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 (prin1 list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2718 (princ "(list ") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2719 (if (eieio-object-p (car list)) (princ "\n ")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2720 (while list |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2721 (if (eieio-object-p (car list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2722 (object-write (car list)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2723 (princ "'") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2724 (prin1 (car list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2725 (princ " ") |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2726 (setq list (cdr list))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2727 (princ (make-string (* eieio-print-depth 2) ? )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2728 (princ ")"))) |
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 ;;; Unimplemented functions from CLOS |
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 (defun change-class (obj class) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2734 "Change the class of OBJ to type CLASS. |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2735 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
|
2736 of `eq'." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2737 (error "Eieio: `change-class' is unimplemented")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2738 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2739 ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2740 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2741 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2742 ;;; Interfacing with edebug |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2743 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2744 (defun eieio-edebug-prin1-to-string (object &optional noescape) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2745 "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
|
2746 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
|
2747 (cond ((class-p object) (class-name object)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2748 ((eieio-object-p object) (object-print object)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2749 ((and (listp object) (or (class-p (car object)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2750 (eieio-object-p (car object)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2751 (concat "(" (mapconcat 'eieio-edebug-prin1-to-string object " ") ")")) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2752 (t (prin1-to-string object noescape)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2753 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2754 (add-hook 'edebug-setup-hook |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2755 (lambda () |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2756 (def-edebug-spec defmethod |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2757 (&define ; this means we are defining something |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2758 [&or name ("setf" :name setf name)] |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2759 ;; ^^ This is the methods symbol |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2760 [ &optional symbolp ] ; this is key :before etc |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2761 list ; arguments |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2762 [ &optional stringp ] ; documentation string |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2763 def-body ; part to be debugged |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2764 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2765 ;; The rest of the macros |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2766 (def-edebug-spec oref (form quote)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2767 (def-edebug-spec oref-default (form quote)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2768 (def-edebug-spec oset (form quote form)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2769 (def-edebug-spec oset-default (form quote form)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2770 (def-edebug-spec class-v form) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2771 (def-edebug-spec class-p form) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2772 (def-edebug-spec eieio-object-p form) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2773 (def-edebug-spec class-constructor form) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2774 (def-edebug-spec generic-p form) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2775 (def-edebug-spec with-slots (list list def-body)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2776 ;; 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
|
2777 ;; 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
|
2778 ;; appeared as "#1 =" which was not useful. This allows |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2779 ;; 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
|
2780 ;; meant to with `object-print' and `class-name' |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2781 ;; (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
|
2782 ) |
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 (eval-after-load "cedet-edebug" |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2786 '(progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2787 (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
|
2788 (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
|
2789 (cedet-edebug-add-print-override '(and (listp object) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2790 (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
|
2791 '(cedet-edebug-prin1-recurse object) ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2792 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2793 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2794 ;;; Interfacing with imenu in emacs lisp mode |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2795 ;; (Only if the expression is defined) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2796 ;; |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2797 (if (eval-when-compile (boundp 'list-imenu-generic-expression)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2798 (progn |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2799 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2800 (defun eieio-update-lisp-imenu-expression () |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2801 "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
|
2802 (let ((exp lisp-imenu-generic-expression)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2803 (while exp |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2804 ;; it's of the form '( ( title expr indx ) ... ) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2805 (let* ((subcar (cdr (car exp))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2806 (substr (car subcar))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2807 (if (and (not (string-match "|method\\\\" substr)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2808 (string-match "|advice\\\\" substr)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2809 (setcar subcar |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2810 (replace-match "|advice\\|method\\" t t substr 0)))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2811 (setq exp (cdr exp))))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2812 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2813 (eieio-update-lisp-imenu-expression) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2814 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2815 )) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2816 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2817 ;;; 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
|
2818 ;; |
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 '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
|
2821 (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
|
2822 (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
|
2823 (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
|
2824 (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
|
2825 (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
|
2826 (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
|
2827 (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
|
2828 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2829 (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
|
2830 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2831 ;; 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
|
2832 (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
|
2833 ;; (require 'advice) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2834 ;; (defadvice describe-variable (around eieio-describe activate) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2835 ;; "Display the full documentation of FUNCTION (a symbol). |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2836 ;; Returns the documentation as a string, also." |
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-class (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 ;; (defadvice describe-function (around eieio-describe activate) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2842 ;; "Display the full documentation of VARIABLE (a symbol). |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2843 ;; Returns the documentation as a string, also." |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2844 ;; (if (generic-p (ad-get-arg 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2845 ;; (eieio-describe-generic (ad-get-arg 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2846 ;; (if (class-p (ad-get-arg 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2847 ;; (eieio-describe-constructor (ad-get-arg 0)) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2848 ;; ad-do-it))) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2849 |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2850 (provide 'eieio) |
2efe3dc24373
Add files for the EIEIO library.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2851 ;;; eieio ends here |