1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-07 15:00:34 -08:00

Cleanup some of EIEIO's namespace.

* lisp/emacs-lisp/eieio.el (eieio--define-field-accessors): New macro.
Use it to define all the class-* and object-* field accessors (renamed
to eieio--class-* and eieio--object-*).  Update all uses.
(eieio--class-num-slots, eieio--object-num-slots): Rename from
class-num-slots and object-num-slots.
(eieio--check-type): New macro.
(eieio-defclass, eieio-oref, eieio-oref-default, same-class-p)
(object-of-class-p, child-of-class-p, object-slots, class-slot-initarg)
(eieio-oset, eieio-oset-default, object-assoc, object-assoc-list)
(object-assoc-list-safe): Use it.
(eieio-defclass): Tighten regexp.
(eieio--defmethod): Use `memq'.  Signal an error for unknown method kind.
Remove unreachable code.
(object-class-fast): Declare obsolete.
(eieio-class-name, eieio-object-name, eieio-object-set-name-string)
(eieio-object-class, eieio-object-class-name, eieio-class-parents)
(eieio-class-children, eieio-class-precedence-list, eieio-class-parent):
Rename from class-name, object-name, object-set-name-string,
object-class, object-class-name, class-parents, class-children,
class-precedence-list, class-parent; with obsolete alias.
(class-of, class-direct-superclasses, class-direct-subclasses):
Declare obsolete.
(eieio-defmethod): Use `memq'; remove unreachable code.
* lisp/emacs-lisp/eieio-base.el (eieio-persistent-read):
* lisp/emacs-lisp/eieio-opt.el (eieio-class-button, eieio-describe-generic)
(eieio-browse-tree, eieio-browse): Use eieio--check-type.
This commit is contained in:
Stefan Monnier 2013-02-18 21:57:04 -05:00
parent 6a0fda530d
commit 8ca4f1e02e
7 changed files with 441 additions and 391 deletions

View file

