File: eieio.texi

package info (click to toggle)
xae 1.0beta6-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 28,184 kB
  • ctags: 12,210
  • sloc: java: 27,149; xml: 20,864; lisp: 12,921; perl: 1,054; sh: 237; makefile: 169
file content (1050 lines) | stat: -rw-r--r-- 38,874 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
\input texinfo   @c -*-texinfo-*-
@c
@c $Id: eieio.texi,v 1.31 2000/08/20 22:56:52 zappo Exp $
@c
@setfilename eieio.info
@settitle Enhanced Implementation of Emacs Interpreted Objects

@ifinfo
@format
START-INFO-DIR-ENTRY
* eieio: (eieio).       Objects for Emacs
END-INFO-DIR-ENTRY
@end format
@end ifinfo

@titlepage
@sp 10
@center @titlefont{eieio}
@vskip 0pt plus 1 fill
Copyright @copyright{} 1995,1996,1998, 1999, 2000 Eric M. Ludlam
@end titlepage


@node Top, , , (dir)Top
@comment  node-name,  next,  previous,  up

EIEIO is a framework for writing object oriented applications in emacs
lisp, and is a result of my taking various object oriented classes at
work and my attempt to understand some of it better by implementing it.
The real reason I started eieio is because someone in one of my classes
said "I bet emacs can't do that!".  Well then, I just had to prove them
wrong!

@menu
* Introduction::          Why use eieio?  Basic overview, samples list.
* CLOS compatibility::    What are the differences?
* Building Classes::      How to write out new class structures.
* Default Superclass::    The grand-daddy of all superclasses.
* Making New Objects::    How to construct new objects.
* Accessing Slots::       How to access a slot.
* Writing Methods::       How to write a CLOS style method.
* Writing Methods::       How to write an embedded class method.
* Predicates::            Class-p, Object-p, etc-p.
* Association Lists::     List of objects as association lists.
* Introspection::         Looking inside a class.
* Signals::               When you make errors
* Browsing::              Browsing your class lists.
* Class Values::          Displaying information about a class or object.
* Customizing::           Customizing objects.
* Documentation::         Automatically creating texinfo documentation
* Demo Programs::         Some examples using eieio.
* Function Index::
@end menu

