annotate doc/misc/eieio.texi @ 107739:813096803a4a

Merge from trunk
author Jan D. <jan.h.d@swipnet.se>
date Tue, 23 Mar 2010 20:32:31 +0100
parents f412ff4a9f03
children f1266b2f017e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1 \input texinfo
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
2 @setfilename ../../info/eieio
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
3 @set TITLE Enhanced Implementation of Emacs Interpreted Objects
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
4 @set AUTHOR Eric M. Ludlam
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
5 @settitle @value{TITLE}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
6
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
7 @c *************************************************************************
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
8 @c @ Header
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
9 @c *************************************************************************
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
10
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
11 @copying
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
12 This manual documents EIEIO, an object framework for Emacs Lisp.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
13
106719
b7f28f66e31e eieio.texi (Naming Conventions): Correction to xref on elisp
Eli Zaretskii <eliz@gnu.org>
parents: 105754
diff changeset
14 Copyright @copyright{} 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
15
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
16 @quotation
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
17 Permission is granted to copy, distribute and/or modify this document
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
18 under the terms of the GNU Free Documentation License, Version 1.3 or
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
19 any later version published by the Free Software Foundation; with no
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
20 Invariant Sections, with the Front-Cover texts being ``A GNU Manual,''
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
21 and with the Back-Cover Texts as in (a) below. A copy of the license
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
22 is included in the section entitled ``GNU Free Documentation License.''
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
23
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
24 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
25 modify this GNU manual. Buying copies from the FSF supports it in
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
26 developing GNU and promoting software freedom.''
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
27 @end quotation
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
28 @end copying
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
29
107093
f412ff4a9f03 Use standard format for direntry
Mark A. Hershberger <mah@everybody.org>
parents: 106886
diff changeset
30 @dircategory Emacs
f412ff4a9f03 Use standard format for direntry
Mark A. Hershberger <mah@everybody.org>
parents: 106886
diff changeset
31 @direntry
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
32 * eieio: (eieio). Objects for Emacs
107093
f412ff4a9f03 Use standard format for direntry
Mark A. Hershberger <mah@everybody.org>
parents: 106886
diff changeset
33 @end direntry
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
34
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
35 @titlepage
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
36 @center @titlefont{@value{TITLE}}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
37 @sp 4
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
38 @center by @value{AUTHOR}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
39 @end titlepage
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
40 @page
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
41
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
42 @macro eieio{}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
43 @i{EIEIO}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
44 @end macro
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
45
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
46 @node Top, Quick Start, (dir), (dir)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
47 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
48 @top EIEIO
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
49
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
50 @eieio{} (``Enhanced Implementation of Emacs Interpreted Objects'') is
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
51 a CLOS (Common Lisp Object System) compatibility layer for Emacs Lisp.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
52 It provides a framework for writing object-oriented applications in
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
53 Emacs.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
54
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
55 @ifnottex
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
56 @insertcopying
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
57 @end ifnottex
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
58
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
59 @menu
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
60 * Quick Start:: Quick start for EIEIO.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
61 * Introduction:: Why use @eieio{}? Basic overview, samples list.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
62 * Building Classes:: How to write new class structures.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
63 * Making New Objects:: How to construct new objects.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
64 * Accessing Slots:: How to access a slot.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
65 * Writing Methods:: How to write a method.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
66 @c * Method Invocation:: How methods are invoked.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
67 * Predicates:: Class-p, Object-p, etc-p.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
68 * Association Lists:: List of objects as association lists.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
69 * Customizing:: Customizing objects.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
70 * Introspection:: Looking inside a class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
71 * Base Classes:: Additional classes you can inherit from.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
72 * Browsing:: Browsing your class lists.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
73 * Class Values:: Displaying information about a class or object.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
74 * Default Superclass:: The root superclasses.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
75 * Signals:: When you make errors
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
76 * Naming Conventions:: Name your objects in an Emacs friendly way.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
77 * CLOS compatibility:: What are the differences?
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
78 * Wish List:: Things about EIEIO that could be improved.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
79 * Function Index::
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
80 @end menu
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
81
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
82 @node Quick Start
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
83 @chapter Quick Start
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
84
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
85 @eieio{} provides an Object Oriented layer for Emacs Lisp. You can
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
86 use @eieio{} to create classes, methods for those classes, and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
87 instances of classes.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
88
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
89 Here is a simple example of a class named @code{record}, containing
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
90 three slots named @code{name}, @code{birthday}, and @code{phone}:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
91
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
92 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
93 (defclass record () ; No superclasses
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
94 ((name :initarg :name
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
95 :initform ""
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
96 :type string
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
97 :custom string
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
98 :documentation "The name of a person.")
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
99 (birthday :initarg :birthday
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
100 :initform "Jan 1, 1970"
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
101 :custom string
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
102 :type string
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
103 :documentation "The person's birthday.")
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
104 (phone :initarg :phone
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
105 :initform ""
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
106 :documentation "Phone number."))
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
107 "A single record for tracking people I know.")
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
108 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
109
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
110 Each class can have methods, which are defined like this:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
111
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
112 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
113 (defmethod call-record ((rec record) &optional scriptname)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
114 "Dial the phone for the record REC.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
115 Execute the program SCRIPTNAME to dial the phone."
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
116 (message "Dialing the phone for %s" (oref rec name))
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
117 (shell-command (concat (or scriptname "dialphone.sh")
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
118 " "
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
119 (oref rec phone))))
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
120 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
121
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
122 @noindent
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
123 In this example, the first argument to @code{call-record} is a list,
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
124 of the form (@var{varname} @var{classname}). @var{varname} is the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
125 name of the variable used for the first argument; @var{classname} is
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
126 the name of the class that is expected as the first argument for this
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
127 method.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
128
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
129 @eieio{} dispatches methods based on the type of the first argument.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
130 You can have multiple methods with the same name for different classes
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
131 of object. When the @code{call-record} method is called, the first
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
132 argument is examined to determine the class of that argument, and the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
133 method matching the input type is then executed.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
134
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
135 Once the behavior of a class is defined, you can create a new
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
136 object of type @code{record}. Objects are created by calling the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
137 constructor. The constructor is a function with the same name as your
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
138 class which returns a new instance of that class. Here is an example:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
139
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
140 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
141 (setq rec (record "Eric" :name "Eric" :birthday "June" :phone "555-5555"))
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
142 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
143
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
144 @noindent
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
145 The first argument is the name given to this instance. Each instance
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
146 is given a name, so different instances can be easily distinguished
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
147 when debugging.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
148
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
149 It can be a bit repetitive to also have a :name slot. To avoid doing
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
150 this, it is sometimes handy to use the base class @code{eieio-named}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
151 @xref{eieio-named}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
152
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
153 Calling methods on an object is a lot like calling any function. The
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
154 first argument should be an object of a class which has had this
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
155 method defined for it. In this example it would look like this:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
156
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
157 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
158 (call-record rec)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
159 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
160
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
161 @noindent
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
162 or
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
163
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
164 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
165 (call-record rec "my-call-script")
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
166 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
167
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
168 In these examples, @eieio{} automatically examines the class of
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
169 @code{rec}, and ensures that the method defined above is called. If
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
170 @code{rec} is some other class lacking a @code{call-record} method, or
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
171 some other data type, Emacs signals a @code{no-method-definition}
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
172 error. @ref{Signals}.
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
173
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
174 @node Introduction
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
175 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
176 @chapter Introduction
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
177
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
178 Due to restrictions in the Emacs Lisp language, CLOS cannot be
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
179 completely supported, and a few functions have been added in place of
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
180 setf.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
181
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
182 @eieio{} supports the following features:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
183
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
184 @enumerate
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
185 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
186 A structured framework for the creation of basic classes with attributes
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
187 and methods using singular inheritance similar to CLOS.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
188 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
189 Type checking, and slot unbinding.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
190 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
191 Method definitions similar to CLOS.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
192 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
193 Simple and complex class browsers.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
194 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
195 Edebug support for methods.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
196 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
197 Imenu updates.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
198 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
199 Byte compilation support of methods.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
200 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
201 Help system extensions for classes and methods.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
202 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
203 Automatic texinfo documentation generator.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
204 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
205 Several base classes for interesting tasks.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
206 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
207 Simple test suite.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
208 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
209 Public and private classifications for slots (extensions to CLOS)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
210 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
211 Customization support in a class (extension to CLOS)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
212 @end enumerate
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
213
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
214 Here are some CLOS features that @eieio{} presently lacks:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
215
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
216 @table @asis
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
217 @item Complete @code{defclass} tag support
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
218 All CLOS tags are currently supported, but the following are not
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
219 currently implemented correctly:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
220
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
221 @table @code
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
222 @item :metaclass
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
223 There is only one base superclass for all @eieio{} classes, which is
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
224 the @code{eieio-default-superclass}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
225 @item :default-initargs
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
226 Each slot has an @code{:initarg} tag, so this is not really necessary.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
227 @end table
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
228
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
229 @item Mock object initializers
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
230 Each class contains a mock object used for fast initialization of
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
231 instantiated objects. Using functions with side effects on object slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
232 values can potentially cause modifications in the mock object. @eieio{}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
233 should use a deep copy but currently does not.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
234
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
235 @item @code{:around} method tag
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
236 This CLOS method tag is non-functional.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
237
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
238 @end table
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
239
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
240 @node Building Classes
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
241 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
242 @chapter Building Classes
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
243
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
244 A @dfn{class} is a definition for organizing data and methods
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
245 together. An @eieio{} class has structures similar to the classes
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
246 found in other object-oriented (OO) languages.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
247
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
248 To create a new class, use the @code{defclass} macro:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
249
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
250 @defmac defclass class-name superclass-list slot-list &rest options-and-doc
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
251
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
252 Create a new class named @var{class-name}. The class is represented
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
253 by a self-referential symbol with the name @var{class-name}. @eieio{}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
254 stores the structure of the class as a symbol property of
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
255 @var{class-name} (@pxref{Symbol Components,,,elisp,GNU Emacs Lisp
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
256 Reference Manual}).
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
257
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
258 The @var{class-name} symbol's variable documentation string is a
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
259 modified version of the doc string found in @var{options-and-doc}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
260 Each time a method is defined, the symbol's documentation string is
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
261 updated to include the methods documentation as well.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
262
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
263 The parent classes for @var{class-name} is @var{superclass-list}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
264 Each element of @var{superclass-list} must be a class. These classes
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
265 are the parents of the class being created. Every slot that appears
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
266 in each parent class is replicated in the new class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
267
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
268 If two parents share the same slot name, the parent which appears in
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
269 the @var{superclass-list} first sets the tags for that slot. If the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
270 new class has a slot with the same name as the parent, the new slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
271 overrides the parent's slot.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
272 @end defmac
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
273
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
274 @noindent
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
275 Whenever defclass is used to create a new class, two predicates are
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
276 created for it, named @code{@var{CLASS-NAME}-p} and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
277 @code{@var{CLASS-NAME}-child-p}:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
278
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
279 @defun CLASS-NAME-p object
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
280 Return @code{t} if @var{OBJECT} is of the class @var{CLASS-NAME}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
281 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
282
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
283 @defun CLASS-NAME-child-p object
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
284 Return @code{t} if @var{OBJECT} is of the class @var{CLASS-NAME},
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
285 or is of a subclass of @var{CLASS-NAME}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
286 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
287
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
288 @defvar eieio-error-unsupported-class-tags
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
289 If non-nil, @code{defclass} signals an error if a tag in a slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
290 specifier is unsupported.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
291
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
292 This option is here to support programs written with older versions of
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
293 @eieio{}, which did not produce such errors.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
294 @end defvar
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
295
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
296 @menu
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
297 * Inheritance:: How to specify parents classes
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
298 * Slot Options:: How to specify features of a slot.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
299 * Class Options:: How to specify features for this class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
300 @end menu
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
301
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
302 @node Inheritance
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
303 @section Inheritance
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
304
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
305 @dfn{Inheritance} is a basic feature of an object-oriented language.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
306 In @eieio{}, a defined class specifies the super classes from which it
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
307 inherits by using the second argument to @code{defclass}. Here is an
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
308 example:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
309
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
310 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
311 (defclass my-baseclass ()
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
312 ((slot-A :initarg :slot-A)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
313 (slot-B :initarg :slot-B))
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
314 "My Baseclass.")
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
315 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
316
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
317 @noindent
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
318 To subclass from @code{my-baseclass}, we specify it in the superclass
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
319 list:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
320
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
321 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
322 (defclass my-subclass (my-baseclass)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
323 ((specific-slot-A :initarg specific-slot-A)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
324 )
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
325 "My subclass of my-baseclass")
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
326 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
327
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
328 @indent
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
329 Instances of @code{my-subclass} will inherit @code{slot-A} and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
330 @code{slot-B}, in addition to having @code{specific-slot-A} from the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
331 declaration of @code{my-subclass}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
332
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
333 @eieio{} also supports multiple inheritance. Suppose we define a
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
334 second baseclass, perhaps an ``interface'' class, like this:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
335
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
336 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
337 (defclass my-interface ()
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
338 ((interface-slot :initarg :interface-slot))
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
339 "An interface to special behavior."
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
340 :abstract t)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
341 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
342
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
343 @noindent
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
344 The interface class defines a special @code{interface-slot}, and also
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
345 specifies itself as abstract. Abstract classes cannot be
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
346 instantiated. It is not required to make interfaces abstract, but it
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
347 is a good programming practice.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
348
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
349 We can now modify our definition of @code{my-subclass} to use this
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
350 interface class, together with our original base class:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
351
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
352 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
353 (defclass my-subclass (my-baseclass my-interface)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
354 ((specific-slot-A :initarg specific-slot-A)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
355 )
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
356 "My subclass of my-baseclass")
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
357 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
358
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
359 @noindent
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
360 With this, @code{my-subclass} also has @code{interface-slot}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
361
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
362 If @code{my-baseclass} and @code{my-interface} had slots with the same
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
363 name, then the superclass showing up in the list first defines the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
364 slot attributes.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
365
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
366 Inheritance in @eieio{} is more than just combining different slots.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
367 It is also important in method invocation. @ref{Methods}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
368
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
369 If a method is called on an instance of @code{my-subclass}, and that
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
370 method only has an implementation on @code{my-baseclass}, or perhaps
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
371 @code{my-interface}, then the implementation for the baseclass is
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
372 called.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
373
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
374 If there is a method implementation for @code{my-subclass}, and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
375 another in @code{my-baseclass}, the implementation for
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
376 @code{my-subclass} can call up to the superclass as well.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
377
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
378 @node Slot Options
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
379 @section Slot Options
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
380
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
381 The @var{slot-list} argument to @code{defclass} is a list of elements
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
382 where each element defines one slot. Each slot is a list of the form
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
383
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
384 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
385 (SLOT-NAME :TAG1 ATTRIB-VALUE1
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
386 :TAG2 ATTRIB-VALUE2
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
387 :TAGN ATTRIB-VALUEN)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
388 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
389
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
390 @noindent
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
391 where @var{SLOT-NAME} is a symbol that will be used to refer to the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
392 slot. @var{:TAG} is a symbol that describes a feature to be set
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
393 on the slot. @var{ATTRIB-VALUE} is a lisp expression that will be
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
394 used for @var{:TAG}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
395
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
396 Valid tags are:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
397
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
398 @table @code
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
399 @item :initarg
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
400 A symbol that can be used in the argument list of the constructor to
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
401 specify a value for the new instance being created.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
402
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
403 A good symbol to use for initarg is one that starts with a colon @code{:}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
404
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
405 The slot specified like this:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
406 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
407 (myslot :initarg :myslot)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
408 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
409 could then be initialized to the number 1 like this:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
410 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
411 (myobject "name" :myslot 1)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
412 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
413
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
414 @xref{Making New Objects}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
415
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
416 @item :initform
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
417 A expression used as the default value for this slot.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
418
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
419 If @code{:initform} is left out, that slot defaults to being unbound.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
420 It is an error to reference an unbound slot, so if you need
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
421 slots to always be in a bound state, you should always use an
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
422 @code{:initform} specifier.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
423
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
424 Use @code{slot-boundp} to test if a slot is unbound
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
425 (@pxref{Predicates}). Use @code{slot-makeunbound} to set a slot to
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
426 being unbound after giving it a value (@pxref{Accessing Slots}).
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
427
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
428 The value passed to initform is automatically quoted. Thus,
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
429 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
430 :initform (1 2 3)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
431 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
432 appears as the specified list in the default object.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
433 A symbol that is a function like this:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
434 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
435 :initform +
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
436 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
437 will set the initial value as that symbol.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
438 A function that is a lambda expression, like this:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
439 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
440 :initform (lambda () some-variablename)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
441 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
442
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
443 will be evaluated at instantiation time to the value of
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
444 @code{some-variablename}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
445 @c This feature was more annoying than useful. Use the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
446 @c `initialize-instance' function to do this.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
447 @c
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
448 @c On the other hand, if you need code to be
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
449 @c executed at instantiation time as the initform, code like this:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
450 @c @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
451 @c :initform (lambda () (+ 1 some-global-var))
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
452 @c @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
453 @c will be identified as a function call, and be executed in place.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
454
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
455 @cindex lambda-default
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
456
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
457
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
458 Lastly, using the function @code{lambda-default} instead of
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
459 @code{lambda} will let you specify a lambda expression to use as the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
460 value, without evaluation, thus:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
461 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
462 :initform (lambda-default () some-variablename)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
463 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
464 @c @@TODO - This will be deleted after fair warning.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
465 will not be evaluated at instantiation time, and the value in this
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
466 slot will instead be @code{(lambda () some-variablename)}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
467
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
468 After a class has been created with @code{defclass}, you can change
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
469 that default value with @code{oset-default}. @ref{Accessing Slots}.
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
470
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
471 @item :type
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
472 An unquoted type specifier used to validate data set into this slot.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
473 @xref{(cl)Type Predicates}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
474 Here are some examples:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
475 @table @code
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
476 @item symbol
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
477 A symbol.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
478 @item number
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
479 A number type
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
480 @item my-class-name
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
481 An object of your class type.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
482 @item (or null symbol)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
483 A symbol, or nil.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
484 @item function
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
485 A function symbol, or a @code{lambda-default} expression.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
486
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
487 @end table
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
488
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
489 @item :allocation
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
490 Either :class or :instance (defaults to :instance) used to
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
491 specify how data is stored. Slots stored per instance have unique
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
492 values for each object. Slots stored per class have shared values for
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
493 each object. If one object changes a :class allocated slot, then all
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
494 objects for that class gain the new value.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
495
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
496 @item :documentation
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
497 Documentation detailing the use of this slot. This documentation is
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
498 exposed when the user describes a class, and during customization of an
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
499 object.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
500
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
501 @item :accessor
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
502 Name of a generic function which can be used to fetch the value of this slot.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
503 You can call this function later on your object and retrieve the value
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
504 of the slot.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
505
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
506 This options is in the CLOS spec, but is not fully compliant in @eieio{}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
507
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
508 @item :writer
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
509 Name of a generic function which will write this slot.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
510
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
511 This options is in the CLOS spec, but is not fully compliant in @eieio{}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
512
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
513 @item :reader
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
514 Name of a generic function which will read this slot.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
515
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
516 This options is in the CLOS spec, but is not fully compliant in @eieio{}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
517
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
518 @item :custom
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
519 A custom :type specifier used when editing an object of this type.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
520 See documentation for @code{defcustom} for details. This specifier is
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
521 equivalent to the :type spec of a @code{defcustom} call.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
522
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
523 This options is specific to Emacs, and is not in the CLOS spec.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
524
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
525 @item :label
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
526 When customizing an object, the value of :label will be used instead
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
527 of the slot name. This enables better descriptions of the data than
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
528 would usually be afforded.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
529
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
530 This options is specific to Emacs, and is not in the CLOS spec.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
531
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
532 @item :group
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
533 Similar to @code{defcustom}'s :group command, this organizes different
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
534 slots in an object into groups. When customizing an object, only the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
535 slots belonging to a specific group need be worked with, simplifying the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
536 size of the display.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
537
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
538 This options is specific to Emacs, and is not in the CLOS spec.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
539
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
540 @item :printer
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
541 This routine takes a symbol which is a function name. The function
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
542 should accept one argument. The argument is the value from the slot
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
543 to be printed. The function in @code{object-write} will write the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
544 slot value out to a printable form on @code{standard-output}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
545
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
546 The output format MUST be something that could in turn be interpreted
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
547 with @code{read} such that the object can be brought back in from the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
548 output stream. Thus, if you wanted to output a symbol, you would need
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
549 to quote the symbol. If you wanted to run a function on load, you
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
550 can output the code to do the construction of the value.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
551
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
552 @item :protection
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
553 When using a slot referencing function such as @code{slot-value}, and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
554 the value behind @var{slot} is private or protected, then the current
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
555 scope of operation must be within a method of the calling object.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
556
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
557 Valid values are:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
558
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
559 @table @code
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
560 @item :public
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
561 Access this slot from any scope.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
562 @item :protected
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
563 Access this slot only from methods of the same class or a child class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
564 @item :private
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
565 Access this slot only from methods of the same class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
566 @end table
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
567
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
568 This options is specific to Emacs, and is not in the CLOS spec.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
569
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
570 @end table
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
571
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
572 @node Class Options
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
573 @section Class Options
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
574
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
575 In the @var{options-and-doc} arguments to @code{defclass}, the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
576 following class options may be specified:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
577
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
578 @table @code
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
579 @item :documentation
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
580 A documentation string for this class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
581
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
582 If an Emacs-style documentation string is also provided, then this
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
583 option is ignored. An Emacs-style documentation string is not
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
584 prefixed by the @code{:documentation} tag, and appears after the list
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
585 of slots, and before the options.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
586
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
587 @item :allow-nil-initform
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
588 If this option is non-nil, and the @code{:initform} is @code{nil}, but
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
589 the @code{:type} is specifies something such as @code{string} then allow
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
590 this to pass. The default is to have this option be off. This is
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
591 implemented as an alternative to unbound slots.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
592
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
593 This options is specific to Emacs, and is not in the CLOS spec.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
594
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
595 @item :abstract
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
596 A class which is @code{:abstract} cannot be instantiated, and instead
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
597 is used to define an interface which subclasses should implement.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
598
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
599 This option is specific to Emacs, and is not in the CLOS spec.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
600
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
601 @item :custom-groups
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
602 This is a list of groups that can be customized within this class. This
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
603 slot is auto-generated when a class is created and need not be
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
604 specified. It can be retrieved with the @code{class-option} command,
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
605 however, to see what groups are available.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
606
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
607 This option is specific to Emacs, and is not in the CLOS spec.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
608
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
609 @item :method-invocation-order
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
610 This controls the order in which method resolution occurs for
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
611 @code{:primary} methods in cases of multiple inheritance. The order
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
612 affects which method is called first in a tree, and if
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
613 @code{call-next-method} is used, it controls the order in which the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
614 stack of methods are run.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
615
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
616 Valid values are:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
617
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
618 @table @code
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
619 @item :breadth-first
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
620 Search for methods in the class hierarchy in breadth first order.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
621 This is the default.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
622 @item :depth-first
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
623 Search for methods in the class hierarchy in a depth first order.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
624 @end table
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
625
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
626 @c @xref{Method Invocation}, for more on method invocation order.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
627
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
628 @item :metaclass
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
629 Unsupported CLOS option. Enables the use of a different base class other
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
630 than @code{standard-class}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
631
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
632 @item :default-initargs
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
633 Unsupported CLOS option. Specifies a list of initargs to be used when
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
634 creating new objects. As far as I can tell, this duplicates the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
635 function of @code{:initform}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
636 @end table
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
637
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
638 @xref{CLOS compatibility}, for more details on CLOS tags versus
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
639 @eieio{}-specific tags.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
640
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
641 @node Making New Objects
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
642 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
643 @chapter Making New Objects
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
644
106886
a50b302b7928 Minor Semantic and EIEIO manual fixes.
Chong Yidong <cyd@stupidchicken.com>
parents: 106719
diff changeset
645 Suppose we have a simple class is defined, such as:
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
646
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
647 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
648 (defclass record ()
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
649 ( ) "Doc String")
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
650 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
651
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
652 @noindent
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
653 It is now possible to create objects of that class type.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
654
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
655 Calling @code{defclass} has defined two new functions. One is the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
656 constructor @var{record}, and the other is the predicate,
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
657 @var{record-p}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
658
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
659 @defun record object-name &rest slots
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
660
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
661 This creates and returns a new object. This object is not assigned to
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
662 anything, and will be garbage collected if not saved. This object
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
663 will be given the string name @var{object-name}. There can be
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
664 multiple objects of the same name, but the name slot provides a handy
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
665 way to keep track of your objects. @var{slots} is just all the slots
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
666 you wish to preset. Any slot set as such @emph{will not} get its
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
667 default value, and any side effects from a slot's @code{:initform}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
668 that may be a function will not occur.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
669
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
670 An example pair would appear simply as @code{:value 1}. Of course you
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
671 can do any valid Lispy thing you want with it, such as
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
672 @code{:value (if (boundp 'special-symbol) special-symbol nil)}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
673
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
674 Example of creating an object from a class:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
675
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
676 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
677 (record "test" :value 3 :reference nil)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
678 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
679
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
680 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
681
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
682 To create an object from a class symbol, use @code{make-instance}.
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
683
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
684 @defun make-instance class &rest initargs
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
685 @anchor{make-instance}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
686 Make a new instance of @var{class} based on @var{initargs}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
687 @var{class} is a class symbol. For example:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
688
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
689 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
690 (make-instance 'foo)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
691 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
692
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
693 @var{initargs} is a property list with keywords based on the @code{:initarg}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
694 for each slot. For example:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
695
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
696 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
697 (make-instance @code{'foo} @code{:slot1} value1 @code{:slotN} valueN)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
698 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
699
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
700 Compatibility note:
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
701
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
702 If the first element of @var{initargs} is a string, it is used as the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
703 name of the class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
704
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
705 In @eieio{}, the class' constructor requires a name for use when printing.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
706 @dfn{make-instance} in CLOS doesn't use names the way Emacs does, so the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
707 class is used as the name slot instead when @var{initargs} doesn't start with
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
708 a string.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
709 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
710
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
711 @node Accessing Slots
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
712 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
713 @chapter Accessing Slots
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
714
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
715 There are several ways to access slot values in an object. The naming
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
716 and argument-order conventions are similar to those used for
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
717 referencing vectors (@pxref{Vectors,,,elisp,GNU Emacs Lisp Reference
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
718 Manual}).
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
719
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
720 @defmac oset object slot value
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
721 This macro sets the value behind @var{slot} to @var{value} in
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
722 @var{object}. It returns @var{value}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
723 @end defmac
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
724
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
725 @defmac oset-default class slot value
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
726 This macro sets the @code{:initform} for @var{slot} in @var{class} to
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
727 @var{value}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
728
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
729 This allows the user to set both public and private defaults after the
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
730 class has been constructed, and provides a way to configure the
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
731 default behavior of packages built with classes (the same way
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
732 @code{setq-default} does for buffer-local variables).
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
733
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
734 For example, if a user wanted all @code{data-objects} (@pxref{Building
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
735 Classes}) to inform a special object of his own devising when they
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
736 changed, this can be arranged by simply executing this bit of code:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
737
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
738 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
739 (oset-default data-object reference (list my-special-object))
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
740 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
741 @end defmac
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
742
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
743 @defmac oref obj slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
744 @anchor{oref}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
745 Retrieve the value stored in @var{obj} in the slot named by @var{slot}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
746 Slot is the name of the slot when created by @dfn{defclass} or the label
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
747 created by the @code{:initarg} tag.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
748 @end defmac
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
749
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
750 @defmac oref-default obj slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
751 @anchor{oref-default}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
752 Gets the default value of @var{obj} (maybe a class) for @var{slot}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
753 The default value is the value installed in a class with the @code{:initform}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
754 tag. @var{slot} can be the slot name, or the tag specified by the @code{:initarg}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
755 tag in the @dfn{defclass} call.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
756 @end defmac
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
757
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
758 The following accessors are defined by CLOS to reference or modify
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
759 slot values, and use the previously mentioned set/ref routines.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
760
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
761 @defun slot-value object slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
762 @anchor{slot-value}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
763 This function retrieves the value of @var{slot} from @var{object}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
764 Unlike @code{oref}, the symbol for @var{slot} must be quoted.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
765 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
766
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
767 @defun set-slot-value object slot value
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
768 @anchor{set-slot-value}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
769 This is not a CLOS function, but is meant to mirror @code{slot-value} if
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
770 you don't want to use the cl package's @code{setf} function. This
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
771 function sets the value of @var{slot} from @var{object}. Unlike
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
772 @code{oset}, the symbol for @var{slot} must be quoted.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
773 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
774
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
775 @defun slot-makeunbound object slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
776 This function unbinds @var{slot} in @var{object}. Referencing an
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
777 unbound slot can signal an error.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
778 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
779
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
780 @defun object-add-to-list object slot item &optional append
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
781 @anchor{object-add-to-list}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
782 In OBJECT's @var{slot}, add @var{item} to the list of elements.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
783 Optional argument @var{append} indicates we need to append to the list.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
784 If @var{item} already exists in the list in @var{slot}, then it is not added.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
785 Comparison is done with @dfn{equal} through the @dfn{member} function call.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
786 If @var{slot} is unbound, bind it to the list containing @var{item}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
787 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
788
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
789 @defun object-remove-from-list object slot item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
790 @anchor{object-remove-from-list}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
791 In OBJECT's @var{slot}, remove occurrences of @var{item}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
792 Deletion is done with @dfn{delete}, which deletes by side effect
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
793 and comparisons are done with @dfn{equal}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
794 If @var{slot} is unbound, do nothing.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
795 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
796
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
797 @defun with-slots spec-list object &rest body
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
798 @anchor{with-slots}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
799 Bind @var{spec-list} lexically to slot values in @var{object}, and execute @var{body}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
800 This establishes a lexical environment for referring to the slots in
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
801 the instance named by the given slot-names as though they were
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
802 variables. Within such a context the value of the slot can be
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
803 specified by using its slot name, as if it were a lexically bound
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
804 variable. Both setf and setq can be used to set the value of the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
805 slot.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
806
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
807 @var{spec-list} is of a form similar to @dfn{let}. For example:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
808
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
809 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
810 ((VAR1 SLOT1)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
811 SLOT2
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
812 SLOTN
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
813 (VARN+1 SLOTN+1))
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
814 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
815
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
816 Where each @var{var} is the local variable given to the associated
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
817 @var{slot}. A slot specified without a variable name is given a
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
818 variable name of the same name as the slot.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
819
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
820 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
821 (defclass myclass () (x :initarg 1))
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
822 (setq mc (make-instance 'myclass))
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
823 (with-slots (x) mc x) => 1
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
824 (with-slots ((something x)) mc something) => 1
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
825 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
826 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
827
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
828 @node Writing Methods
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
829 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
830 @chapter Writing Methods
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
831
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
832 Writing a method in @eieio{} is similar to writing a function. The
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
833 differences are that there are some extra options and there can be
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
834 multiple definitions under the same function symbol.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
835
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
836 Where a method defines an implementation for a particular data type, a
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
837 @dfn{generic method} accepts any argument, but contains no code. It
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
838 is used to provide the dispatching to the defined methods. A generic
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
839 method has no body, and is merely a symbol upon which methods are
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
840 attached. It also provides the base documentation for what methods
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
841 with that name do.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
842
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
843 @menu
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
844 * Generics::
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
845 * Methods::
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
846 * Static Methods::
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
847 @end menu
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
848
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
849 @node Generics
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
850 @section Generics
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
851
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
852 Each @eieio{} method has one corresponding generic. This generic
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
853 provides a function binding and the base documentation for the method
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
854 symbol (@pxref{Symbol Components,,,elisp,GNU Emacs Lisp Reference
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
855 Manual}).
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
856
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
857 @defmac defgeneric method arglist [doc-string]
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
858 This macro turns the (unquoted) symbol @var{method} into a function.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
859 @var{arglist} is the default list of arguments to use (not implemented
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
860 yet). @var{doc-string} is the documentation used for this symbol.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
861
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
862 A generic function acts as a placeholder for methods. There is no
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
863 need to call @code{defgeneric} yourself, as @code{defmethod} will call
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
864 it if necessary. Currently the argument list is unused.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
865
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
866 @code{defgeneric} signals an error if you attempt to turn an existing
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
867 Emacs Lisp function into a generic function.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
868
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
869 You can also create a generic method with @code{defmethod}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
870 (@pxref{Methods}). When a method is created and there is no generic
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
871 method in place with that name, then a new generic will be created,
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
872 and the new method will use it.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
873 @end defmac
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
874
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
875 In CLOS, a generic call also be used to provide an argument list and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
876 dispatch precedence for all the arguments. In @eieio{}, dispatching
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
877 only occurs for the first argument, so the @var{arglist} is not used.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
878
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
879 @node Methods
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
880 @section Methods
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
881
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
882 A method is a function that is executed if the first argument passed
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
883 to it matches the method's class. Different @eieio{} classes may
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
884 share the same method names.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
885
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
886 Methods are created with the @code{defmethod} macro, which is similar
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
887 to @code{defun}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
888
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
889 @defmac defmethod method [:before | :primary | :after | :static ] arglist [doc-string] forms
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
890
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
891 @var{method} is the name of the function to create.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
892
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
893 @code{:before} and @code{:after} specify execution order (i.e., when
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
894 this form is called). If neither of these symbols are present, the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
895 default priority is used (before @code{:after} and after
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
896 @code{:before}); this default priority is represented in CLOS as
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
897 @code{:primary}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
898
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
899 @b{Note:} The @code{:BEFORE}, @code{:PRIMARY}, @code{:AFTER}, and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
900 @code{:STATIC} method tags were in all capital letters in previous
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
901 versions of @eieio{}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
902
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
903 @var{arglist} is the list of arguments to this method. The first
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
904 argument in this list---and @emph{only} the first argument---may have
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
905 a type specifier (see the example below). If no type specifier is
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
906 supplied, the method applies to any object.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
907
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
908 @var{doc-string} is the documentation attached to the implementation.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
909 All method doc-strings are incorporated into the generic method's
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
910 function documentation.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
911
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
912 @var{forms} is the body of the function.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
913
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
914 @end defmac
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
915
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
916 @noindent
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
917 In the following example, we create a method @code{mymethod} for the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
918 @code{classname} class:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
919
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
920 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
921 (defmethod mymethod ((obj classname) secondarg)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
922 "Doc string" )
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
923 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
924
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
925 @noindent
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
926 This method only executes if the @var{obj} argument passed to it is an
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
927 @eieio{} object of class @code{classname}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
928
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
929 A method with no type specifier is a @dfn{default method}. If a given
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
930 class has no implementation, then the default method is called when
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
931 that method is used on a given object of that class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
932
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
933 Only one default method per execution specifier (@code{:before},
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
934 @code{:primary}, or @code{:after}) is allowed. If two
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
935 @code{defmethod}s appear with @var{arglist}s lacking a type specifier,
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
936 and having the same execution specifier, then the first implementation
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
937 is replaced.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
938
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
939 When a method is called on an object, but there is no method specified
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
940 for that object, but there is a method specified for object's parent
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
941 class, the parent class' method is called. If there is a method
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
942 defined for both, only the child's method is called. A child method
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
943 may call a parent's method using @code{call-next-method}, described
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
944 below.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
945
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
946 If multiple methods and default methods are defined for the same
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
947 method and class, they are executed in this order:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
948
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
949 @enumerate
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
950 @item method :before
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
951 @item default :before
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
952 @item method :primary
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
953 @item default :primary
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
954 @item method :after
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
955 @item default :after
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
956 @end enumerate
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
957
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
958 If no methods exist, Emacs signals a @code{no-method-definition}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
959 error. @xref{Signals}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
960
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
961 @defun call-next-method &rest replacement-args
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
962 @anchor{call-next-method}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
963
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
964 This function calls the superclass method from a subclass method.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
965 This is the ``next method'' specified in the current method list.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
966
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
967 If @var{replacement-args} is non-@code{nil}, then use them instead of
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
968 @code{eieio-generic-call-arglst}. At the top level, the generic
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
969 argument list is passed in.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
970
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
971 Use @code{next-method-p} to find out if there is a next method to
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
972 call.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
973 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
974
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
975 @defun next-method-p
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
976 @anchor{next-method-p}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
977 Non-@code{nil} if there is a next method.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
978 Returns a list of lambda expressions which is the @code{next-method}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
979 order.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
980 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
981
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
982 At present, @eieio{} does not implement all the features of CLOS:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
983
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
984 @enumerate
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
985 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
986 There is currently no @code{:around} tag.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
987 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
988 CLOS allows multiple sets of type-cast arguments, but @eieio{} only
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
989 allows the first argument to be cast.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
990 @end enumerate
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
991
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
992 @node Static Methods
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
993 @section Static Methods
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
994
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
995 Static methods do not depend on an object instance, but instead
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
996 operate on an object's class. You can create a static method by using
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
997 the @code{:static} key with @code{defmethod}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
998
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
999 Do not treat the first argument of a @code{:static} method as an
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1000 object unless you test it first. Use the functions
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1001 @code{oref-default} or @code{oset-default} which will work on a class,
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1002 or on the class of an object.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1003
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1004 A Class' @code{constructor} method is defined as a @code{:static}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1005 method.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1006
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1007 @b{Note:} The @code{:static} keyword is unique to @eieio{}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1008
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1009 @c TODO - Write some more about static methods here
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1010
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1011 @c @node Method Invocation
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1012 @c @chapter Method Invocation
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1013
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1014 @c TODO - writeme
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1015
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1016 @node Predicates
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1017 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1018 @chapter Predicates and Utilities
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1019
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1020 Now that we know how to create classes, access slots, and define
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1021 methods, it might be useful to verify that everything is doing ok. To
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1022 help with this a plethora of predicates have been created.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1023
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1024 @defun find-class symbol &optional errorp
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1025 @anchor{find-class}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1026 Return the class that @var{symbol} represents.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1027 If there is no class, @code{nil} is returned if @var{errorp} is @code{nil}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1028 If @var{errorp} is non-@code{nil}, @code{wrong-argument-type} is signaled.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1029 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1030
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1031 @defun class-p class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1032 @anchor{class-p}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1033 Return @code{t} if @var{class} is a valid class vector.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1034 @var{class} is a symbol.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1035 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1036
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1037 @defun slot-exists-p object-or-class slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1038 @anchor{slot-exists-p}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1039 Non-@code{nil} if @var{object-or-class} has @var{slot}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1040 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1041
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1042 @defun slot-boundp object slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1043 @anchor{slot-boundp}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1044 Non-@code{nil} if OBJECT's @var{slot} is bound.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1045 Setting a slot's value makes it bound. Calling @dfn{slot-makeunbound} will
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1046 make a slot unbound.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1047 @var{object} can be an instance or a class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1048 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1049
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1050 @defun class-name class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1051 Return a string of the form @samp{#<class myclassname>} which should look
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1052 similar to other Lisp objects like buffers and processes. Printing a
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1053 class results only in a symbol.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1054 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1055
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1056 @defun class-option class option
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1057 Return the value in @var{CLASS} of a given @var{OPTION}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1058 For example:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1059
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1060 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1061 (class-option eieio-default-superclass :documentation)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1062 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1063
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1064 Will fetch the documentation string for @code{eieio-default-superclass}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1065 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1066
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1067 @defun class-constructor class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1068 Return a symbol used as a constructor for @var{class}. The
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1069 constructor is a function used to create new instances of
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1070 @var{CLASS}. This function provides a way to make an object of a class
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1071 without knowing what it is. This is not a part of CLOS.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1072 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1073
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1074 @defun object-name obj
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1075 Return a string of the form @samp{#<object-class myobjname>} for @var{obj}.
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1076 This should look like Lisp symbols from other parts of Emacs such as
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1077 buffers and processes, and is shorter and cleaner than printing the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1078 object's vector. It is more useful to use @code{object-print} to get
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1079 and object's print form, as this allows the object to add extra display
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1080 information into the symbol.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1081 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1082
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1083 @defun object-class obj
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1084 Returns the class symbol from @var{obj}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1085 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1086
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1087 @defun class-of obj
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1088 CLOS symbol which does the same thing as @code{object-class}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1089 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1090
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1091 @defun object-class-fast obj
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1092 Same as @code{object-class} except this is a macro, and no
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1093 type-checking is performed.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1094 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1095
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1096 @defun object-class-name obj
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1097 Returns the symbol of @var{obj}'s class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1098 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1099
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1100 @defun class-parents class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1101 Returns the direct parents class of @var{class}. Returns @code{nil} if
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1102 it is a superclass.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1103 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1104
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1105 @defun class-parents-fast class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1106 Just like @code{class-parent} except it is a macro and no type checking
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1107 is performed.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1108 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1109
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1110 @defun class-parent class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1111 Deprecated function which returns the first parent of @var{class}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1112 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1113
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1114 @defun class-children class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1115 Return the list of classes inheriting from @var{class}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1116 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1117
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1118 @defun class-children-fast class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1119 Just like @code{class-children}, but with no checks.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1120 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1121
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1122 @defun same-class-p obj class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1123 Returns @code{t} if @var{obj}'s class is the same as @var{class}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1124 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1125
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1126 @defun same-class-fast-p obj class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1127 Same as @code{same-class-p} except this is a macro and no type checking
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1128 is performed.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1129 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1130
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1131 @defun object-of-class-p obj class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1132 Returns @code{t} if @var{obj} inherits anything from @var{class}. This
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1133 is different from @code{same-class-p} because it checks for inheritance.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1134 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1135
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1136 @defun child-of-class-p child class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1137 Returns @code{t} if @var{child} is a subclass of @var{class}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1138 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1139
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1140 @defun generic-p method-symbol
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1141 Returns @code{t} if @code{method-symbol} is a generic function, as
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1142 opposed to a regular Emacs Lisp function.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1143 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1144
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1145 @node Association Lists
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1146 @chapter Association Lists
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1147
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1148 Lisp offers the concept of association lists, with primitives such as
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1149 @code{assoc} used to access them. The following functions can be used
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1150 to manage association lists of @eieio{} objects:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1151
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1152 @defun object-assoc key slot list
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1153 @anchor{object-assoc}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1154 Return an object if @var{key} is @dfn{equal} to SLOT's value of an object in @var{list}.
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1155 @var{list} is a list of objects whose slots are searched.
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1156 Objects in @var{list} do not need to have a slot named @var{slot}, nor does
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1157 @var{slot} need to be bound. If these errors occur, those objects will
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1158 be ignored.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1159 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1160
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1161
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1162 @defun object-assoc-list slot list
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1163 Return an association list generated by extracting @var{slot} from all
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1164 objects in @var{list}. For each element of @var{list} the @code{car} is
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1165 the value of @var{slot}, and the @code{cdr} is the object it was
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1166 extracted from. This is useful for generating completion tables.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1167 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1168
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1169 @defun eieio-build-class-alist &optional base-class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1170 Returns an alist of all currently defined classes. This alist is
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1171 suitable for completion lists used by interactive functions to select a
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1172 class. The optional argument @var{base-class} allows the programmer to
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1173 select only a subset of classes which includes @var{base-class} and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1174 all its subclasses.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1175 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1176
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1177 @node Customizing
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1178 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1179 @chapter Customizing Objects
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1180
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1181 @eieio{} supports the Custom facility through two new widget types.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1182 If a variable is declared as type @code{object}, then full editing of
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1183 slots via the widgets is made possible. This should be used
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1184 carefully, however, because modified objects are cloned, so if there
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1185 are other references to these objects, they will no longer be linked
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1186 together.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1187
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1188 If you want in place editing of objects, use the following methods:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1189
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1190 @defun eieio-customize-object object
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1191 Create a custom buffer and insert a widget for editing @var{object}. At
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1192 the end, an @code{Apply} and @code{Reset} button are available. This
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1193 will edit the object "in place" so references to it are also changed.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1194 There is no effort to prevent multiple edits of a singular object, so
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1195 care must be taken by the user of this function.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1196 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1197
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1198 @defun eieio-custom-widget-insert object flags
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1199 This method inserts an edit object into the current buffer in place.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1200 It is implemented as @code{(widget-create 'object-edit :value object)}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1201 This method is provided as a locale for adding tracking, or
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1202 specializing the widget insert procedure for any object.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1203 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1204
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1205 To define a slot with an object in it, use the @code{object} tag. This
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1206 widget type will be automatically converted to @code{object-edit} if you
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1207 do in place editing of you object.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1208
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1209 If you want to have additional actions taken when a user clicks on the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1210 @code{Apply} button, then overload the method @code{eieio-done-customizing}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1211 This method does nothing by default, but that may change in the future.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1212 This would be the best way to make your objects persistent when using
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1213 in-place editing.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1214
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1215 @section Widget extention
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1216
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1217 When widgets are being created, one new widget extention has been added,
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1218 called the @code{:slotofchoices}. When this occurs in a widget
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1219 definition, all elements after it are removed, and the slot is specifies
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1220 is queried and converted into a series of constants.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1221
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1222 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1223 (choice (const :tag "None" nil)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1224 :slotofchoices morestuff)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1225 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1226
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1227 and if the slot @code{morestuff} contains @code{(sym1 sym2 sym3)}, the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1228 above example is converted into:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1229
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1230 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1231 (choice (const :tag "None" nil)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1232 (const sym1)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1233 (const sym2)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1234 (const sym3))
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1235 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1236
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1237 This is useful when a given item needs to be selected from a list of
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1238 items defined in this second slot.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1239
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1240 @node Introspection
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1241 @chapter Introspection
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1242
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1243 Introspection permits a programmer to peek at the contents of a class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1244 without any previous knowledge of that class. While @eieio{} implements
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1245 objects on top of vectors, and thus everything is technically visible,
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1246 some functions have been provided. None of these functions are a part
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1247 of CLOS.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1248
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1249 @defun object-slots obj
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1250 Return the list of public slots for @var{obj}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1251 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1252
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1253 @defun class-slot-initarg class slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1254 For the given @var{class} return the :initarg associated with
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1255 @var{slot}. Not all slots have initargs, so the return value can be
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1256 nil.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1257 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1258
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1259 @node Base Classes
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1260 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1261 @chapter Base Classes
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1262
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1263 All defined classes, if created with no specified parent class,
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1264 inherit from a special class called @code{eieio-default-superclass}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1265 @xref{Default Superclass}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1266
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1267 Often, it is more convenient to inherit from one of the other base
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1268 classes provided by @eieio{}, which have useful pre-defined
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1269 properties. (Since @eieio{} supports multiple inheritance, you can
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1270 even inherit from more than one of these classes at once.)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1271
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1272 @menu
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1273 * eieio-instance-inheritor:: Enable value inheritance between instances.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1274 * eieio-instance-tracker:: Enable self tracking instances.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1275 * eieio-singleton:: Only one instance of a given class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1276 * eieio-persistent:: Enable persistence for a class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1277 * eieio-named:: Use the object name as a :name slot.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1278 * eieio-speedbar:: Enable speedbar support in your objects.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1279 @end menu
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1280
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1281 @node eieio-instance-inheritor
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1282 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1283 @section @code{eieio-instance-inheritor}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1284
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1285 This class is defined in the package @file{eieio-base}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1286
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1287 Instance inheritance is a mechanism whereby the value of a slot in
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1288 object instance can reference the parent instance. If the parent's slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1289 value is changed, then the child instance is also changed. If the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1290 child's slot is set, then the parent's slot is not modified.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1291
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1292 @deftp {Class} eieio-instance-inheritor parent-instance
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1293 A class whose instances are enabled with instance inheritance.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1294 The @var{parent-instance} slot indicates the instance which is
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1295 considered the parent of the current instance. Default is @code{nil}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1296 @end deftp
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1297
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1298 @cindex clone
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1299 To use this class, inherit from it with your own class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1300 To make a new instance that inherits from and existing instance of your
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1301 class, use the @code{clone} method with additional parameters
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1302 to specify local values.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1303
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1304 @cindex slot-unbound
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1305 The @code{eieio-instance-inheritor} class works by causing cloned
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1306 objects to have all slots unbound. This class' @code{slot-unbound}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1307 method will cause references to unbound slots to be redirected to the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1308 parent instance. If the parent slot is also unbound, then
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1309 @code{slot-unbound} will signal an error named @code{slot-unbound}.
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1310
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1311 @node eieio-instance-tracker
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1312 @section @code{eieio-instance-tracker}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1313
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1314 This class is defined in the package @file{eieio-base}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1315
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1316 Sometimes it is useful to keep a master list of all instances of a given
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1317 class. The class @code{eieio-instance-tracker} performs this task.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1318
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1319 @deftp {Class} eieio-instance-tracker tracker-symbol
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1320 Enable instance tracking for this class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1321 The slot @var{tracker-symbol} should be initialized in inheritors of
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1322 this class to a symbol created with @code{defvar}. This symbol will
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1323 serve as the variable used as a master list of all objects of the given
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1324 class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1325 @end deftp
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1326
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1327 @defmethod eieio-instance-tracker initialize-instance obj slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1328 This method is defined as an @code{:after} method.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1329 It adds new instances to the master list. Do not overload this method
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1330 unless you use @code{call-next-method.}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1331 @end defmethod
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1332
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1333 @defmethod eieio-instance-tracker delete-instance obj
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1334 Remove @var{obj} from the master list of instances of this class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1335 This may let the garbage collector nab this instance.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1336 @end defmethod
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1337
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1338 @deffn eieio-instance-tracker-find key slot list-symbol
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1339 This convenience function lets you find instances. @var{key} is the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1340 value to search for. @var{slot} is the slot to compare @var{KEY}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1341 against. The function @code{equal} is used for comparison.
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1342 The parameter @var{list-symbol} is the variable symbol which contains the
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1343 list of objects to be searched.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1344 @end deffn
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1345
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1346 @node eieio-singleton
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1347 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1348 @section @code{eieio-singleton}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1349
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1350 This class is defined in the package @file{eieio-base}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1351
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1352 @deftp {Class} eieio-singleton
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1353 Inheriting from the singleton class will guarantee that there will
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1354 only ever be one instance of this class. Multiple calls to
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1355 @code{make-instance} will always return the same object.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1356 @end deftp
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1357
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1358 @node eieio-persistent
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1359 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1360 @section @code{eieio-persistent}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1361
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1362 This class is defined in the package @file{eieio-base}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1363
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1364 If you want an object, or set of objects to be persistent, meaning the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1365 slot values are important to keep saved between sessions, then you will
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1366 want your top level object to inherit from @code{eieio-persistent}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1367
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1368 To make sure your persistent object can be moved, make sure all file
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1369 names stored to disk are made relative with
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1370 @code{eieio-persistent-path-relative}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1371
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1372 @deftp {Class} eieio-persistent file file-header-line
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1373 Enables persistence for instances of this class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1374 Slot @var{file} with initarg @code{:file} is the file name in which this
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1375 object will be saved.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1376 Class allocated slot @var{file-header-line} is used with method
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1377 @code{object-write} as a header comment.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1378 @end deftp
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1379
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1380 All objects can write themselves to a file, but persistent objects have
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1381 several additional methods that aid in maintaining them.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1382
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1383 @defmethod eieio-persistent eieio-persistent-save obj &optional file
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1384 Write the object @var{obj} to its file.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1385 If optional argument @var{file} is specified, use that file name
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1386 instead.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1387 @end defmethod
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1388
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1389 @defmethod eieio-persistent eieio-persistent-path-relative obj file
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1390 Return a file name derived from @var{file} which is relative to the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1391 stored location of @var{OBJ}. This method should be used to convert
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1392 file names so that they are relative to the save file, making any system
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1393 of files movable from one location to another.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1394 @end defmethod
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1395
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1396 @defmethod eieio-persistent object-write obj &optional comment
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1397 Like @code{object-write} for @code{standard-object}, but will derive
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1398 a header line comment from the class allocated slot if one is not
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1399 provided.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1400 @end defmethod
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1401
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1402 @defun eieio-persistent-read filename
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1403 Read @var{filename} which contains an @code{eieio-persistent} object
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1404 previously written with @code{eieio-persistent-save}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1405 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1406
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1407 @node eieio-named
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1408 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1409 @section @code{eieio-named}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1410
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1411 This class is defined in the package @file{eieio-base}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1412
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1413 @deftp {Class} eieio-named
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1414 Object with a name.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1415 Name storage already occurs in an object. This object provides get/set
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1416 access to it.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1417 @end deftp
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1418
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1419 @node eieio-speedbar
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1420 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1421 @section @code{eieio-speedbar}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1422
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1423 This class is in package @file{eieio-speedbar}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1424
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1425 If a series of class instances map to a tree structure, it is possible
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1426 to cause your classes to be displayable in Speedbar. @xref{Top,,,speedbar}.
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1427 Inheriting from these classes will enable a speedbar major display mode
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1428 with a minimum of effort.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1429
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1430 @deftp {Class} eieio-speedbar buttontype buttonface
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1431 Enables base speedbar display for a class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1432 @cindex speedbar-make-tag-line
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1433 The slot @var{buttontype} is any of the symbols allowed by the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1434 function @code{speedbar-make-tag-line} for the @var{exp-button-type}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1435 argument @xref{Extending,,,speedbar}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1436 The slot @var{buttonface} is the face to use for the text of the string
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1437 displayed in speedbar.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1438 The slots @var{buttontype} and @var{buttonface} are class allocated
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1439 slots, and do not take up space in your instances.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1440 @end deftp
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1441
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1442 @deftp {Class} eieio-speedbar-directory-button buttontype buttonface
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1443 This class inherits from @code{eieio-speedbar} and initializes
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1444 @var{buttontype} and @var{buttonface} to appear as directory level lines.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1445 @end deftp
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1446
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1447 @deftp {Class} eieio-speedbar-file-button buttontype buttonface
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1448 This class inherits from @code{eieio-speedbar} and initializes
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1449 @var{buttontype} and @var{buttonface} to appear as file level lines.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1450 @end deftp
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1451
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1452 To use these classes, inherit from one of them in you class. You can
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1453 use multiple inheritance with them safely. To customize your class for
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1454 speedbar display, override the default values for @var{buttontype} and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1455 @var{buttonface} to get the desired effects.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1456
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1457 Useful methods to define for your new class include:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1458
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1459 @defmethod eieio-speedbar eieio-speedbar-derive-line-path obj depth
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1460 Return a string representing a directory associated with an instance
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1461 of @var{obj}. @var{depth} can be used to indice how many levels of
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1462 indentation have been opened by the user where @var{obj} is shown.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1463 @end defmethod
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1464
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1465
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1466 @defmethod eieio-speedbar eieio-speedbar-description obj
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1467 Return a string description of @var{OBJ}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1468 This is shown in the minibuffer or tooltip when the mouse hovers over
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1469 this instance in speedbar.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1470 @end defmethod
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1471
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1472 @defmethod eieio-speedbar eieio-speedbar-child-description obj
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1473 Return a string representing a description of a child node of @var{obj}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1474 when that child is not an object. It is often useful to just use
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1475 item info helper functions such as @code{speedbar-item-info-file-helper}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1476 @end defmethod
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1477
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1478 @defmethod eieio-speedbar eieio-speedbar-object-buttonname obj
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1479 Return a string which is the text displayed in speedbar for @var{obj}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1480 @end defmethod
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1481
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1482 @defmethod eieio-speedbar eieio-speedbar-object-children obj
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1483 Return a list of children of @var{obj}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1484 @end defmethod
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1485
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1486 @defmethod eieio-speedbar eieio-speedbar-child-make-tag-lines obj depth
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1487 This method inserts a list of speedbar tag lines for @var{obj} to
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1488 represent its children. Implement this method for your class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1489 if your children are not objects themselves. You still need to
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1490 implement @code{eieio-speedbar-object-children}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1491
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1492 In this method, use techniques specified in the Speedbar manual.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1493 @xref{Extending,,,speedbar}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1494 @end defmethod
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1495
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1496 Some other functions you will need to learn to use are:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1497
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1498 @deffn eieio-speedbar-create make-map key-map menu name toplevelfn
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1499 Register your object display mode with speedbar.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1500 @var{make-map} is a function which initialized you keymap.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1501 @var{key-map} is a symbol you keymap is installed into.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1502 @var{menu} is an easy menu vector representing menu items specific to your
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1503 object display.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1504 @var{name} is a short string to use as a name identifying you mode.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1505 @var{toplevelfn} is a function called which must return a list of
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1506 objects representing those in the instance system you wish to browse in
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1507 speedbar.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1508
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1509 Read the Extending chapter in the speedbar manual for more information
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1510 on how speedbar modes work
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1511 @xref{Extending,,,speedbar}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1512 @end deffn
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1513
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1514 @node Browsing
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1515 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1516 @chapter Browsing class trees
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1517
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1518 The command @kbd{M-x eieio-browse} displays a buffer listing all the
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1519 currently loaded classes in Emacs. The classes are listed in an
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1520 indented tree structure, starting from @code{eieio-default-superclass}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1521 (@pxref{Default Superclass}).
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1522
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1523 With a prefix argument, this command prompts for a class name; it then
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1524 lists only that class and its subclasses.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1525
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1526 Here is a sample tree from our current example:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1527
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1528 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1529 eieio-default-superclass
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1530 +--data-object
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1531 +--data-object-symbol
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1532 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1533
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1534 Note: new classes are consed into the inheritance lists, so the tree
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1535 comes out upside-down.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1536
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1537 @node Class Values
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1538 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1539 @chapter Class Values
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1540
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1541 Details about any class or object can be retrieved using the function
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1542 @code{eieio-describe-class}. Interactively, type in the name of
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1543 a class. In a program, pass it a string with the name of a class, a
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1544 class symbol, or an object. The resulting buffer will display all slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1545 names.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1546
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1547 Additionally, all methods defined to have functionality on this class
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1548 are displayed.
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1549
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1550 @node Default Superclass
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1551 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1552 @chapter Default Superclass
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1553
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1554 All defined classes, if created with no specified parent class, will
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1555 inherit from a special class stored in
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1556 @code{eieio-default-superclass}. This superclass is quite simple, but
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1557 with it, certain default methods or attributes can be added to all
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1558 objects. In CLOS, this would be named @code{STANDARD-CLASS}, and that
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1559 symbol is an alias to @code{eieio-default-superclass}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1560 @refill
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1561
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1562 Currently, the default superclass is defined as follows:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1563
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1564 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1565 (defclass eieio-default-superclass nil
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1566 nil
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1567 "Default parent class for classes with no specified parent class.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1568 Its slots are automatically adopted by classes with no specified
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1569 parents. This class is not stored in the `parent' slot of a class vector."
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1570 :abstract t)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1571 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1572
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1573 The default superclass implements several methods providing a default
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1574 behavior for all objects created by @eieio{}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1575
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1576 @menu
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1577 * Initialization:: How objects are initialized
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1578 * Basic Methods:: Clone, print, and write
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1579 * Signal Handling:: Methods for managing signals.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1580 @end menu
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1581
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1582 @node Initialization
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1583 @section Initialization
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1584
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1585 When creating an object of any type, you can use its constructor, or
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1586 @code{make-instance}. This, in turns calls the method
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1587 @code{initialize-instance}, which then calls the method
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1588 @code{shared-initialize}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1589
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1590 These methods are all implemented on the default superclass so you do
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1591 not need to write them yourself, unless you need to override one of
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1592 their behaviors.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1593
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1594 Users should not need to call @code{initialize-instance} or
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1595 @code{shared-initialize}, as these are used by @code{make-instance} to
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1596 initialize the object. They are instead provided so that users can
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1597 augment these behaviors.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1598
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1599 @defun initialize-instance obj &rest slots
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1600 Initialize @var{obj}. Sets slots of @var{obj} with @var{slots} which
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1601 is a list of name/value pairs. These are actually just passed to
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1602 @code{shared-initialize}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1603 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1604
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1605 @defun shared-initialize obj &rest slots
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1606 Sets slots of @var{obj} with @var{slots} which is a list of name/value
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1607 pairs.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1608
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1609 This is called from the default @code{constructor}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1610 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1611
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1612 @node Basic Methods
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1613 @section Basic Methods
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1614
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1615 Additional useful methods defined on the base subclass are:
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1616
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1617 @defun clone obj &rest params
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1618 @anchor{clone}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1619 Make a copy of @var{obj}, and then apply @var{params}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1620 @var{params} is a parameter list of the same form as @var{initialize-instance}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1621 which are applied to change the object. When overloading @dfn{clone}, be
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1622 sure to call @dfn{call-next-method} first and modify the returned object.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1623 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1624
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1625 @defun object-print this &rest strings
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1626 @anchor{object-print}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1627 Pretty printer for object @var{this}. Call function @dfn{object-name} with @var{strings}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1628 The default method for printing object @var{this} is to use the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1629 function @dfn{object-name}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1630
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1631 It is sometimes useful to put a summary of the object into the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1632 default #<notation> string when using eieio browsing tools.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1633
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1634 Implement this function and specify @var{strings} in a call to
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1635 @dfn{call-next-method} to provide additional summary information.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1636 When passing in extra strings from child classes, always remember
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1637 to prepend a space.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1638
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1639 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1640 (defclass data-object ()
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1641 (value)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1642 "Object containing one data slot.")
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1643
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1644 (defmethod object-print ((this data-object) &optional strings)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1645 "Return a string with a summary of the data object as part of the name."
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1646 (apply 'call-next-method this
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1647 (cons (format " value: %s" (render this)) strings)))
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1648 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1649
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1650 Here is what some output could look like:
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1651 @example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1652 (object-print test-object)
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1653 => #<data-object test-object value: 3>
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1654 @end example
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1655 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1656
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1657 @defun object-write obj &optional comment
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1658 Write @var{obj} onto a stream in a readable fashion. The resulting
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1659 output will be Lisp code which can be used with @code{read} and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1660 @code{eval} to recover the object. Only slots with @code{:initarg}s
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1661 are written to the stream.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1662 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1663
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1664 @node Signal Handling
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1665 @section Signal Handling
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1666
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1667 The default superclass defines methods for managing error conditions.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1668 These methods all throw a signal for a particular error condition.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1669
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1670 By implementing one of these methods for a class, you can change the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1671 behavior that occurs during one of these error cases, or even ignore
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1672 the error by providing some behavior.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1673
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1674 @defun slot-missing object slot-name operation &optional new-value
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1675 @anchor{slot-missing}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1676 Method invoked when an attempt to access a slot in @var{object} fails.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1677 @var{slot-name} is the name of the failed slot, @var{operation} is the type of access
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1678 that was requested, and optional @var{new-value} is the value that was desired
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1679 to be set.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1680
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1681 This method is called from @code{oref}, @code{oset}, and other functions which
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1682 directly reference slots in EIEIO objects.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1683
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1684 The default method signals an error of type @code{invalid-slot-name}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1685 @xref{Signals}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1686
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1687 You may override this behavior, but it is not expected to return in the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1688 current implementation.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1689
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1690 This function takes arguments in a different order than in CLOS.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1691 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1692
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1693 @defun slot-unbound object class slot-name fn
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1694 @anchor{slot-unbound}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1695 Slot unbound is invoked during an attempt to reference an unbound slot.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1696 @var{object} is the instance of the object being reference. @var{class} is the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1697 class of @var{object}, and @var{slot-name} is the offending slot. This function
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1698 throws the signal @code{unbound-slot}. You can overload this function and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1699 return the value to use in place of the unbound value.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1700 Argument @var{fn} is the function signaling this error.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1701 Use @dfn{slot-boundp} to determine if a slot is bound or not.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1702
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1703 In @var{clos}, the argument list is (@var{class} @var{object} @var{slot-name}), but
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1704 @var{eieio} can only dispatch on the first argument, so the first two are swapped.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1705 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1706
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1707 @defun no-applicable-method object method &rest args
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1708 @anchor{no-applicable-method}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1709 Called if there are no implementations for @var{object} in @var{method}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1710 @var{object} is the object which has no method implementation.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1711 @var{args} are the arguments that were passed to @var{method}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1712
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1713 Implement this for a class to block this signal. The return
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1714 value becomes the return value of the original method call.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1715 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1716
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1717 @defun no-next-method object &rest args
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1718 @anchor{no-next-method}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1719 Called from @dfn{call-next-method} when no additional methods are available.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1720 @var{object} is othe object being called on @dfn{call-next-method}.
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1721 @var{args} are the arguments it is called by.
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1722 This method signals @dfn{no-next-method} by default. Override this
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1723 method to not throw an error, and its return value becomes the
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1724 return value of @dfn{call-next-method}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1725 @end defun
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1726
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1727 @node Signals
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1728 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1729 @chapter Signals
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1730
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1731 There are new condition names (signals) that can be caught when using
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1732 @eieio{}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1733
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1734 @deffn Signal invalid-slot-name obj-or-class slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1735 This signal is called when an attempt to reference a slot in an
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1736 @var{obj-or-class} is made, and the @var{slot} is not defined for
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1737 it.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1738 @end deffn
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1739
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1740 @deffn Signal no-method-definition method arguments
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1741 This signal is called when @var{method} is called, with @var{arguments}
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1742 and nothing is resolved. This occurs when @var{method} has been
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1743 defined, but the arguments make it impossible for @eieio{} to determine
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1744 which method body to run.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1745
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1746 To prevent this signal from occurring in your class, implement the
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1747 method @code{no-applicable-method} for your class. This method is
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1748 called when to throw this signal, so implementing this for your class
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1749 allows you block the signal, and perform some work.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1750 @end deffn
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1751
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1752 @deffn Signal no-next-method class arguments
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1753 This signal is called if the function @code{call-next-method} is called
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1754 and there is no next method to be called.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1755
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1756 Overload the method @code{no-next-method} to protect against this signal.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1757 @end deffn
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1758
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1759 @deffn Signal invalid-slot-type slot spec value
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1760 This signal is called when an attempt to set @var{slot} is made, and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1761 @var{value} doesn't match the specified type @var{spec}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1762
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1763 In @eieio{}, this is also used if a slot specifier has an invalid value
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1764 during a @code{defclass}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1765 @end deffn
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1766
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1767 @deffn Signal unbound-slot object class slot
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1768 This signal is called when an attempt to reference @var{slot} in
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1769 @var{object} is made, and that instance is currently unbound.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1770 @end deffn
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1771
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1772 @node Naming Conventions
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1773 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1774 @chapter Naming Conventions
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1775
106719
b7f28f66e31e eieio.texi (Naming Conventions): Correction to xref on elisp
Eli Zaretskii <eliz@gnu.org>
parents: 105754
diff changeset
1776 @xref{Tips,,Tips and Conventions,elisp,GNU Emacs Lisp Reference
b7f28f66e31e eieio.texi (Naming Conventions): Correction to xref on elisp
Eli Zaretskii <eliz@gnu.org>
parents: 105754
diff changeset
1777 Manual}, for a description of Emacs Lisp programming conventions.
b7f28f66e31e eieio.texi (Naming Conventions): Correction to xref on elisp
Eli Zaretskii <eliz@gnu.org>
parents: 105754
diff changeset
1778 These conventions help ensure that Emacs packages work nicely one
b7f28f66e31e eieio.texi (Naming Conventions): Correction to xref on elisp
Eli Zaretskii <eliz@gnu.org>
parents: 105754
diff changeset
1779 another, so an @eieio{}-based program should follow them. Here are
b7f28f66e31e eieio.texi (Naming Conventions): Correction to xref on elisp
Eli Zaretskii <eliz@gnu.org>
parents: 105754
diff changeset
1780 some conventions that apply specifically to @eieio{}-based programs:
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1781
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1782 @itemize
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1783
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1784 @item Come up with a package prefix that is relatively short. Prefix
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1785 all classes, and methods with your prefix. This is a standard
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1786 convention for functions and variables in Emacs.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1787
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1788 @item Do not prefix method names with the class name. All methods in
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1789 @eieio{} are ``virtual'', and are dynamically dispatched. Anyone can
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1790 override your methods at any time. Your methods should be prefixed
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1791 with your package name.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1792
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1793 @item Do not prefix slots in your class. The slots are always locally
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1794 scoped to your class, and need no prefixing.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1795
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1796 @item If your library inherits from other libraries of classes, you
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1797 must ``require'' that library with the @code{require} command.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1798
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1799 @end itemize
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1800
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1801 @node CLOS compatibility
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1802 @comment node-name, next, previous, up
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1803 @chapter CLOS compatibility
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1804
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1805 Currently, the following functions should behave almost as expected from
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1806 CLOS.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1807
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1808 @table @code
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1809
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1810 @item defclass
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1811 All slot keywords are available but not all work correctly.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1812 Slot keyword differences are:
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1813
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1814 @table @asis
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1815
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1816 @item :reader, and :writer tags
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1817 Create methods that signal errors instead of creating an unqualified
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1818 method. You can still create new ones to do its business.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1819
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1820 @item :accessor
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1821 This should create an unqualified method to access a slot, but
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1822 instead pre-builds a method that gets the slot's value.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1823
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1824 @item :type
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1825 Specifier uses the @code{typep} function from the @file{cl}
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1826 package. @xref{(cl)Type Predicates}. It therefore has the same issues as
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1827 that package. Extensions include the ability to provide object names.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1828 @end table
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1829
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1830 Defclass also supports class options, but does not currently use values
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1831 of @code{:metaclass}, and @code{:default-initargs}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1832
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1833 @item make-instance
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1834 Make instance works as expected, however it just uses the @eieio{} instance
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1835 creator automatically generated when a new class is created.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1836 @xref{Making New Objects}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1837
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1838 @item defgeneric
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1839 Creates the desired symbol, and accepts all of the expected arguments
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1840 except @code{:around}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1841
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1842 @item defmethod
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1843 Calls defgeneric, and accepts most of the expected arguments. Only
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1844 the first argument to the created method may have a type specifier.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1845 To type cast against a class, the class must exist before defmethod is
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1846 called. In addition, the @code{:around} tag is not supported.
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1847
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1848 @item call-next-method
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1849 Inside a method, calls the next available method up the inheritance tree
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1850 for the given object. This is different than that found in CLOS because
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1851 in @eieio{} this function accepts replacement arguments. This permits
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1852 subclasses to modify arguments as they are passed up the tree. If no
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1853 arguments are given, the expected CLOS behavior is used.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1854 @item setf
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1855 If the common-lisp subsystem is loaded, the setf parameters are also
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1856 loaded so the form @code{(setf (slot-value object slot) t)} should
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1857 work.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1858 @end table
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1859
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1860 CLOS supports the @code{describe} command, but @eieio{} only provides
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1861 @code{eieio-describe-class}, and @code{eieio-describe-generic}. These
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1862 functions are adviced into @code{describe-variable}, and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1863 @code{describe-function}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1864
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1865 When creating a new class (@pxref{Building Classes}) there are several
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1866 new keywords supported by @eieio{}.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1867
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1868 In @eieio{} tags are in lower case, not mixed case.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1869
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1870 @node Wish List
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1871 @chapter Wish List
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1872
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1873 @eieio{} is an incomplete implementation of CLOS. Finding ways to
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1874 improve the compatibility would help make CLOS style programs run
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1875 better in Emacs.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1876
105528
6d711c116f28 * eieio.texi: Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 105494
diff changeset
1877 Some important compatibility features that would be good to add are:
105494
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1878
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1879 @enumerate
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1880 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1881 @code{:around} method key.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1882
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1883 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1884 Method dispatch for built-in types.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1885 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1886 Method dispatch for multiple argument typing.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1887 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1888 Improve integration with the @file{cl} package.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1889 @end enumerate
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1890
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1891 There are also improvements to be made to allow @eieio{} to operate
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1892 better in the Emacs environment.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1893
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1894 @enumerate
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1895 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1896 Allow subclasing of Emacs built-in types, such as faces, markers, and
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1897 buffers.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1898 @item
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1899 Allow method overloading of method-like functions in Emacs.
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1900 @end enumerate
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1901
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1902 @node Function Index
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1903 @unnumbered Function Index
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1904
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1905 @printindex fn
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1906
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1907 @contents
6104e7688824 * eieio.texi:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1908 @bye
105754
2313ef258869 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 105528
diff changeset
1909
2313ef258869 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 105528
diff changeset
1910 @ignore
2313ef258869 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 105528
diff changeset
1911 arch-tag: 7225b7c7-2462-4563-99e7-836a20172178
2313ef258869 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 105528
diff changeset
1912 @end ignore