annotate lisp/emacs-lisp/eieio.el @ 105506:29b5ee370673

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