As of this writing, updates can be found at:
  @uref{ftp://ftp.ultranet.com/pub/zappo}.

@node Introduction, CLOS compatibility, Top, Top
@comment  node-name,  next,  previous,  up
@chapter Introduction


  EIEIO is a CLOS (Common Lisp Object System) compatibility layer.  Due
to restrictions in the Emacs Lisp language, CLOS cannot be completely
supported, and a few functions have been added in place of setf.

@section What EIEIO supports

@enumerate
@item
A structured framework for the creation of basic classes with attributes
and methods using singular inheritance similar to CLOS.
@item
Public and private classifications for slots (extensions to CLOS)
@item
Type checking, and slot unbinding.
@item
Customization support in a class (extension to CLOS)
@item
Method definitions similar to CLOS.
@item
Simple and complex class browsers.
@item
Edebug support for methods.
@item
Imenu updates.
@item
Byte compilation support of methods.
@item
Help system extentions for classes and methods.
@item
Speedbar classes so you can create easy displays of object hierarchies.
@item
Automatic texinfo documentation generator.
@item
Simple test suite.
@end enumerate

@section Issues using EIEIO

@table @asis
@item Complete @code{defclass} tag support
All CLOS tags are currently supported, but some are not currently
implemented correctly.
@item Mock object initializers
Each class contains a mock object used for fast initialization of
instantiated objects.  Using functions with side effects on object slot
values can potentially cause modifications in the mock object.  EIEIO
should use a deep copy but currently does not.
@item :AROUND method tag
This CLOS method tag is non-functional.
@end table

@section EIEIO example programs that are almost useful.

@table @asis
@item tree
Draw a structured tree by building a series of embedded lists of
`tree-node' class objects.  Includes the functions `eieio-class-tree' to
browse your current eieio inheritance structure
@item call-tree
Pass it an Emacs Lisp function (not byte compiled) to generate a call tree
using the tree tool
@item chart
Uses eieio to manage charts/axis/sequences, and allows display of simple
bar-charts.  Example programs are available displaying emacs memory
usage and list occupation, in addition to file counts and size charts.
There's even a sample that will display a chart of who sends you the most
email!  See doc-string for `chart-bar-quickie' to make your own bar
charts easily.
@item eieio-speedbar
Classes for implementing a speedbar display.  If you write a program
that uses a system of objects, and your classes inherit from those in
@file{eieio-speedbar}, then you can write a speedbar display for your
objects in very little time.
@end table

@section EIEIO wish list

@enumerate
@item
More CLOS compatibility.
@item
Integrate in the desired built-in methods into the object browser.
@item
Create some objects over pre-existing emacs-lisp stuff for fun, like
faces, processes, buffers, frames and windows as examples.
@end enumerate

@node CLOS compatibility, Building Classes, Introduction, Top
@comment  node-name,  next,  previous,  up
@chapter CLOS compatibility

As you read this, it is important to know that I have just recently
learned some of the CLOS syntax, but have never used it myself.  I'm
primarily and Emacs Lisp hacker who wrote EIEIO to help myself learn
some of the mechanics of Object Oriented programming.

Currently, the following functions should behave almost as expected from
CLOS.

@table @code
@item defclass
All slot keywords are available but not all work correctly.
Slot keyword differences are:

@table @asis
@item :reader, and :writer tags
Create methods that throw errors instead of creating an unqualified
method.  You can still create new ones to do its business.
@item :accessor
This should create an unqualified method to access a slot, but
instead pre-builds a method that gets the slot's value.
@item :type
Specifier uses the @code{typep} function from the @file{cl}
package.  @xref{(cl)Type Predicates}. It therefore has the same issues as
that package.  Extensions include the ability to provide object names.
@end table

Defclass also supports class options, but does not currently use values
of @code{:metaclass}, and @code{:default-initargs}.

@item make-instance
Make instance works as expected, however it just uses the EIEIO instance
creator automatically generated when a new class is created.
@xref{Making New Objects}.
@item defgeneric
Creates the desired symbol, and accepts all of the expected arguments
except @code{:AROUND}.
@item defmethod
Calls defgeneric, and accepts most of the expected arguments.  Only the
first argument to the created method may be type cast, though any
argument can be syntactically type cast.  (And promptly ignored)  To
type cast against a class, the class must exist before defmethod is
called. In addition, the @code{:AROUND} tag is not supported.
@item call-next-method
Inside a method, calls the next available method up the inheritance tree
for the given object.  This is different than that found in CLOS because
in EIEIO this function accepts replacement arguments.  This permits
subclasses to modify arguments as they are passed up the tree.  If no
arguments are given, the expected CLOS behavior is used.
@item setf
If the common-lisp subsystem is loaded, the setf parameters are also
loaded so the form @code{(setf (slot-value object slot) t)} should
work.
@end table

CLOS supports the @code{describe} command, but eieio only provides
@code{eieio-describe-class}, and @code{eieio-describe-generic}.  These
functions are adviced into @code{describe-variable}, and
@code{describe-function}.

When creating a new class (@pxref{Building Classes}) there are several
new keywords supported by EIEIO.

In EIEIO tags are in lower case, not mixed case.

@node Building Classes, Default Superclass, CLOS compatibility, Top
@comment  node-name,  next,  previous,  up
@chapter Building Classes

A class in EIEIO has a similar structure to that found in other
languages.  A new class is created with @code{defclass}

@defun defclass class-name superclass-list slot-list options-or-doc

This function is specified by CLOS, and EIEIO conforms in structure.

Creates a new class called @code{class-name}. The created variable's
documentation string is set to a modified version of the doc string
found in @var{options-or-doc}.  Each time a slot is defined the
variables documentation string is updated to include the methods
documentation as well.

The parent class for @code{class-name} is @var{superclass-list} which
must be a list.  Each element of this list must be a class.  These
classes form the parents of the class being created.  Every slot in
parent is replicated in the new class.  If two parents share the same
slot name, the parent which appears in the list first sets the attributes
for that slot.  If a slot in the new class' slot list matches a parent,
then the new specifications for the child class override that of the
parent.

@var{slot-list} is a list of lists.  Each sublist defines an attribute.
These lists are of the form @code{(name :tag1 value1 :tag2 value2 :tagn
valuen)}.  Some valid CLOS tags are:

@table @code
@item :initarg
The argument used during initialization.  @xref{Making New Objects}.
@item :initform
A lisp expression used to generate the default value for this slot.
If :initform is left out, that slot defaults to being unbound.
@item :type
An unquoted type specifier used to validate data set into this slot.
@xref{(cl)Type Predicates}.
@item :allocation
Unsupported: Either :class or :instance (defaults to :instance) used to
specify how data is stored.
@item :documentation
Documentation detailing the use of this slot.
@end table

Some tags whose behaviors do not yet match CLOS are:

@table @code
@item :accessor
Name of a generic function which can be used to fetch the value of this slot.
@item :writer
Name of a generic function which will write this slot.
@item :reader
Name of a generic function which will read this slot.
@end table

Some tags which are unique to EIEIO are:

@table @code
@item :custom
A custom :type specifier used when editing an object of this type.
@item :protection
A CLOS unsupported specifier which indicates that only methods of this
class may access this slot.

When using a slot referencing function, if the value behind @var{slot}
is private, then the current scope of operation must be within a method
of the calling object.
@end table

Additionally, CLOS style class options are available.  These are various
options attached to a class.  These options can occur in place or in
addition to a documentation string.  If both occur, then the options
appear before the documentation string.  In CLOS, documentation is one
of the options available to a class, so the ability to have a standalone
documentation string is specific to Emacs.  

Possible class options are:
@table @code
@item :documentation
Doc string to use for this class.  If an Emacs style documentation
string is also provided, then this option is ignored.
@item :allow-nil-initform
This is not a CLOS option.

If this option is non-nil, and the @code{:initform} is @code{nil}, but
the @code{:type} is specifies something such as @code{string} then allow
this to pass.  The default is to have this option be off.  This is
implemented as an alternative to unbound slots.
@item :metaclass
Unsupported CLOS option.  Enables the use of a different base class other
than @code{standard-class}.
@item :default-initargs
Unsupported CLOS option.  Specifies a list of initargs to be used when
creating new objects.  As far as I can tell, this duplicates the
function of @code{:initform}.
@end table

@xref{CLOS compatibility}, for more details on CLOS tags versus EIEIO
specific tags.

The whole definition may look like this:
@example
(defclass data-object ()
  ((value :initarg :value
	  :initform nil
	  :accessor get-value
	  :documentation "Lisp object which represents the data this 
object maintains."
	  :protection private)
   (reference :initarg :reference
	      :initform nil
              :type list
              :custom (repeat object)
	      :documentation "List of objects looking at me.  The method 
`update-symbol' is called for each member of `reference' whenever 
`value' is modified."
	      :protection private)
   )
  "Data object which tracks referencers.")
@end example

@end defun

@defvar eieio-error-unsupported-class-tags
If Non-nil, then @code{defclass} will throw an error if a tag
in a slot specifier is unsupported.
@end defvar

@node Default Superclass, Making New Objects, Building Classes, Top
@comment  node-name,  next,  previous,  up
@chapter Default Superclass

All defined classes, if created as a superclass (With no specified
parent class) will actually inherit from a special superclass stored in
@code{eieio-default-superclass}.  This superclass is actually quite
simple, but with it, certain default methods or attributes can be added
to all objects at any time, without updating their code in the future
(If there is a change).  In CLOS, this would be named
@code{STANDARD-CLASS} and is aliased.

Currently, the default superclass is defined as follows:

@example
(defclass eieio-default-superclass nil
  nil
  )
 "Default class used as parent class for superclasses.  It's
slots are automatically adopted by such superclasses but not stored
in the `parent' slot.  When searching for attributes or methods, when
the last parent is found, the search will recurse to this class.")
@end example

When creating an object of any type, you can use it's constructor, or
@code{make-instance}.  This, in turns calls the method
@code{initialize-instance}, which then calls the method
@code{shared-initialize}.

@defun initialize-instance obj &rest slots
Initialize @var{obj}.  Sets slots of @var{obj} with @var{slots} which
is a list of name/value pairs.  These are actually just passed to
@code{shared-initialize}.
@end defun

@defun shared-initialize obj &rest slots
Sets slots of @var{obj} with @var{slots} which is a list of name/value
pairs.
@end defun

These methods are used to override errors:

@defun slot-missing object slot operation &optional new-value
This method is called when there is an attempt to access a slot that
does not exist for a given object.  The default method signals an error
of type @code{invalid-slot-name}.  @xref{Signals}.

You may override this behavior, but it is not expected to return in the
current implementation.

This function takes arguments in a different order than in CLOS.
@end defun

@defun slot-unbound object class slot-name fn
This method is called when there is an attempt to access a slot that is
not bound.  This will throw an @code{unbound-slot} signal.  If
overridden it's return value will be returned from the function
attempting to reference its value.
@end defun

@defun no-applicable-method object method
This method is called when there is an attempt to call a method on
@var{object} when there is no method to call.  The default method throws
a @code{no-method-definition} signal.  The return value of this function
becomes the return value of the non-existent method.
@end defun

@defun no-next-method object args
This method is called when an attempt to call @code{call-next-method} is
made, and there is no next method that can be called.    The return
value becomes the return value of @code{call-next-method}.
@end defun

Additional useful methods are:

@defun clone obj &rest params
Make a deep copy of @var{obj}.  Once this copy is made, make
modifications specified by @var{params}.  @var{params} uses the same
format as the @var{slots} of @code{initialize-instance}.  The only
other change is to modify the name with an incrementing numeric.
@end defun

@defun object-print obj &rest strings
Construct a printing lisp symbol for @var{OBJ}.  This would look like:
@example
 #<class-name "objname">
@end example
STRINGS are additional parameters passed in by overloading functions to
add more data into the printing abbreviation.

@example
(defclass data-object ()
   (value)
   "Object containing one data slot.")

(defmethod object-print ((this data-object) &optional strings)
  "Return a string with a summary of the data object as part of the name."
  (apply 'call-next-method this 
	 (cons (format " value: %s" (render this)) strings)))
@end example

here is what some output could look like:
@example
(object-print test-object)
   => #<data-object test-object value: 3>
@end example
@end defun

@defun object-write obj &optional comment
Write @var{obj} onto a stream in a readable fashion.  The resulting
output will be lisp code which can be used with @code{read} and
@code{eval} to recover the object.  Only slots with @code{:initarg}s
are written to the stream.
@end defun

@node Making New Objects, Accessing Slots, Default Superclass, Top
@comment  node-name,  next,  previous,  up
@chapter Making New Objects

Once we have defined our classes, it's time to create objects with the
specified structure.  After we call @code{defclass} two new functions
are created, one of which is @code{classname}.  Thus, from the example at
the end of the previous chapter @xref{Building Classes}, we would have
the functions @code{data-object} and @code{data-object-p}.

@defun classname object-name &rest slots

This creates and returns a new object.  This object is not assigned to
anything, and will be garbage collected if not saved.  This object will
be given the string name @var{object-name}.  There can be multiple
objects of the same name, but the name slot provides a handy way to
keep track of your objects.  @var{slots} is just all the slots you
wish to preset.  Any slot set as such WILL NOT get it's default value,
and any side effects from an attributes default function will not occur.
An example pair would appear simply as @code{:value 1}.  Of course you
can do any valid lispy thing you want with it, such as
@code{:value (if (boundp 'special-symbol) special-symbol nil)}

Example of creating an object from a class, @ref{Building Classes}:

@example
(data-object "test" :value 3 :reference nil)
@end example

@end defun

@node Accessing Slots, Writing Methods, Making New Objects, Top
@comment  node-name,  next,  previous,  up
@chapter Accessing Slots

There are several ways to access slot values in an object.  The naming
convention and argument order is similar to that found in Emacs Lisp for
referencing vectors.  The basics for referencing, setting, and calling
methods are all accounted for.

@defun oset object slot value

This sets the value behind @var{slot} to @var{value} in @var{object}.
@code{oset} returns @var{value}.
@end defun

@defun oset-default class slot value

This sets the slot @var{slot} in @var{class} which is initialized with
the @code{:initform} tag to @var{value}.  This will allow a user to set
both public and private defaults after the class has been constructed.
This function is intrusive, and is offered as a way to allow users to
configure the default behavior of packages built with classes the same
way @code{setq-default} is used for buffer-local variables.

For example, if a user wanted all @code{data-objects} (@pxref{Building
Classes}) to inform a special object of his own devising when they
changed, this can be arranged by simply executing this bit of code:

@example
(oset-default data-object reference (list my-special-object))
@end example

@end defun

@defun oref object slot

This recalls the value in slot @var{slot} in @var{object} and returns
it.
@end defun

@defun oref-default object slot

This gets the default value in @var{object}'s class definition for
@code{slot}.  This can be different from the value returned by
@code{oref}.  @var{object} can also be a class symbol or an instantiated
object.
@end defun

These next accessors are defined by CLOS to reference or modify slot
values, and use the previously mentioned set/ref routines.

@defun slot-value object slot
This function retrieves the value of @var{slot} from @var{object}.
Unlike @code{oref}, the symbol for @var{slot} must be quoted in.
@end defun

@defun set-slot-value object slot value
This is not a CLOS function, but is meant to mirror @code{slot-value} if
you don't want to use the cl package's @code{setf} function.  This
function sets the value of @var{slot} from @var{object}.  Unlike
@code{oset}, the symbol for @var{slot} must be quoted in.
@end defun

@defun slot-makeunbound object slot
This function unbinds @var{slot} in @var{object}.  Referencing an
unbound slot can throw an error.
@end defun

@defun with-slots entries object forms
Bind @var{entries} lexically to the specified slot values in
@var{object}, and execute @var{forms}.  In CLOS, it would be possible to
set values in OBJECT by using @code{setf} to assign to these values, but
in Emacs, you may only read the values, or set the local variable to a
new value.

@example
(defclass myclass () (x :initarg 1))
(setq mc (make-instance 'myclass))
(with-slots (x) mc x)                      => 1
(with-slots ((something x)) mc something)  => 1
@end example
@end defun

@node Writing Methods, Predicates, Accessing Slots, Top
@comment  node-name,  next,  previous,  up
@chapter Writing Methods

Writing a CLOS style method is similar to writing a function.  The
differences are that there are some extra options and there can be
multiple implementations of a single method which interact interestingly
with each other.

Each method created verifies that there is a @dfn{generic method}
available to attach to.  A generic method has no body, and is merely a
symbol upon which methods are attached.

@defun defgeneric method arglist [doc-string]

@var{method} is the unquoted symbol to turn into a function.
@var{arglist} is the default list of arguments to use (not implemented yet).
@var{doc-string} is the documentation used for this symbol.

A generic function acts as a place holder for methods.  There is no need
to call @code{defgeneric} yourself, as @code{defmethod} will call it if
necessary.  Currently the argument list is unused.

@code{defgeneric} will prevent you from turning an existing emacs lisp
function into a generic function.
@end defun

@defun defmethod method [:BEFORE | :PRIMARY | :AFTER] arglist [doc-string] forms

@var{method} is the name of the function to be created.

@var{:BEFORE | :AFTER} represent when this form is to be called.  If
neither of these symbols are present, then the default priority is,
before @var{:AFTER}, after @var{:BEFORE}, and is represented in CLOS as
@var{PRIMARY}.

@code{arglist} is the argument list.  Unlike CLOS, only the FIRST
argument may be type-cast, and it may only be type-cast to an EIEIO
object.  An arglist such as @code{(a b)} would classify the function as
generic call, which has no object it can talk to (none is passed in) and
merely allows the creation of side-effects.  If the arglist appears as
@code{((this data-object) b)} then the form is stored as belonging to
the class @code{data-object}.  If two @code{defmethod}s appear with
arglists such as @code{(a b)} and @code{(c d)} then one of the
implementations will be overwritten, but generic and multiple type cast
arglists can co-exist.

When called, if there is a method cast against the object's parent
class, but not for that object's class, the parent class' method will be
called.  If there is a method defined for both, only the child's method
is called.

@var{doc-string} is the documentation attached to the implementation.
All method doc-strings are concatenated into the generic method's
function documentation.

@var{forms} is the body of the function.

If multiple methods and generics are defined for the same method name,
they are executed in this order:

@table @asis
@item method :BEFORE
@item generic :BEFORE
@item method :PRIMARY
@item generic :PRIMARY
@item method :AFTER
@item generic :AFTER
@end table
@end defun

See the file @file{eieio-test.el} for an example testing these
differently tagged methods.

@defun call-next-method &rest replacement-args

While running inside a CLOS method, calling this function will call the
method associated with the parent of the class of the currently running
method with the same parameters.

Optional arguments @var{replacement-args} can be used to replace the
arguments the next method would be called with.  Useful if a child class
wishes to add additional behaviors through the modification of the
parameters.  This is not a feature of CLOS.

For example code @xref{Default Superclass}.

@end defun

@defun call-next-method-p

Return t if there is a next method we can call.

@end defun

In this implementation, not all features of CLOS exist.

@enumerate
@item
There is currently no :AROUND tag.
@item
CLOS allows multiple sets of type-cast arguments, where eieio only
allows the first argument to be cast.
@end enumerate

@node Predicates, Association Lists, Writing Methods, Top
@comment  node-name,  next,  previous,  up
@chapter Predicates and Utilities

Now that we know how to create classes, access slots, and define
methods, it might be useful to verify that everything is doing ok.  To
help with this a plethora of predicates have been created.

@defun class-v class
Return a vector with all the class's important parts in it.  This vector
is not a copy.  Changing this vector changes the class.  The CLOS method
@code{find-class} will have the same effect.
@end defun

@defun find-class symbol &optional errorp
CLOS function.  In EIEIO it returns the vector definition of the class.
If there is no class, @code{nil} is returned if @var{errorp} is
@code{nil}.
@end defun

@defun class-p class
Return non-@code{nil} if @var{class} is a class type.
@end defun

@defun object-p obj
Return non-@code{nil} if @var{obj} is an object.
@end defun

@defun slot-exists-p obj slot
Return Non-@code{nil} if @var{obj} contains @var{slot} in its class.
@end defun

@defun slot-boundp obj slot
Return Non-@code{nil} if @var{obj}'s @var{slot} is bound.  A slot is
unbound if it has no :initform, and was never set.
@end defun

@defun class-name class
Return a string of the form #<class myclassname> which should look
similar to other lisp objects like buffers and processes.  Printing a
class results only in a symbol.  
@end defun

@defun class-constructor class
Return a symbol used as a constructor for @var{class}.  This way you can
make an object of a passed in class without knowing what it is.  This is
not a part of CLOS.
@end defun

@defun object-name obj
Return a string of the form #<object-class myobjname> for @var{obj}.
This should look like lisp symbols from other parts of emacs such as
buffers and processes, and is shorter and cleaner than printing the
object's vector.  It is more useful to use @code{object-print} to get
and object's print form, as this allows the object to add extra display
information into the symbol.
@end defun

@defun object-class obj
Returns the class symbol from @var{obj}.
@end defun

@defun class-of obj
CLOS symbol which does the same thing as @code{object-class}
@end defun

@defun object-class-fast obj
Same as @code{object-class} except this is a macro, and no
type-checking is performed.
@end defun

@defun object-class-name obj
Returns the symbol of @var{obj}'s class.
@end defun

@defun class-parents class
Returns the direct parents class of @var{class}.  Returns @code{nil} if
it is a superclass.
@end defun

@defun class-parents-fast class
Just like @code{class-parent} except it is a macro and no type checking
is performed.
@end defun

@defun class-parent class
Deprecated function which returns the first parent of @var{class}.
@end defun

@defun class-children class
Return the list of classes inheriting from @var{class}.
@end defun

@defun class-children-fast class
Just like @code{class-children}, but with no checks.
@end defun

@defun same-class-p obj class
Returns @code{t} if @var{obj}'s class is the same as @var{class}.
@end defun

@defun same-class-fast-p obj class
Same as @code{same-class-p} except this is a macro and no type checking
is performed.
@end defun

@defun obj-of-class-p obj class
Returns @code{t} if @var{obj} inherits anything from @var{class}.  This
is different from @code{same-class-p} because it checks for inheritance.
@end defun

@defun child-of-class-p child class
Returns @code{t} if @var{child} is a subclass of @var{class}.
@end defun

@defun generic-p method-symbol
Returns @code{t} if @code{method-symbol} is a generic function, as
opposed to a regular emacs list function.
@end defun

It is also important to note, that for every created class, a two
predicates are created for it.  Thus in our example, the function
@code{data-object-p} is created, and return @code{t} if passed an object
of the appropriate type.  Also, the function @code{data-object-child-p}
is created which returns @code{t} if the object passed to it is of a
type which inherits from @code{data-object}.

@node Association Lists, Introspection, Predicates, Top
@chapter Association Lists

Lisp offers the concept of association lists, with primitives such as
@code{assoc} used to access them.  Eieio provides a few such functions
to help with using lists of objects easily.

@defun object-assoc key slot list
Returns the first object in @var{list} for which @var{key} is in
@var{slot}.
@end defun

@defun object-assoc-list slot list
Return an association list generated by extracting @var{slot} from all
objects in @var{list}.  For each element of @var{list} the @code{car} is
the value of @var{slot}, and the @code{cdr} is the object it was
extracted from.  This is useful for generating completion tables.
@end defun

@defun eieio-build-class-alist &optional base-class
Returns an alist of all currently defined classes.  This alist is
suitable for completion lists used by interactive functions to select a
class.  The optional argument @var{base-class} allows the programmer to
select only a subset of classes to choose from should it prove
necessary.
@end defun

@node Introspection, Signals, Association Lists, Top
@chapter Introspection

Introspection permits a programmer to peek at the contents of a class
without any previous knowledge of that class.  While EIEIO implements
objects on top of vectors, and thus everything is technically visible,
some functions have been provided.  None of these functions are a part
of CLOS.

@defun obj-slots obj
Return the list of public slots for @var{obj}.
@end defun

@defun class-slot-initarg class slot
For the given @var{class} return the :initarg associated with
@var{slot}.  Not all slots have initargs, so the return value can be
nil.
@end defun

@node Signals, Browsing, Introspection, Top
@comment  node-name,  next,  previous,  up
@chapter Signals

There are new signal types that can be caught when using eieio.

@deffn Signal invalid-slot-name obj-or-class slot
This signal is called when an attempt to reference a slot in an
@var{obj-or-class} is made, and the @var{slot} is not defined for
it.
@end deffn

@deffn Signal no-method-definition method arguments
This signal is called when @var{method} is called, with @var{arguments}
and nothing is resolved.  This occurs when @var{method} has been
defined, but the arguments make it impossible for eieio to determine
which method body to run.

Overload the method @code{no-method-definition} to protect against this
signal.
@end deffn

@deffn Signal no-next-method class arguments
This signal is called if the function @code{call-next-method} is called
and there is no next method to be called.

Overload the method @code{no-next-method} to protect against this signal.
@end deffn

@deffn Signal invalid-slot-type slot spec value
This signal is called when an attempt to set @var{slot} is made, and
@var{var} doesn't match the specified type @var{spec}.

In EIEIO, this is also used of a slot specifier has an invalid value
during a @code{defclass}.
@end deffn

@deffn Signal unbound-slot object class slot
This signal is called when an attempt to reference @var{slot} in
@var{object} is made, and that instance is currently unbound.
@end deffn

@node Browsing, Class Values, Signals, Top
@comment  node-name,  next,  previous,  up
@chapter Browsing class trees

To browse all the currently loaded classes in emacs, simply run the
EIEIO browser.  @kbd{M-x eieio-browse}.  This browses all the way from
the default super-duper class eieio-default-superclass, and lists all
children in an indented tree structure.

To browse only from a specific class, pass it in as an alternate
parameter.

Here is a sample tree from our current example:

@example
eieio-default-superclass
  +--data-object
       +--data-object-symbol
@end example

Note that we start with eieio-default-superclass.  @xref{Default Superclass}.

Note: new classes are consed into the inheritance lists, so the tree
comes out upside-down.

It is also possible to use the function @code{eieio-class-tree} in the
@file{tree.el} package.  This will create an interactive tree.  Clicking
on nodes will allow expansion/contraction of branches, or editing of a
class.  @xref{Class Values}.

@node Class Values, Customizing, Browsing, Top
@comment  node-name,  next,  previous,  up
@chapter Class Values

Details about any class or object can be retrieved using the function
@code{eieio-describe-class} function.  Interactively, type in the name of
a class.  In a program, pass it a string with the name of a class, a
class symbol, or an object.  The resulting buffer will display all slot
names.

Additionally, all methods defined to have functionality on this class is
displayed.

@node Customizing, Documentation, Class Values, Top
@comment node-name, next, previous, up
@chapter Customizing Objects

In Emacs 20 a useful customization utility became available called
`custom'.  EIEIO supports custom through two new widget types.  If a
variable is declared as type @code{'object}, then full editing of slots
via the widgets is made possible.  This should be used carefully,
however, because objects modified are cloned, so if there are other
references to these objects, they will no longer be linked together.

If you want in place editing of objects, use the following methods:

@defun eieio-customize-object object
Create a custom buffer and insert a widget for editing @var{object}.  At
the end, an @code{Apply} and @code{Reset} button are available.  This
will edit the object "in place" so references to it are also changed.
There is no effort to prevent multiple edits of a singular object, so
care must be taken by the user of this function.
@end defun

@defun eieio-custom-widget-insert object flags
This method inserts an edit object into the current buffer in place.
It's sole code is @code{(widget-create 'object-edit :value object)} and
is provided as a locale for adding tracking, or specializing the widget
insert procedure for any object.
@end defun

To define a slot with an object in it, use the @code{object} tag.  This
widget type will be automatically converted to @code{object-edit} if you
do in place editing of you object.

If you want to have additional actions taken when a user clicks on the
@code{Apply} button, then overload the method @code{eieio-done-customizing}.
This method does nothing by default, but that may change in the future.
This would be the best way to make your objects persistent when using
in-place editing.

@node Documentation, Demo Programs, Customizing, Top
@comment  node-name,  next,  previous,  up
@chapter Documentation

It is possible to automatically create documentation for your classes in
texinfo format by using the tools in the file @file{eieio-doc.el}

@deffn Command eieiodoc-class class indexstring &optional skiplist

This will start at the current point, and created an indented menu of
all the child classes of, and including @var{class}, but skipping any
classes that might be in @var{skiplist} It will then create nodes for
all these classes, subsection headings, and indexes.

Each class will be indexed using the texinfo labeled index
@var{indexstring} which is a two letter description.
@xref{(texinfo) New Indices}.

To use this command, the texinfo macro

@example
@@defindex @@var @{ indexstring @}
@end example

@noindent
where @var{indexstring} is replaced with the two letter code.

Next, an inheritance tree will be created listing all parents of that
section's class.

Then,all the slots will be expanded in tables, and described
using the documentation strings from the code.  Default values will also
be displayed.  Only those slots with @code{:initarg} specified will be
expanded, others will be hidden.  If a slot is inherited from a parent,
that slot will also be skipped unless the default value is different.
If there is a change, then the documentation part of the slot will be
replace with an @@xref back to the parent.

Only classes loaded into emacs' memory can be documented.

@end deffn

@node Demo Programs, Function Index, Documentation, Top
@comment  node-name,  next,  previous,  up
@chapter Demo Programs

There are many sample programs I have written for eieio which could
become useful components of other applications, or are good stand alone
programs providing some useful functionality.  The file, and
functionality of these appear below:

@table @code
@item tree
Maintains and displays a tree structure in a buffer.  Nodes in the tree
can be clicked on for editing, node expansion, and simple information.
Includes a sample program for showing directory trees, and to draw trees
of the eieio class structures.
@item call-tree
Parses a non-byte-compiled function, and generates a call tree from it,
and all sub-non-byte-compiled functions.  Provides protection from
recursive functions.
@item chart
Draw bar charts from data.  Examples include displaying sizes of emacs
values, file distribution, and rmail distributions.
@end table

@node Function Index,  , Demo Programs, Top
@unnumbered Function Index

@printindex fn

@contents
@bye