diff options
| author | Stefan Monnier | 2015-01-31 00:48:14 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2015-01-31 00:48:14 -0500 |
| commit | e0be229d5f5e790338a71617a1c244029da4c75b (patch) | |
| tree | 0f0d46006c22a480b85f006b2638801bd3af6b83 | |
| parent | d5e3922e08587e7eb9e5aec2e9f84cbda405f857 (diff) | |
| download | emacs-e0be229d5f5e790338a71617a1c244029da4c75b.tar.gz emacs-e0be229d5f5e790338a71617a1c244029da4c75b.zip | |
EIEIO: Simplify help hyperlinks; Try and reduce hardcoding in .elc
* lisp/emacs-lisp/cl-generic.el (cl--generic-search-method): Fix regexp.
* lisp/emacs-lisp/eieio-core.el (eieio--check-type): Remove.
Use cl-check-type everywhere instead.
(eieio-class-object): Remove, use find-class instead when needed.
(class-p): Don't inline.
(eieio-object-p): Check more thoroughly, so we don't treat cl-structs,
such as eieio classes, as objects. Don't inline.
(object-p): Mark as obsolete.
(eieio-defclass-autoload, eieio-defclass-internal, eieio-oref)
(eieio--generic-tagcode): Avoid `class-p'.
(eieio-make-class-predicate, eieio-make-child-predicate): New functions.
(eieio-defclass-internal): Use current-load-list rather than
`class-location'.
* lisp/emacs-lisp/eieio-opt.el (eieio-help-class, eieio-help-constructor):
Use find-lisp-object-file-name, help-fns-short-filename and new calling
convention for eieio-class-def.
(eieio-build-class-list): Remove function, unused.
(eieio-method-def): Remove button type, unused.
(eieio-class-def): Inherit from help-function-def.
(eieio--defclass-regexp): New constant.
(find-function-regexp-alist): Use it.
(eieio--specializers-apply-to-class-p): Handle eieio--static as well.
(eieio-help-find-method-definition, eieio-help-find-class-definition):
Remove functions.
* lisp/emacs-lisp/eieio.el (defclass): Use new eieio-make-class-predicate
and eieio-make-child-predicate.
(eieio-class-parents): Use eieio--class-object.
(slot-boundp, find-class, eieio-override-prin1): Avoid class-p.
(slot-exists-p): Use find-class.
* test/automated/eieio-tests.el (eieio-test-23-inheritance-check): Simplify.
| -rw-r--r-- | lisp/ChangeLog | 35 | ||||
| -rw-r--r-- | lisp/emacs-lisp/cl-generic.el | 3 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio-base.el | 4 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio-core.el | 111 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio-datadebug.el | 2 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio-opt.el | 99 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio.el | 71 | ||||
| -rw-r--r-- | test/ChangeLog | 4 | ||||
| -rw-r--r-- | test/automated/eieio-tests.el | 5 |
9 files changed, 145 insertions, 189 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3724388dfda..0a3c7c95929 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,38 @@ | |||
| 1 | 2015-01-31 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * emacs-lisp/eieio.el (defclass): Use new eieio-make-class-predicate | ||
| 4 | and eieio-make-child-predicate. | ||
| 5 | (eieio-class-parents): Use eieio--class-object. | ||
| 6 | (slot-boundp, find-class, eieio-override-prin1): Avoid class-p. | ||
| 7 | (slot-exists-p): Use find-class. | ||
| 8 | |||
| 9 | * emacs-lisp/eieio-opt.el (eieio-help-class, eieio-help-constructor): | ||
| 10 | Use find-lisp-object-file-name, help-fns-short-filename and new calling | ||
| 11 | convention for eieio-class-def. | ||
| 12 | (eieio-build-class-list): Remove function, unused. | ||
| 13 | (eieio-method-def): Remove button type, unused. | ||
| 14 | (eieio-class-def): Inherit from help-function-def. | ||
| 15 | (eieio--defclass-regexp): New constant. | ||
| 16 | (find-function-regexp-alist): Use it. | ||
| 17 | (eieio--specializers-apply-to-class-p): Handle eieio--static as well. | ||
| 18 | (eieio-help-find-method-definition, eieio-help-find-class-definition): | ||
| 19 | Remove functions. | ||
| 20 | |||
| 21 | * emacs-lisp/eieio-core.el (eieio--check-type): Remove. | ||
| 22 | Use cl-check-type everywhere instead. | ||
| 23 | (eieio-class-object): Remove, use find-class instead when needed. | ||
| 24 | (class-p): Don't inline. | ||
| 25 | (eieio-object-p): Check more thoroughly, so we don't treat cl-structs, | ||
| 26 | such as eieio classes, as objects. Don't inline. | ||
| 27 | (object-p): Mark as obsolete. | ||
| 28 | (eieio-defclass-autoload, eieio-defclass-internal, eieio-oref) | ||
| 29 | (eieio--generic-tagcode): Avoid `class-p'. | ||
| 30 | (eieio-make-class-predicate, eieio-make-child-predicate): New functions. | ||
| 31 | (eieio-defclass-internal): Use current-load-list rather than | ||
| 32 | `class-location'. | ||
| 33 | |||
| 34 | * emacs-lisp/cl-generic.el (cl--generic-search-method): Fix regexp. | ||
| 35 | |||
| 1 | 2015-01-30 Stefan Monnier <monnier@iro.umontreal.ca> | 36 | 2015-01-30 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 37 | ||
| 3 | * emacs-lisp/backquote.el (backquote-delay-process): Don't reuse `s' | 38 | * emacs-lisp/backquote.el (backquote-delay-process): Don't reuse `s' |
diff --git a/lisp/emacs-lisp/cl-generic.el b/lisp/emacs-lisp/cl-generic.el index 3e34ab6e4d2..72ec8ec1801 100644 --- a/lisp/emacs-lisp/cl-generic.el +++ b/lisp/emacs-lisp/cl-generic.el | |||
| @@ -635,7 +635,8 @@ Can only be used from within the lexical body of a primary or around method." | |||
| 635 | 635 | ||
| 636 | (defun cl--generic-search-method (met-name) | 636 | (defun cl--generic-search-method (met-name) |
| 637 | (let ((base-re (concat "(\\(?:cl-\\)?defmethod[ \t]+" | 637 | (let ((base-re (concat "(\\(?:cl-\\)?defmethod[ \t]+" |
| 638 | (regexp-quote (format "%s\\_>" (car met-name)))))) | 638 | (regexp-quote (format "%s" (car met-name))) |
| 639 | "\\_>"))) | ||
| 639 | (or | 640 | (or |
| 640 | (re-search-forward | 641 | (re-search-forward |
| 641 | (concat base-re "[^&\"\n]*" | 642 | (concat base-re "[^&\"\n]*" |
diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el index feb06711cb3..46585ee76c6 100644 --- a/lisp/emacs-lisp/eieio-base.el +++ b/lisp/emacs-lisp/eieio-base.el | |||
| @@ -219,7 +219,7 @@ for CLASS. Optional ALLOW-SUBCLASS says that it is ok for | |||
| 219 | being pedantic." | 219 | being pedantic." |
| 220 | (unless class | 220 | (unless class |
| 221 | (message "Unsafe call to `eieio-persistent-read'.")) | 221 | (message "Unsafe call to `eieio-persistent-read'.")) |
| 222 | (when class (eieio--check-type class-p class)) | 222 | (when class (cl-check-type class class)) |
| 223 | (let ((ret nil) | 223 | (let ((ret nil) |
| 224 | (buffstr nil)) | 224 | (buffstr nil)) |
| 225 | (unwind-protect | 225 | (unwind-protect |
| @@ -481,7 +481,7 @@ instance." | |||
| 481 | 481 | ||
| 482 | (cl-defmethod eieio-object-set-name-string ((obj eieio-named) name) | 482 | (cl-defmethod eieio-object-set-name-string ((obj eieio-named) name) |
| 483 | "Set the string which is OBJ's NAME." | 483 | "Set the string which is OBJ's NAME." |
| 484 | (eieio--check-type stringp name) | 484 | (cl-check-type name string) |
| 485 | (eieio-oset obj 'object-name name)) | 485 | (eieio-oset obj 'object-name name)) |
| 486 | 486 | ||
| 487 | (cl-defmethod clone ((obj eieio-named) &rest params) | 487 | (cl-defmethod clone ((obj eieio-named) &rest params) |
diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el index d8d39020d0f..77d8c01388b 100644 --- a/lisp/emacs-lisp/eieio-core.el +++ b/lisp/emacs-lisp/eieio-core.el | |||
| @@ -40,6 +40,8 @@ | |||
| 40 | (declare-function slot-unbound "eieio") | 40 | (declare-function slot-unbound "eieio") |
| 41 | (declare-function slot-missing "eieio") | 41 | (declare-function slot-missing "eieio") |
| 42 | (declare-function child-of-class-p "eieio") | 42 | (declare-function child-of-class-p "eieio") |
| 43 | (declare-function same-class-p "eieio") | ||
| 44 | (declare-function object-of-class-p "eieio") | ||
| 43 | 45 | ||
| 44 | 46 | ||
| 45 | ;;; | 47 | ;;; |
| @@ -154,15 +156,6 @@ Currently under control of this var: | |||
| 154 | 156 | ||
| 155 | 157 | ||
| 156 | ;;; Important macros used internally in eieio. | 158 | ;;; Important macros used internally in eieio. |
| 157 | ;; | ||
| 158 | (defmacro eieio--check-type (type obj) | ||
| 159 | (unless (symbolp obj) | ||
| 160 | (error "eieio--check-type wants OBJ to be a variable")) | ||
| 161 | `(if (not ,(cond | ||
| 162 | ((eq 'or (car-safe type)) | ||
| 163 | `(or ,@(mapcar (lambda (type) `(,type ,obj)) (cdr type)))) | ||
| 164 | (t `(,type ,obj)))) | ||
| 165 | (signal 'wrong-type-argument (list ',type ,obj)))) | ||
| 166 | 159 | ||
| 167 | (defmacro eieio--class-v (class) ;Use a macro, so it acts as a GV place. | 160 | (defmacro eieio--class-v (class) ;Use a macro, so it acts as a GV place. |
| 168 | "Internal: Return the class vector from the CLASS symbol." | 161 | "Internal: Return the class vector from the CLASS symbol." |
| @@ -183,27 +176,17 @@ Currently under control of this var: | |||
| 183 | (eq (aref class 0) 'defclass) | 176 | (eq (aref class 0) 'defclass) |
| 184 | (error nil))) | 177 | (error nil))) |
| 185 | 178 | ||
| 186 | (defsubst eieio-class-object (class) | 179 | (defun class-p (class) |
| 187 | "Check that CLASS is a class and return the corresponding object." | ||
| 188 | (let ((c (eieio--class-object class))) | ||
| 189 | (eieio--check-type eieio--class-p c) | ||
| 190 | c)) | ||
| 191 | |||
| 192 | (defsubst class-p (class) | ||
| 193 | "Return non-nil if CLASS is a valid class vector. | 180 | "Return non-nil if CLASS is a valid class vector. |
| 194 | CLASS is a symbol." ;FIXME: Is it a vector or a symbol? | 181 | CLASS is a symbol." ;FIXME: Is it a vector or a symbol? |
| 195 | ;; this new method is faster since it doesn't waste time checking lots of | 182 | (and (symbolp class) (eieio--class-p (eieio--class-v class)))) |
| 196 | ;; things. | ||
| 197 | (condition-case nil | ||
| 198 | (eq (aref (eieio--class-v class) 0) 'defclass) | ||
| 199 | (error nil))) | ||
| 200 | 183 | ||
| 201 | (defun eieio-class-name (class) | 184 | (defun eieio-class-name (class) |
| 202 | "Return a Lisp like symbol name for CLASS." | 185 | "Return a Lisp like symbol name for CLASS." |
| 203 | ;; FIXME: What's a "Lisp like symbol name"? | 186 | ;; FIXME: What's a "Lisp like symbol name"? |
| 204 | ;; FIXME: CLOS returns a symbol, but the code returns a string. | 187 | ;; FIXME: CLOS returns a symbol, but the code returns a string. |
| 205 | (if (eieio--class-p class) (setq class (eieio--class-symbol class))) | 188 | (if (eieio--class-p class) (setq class (eieio--class-symbol class))) |
| 206 | (eieio--check-type class-p class) | 189 | (cl-check-type class class) |
| 207 | ;; I think this is supposed to return a symbol, but to me CLASS is a symbol, | 190 | ;; I think this is supposed to return a symbol, but to me CLASS is a symbol, |
| 208 | ;; and I wanted a string. Arg! | 191 | ;; and I wanted a string. Arg! |
| 209 | (format "#<class %s>" (symbol-name class))) | 192 | (format "#<class %s>" (symbol-name class))) |
| @@ -221,14 +204,17 @@ CLASS is a symbol." ;FIXME: Is it a vector or a symbol? | |||
| 221 | Return nil if that option doesn't exist." | 204 | Return nil if that option doesn't exist." |
| 222 | (eieio--class-option-assoc (eieio--class-options class) option)) | 205 | (eieio--class-option-assoc (eieio--class-options class) option)) |
| 223 | 206 | ||
| 224 | (defsubst eieio-object-p (obj) | 207 | (defun eieio-object-p (obj) |
| 225 | "Return non-nil if OBJ is an EIEIO object." | 208 | "Return non-nil if OBJ is an EIEIO object." |
| 226 | (and (vectorp obj) | 209 | (and (vectorp obj) |
| 227 | (> (length obj) 0) | 210 | (> (length obj) 0) |
| 228 | (eq (symbol-function (eieio--class-tag obj)) | 211 | (let ((tag (eieio--object-class-tag obj))) |
| 229 | :quick-object-witness-check))) | 212 | (and (symbolp tag) |
| 213 | ;; (eq (symbol-function tag) :quick-object-witness-check) | ||
| 214 | (boundp tag) | ||
| 215 | (eieio--class-p (symbol-value tag)))))) | ||
| 230 | 216 | ||
| 231 | (defalias 'object-p 'eieio-object-p) | 217 | (define-obsolete-function-alias 'object-p 'eieio-object-p "25.1") |
| 232 | 218 | ||
| 233 | (defsubst class-abstract-p (class) | 219 | (defsubst class-abstract-p (class) |
| 234 | "Return non-nil if CLASS is abstract. | 220 | "Return non-nil if CLASS is abstract. |
| @@ -266,10 +252,9 @@ It creates an autoload function for CNAME's constructor." | |||
| 266 | ;; simply not exist yet. So instead we just don't store the list of parents | 252 | ;; simply not exist yet. So instead we just don't store the list of parents |
| 267 | ;; here in eieio-defclass-autoload at all, since it seems that they're just | 253 | ;; here in eieio-defclass-autoload at all, since it seems that they're just |
| 268 | ;; not needed before the class is actually loaded. | 254 | ;; not needed before the class is actually loaded. |
| 269 | (let* ((oldc (when (class-p cname) (eieio--class-v cname))) | 255 | (let* ((oldc (eieio--class-v cname)) |
| 270 | (newc (eieio--class-make cname)) | 256 | (newc (eieio--class-make cname))) |
| 271 | ) | 257 | (if (eieio--class-p oldc) |
| 272 | (if oldc | ||
| 273 | nil ;; Do nothing if we already have this class. | 258 | nil ;; Do nothing if we already have this class. |
| 274 | 259 | ||
| 275 | ;; turn this into a usable self-pointing symbol | 260 | ;; turn this into a usable self-pointing symbol |
| @@ -300,7 +285,21 @@ It creates an autoload function for CNAME's constructor." | |||
| 300 | (cl-every (lambda (elem) (cl-typep elem ',elem-type)) | 285 | (cl-every (lambda (elem) (cl-typep elem ',elem-type)) |
| 301 | list))))) | 286 | list))))) |
| 302 | 287 | ||
| 303 | (declare-function eieio--defmethod "eieio-generic" (method kind argclass code)) | 288 | |
| 289 | (defun eieio-make-class-predicate (class) | ||
| 290 | (lambda (obj) | ||
| 291 | ;; (:docstring (format "Test OBJ to see if it's an object of type %S." | ||
| 292 | ;; class)) | ||
| 293 | (and (eieio-object-p obj) | ||
| 294 | (same-class-p obj class)))) | ||
| 295 | |||
| 296 | (defun eieio-make-child-predicate (class) | ||
| 297 | (lambda (obj) | ||
| 298 | ;; (:docstring (format | ||
| 299 | ;; "Test OBJ to see if it's an object is a child of type %S." | ||
| 300 | ;; class)) | ||
| 301 | (and (eieio-object-p obj) | ||
| 302 | (object-of-class-p obj class)))) | ||
| 304 | 303 | ||
| 305 | (defun eieio-defclass-internal (cname superclasses slots options) | 304 | (defun eieio-defclass-internal (cname superclasses slots options) |
| 306 | "Define CNAME as a new subclass of SUPERCLASSES. | 305 | "Define CNAME as a new subclass of SUPERCLASSES. |
| @@ -314,7 +313,7 @@ See `defclass' for more information." | |||
| 314 | (setq eieio-hook nil) | 313 | (setq eieio-hook nil) |
| 315 | 314 | ||
| 316 | (let* ((pname superclasses) | 315 | (let* ((pname superclasses) |
| 317 | (oldc (when (class-p cname) (eieio--class-v cname))) | 316 | (oldc (let ((c (eieio--class-v cname))) (if (eieio--class-p c) c))) |
| 318 | (newc (if (and oldc (not (eieio--class-default-object-cache oldc))) | 317 | (newc (if (and oldc (not (eieio--class-default-object-cache oldc))) |
| 319 | ;; The oldc class is a stub setup by eieio-defclass-autoload. | 318 | ;; The oldc class is a stub setup by eieio-defclass-autoload. |
| 320 | ;; Reuse it instead of creating a new one, so that existing | 319 | ;; Reuse it instead of creating a new one, so that existing |
| @@ -342,19 +341,20 @@ See `defclass' for more information." | |||
| 342 | (if pname | 341 | (if pname |
| 343 | (progn | 342 | (progn |
| 344 | (dolist (p pname) | 343 | (dolist (p pname) |
| 345 | (if (and p (symbolp p)) | 344 | (if (not (and p (symbolp p))) |
| 346 | (if (not (class-p p)) | 345 | (error "Invalid parent class %S" p) |
| 346 | (let ((c (eieio--class-v p))) | ||
| 347 | (if (not (eieio--class-p c)) | ||
| 347 | ;; bad class | 348 | ;; bad class |
| 348 | (error "Given parent class %S is not a class" p) | 349 | (error "Given parent class %S is not a class" p) |
| 349 | ;; good parent class... | 350 | ;; good parent class... |
| 350 | ;; save new child in parent | 351 | ;; save new child in parent |
| 351 | (cl-pushnew cname (eieio--class-children (eieio--class-v p))) | 352 | (cl-pushnew cname (eieio--class-children c)) |
| 352 | ;; Get custom groups, and store them into our local copy. | 353 | ;; Get custom groups, and store them into our local copy. |
| 353 | (mapc (lambda (g) (cl-pushnew g groups :test #'equal)) | 354 | (mapc (lambda (g) (cl-pushnew g groups :test #'equal)) |
| 354 | (eieio--class-option (eieio--class-v p) :custom-groups)) | 355 | (eieio--class-option c :custom-groups)) |
| 355 | ;; save parent in child | 356 | ;; Save parent in child. |
| 356 | (push (eieio--class-v p) (eieio--class-parent newc))) | 357 | (push c (eieio--class-parent newc)))))) |
| 357 | (error "Invalid parent class %S" p))) | ||
| 358 | ;; Reverse the list of our parents so that they are prioritized in | 358 | ;; Reverse the list of our parents so that they are prioritized in |
| 359 | ;; the same order as specified in the code. | 359 | ;; the same order as specified in the code. |
| 360 | (cl-callf nreverse (eieio--class-parent newc))) | 360 | (cl-callf nreverse (eieio--class-parent newc))) |
| @@ -506,13 +506,7 @@ See `defclass' for more information." | |||
| 506 | (eieio--class-option-assoc options :documentation)) | 506 | (eieio--class-option-assoc options :documentation)) |
| 507 | 507 | ||
| 508 | ;; Save the file location where this class is defined. | 508 | ;; Save the file location where this class is defined. |
| 509 | (let ((fname (if load-in-progress | 509 | (add-to-list 'current-load-list `(eieio-defclass . ,cname)) |
| 510 | load-file-name | ||
| 511 | buffer-file-name))) | ||
| 512 | (when fname | ||
| 513 | (when (string-match "\\.elc\\'" fname) | ||
| 514 | (setq fname (substring fname 0 (1- (length fname))))) | ||
| 515 | (put cname 'class-location fname))) | ||
| 516 | 510 | ||
| 517 | ;; We have a list of custom groups. Store them into the options. | 511 | ;; We have a list of custom groups. Store them into the options. |
| 518 | (let ((g (eieio--class-option-assoc options :custom-groups))) | 512 | (let ((g (eieio--class-option-assoc options :custom-groups))) |
| @@ -909,12 +903,13 @@ Argument FN is the function calling this verifier." | |||
| 909 | ;; | 903 | ;; |
| 910 | (defun eieio-oref (obj slot) | 904 | (defun eieio-oref (obj slot) |
| 911 | "Return the value in OBJ at SLOT in the object vector." | 905 | "Return the value in OBJ at SLOT in the object vector." |
| 912 | (eieio--check-type (or eieio-object-p class-p) obj) | 906 | (cl-check-type slot symbol) |
| 913 | (eieio--check-type symbolp slot) | 907 | (cl-check-type obj (or eieio-object class)) |
| 914 | (if (class-p obj) (eieio-class-un-autoload obj)) | ||
| 915 | (let* ((class (cond ((symbolp obj) | 908 | (let* ((class (cond ((symbolp obj) |
| 916 | (error "eieio-oref called on a class!") | 909 | (error "eieio-oref called on a class!") |
| 917 | (eieio--class-v obj)) | 910 | (let ((c (eieio--class-v obj))) |
| 911 | (if (eieio--class-p c) (eieio-class-un-autoload obj)) | ||
| 912 | c)) | ||
| 918 | (t (eieio--object-class-object obj)))) | 913 | (t (eieio--object-class-object obj)))) |
| 919 | (c (eieio--slot-name-index class obj slot))) | 914 | (c (eieio--slot-name-index class obj slot))) |
| 920 | (if (not c) | 915 | (if (not c) |
| @@ -929,15 +924,15 @@ Argument FN is the function calling this verifier." | |||
| 929 | (slot-missing obj slot 'oref) | 924 | (slot-missing obj slot 'oref) |
| 930 | ;;(signal 'invalid-slot-name (list (eieio-object-name obj) slot)) | 925 | ;;(signal 'invalid-slot-name (list (eieio-object-name obj) slot)) |
| 931 | ) | 926 | ) |
| 932 | (eieio--check-type eieio-object-p obj) | 927 | (cl-check-type obj eieio-object) |
| 933 | (eieio-barf-if-slot-unbound (aref obj c) obj slot 'oref)))) | 928 | (eieio-barf-if-slot-unbound (aref obj c) obj slot 'oref)))) |
| 934 | 929 | ||
| 935 | 930 | ||
| 936 | (defun eieio-oref-default (obj slot) | 931 | (defun eieio-oref-default (obj slot) |
| 937 | "Do the work for the macro `oref-default' with similar parameters. | 932 | "Do the work for the macro `oref-default' with similar parameters. |
| 938 | Fills in OBJ's SLOT with its default value." | 933 | Fills in OBJ's SLOT with its default value." |
| 939 | (eieio--check-type (or eieio-object-p class-p) obj) | 934 | (cl-check-type obj (or eieio-object class)) |
| 940 | (eieio--check-type symbolp slot) | 935 | (cl-check-type slot symbol) |
| 941 | (let* ((cl (cond ((symbolp obj) (eieio--class-v obj)) | 936 | (let* ((cl (cond ((symbolp obj) (eieio--class-v obj)) |
| 942 | (t (eieio--object-class-object obj)))) | 937 | (t (eieio--object-class-object obj)))) |
| 943 | (c (eieio--slot-name-index cl obj slot))) | 938 | (c (eieio--slot-name-index cl obj slot))) |
| @@ -975,8 +970,8 @@ Fills in OBJ's SLOT with its default value." | |||
| 975 | (defun eieio-oset (obj slot value) | 970 | (defun eieio-oset (obj slot value) |
| 976 | "Do the work for the macro `oset'. | 971 | "Do the work for the macro `oset'. |
| 977 | Fills in OBJ's SLOT with VALUE." | 972 | Fills in OBJ's SLOT with VALUE." |
| 978 | (eieio--check-type eieio-object-p obj) | 973 | (cl-check-type obj eieio-object) |
| 979 | (eieio--check-type symbolp slot) | 974 | (cl-check-type slot symbol) |
| 980 | (let* ((class (eieio--object-class-object obj)) | 975 | (let* ((class (eieio--object-class-object obj)) |
| 981 | (c (eieio--slot-name-index class obj slot))) | 976 | (c (eieio--slot-name-index class obj slot))) |
| 982 | (if (not c) | 977 | (if (not c) |
| @@ -1000,8 +995,8 @@ Fills in OBJ's SLOT with VALUE." | |||
| 1000 | "Do the work for the macro `oset-default'. | 995 | "Do the work for the macro `oset-default'. |
| 1001 | Fills in the default value in CLASS' in SLOT with VALUE." | 996 | Fills in the default value in CLASS' in SLOT with VALUE." |
| 1002 | (setq class (eieio--class-object class)) | 997 | (setq class (eieio--class-object class)) |
| 1003 | (eieio--check-type eieio--class-p class) | 998 | (cl-check-type class eieio--class) |
| 1004 | (eieio--check-type symbolp slot) | 999 | (cl-check-type slot symbol) |
| 1005 | (let* ((c (eieio--slot-name-index class nil slot))) | 1000 | (let* ((c (eieio--slot-name-index class nil slot))) |
| 1006 | (if (not c) | 1001 | (if (not c) |
| 1007 | ;; It might be missing because it is a :class allocated slot. | 1002 | ;; It might be missing because it is a :class allocated slot. |
| @@ -1223,7 +1218,7 @@ method invocation orders of the involved classes." | |||
| 1223 | ;; A class must be defined before it can be used as a parameter | 1218 | ;; A class must be defined before it can be used as a parameter |
| 1224 | ;; specializer in a defmethod form. | 1219 | ;; specializer in a defmethod form. |
| 1225 | ;; So we can ignore types that are not known to denote classes. | 1220 | ;; So we can ignore types that are not known to denote classes. |
| 1226 | (and (class-p type) | 1221 | (and (eieio--class-p (eieio--class-object type)) |
| 1227 | ;; Use the exact same code as for cl-struct, so that methods | 1222 | ;; Use the exact same code as for cl-struct, so that methods |
| 1228 | ;; that dispatch on both kinds of objects get to share this | 1223 | ;; that dispatch on both kinds of objects get to share this |
| 1229 | ;; part of the dispatch code. | 1224 | ;; part of the dispatch code. |
diff --git a/lisp/emacs-lisp/eieio-datadebug.el b/lisp/emacs-lisp/eieio-datadebug.el index 119f7cce038..82349192e5e 100644 --- a/lisp/emacs-lisp/eieio-datadebug.el +++ b/lisp/emacs-lisp/eieio-datadebug.el | |||
| @@ -117,7 +117,7 @@ PREBUTTONTEXT is some text between PREFIX and the object button." | |||
| 117 | (setq publa (cdr publa))))))) | 117 | (setq publa (cdr publa))))))) |
| 118 | 118 | ||
| 119 | ;;; Augment the Data debug thing display list. | 119 | ;;; Augment the Data debug thing display list. |
| 120 | (data-debug-add-specialized-thing (lambda (thing) (object-p thing)) | 120 | (data-debug-add-specialized-thing (lambda (thing) (eieio-object-p thing)) |
| 121 | #'data-debug-insert-object-button) | 121 | #'data-debug-insert-object-button) |
| 122 | 122 | ||
| 123 | ;;; DEBUG METHODS | 123 | ;;; DEBUG METHODS |
diff --git a/lisp/emacs-lisp/eieio-opt.el b/lisp/emacs-lisp/eieio-opt.el index 8d40edf5624..304ee364dc8 100644 --- a/lisp/emacs-lisp/eieio-opt.el +++ b/lisp/emacs-lisp/eieio-opt.el | |||
| @@ -45,7 +45,7 @@ variable `eieio-default-superclass'." | |||
| 45 | nil t))) | 45 | nil t))) |
| 46 | nil)) | 46 | nil)) |
| 47 | (if (not root-class) (setq root-class 'eieio-default-superclass)) | 47 | (if (not root-class) (setq root-class 'eieio-default-superclass)) |
| 48 | (eieio--check-type class-p root-class) | 48 | (cl-check-type root-class class) |
| 49 | (display-buffer (get-buffer-create "*EIEIO OBJECT BROWSE*") t) | 49 | (display-buffer (get-buffer-create "*EIEIO OBJECT BROWSE*") t) |
| 50 | (with-current-buffer (get-buffer "*EIEIO OBJECT BROWSE*") | 50 | (with-current-buffer (get-buffer "*EIEIO OBJECT BROWSE*") |
| 51 | (erase-buffer) | 51 | (erase-buffer) |
| @@ -58,7 +58,7 @@ variable `eieio-default-superclass'." | |||
| 58 | Argument THIS-ROOT is the local root of the tree. | 58 | Argument THIS-ROOT is the local root of the tree. |
| 59 | Argument PREFIX is the character prefix to use. | 59 | Argument PREFIX is the character prefix to use. |
| 60 | Argument CH-PREFIX is another character prefix to display." | 60 | Argument CH-PREFIX is another character prefix to display." |
| 61 | (eieio--check-type class-p this-root) | 61 | (cl-check-type this-root class) |
| 62 | (let ((myname (symbol-name this-root)) | 62 | (let ((myname (symbol-name this-root)) |
| 63 | (chl (eieio--class-children (eieio--class-v this-root))) | 63 | (chl (eieio--class-children (eieio--class-v this-root))) |
| 64 | (fprefix (concat ch-prefix " +--")) | 64 | (fprefix (concat ch-prefix " +--")) |
| @@ -85,12 +85,12 @@ If CLASS is actually an object, then also display current values of that object. | |||
| 85 | "n abstract" | 85 | "n abstract" |
| 86 | "") | 86 | "") |
| 87 | " class") | 87 | " class") |
| 88 | (let ((location (get class 'class-location))) | 88 | (let ((location (find-lisp-object-file-name class 'eieio-defclass))) |
| 89 | (when location | 89 | (when location |
| 90 | (insert " in `") | 90 | (insert " in `") |
| 91 | (help-insert-xref-button | 91 | (help-insert-xref-button |
| 92 | (file-name-nondirectory location) | 92 | (help-fns-short-filename location) |
| 93 | 'eieio-class-def class location) | 93 | 'eieio-class-def class location 'eieio-defclass) |
| 94 | (insert "'"))) | 94 | (insert "'"))) |
| 95 | (insert ".\n") | 95 | (insert ".\n") |
| 96 | ;; Parents | 96 | ;; Parents |
| @@ -204,15 +204,6 @@ Outputs to the current buffer." | |||
| 204 | prot (cdr prot) | 204 | prot (cdr prot) |
| 205 | i (1+ i))))) | 205 | i (1+ i))))) |
| 206 | 206 | ||
| 207 | (defun eieio-build-class-list (class) | ||
| 208 | "Return a list of all classes that inherit from CLASS." | ||
| 209 | (if (class-p class) | ||
| 210 | (cl-mapcan | ||
| 211 | (lambda (c) | ||
| 212 | (append (list c) (eieio-build-class-list c))) | ||
| 213 | (eieio--class-children (eieio--class-v class))) | ||
| 214 | (list class))) | ||
| 215 | |||
| 216 | (defun eieio-build-class-alist (&optional class instantiable-only buildlist) | 207 | (defun eieio-build-class-alist (&optional class instantiable-only buildlist) |
| 217 | "Return an alist of all currently active classes for completion purposes. | 208 | "Return an alist of all currently active classes for completion purposes. |
| 218 | Optional argument CLASS is the class to start with. | 209 | Optional argument CLASS is the class to start with. |
| @@ -256,24 +247,22 @@ are not abstract." | |||
| 256 | 247 | ||
| 257 | ;;; METHOD COMPLETION / DOC | 248 | ;;; METHOD COMPLETION / DOC |
| 258 | 249 | ||
| 259 | (define-button-type 'eieio-method-def | ||
| 260 | :supertype 'help-xref | ||
| 261 | 'help-function (lambda (class method file) | ||
| 262 | (eieio-help-find-method-definition class method file)) | ||
| 263 | 'help-echo (purecopy "mouse-2, RET: find method's definition")) | ||
| 264 | |||
| 265 | (define-button-type 'eieio-class-def | 250 | (define-button-type 'eieio-class-def |
| 266 | :supertype 'help-xref | 251 | :supertype 'help-function-def |
| 267 | 'help-function (lambda (class file) | ||
| 268 | (eieio-help-find-class-definition class file)) | ||
| 269 | 'help-echo (purecopy "mouse-2, RET: find class definition")) | 252 | 'help-echo (purecopy "mouse-2, RET: find class definition")) |
| 270 | 253 | ||
| 254 | (defconst eieio--defclass-regexp "(defclass[ \t\r\n]+%s[ \t\r\n]+") | ||
| 255 | (with-eval-after-load 'find-func | ||
| 256 | (defvar find-function-regexp-alist) | ||
| 257 | (add-to-list 'find-function-regexp-alist | ||
| 258 | `(eieio-defclass . eieio--defclass-regexp))) | ||
| 259 | |||
| 271 | ;;;###autoload | 260 | ;;;###autoload |
| 272 | (defun eieio-help-constructor (ctr) | 261 | (defun eieio-help-constructor (ctr) |
| 273 | "Describe CTR if it is a class constructor." | 262 | "Describe CTR if it is a class constructor." |
| 274 | (when (class-p ctr) | 263 | (when (class-p ctr) |
| 275 | (erase-buffer) | 264 | (erase-buffer) |
| 276 | (let ((location (get ctr 'class-location)) | 265 | (let ((location (find-lisp-object-file-name ctr 'eieio-defclass)) |
| 277 | (def (symbol-function ctr))) | 266 | (def (symbol-function ctr))) |
| 278 | (goto-char (point-min)) | 267 | (goto-char (point-min)) |
| 279 | (prin1 ctr) | 268 | (prin1 ctr) |
| @@ -288,8 +277,8 @@ are not abstract." | |||
| 288 | (when location | 277 | (when location |
| 289 | (insert " in `") | 278 | (insert " in `") |
| 290 | (help-insert-xref-button | 279 | (help-insert-xref-button |
| 291 | (file-name-nondirectory location) | 280 | (help-fns-short-filename location) |
| 292 | 'eieio-class-def ctr location) | 281 | 'eieio-class-def ctr location 'eieio-defclass) |
| 293 | (insert "'")) | 282 | (insert "'")) |
| 294 | (insert ".\nCreates an object of class " (symbol-name ctr) ".") | 283 | (insert ".\nCreates an object of class " (symbol-name ctr) ".") |
| 295 | (goto-char (point-max)) | 284 | (goto-char (point-max)) |
| @@ -304,7 +293,7 @@ are not abstract." | |||
| 304 | "Return non-nil if a method with SPECIALIZERS applies to CLASS." | 293 | "Return non-nil if a method with SPECIALIZERS applies to CLASS." |
| 305 | (let ((applies nil)) | 294 | (let ((applies nil)) |
| 306 | (dolist (specializer specializers) | 295 | (dolist (specializer specializers) |
| 307 | (if (eq 'subclass (car-safe specializer)) | 296 | (if (memq (car-safe specializer) '(subclass eieio--static)) |
| 308 | (setq specializer (nth 1 specializer))) | 297 | (setq specializer (nth 1 specializer))) |
| 309 | ;; Don't include the methods that are "too generic", such as those | 298 | ;; Don't include the methods that are "too generic", such as those |
| 310 | ;; applying to `eieio-default-superclass'. | 299 | ;; applying to `eieio-default-superclass'. |
| @@ -443,60 +432,6 @@ The value returned is a list of elements of the form | |||
| 443 | (terpri) | 432 | (terpri) |
| 444 | )) | 433 | )) |
| 445 | 434 | ||
| 446 | ;;; HELP AUGMENTATION | ||
| 447 | ;; | ||
| 448 | (defun eieio-help-find-method-definition (class method file) | ||
| 449 | (let ((filename (find-library-name file)) | ||
| 450 | location buf) | ||
| 451 | (when (symbolp class) | ||
| 452 | (setq class (symbol-name class))) | ||
| 453 | (when (symbolp method) | ||
| 454 | (setq method (symbol-name method))) | ||
| 455 | (when (null filename) | ||
| 456 | (error "Cannot find library %s" file)) | ||
| 457 | (setq buf (find-file-noselect filename)) | ||
| 458 | (with-current-buffer buf | ||
| 459 | (goto-char (point-min)) | ||
| 460 | (when | ||
| 461 | (re-search-forward | ||
| 462 | ;; Regexp for searching methods. | ||
| 463 | (concat "(defmethod[ \t\r\n]+" method | ||
| 464 | "\\([ \t\r\n]+:[a-zA-Z]+\\)?" | ||
| 465 | "[ \t\r\n]+(\\s-*(\\(\\sw\\|\\s_\\)+\\s-+" | ||
| 466 | class | ||
| 467 | "\\s-*)") | ||
| 468 | nil t) | ||
| 469 | (setq location (match-beginning 0)))) | ||
| 470 | (if (null location) | ||
| 471 | (message "Unable to find location in file") | ||
| 472 | (pop-to-buffer buf) | ||
| 473 | (goto-char location) | ||
| 474 | (recenter) | ||
| 475 | (beginning-of-line)))) | ||
| 476 | |||
| 477 | (defun eieio-help-find-class-definition (class file) | ||
| 478 | (when (symbolp class) | ||
| 479 | (setq class (symbol-name class))) | ||
| 480 | (let ((filename (find-library-name file)) | ||
| 481 | location buf) | ||
| 482 | (when (null filename) | ||
| 483 | (error "Cannot find library %s" file)) | ||
| 484 | (setq buf (find-file-noselect filename)) | ||
| 485 | (with-current-buffer buf | ||
| 486 | (goto-char (point-min)) | ||
| 487 | (when | ||
| 488 | (re-search-forward | ||
| 489 | ;; Regexp for searching a class. | ||
| 490 | (concat "(defclass[ \t\r\n]+" class "[ \t\r\n]+") | ||
| 491 | nil t) | ||
| 492 | (setq location (match-beginning 0)))) | ||
| 493 | (if (null location) | ||
| 494 | (message "Unable to find location in file") | ||
| 495 | (pop-to-buffer buf) | ||
| 496 | (goto-char location) | ||
| 497 | (recenter) | ||
| 498 | (beginning-of-line)))) | ||
| 499 | |||
| 500 | ;;; SPEEDBAR SUPPORT | 435 | ;;; SPEEDBAR SUPPORT |
| 501 | ;; | 436 | ;; |
| 502 | 437 | ||
| @@ -546,7 +481,7 @@ current expansion depth." | |||
| 546 | 481 | ||
| 547 | (defun eieio-class-button (class depth) | 482 | (defun eieio-class-button (class depth) |
| 548 | "Draw a speedbar button at the current point for CLASS at DEPTH." | 483 | "Draw a speedbar button at the current point for CLASS at DEPTH." |
| 549 | (eieio--check-type class-p class) | 484 | (cl-check-type class class) |
| 550 | (let ((subclasses (eieio--class-children (eieio--class-v class)))) | 485 | (let ((subclasses (eieio--class-children (eieio--class-v class)))) |
| 551 | (if subclasses | 486 | (if subclasses |
| 552 | (speedbar-make-tag-line 'angle ?+ | 487 | (speedbar-make-tag-line 'angle ?+ |
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index 91469b4b96c..526090954a9 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el | |||
| @@ -110,7 +110,7 @@ Options in CLOS not supported in EIEIO: | |||
| 110 | Due to the way class options are set up, you can add any tags you wish, | 110 | Due to the way class options are set up, you can add any tags you wish, |
| 111 | and reference them using the function `class-option'." | 111 | and reference them using the function `class-option'." |
| 112 | (declare (doc-string 4)) | 112 | (declare (doc-string 4)) |
| 113 | (eieio--check-type listp superclasses) | 113 | (cl-check-type superclasses list) |
| 114 | 114 | ||
| 115 | (cond ((and (stringp (car options-and-doc)) | 115 | (cond ((and (stringp (car options-and-doc)) |
| 116 | (/= 1 (% (length options-and-doc) 2))) | 116 | (/= 1 (% (length options-and-doc) 2))) |
| @@ -223,18 +223,9 @@ This method is obsolete." | |||
| 223 | ;; referencing classes. ei, a class whose slot can contain only | 223 | ;; referencing classes. ei, a class whose slot can contain only |
| 224 | ;; pointers to itself. | 224 | ;; pointers to itself. |
| 225 | 225 | ||
| 226 | ;; Create the test function. | 226 | ;; Create the test functions. |
| 227 | (defun ,testsym1 (obj) | 227 | (defalias ',testsym1 (eieio-make-class-predicate ',name)) |
| 228 | ,(format "Test OBJ to see if it an object of type %S." name) | 228 | (defalias ',testsym2 (eieio-make-child-predicate ',name)) |
| 229 | (and (eieio-object-p obj) | ||
| 230 | (same-class-p obj ',name))) | ||
| 231 | |||
| 232 | (defun ,testsym2 (obj) | ||
| 233 | ,(format | ||
| 234 | "Test OBJ to see if it an object is a child of type %S." | ||
| 235 | name) | ||
| 236 | (and (eieio-object-p obj) | ||
| 237 | (object-of-class-p obj ',name))) | ||
| 238 | 229 | ||
| 239 | ,@(when eieio-backward-compatibility | 230 | ,@(when eieio-backward-compatibility |
| 240 | (let ((f (intern (format "%s-child-p" name)))) | 231 | (let ((f (intern (format "%s-child-p" name)))) |
| @@ -374,7 +365,7 @@ variable name of the same name as the slot." | |||
| 374 | (defun eieio-object-name (obj &optional extra) | 365 | (defun eieio-object-name (obj &optional extra) |
| 375 | "Return a Lisp like symbol string for object OBJ. | 366 | "Return a Lisp like symbol string for object OBJ. |
| 376 | If EXTRA, include that in the string returned to represent the symbol." | 367 | If EXTRA, include that in the string returned to represent the symbol." |
| 377 | (eieio--check-type eieio-object-p obj) | 368 | (cl-check-type obj eieio-object) |
| 378 | (format "#<%s %s%s>" (eieio--object-class-name obj) | 369 | (format "#<%s %s%s>" (eieio--object-class-name obj) |
| 379 | (eieio-object-name-string obj) (or extra ""))) | 370 | (eieio-object-name-string obj) (or extra ""))) |
| 380 | (define-obsolete-function-alias 'object-name #'eieio-object-name "24.4") | 371 | (define-obsolete-function-alias 'object-name #'eieio-object-name "24.4") |
| @@ -394,7 +385,7 @@ If EXTRA, include that in the string returned to represent the symbol." | |||
| 394 | (cl-defmethod eieio-object-set-name-string (obj name) | 385 | (cl-defmethod eieio-object-set-name-string (obj name) |
| 395 | "Set the string which is OBJ's NAME." | 386 | "Set the string which is OBJ's NAME." |
| 396 | (declare (obsolete eieio-named "25.1")) | 387 | (declare (obsolete eieio-named "25.1")) |
| 397 | (eieio--check-type stringp name) | 388 | (cl-check-type name string) |
| 398 | (setf (gethash obj eieio--object-names) name)) | 389 | (setf (gethash obj eieio--object-names) name)) |
| 399 | (define-obsolete-function-alias | 390 | (define-obsolete-function-alias |
| 400 | 'object-set-name-string 'eieio-object-set-name-string "24.4") | 391 | 'object-set-name-string 'eieio-object-set-name-string "24.4") |
| @@ -402,7 +393,7 @@ If EXTRA, include that in the string returned to represent the symbol." | |||
| 402 | (defun eieio-object-class (obj) | 393 | (defun eieio-object-class (obj) |
| 403 | "Return the class struct defining OBJ." | 394 | "Return the class struct defining OBJ." |
| 404 | ;; FIXME: We say we return a "struct" but we return a symbol instead! | 395 | ;; FIXME: We say we return a "struct" but we return a symbol instead! |
| 405 | (eieio--check-type eieio-object-p obj) | 396 | (cl-check-type obj eieio-object) |
| 406 | (eieio--object-class-name obj)) | 397 | (eieio--object-class-name obj)) |
| 407 | (define-obsolete-function-alias 'object-class #'eieio-object-class "24.4") | 398 | (define-obsolete-function-alias 'object-class #'eieio-object-class "24.4") |
| 408 | ;; CLOS name, maybe? | 399 | ;; CLOS name, maybe? |
| @@ -410,7 +401,7 @@ If EXTRA, include that in the string returned to represent the symbol." | |||
| 410 | 401 | ||
| 411 | (defun eieio-object-class-name (obj) | 402 | (defun eieio-object-class-name (obj) |
| 412 | "Return a Lisp like symbol name for OBJ's class." | 403 | "Return a Lisp like symbol name for OBJ's class." |
| 413 | (eieio--check-type eieio-object-p obj) | 404 | (cl-check-type obj eieio-object) |
| 414 | (eieio-class-name (eieio--object-class-name obj))) | 405 | (eieio-class-name (eieio--object-class-name obj))) |
| 415 | (define-obsolete-function-alias | 406 | (define-obsolete-function-alias |
| 416 | 'object-class-name 'eieio-object-class-name "24.4") | 407 | 'object-class-name 'eieio-object-class-name "24.4") |
| @@ -419,15 +410,14 @@ If EXTRA, include that in the string returned to represent the symbol." | |||
| 419 | "Return parent classes to CLASS. (overload of variable). | 410 | "Return parent classes to CLASS. (overload of variable). |
| 420 | 411 | ||
| 421 | The CLOS function `class-direct-superclasses' is aliased to this function." | 412 | The CLOS function `class-direct-superclasses' is aliased to this function." |
| 422 | (let ((c (eieio-class-object class))) | 413 | (eieio--class-parent (eieio--class-object class))) |
| 423 | (eieio--class-parent c))) | ||
| 424 | 414 | ||
| 425 | (define-obsolete-function-alias 'class-parents #'eieio-class-parents "24.4") | 415 | (define-obsolete-function-alias 'class-parents #'eieio-class-parents "24.4") |
| 426 | 416 | ||
| 427 | (defun eieio-class-children (class) | 417 | (defun eieio-class-children (class) |
| 428 | "Return child classes to CLASS. | 418 | "Return child classes to CLASS. |
| 429 | The CLOS function `class-direct-subclasses' is aliased to this function." | 419 | The CLOS function `class-direct-subclasses' is aliased to this function." |
| 430 | (eieio--check-type class-p class) | 420 | (cl-check-type class class) |
| 431 | (eieio--class-children (eieio--class-v class))) | 421 | (eieio--class-children (eieio--class-v class))) |
| 432 | (define-obsolete-function-alias | 422 | (define-obsolete-function-alias |
| 433 | 'class-children #'eieio-class-children "24.4") | 423 | 'class-children #'eieio-class-children "24.4") |
| @@ -446,13 +436,13 @@ The CLOS function `class-direct-subclasses' is aliased to this function." | |||
| 446 | (defun same-class-p (obj class) | 436 | (defun same-class-p (obj class) |
| 447 | "Return t if OBJ is of class-type CLASS." | 437 | "Return t if OBJ is of class-type CLASS." |
| 448 | (setq class (eieio--class-object class)) | 438 | (setq class (eieio--class-object class)) |
| 449 | (eieio--check-type eieio--class-p class) | 439 | (cl-check-type class eieio--class) |
| 450 | (eieio--check-type eieio-object-p obj) | 440 | (cl-check-type obj eieio-object) |
| 451 | (eq (eieio--object-class-object obj) class)) | 441 | (eq (eieio--object-class-object obj) class)) |
| 452 | 442 | ||
| 453 | (defun object-of-class-p (obj class) | 443 | (defun object-of-class-p (obj class) |
| 454 | "Return non-nil if OBJ is an instance of CLASS or CLASS' subclasses." | 444 | "Return non-nil if OBJ is an instance of CLASS or CLASS' subclasses." |
| 455 | (eieio--check-type eieio-object-p obj) | 445 | (cl-check-type obj eieio-object) |
| 456 | ;; class will be checked one layer down | 446 | ;; class will be checked one layer down |
| 457 | (child-of-class-p (eieio--object-class-object obj) class)) | 447 | (child-of-class-p (eieio--object-class-object obj) class)) |
| 458 | ;; Backwards compatibility | 448 | ;; Backwards compatibility |
| @@ -461,13 +451,13 @@ The CLOS function `class-direct-subclasses' is aliased to this function." | |||
| 461 | (defun child-of-class-p (child class) | 451 | (defun child-of-class-p (child class) |
| 462 | "Return non-nil if CHILD class is a subclass of CLASS." | 452 | "Return non-nil if CHILD class is a subclass of CLASS." |
| 463 | (setq child (eieio--class-object child)) | 453 | (setq child (eieio--class-object child)) |
| 464 | (eieio--check-type eieio--class-p child) | 454 | (cl-check-type child eieio--class) |
| 465 | ;; `eieio-default-superclass' is never mentioned in eieio--class-parent, | 455 | ;; `eieio-default-superclass' is never mentioned in eieio--class-parent, |
| 466 | ;; so we have to special case it here. | 456 | ;; so we have to special case it here. |
| 467 | (or (eq class 'eieio-default-superclass) | 457 | (or (eq class 'eieio-default-superclass) |
| 468 | (let ((p nil)) | 458 | (let ((p nil)) |
| 469 | (setq class (eieio--class-object class)) | 459 | (setq class (eieio--class-object class)) |
| 470 | (eieio--check-type eieio--class-p class) | 460 | (cl-check-type class eieio--class) |
| 471 | (while (and child (not (eq child class))) | 461 | (while (and child (not (eq child class))) |
| 472 | (setq p (append p (eieio--class-parent child)) | 462 | (setq p (append p (eieio--class-parent child)) |
| 473 | child (pop p))) | 463 | child (pop p))) |
| @@ -475,11 +465,11 @@ The CLOS function `class-direct-subclasses' is aliased to this function." | |||
| 475 | 465 | ||
| 476 | (defun object-slots (obj) | 466 | (defun object-slots (obj) |
| 477 | "Return list of slots available in OBJ." | 467 | "Return list of slots available in OBJ." |
| 478 | (eieio--check-type eieio-object-p obj) | 468 | (cl-check-type obj eieio-object) |
| 479 | (eieio--class-public-a (eieio--object-class-object obj))) | 469 | (eieio--class-public-a (eieio--object-class-object obj))) |
| 480 | 470 | ||
| 481 | (defun eieio--class-slot-initarg (class slot) "Fetch from CLASS, SLOT's :initarg." | 471 | (defun eieio--class-slot-initarg (class slot) "Fetch from CLASS, SLOT's :initarg." |
| 482 | (eieio--check-type eieio--class-p class) | 472 | (cl-check-type class eieio--class) |
| 483 | (let ((ia (eieio--class-initarg-tuples class)) | 473 | (let ((ia (eieio--class-initarg-tuples class)) |
| 484 | (f nil)) | 474 | (f nil)) |
| 485 | (while (and ia (not f)) | 475 | (while (and ia (not f)) |
| @@ -517,7 +507,7 @@ OBJECT can be an instance or a class." | |||
| 517 | ;; Return nil if the magic symbol is in there. | 507 | ;; Return nil if the magic symbol is in there. |
| 518 | (not (eq (cond | 508 | (not (eq (cond |
| 519 | ((eieio-object-p object) (eieio-oref object slot)) | 509 | ((eieio-object-p object) (eieio-oref object slot)) |
| 520 | ((class-p object) (eieio-oref-default object slot)) | 510 | ((symbolp object) (eieio-oref-default object slot)) |
| 521 | (t (signal 'wrong-type-argument (list 'eieio-object-p object)))) | 511 | (t (signal 'wrong-type-argument (list 'eieio-object-p object)))) |
| 522 | eieio-unbound)))) | 512 | eieio-unbound)))) |
| 523 | 513 | ||
| @@ -529,7 +519,8 @@ OBJECT can be an instance or a class." | |||
| 529 | "Return non-nil if OBJECT-OR-CLASS has SLOT." | 519 | "Return non-nil if OBJECT-OR-CLASS has SLOT." |
| 530 | (let ((cv (cond ((eieio-object-p object-or-class) | 520 | (let ((cv (cond ((eieio-object-p object-or-class) |
| 531 | (eieio--object-class-object object-or-class)) | 521 | (eieio--object-class-object object-or-class)) |
| 532 | (t (eieio-class-object object-or-class))))) | 522 | ((eieio--class-p object-or-class) object-or-class) |
| 523 | (t (find-class object-or-class 'error))))) | ||
| 533 | (or (memq slot (eieio--class-public-a cv)) | 524 | (or (memq slot (eieio--class-public-a cv)) |
| 534 | (memq slot (eieio--class-class-allocation-a cv))) | 525 | (memq slot (eieio--class-class-allocation-a cv))) |
| 535 | )) | 526 | )) |
| @@ -538,10 +529,10 @@ OBJECT can be an instance or a class." | |||
| 538 | "Return the class that SYMBOL represents. | 529 | "Return the class that SYMBOL represents. |
| 539 | If there is no class, nil is returned if ERRORP is nil. | 530 | If there is no class, nil is returned if ERRORP is nil. |
| 540 | If ERRORP is non-nil, `wrong-argument-type' is signaled." | 531 | If ERRORP is non-nil, `wrong-argument-type' is signaled." |
| 541 | (if (not (class-p symbol)) | 532 | (let ((class (eieio--class-v symbol))) |
| 542 | (if errorp (signal 'wrong-type-argument (list 'class-p symbol)) | 533 | (cond |
| 543 | nil) | 534 | ((eieio--class-p class) class) |
| 544 | (eieio--class-v symbol))) | 535 | (errorp (signal 'wrong-type-argument (list 'class-p symbol)))))) |
| 545 | 536 | ||
| 546 | ;;; Slightly more complex utility functions for objects | 537 | ;;; Slightly more complex utility functions for objects |
| 547 | ;; | 538 | ;; |
| @@ -551,7 +542,7 @@ LIST is a list of objects whose slots are searched. | |||
| 551 | Objects in LIST do not need to have a slot named SLOT, nor does | 542 | Objects in LIST do not need to have a slot named SLOT, nor does |
| 552 | SLOT need to be bound. If these errors occur, those objects will | 543 | SLOT need to be bound. If these errors occur, those objects will |
| 553 | be ignored." | 544 | be ignored." |
| 554 | (eieio--check-type listp list) | 545 | (cl-check-type list list) |
| 555 | (while (and list (not (condition-case nil | 546 | (while (and list (not (condition-case nil |
| 556 | ;; This prevents errors for missing slots. | 547 | ;; This prevents errors for missing slots. |
| 557 | (equal key (eieio-oref (car list) slot)) | 548 | (equal key (eieio-oref (car list) slot)) |
| @@ -563,7 +554,7 @@ be ignored." | |||
| 563 | "Return an association list with the contents of SLOT as the key element. | 554 | "Return an association list with the contents of SLOT as the key element. |
| 564 | LIST must be a list of objects with SLOT in it. | 555 | LIST must be a list of objects with SLOT in it. |
| 565 | This is useful when you need to do completing read on an object group." | 556 | This is useful when you need to do completing read on an object group." |
| 566 | (eieio--check-type listp list) | 557 | (cl-check-type list list) |
| 567 | (let ((assoclist nil)) | 558 | (let ((assoclist nil)) |
| 568 | (while list | 559 | (while list |
| 569 | (setq assoclist (cons (cons (eieio-oref (car list) slot) | 560 | (setq assoclist (cons (cons (eieio-oref (car list) slot) |
| @@ -577,7 +568,7 @@ This is useful when you need to do completing read on an object group." | |||
| 577 | LIST must be a list of objects, but those objects do not need to have | 568 | LIST must be a list of objects, but those objects do not need to have |
| 578 | SLOT in it. If it does not, then that element is left out of the association | 569 | SLOT in it. If it does not, then that element is left out of the association |
| 579 | list." | 570 | list." |
| 580 | (eieio--check-type listp list) | 571 | (cl-check-type list list) |
| 581 | (let ((assoclist nil)) | 572 | (let ((assoclist nil)) |
| 582 | (while list | 573 | (while list |
| 583 | (if (slot-exists-p (car list) slot) | 574 | (if (slot-exists-p (car list) slot) |
| @@ -869,12 +860,8 @@ this object." | |||
| 869 | (object-write thing)) | 860 | (object-write thing)) |
| 870 | ((consp thing) | 861 | ((consp thing) |
| 871 | (eieio-list-prin1 thing)) | 862 | (eieio-list-prin1 thing)) |
| 872 | ((class-p thing) | 863 | ((eieio--class-p thing) |
| 873 | (princ (eieio-class-name thing))) | 864 | (princ (eieio-class-name thing))) |
| 874 | ((or (keywordp thing) (booleanp thing)) | ||
| 875 | (prin1 thing)) | ||
| 876 | ((symbolp thing) | ||
| 877 | (princ (concat "'" (symbol-name thing)))) | ||
| 878 | (t (prin1 thing)))) | 865 | (t (prin1 thing)))) |
| 879 | 866 | ||
| 880 | (defun eieio-list-prin1 (list) | 867 | (defun eieio-list-prin1 (list) |
| @@ -942,7 +929,7 @@ Optional argument GROUP is the sub-group of slots to display. | |||
| 942 | 929 | ||
| 943 | ;;;*** | 930 | ;;;*** |
| 944 | 931 | ||
| 945 | ;;;### (autoloads nil "eieio-opt" "eieio-opt.el" "b849f8bf1312d5ef57e53d02173e4b5a") | 932 | ;;;### (autoloads nil "eieio-opt" "eieio-opt.el" "ff1097f185bc2c253276a7d19fe2f54a") |
| 946 | ;;; Generated autoloads from eieio-opt.el | 933 | ;;; Generated autoloads from eieio-opt.el |
| 947 | 934 | ||
| 948 | (autoload 'eieio-browse "eieio-opt" "\ | 935 | (autoload 'eieio-browse "eieio-opt" "\ |
diff --git a/test/ChangeLog b/test/ChangeLog index 8e4fdb884a1..a9834cc0f3f 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2015-01-31 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * automated/eieio-tests.el (eieio-test-23-inheritance-check): Simplify. | ||
| 4 | |||
| 1 | 2015-01-30 Stefan Monnier <monnier@iro.umontreal.ca> | 5 | 2015-01-30 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 6 | ||
| 3 | * automated/core-elisp-tests.el (core-elisp-tests-3-backquote): New test. | 7 | * automated/core-elisp-tests.el (core-elisp-tests-3-backquote): New test. |
diff --git a/test/automated/eieio-tests.el b/test/automated/eieio-tests.el index 847aefd63fc..7532609c4c3 100644 --- a/test/automated/eieio-tests.el +++ b/test/automated/eieio-tests.el | |||
| @@ -537,9 +537,8 @@ METHOD is the method that was attempting to be called." | |||
| 537 | (should (object-of-class-p eitest-ab 'class-b)) | 537 | (should (object-of-class-p eitest-ab 'class-b)) |
| 538 | (should (object-of-class-p eitest-ab 'class-ab)) | 538 | (should (object-of-class-p eitest-ab 'class-ab)) |
| 539 | (should (eq (eieio-class-parents 'class-a) nil)) | 539 | (should (eq (eieio-class-parents 'class-a) nil)) |
| 540 | ;; FIXME: eieio-class-parents now returns class objects! | 540 | (should (equal (eieio-class-parents 'class-ab) |
| 541 | (should (equal (mapcar #'eieio-class-object (eieio-class-parents 'class-ab)) | 541 | (mapcar #'find-class '(class-a class-b)))) |
| 542 | (mapcar #'eieio-class-object '(class-a class-b)))) | ||
| 543 | (should (same-class-p eitest-a 'class-a)) | 542 | (should (same-class-p eitest-a 'class-a)) |
| 544 | (should (class-a-p eitest-a)) | 543 | (should (class-a-p eitest-a)) |
| 545 | (should (not (class-a-p eitest-ab))) | 544 | (should (not (class-a-p eitest-ab))) |