@ -65,19 +65,19 @@ SLOT-NAME is the offending slot. FN is the function signaling the error."
"Clone OBJ, initializing `:parent' to OBJ.
All slots are unbound, except those initialized with PARAMS."
(let ((nobj (make-vector (length obj) eieio-unbound))
(nm (aref obj object-name))
(nm (eieio--object-name obj))
(passname (and params (stringp (car params))))
(num 1))
(aset nobj 0 'object)
(aset nobj object-class (aref obj object-class))
(setf (eieio--object-class nobj) (eieio--object-class obj))
;; The following was copied from the default clone.
(if (not passname)
(save-match-data
(if (string-match "-\\([0-9]+\\)" nm)
(setq num (1+ (string-to-number (match-string 1 nm)))
nm (substring nm 0 (match-beginning 0))))
(aset nobj object-name (concat nm "-" (int-to-string num))))
(aset nobj object-name (car params)))
(setf (eieio--object-name nobj) (concat nm "-" (int-to-string num))))
(setf (eieio--object-name nobj) (car params)))
;; Now initialize from params.
(if params (shared-initialize nobj (if passname (cdr params) params)))
(oset nobj parent-instance obj)
@ -232,8 +232,7 @@ for CLASS. Optional ALLOW-SUBCLASS says that it is ok for
being pedantic."
(unless class
(message "Unsafe call to `eieio-persistent-read'."))
(when (and class (not (class-p class)))
(signal 'wrong-type-argument (list 'class-p class)))
(when class (eieio--check-type class-p class))
(let ((ret nil)
(buffstr nil))
(unwind-protect
@ -308,7 +307,7 @@ Second, any text properties will be stripped from strings."
(type nil)
(classtype nil))
(setq slot-idx (- slot-idx 3))
(setq type (aref (aref (class-v class) class-public-type)
(setq type (aref (eieio--class-public-type (class-v class))
slot-idx))
(setq classtype (eieio-persistent-slot-type-is-class-p
@ -482,14 +481,13 @@ Argument SLOT-NAME is the slot that was attempted to be accessed.
OPERATION is the type of access, such as `oref' or `oset'.
NEW-VALUE is the value that was being set into SLOT if OPERATION were
a set type."
(if (or (eq slot-name 'object-name)
(eq slot-name :object-name))
(if (memq slot-name '(object-name :object-name))
(cond ((eq operation 'oset)
(if (not (stringp new-value))
(signal 'invalid-slot-type
(list obj slot-name 'string new-value)))
(object-set-name-string obj new-value))
(t (object-name-string obj)))
(eieio-object-set-name-string obj new-value))
(t (eieio-object-name-string obj)))
(call-next-method)))
(provide 'eieio-base)

View file

@ -192,22 +192,22 @@ Optional argument IGNORE is an extraneous parameter."
(let* ((chil nil)
(obj (widget-get widget :value))
(master-group (widget-get widget :eieio-group))
(cv (class-v (object-class-fast obj)))
(slots (aref cv class-public-a))
(flabel (aref cv class-public-custom-label))
(fgroup (aref cv class-public-custom-group))
(fdoc (aref cv class-public-doc))
(fcust (aref cv class-public-custom)))
(cv (class-v (eieio--object-class obj)))
(slots (eieio--class-public-a cv))
(flabel (eieio--class-public-custom-label cv))
(fgroup (eieio--class-public-custom-group cv))
(fdoc (eieio--class-public-doc cv))
(fcust (eieio--class-public-custom cv)))
;; First line describes the object, but may not editable.
(if (widget-get widget :eieio-show-name)
(setq chil (cons (widget-create-child-and-convert
widget 'string :tag "Object "
:sample-face 'bold
(object-name-string obj))
(eieio-object-name-string obj))
chil)))
;; Display information about the group being shown
(when master-group
(let ((groups (class-option (object-class-fast obj) :custom-groups)))
(let ((groups (class-option (eieio--object-class obj) :custom-groups)))
(widget-insert "Groups:")
(while groups
(widget-insert " ")
@ -260,7 +260,7 @@ Optional argument IGNORE is an extraneous parameter."
(let ((s (symbol-name
(or
(class-slot-initarg
(object-class-fast obj)
(eieio--object-class obj)
(car slots))
(car slots)))))
(capitalize
@ -287,17 +287,17 @@ Optional argument IGNORE is an extraneous parameter."
"Get the value of WIDGET."
(let* ((obj (widget-get widget :value))
(master-group eieio-cog)
(cv (class-v (object-class-fast obj)))
(fgroup (aref cv class-public-custom-group))
(cv (class-v (eieio--object-class obj)))
(fgroup (eieio--class-public-custom-group cv))
(wids (widget-get widget :children))
(name (if (widget-get widget :eieio-show-name)
(car (widget-apply (car wids) :value-inline))
nil))
(chil (if (widget-get widget :eieio-show-name)
(nthcdr 1 wids) wids))
(cv (class-v (object-class-fast obj)))
(slots (aref cv class-public-a))
(fcust (aref cv class-public-custom)))
(cv (class-v (eieio--object-class obj)))
(slots (eieio--class-public-a cv))
(fcust (eieio--class-public-custom cv)))
;; If there are any prefix widgets, clear them.
;; -- None yet
;; Create a batch of initargs for each slot.
@ -316,7 +316,7 @@ Optional argument IGNORE is an extraneous parameter."
fgroup (cdr fgroup)
fcust (cdr fcust)))
;; Set any name updates on it.
(if name (aset obj object-name name))
(if name (setf (eieio--object-name obj) name))
;; This is the same object we had before.
obj))
@ -354,7 +354,7 @@ These groups are specified with the `:group' slot flag."
(let* ((g (or group 'default)))
(switch-to-buffer (get-buffer-create
(concat "*CUSTOMIZE "
(object-name obj) " "
(eieio-object-name obj) " "
(symbol-name g) "*")))
(setq buffer-read-only nil)
(kill-all-local-variables)
@ -367,7 +367,7 @@ These groups are specified with the `:group' slot flag."
;; Add an apply reset option at the top of the buffer.
(eieio-custom-object-apply-reset obj)
(widget-insert "\n\n")
(widget-insert "Edit object " (object-name obj) "\n\n")
(widget-insert "Edit object " (eieio-object-name obj) "\n\n")
;; Create the widget editing the object.
(make-local-variable 'eieio-wo)
(setq eieio-wo (eieio-custom-widget-insert obj :eieio-group g))
@ -452,7 +452,7 @@ Must return the created widget."
(vector (concat "Group " (symbol-name group))
(list 'customize-object obj (list 'quote group))
t))
(class-option (object-class-fast obj) :custom-groups)))
(class-option (eieio--object-class obj) :custom-groups)))
(defvar eieio-read-custom-group-history nil
"History for the custom group reader.")
@ -460,7 +460,7 @@ Must return the created widget."
(defmethod eieio-read-customization-group ((obj eieio-default-superclass))
"Do a completing read on the name of a customization group in OBJ.
Return the symbol for the group, or nil"
(let ((g (class-option (object-class-fast obj) :custom-groups)))
(let ((g (class-option (eieio--object-class obj) :custom-groups)))
(if (= (length g) 1)
(car g)
;; Make the association list

View file

@ -58,9 +58,9 @@ PREBUTTONTEXT is some text between PREFIX and the object button."
(end nil)
(str (object-print object))
(tip (format "Object %s\nClass: %S\nParent(s): %S\n%d slots"
(object-name-string object)
(object-class object)
(class-parents (object-class object))
(eieio-object-name-string object)
(eieio-object-class object)
(eieio-class-parents (eieio-object-class object))
(length (object-slots object))
))
)
@ -82,16 +82,16 @@ PREBUTTONTEXT is some text between PREFIX and the object button."
(defmethod data-debug/eieio-insert-slots ((obj eieio-default-superclass)
prefix)
"Insert the slots of OBJ into the current DDEBUG buffer."
(data-debug-insert-thing (object-name-string obj)
(data-debug-insert-thing (eieio-object-name-string obj)
prefix
"Name: ")
(let* ((cl (object-class obj))
(let* ((cl (eieio-object-class obj))
(cv (class-v cl)))
(data-debug-insert-thing (class-constructor cl)
prefix
"Class: ")
;; Loop over all the public slots
(let ((publa (aref cv class-public-a))
(let ((publa (eieio--class-public-a cv))
)
(while publa
(if (slot-boundp obj (car publa))
@ -123,7 +123,7 @@ PREBUTTONTEXT is some text between PREFIX and the object button."
;;
(defmethod data-debug-show ((obj eieio-default-superclass))
"Run ddebug against any EIEIO object OBJ."
(data-debug-new-buffer (format "*%s DDEBUG*" (object-name obj)))
(data-debug-new-buffer (format "*%s DDEBUG*" (eieio-object-name obj)))
(data-debug-insert-object-slots obj "]"))
;;; DEBUG FUNCTIONS

View file

@ -45,7 +45,7 @@ variable `eieio-default-superclass'."
nil t)))
nil))
(if (not root-class) (setq root-class 'eieio-default-superclass))
(if (not (class-p root-class)) (signal 'wrong-type-argument (list 'class-p root-class)))
(eieio--check-type class-p root-class)
(display-buffer (get-buffer-create "*EIEIO OBJECT BROWSE*") t)
(with-current-buffer (get-buffer "*EIEIO OBJECT BROWSE*")
(erase-buffer)
@ -58,9 +58,9 @@ variable `eieio-default-superclass'."
Argument THIS-ROOT is the local root of the tree.
Argument PREFIX is the character prefix to use.
Argument CH-PREFIX is another character prefix to display."
(if (not (class-p (eval this-root))) (signal 'wrong-type-argument (list 'class-p this-root)))
(eieio--check-type class-p this-root)
(let ((myname (symbol-name this-root))
(chl (aref (class-v this-root) class-children))
(chl (eieio--class-children (class-v this-root)))
(fprefix (concat ch-prefix " +--"))
(mprefix (concat ch-prefix " | "))
(lprefix (concat ch-prefix " ")))
@ -99,7 +99,7 @@ Optional HEADERFCN should be called to insert a few bits of info first."
(princ "'"))
(terpri)
;; Inheritance tree information
(let ((pl (class-parents class)))
(let ((pl (eieio-class-parents class)))
(when pl
(princ " Inherits from ")
(while pl
@ -107,7 +107,7 @@ Optional HEADERFCN should be called to insert a few bits of info first."
(setq pl (cdr pl))
(if pl (princ ", ")))
(terpri)))
(let ((ch (class-children class)))
(let ((ch (eieio-class-children class)))
(when ch
(princ " Children ")
(while ch
@ -177,13 +177,13 @@ Optional HEADERFCN should be called to insert a few bits of info first."
"Describe the slots in CLASS.
Outputs to the standard output."
(let* ((cv (class-v class))
(docs (aref cv class-public-doc))
(names (aref cv class-public-a))
(deflt (aref cv class-public-d))
(types (aref cv class-public-type))
(publp (aref cv class-public-printer))
(docs (eieio--class-public-doc cv))
(names (eieio--class-public-a cv))
(deflt (eieio--class-public-d cv))
(types (eieio--class-public-type cv))
(publp (eieio--class-public-printer cv))
(i 0)
(prot (aref cv class-protection))
(prot (eieio--class-protection cv))
)
(princ "Instance Allocated Slots:")
(terpri)
@ -213,11 +213,11 @@ Outputs to the standard output."
publp (cdr publp)
prot (cdr prot)
i (1+ i)))
(setq docs (aref cv class-class-allocation-doc)
names (aref cv class-class-allocation-a)
types (aref cv class-class-allocation-type)
(setq docs (eieio--class-class-allocation-doc cv)
names (eieio--class-class-allocation-a cv)
types (eieio--class-class-allocation-type cv)
i 0
prot (aref cv class-class-allocation-protection))
prot (eieio--class-class-allocation-protection cv))
(when names
(terpri)
(princ "Class Allocated Slots:"))
@ -281,7 +281,7 @@ Uses `eieio-describe-class' to describe the class being constructed."
(mapcar
(lambda (c)
(append (list c) (eieio-build-class-list c)))
(class-children-fast class)))
(eieio-class-children-fast class)))
(list class)))
(defun eieio-build-class-alist (&optional class instantiable-only buildlist)
@ -291,7 +291,7 @@ If INSTANTIABLE-ONLY is non nil, only allow names of classes which
are not abstract, otherwise allow all classes.
Optional argument BUILDLIST is more list to attach and is used internally."
(let* ((cc (or class eieio-default-superclass))
(sublst (aref (class-v cc) class-children)))
(sublst (eieio--class-children (class-v cc))))
(unless (assoc (symbol-name cc) buildlist)
(when (or (not instantiable-only) (not (class-abstract-p cc)))
(setq buildlist (cons (cons (symbol-name cc) 1) buildlist))))
@ -335,8 +335,7 @@ are not abstract."
"Describe the generic function GENERIC.
Also extracts information about all methods specific to this generic."
(interactive (list (eieio-read-generic "Generic Method: ")))
(if (not (generic-p generic))
(signal 'wrong-type-argument '(generic-p generic)))
(eieio--check-type generic-p generic)
(with-output-to-temp-buffer (help-buffer) ; "*Help*"
(help-setup-xref (list #'eieio-describe-generic generic)
(called-interactively-p 'interactive))
@ -757,9 +756,8 @@ current expansion depth."
(defun eieio-class-button (class depth)
"Draw a speedbar button at the current point for CLASS at DEPTH."
(if (not (class-p class))
(signal 'wrong-type-argument (list 'class-p class)))
(let ((subclasses (aref (class-v class) class-children)))
(eieio--check-type class-p class)
(let ((subclasses (eieio--class-children (class-v class))))
(if subclasses
(speedbar-make-tag-line 'angle ?+
'eieio-sb-expand
@ -784,7 +782,7 @@ Argument INDENT is the depth of indentation."
(speedbar-with-writable
(save-excursion
(end-of-line) (forward-char 1)
(let ((subclasses (aref (class-v class) class-children)))
(let ((subclasses (eieio--class-children (class-v class))))
(while subclasses
(eieio-class-button (car subclasses) (1+ indent))
(setq subclasses (cdr subclasses)))))))

View file

@ -198,7 +198,7 @@ that path."
(defmethod eieio-speedbar-description (object)
"Return a string describing OBJECT."
(object-name-string object))
(eieio-object-name-string object))
(defmethod eieio-speedbar-derive-line-path (object)
"Return the path which OBJECT has something to do with."
@ -206,7 +206,7 @@ that path."
(defmethod eieio-speedbar-object-buttonname (object)
"Return a string to use as a speedbar button for OBJECT."
(object-name-string object))
(eieio-object-name-string object))
(defmethod eieio-speedbar-make-tag-line (object depth)
"Insert a tag line into speedbar at point for OBJECT.
@ -324,7 +324,7 @@ Argument DEPTH is the depth at which the tag line is inserted."
(defmethod eieio-speedbar-child-make-tag-lines ((object eieio-speedbar) depth)
"Base method for creating tag lines for non-object children."
(error "You must implement `eieio-speedbar-child-make-tag-lines' for %s"
(object-name object)))
(eieio-object-name object)))
(defmethod eieio-speedbar-expand ((object eieio-speedbar) depth)
"Expand OBJECT at indentation DEPTH.
@ -365,7 +365,7 @@ TOKEN is the object. INDENT is the current indentation level."
(defmethod eieio-speedbar-child-description ((obj eieio-speedbar))
"Return a description for a child of OBJ which is not an object."
(error "You must implement `eieio-speedbar-child-description' for %s"
(object-name obj)))
(eieio-object-name obj)))
(defun eieio-speedbar-item-info ()
"Display info for the current line when in EDE display mode."

File diff suppressed because it is too large Load diff