diff options
| author | Stefan Monnier | 2012-07-18 03:20:04 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2012-07-18 03:20:04 -0400 |
| commit | 12999ea83fcd94462c1361371f5ab8a7f8c0db98 (patch) | |
| tree | dc099444d95fddf1afabe68b2639a55eb63c18ca | |
| parent | 3ab6e069695d0dd5bb77133a89f858190ab8550a (diff) | |
| download | emacs-12999ea83fcd94462c1361371f5ab8a7f8c0db98.tar.gz emacs-12999ea83fcd94462c1361371f5ab8a7f8c0db98.zip | |
* lisp/emacs-lisp/eieio.el: Adapt further to gv.el.
(eieio-defclass): Use gv-define-setter when possible.
Fixes: debbugs:11970
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio.el | 61 |
2 files changed, 41 insertions, 25 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7ddbd67cf76..df0bacc3507 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2012-07-18 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * emacs-lisp/eieio.el: Adapt further to gv.el (bug#11970). | ||
| 4 | (eieio-defclass): Use gv-define-setter when possible. | ||
| 5 | |||
| 1 | 2012-07-18 Dmitry Antipov <dmantipov@yandex.ru> | 6 | 2012-07-18 Dmitry Antipov <dmantipov@yandex.ru> |
| 2 | 7 | ||
| 3 | Reflect recent changes in Fgarbage_collect. | 8 | Reflect recent changes in Fgarbage_collect. |
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index dcd0608ebba..5f4be78b082 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el | |||
| @@ -44,8 +44,7 @@ | |||
| 44 | 44 | ||
| 45 | ;;; Code: | 45 | ;;; Code: |
| 46 | 46 | ||
| 47 | (eval-when-compile | 47 | (eval-when-compile (require 'cl)) ;FIXME: Use cl-lib! |
| 48 | (require 'cl)) | ||
| 49 | 48 | ||
| 50 | (defvar eieio-version "1.3" | 49 | (defvar eieio-version "1.3" |
| 51 | "Current version of EIEIO.") | 50 | "Current version of EIEIO.") |
| @@ -431,10 +430,10 @@ See `defclass' for more information." | |||
| 431 | (run-hooks 'eieio-hook) | 430 | (run-hooks 'eieio-hook) |
| 432 | (setq eieio-hook nil) | 431 | (setq eieio-hook nil) |
| 433 | 432 | ||
| 434 | (if (not (symbolp cname)) (signal 'wrong-type-argument '(symbolp cname))) | 433 | (if (not (listp superclasses)) |
| 435 | (if (not (listp superclasses)) (signal 'wrong-type-argument '(listp superclasses))) | 434 | (signal 'wrong-type-argument '(listp superclasses))) |
| 436 | 435 | ||
| 437 | (let* ((pname (if superclasses superclasses nil)) | 436 | (let* ((pname superclasses) |
| 438 | (newc (make-vector class-num-slots nil)) | 437 | (newc (make-vector class-num-slots nil)) |
| 439 | (oldc (when (class-p cname) (class-v cname))) | 438 | (oldc (when (class-p cname) (class-v cname))) |
| 440 | (groups nil) ;; list of groups id'd from slots | 439 | (groups nil) ;; list of groups id'd from slots |
| @@ -553,8 +552,8 @@ See `defclass' for more information." | |||
| 553 | (put cname 'cl-deftype-handler | 552 | (put cname 'cl-deftype-handler |
| 554 | (list 'lambda () `(list 'satisfies (quote ,csym))))) | 553 | (list 'lambda () `(list 'satisfies (quote ,csym))))) |
| 555 | 554 | ||
| 556 | ;; before adding new slots, let's add all the methods and classes | 555 | ;; Before adding new slots, let's add all the methods and classes |
| 557 | ;; in from the parent class | 556 | ;; in from the parent class. |
| 558 | (eieio-copy-parents-into-subclass newc superclasses) | 557 | (eieio-copy-parents-into-subclass newc superclasses) |
| 559 | 558 | ||
| 560 | ;; Store the new class vector definition into the symbol. We need to | 559 | ;; Store the new class vector definition into the symbol. We need to |
| @@ -652,9 +651,9 @@ See `defclass' for more information." | |||
| 652 | ;; We need to id the group, and store them in a group list attribute. | 651 | ;; We need to id the group, and store them in a group list attribute. |
| 653 | (mapc (lambda (cg) (add-to-list 'groups cg)) customg) | 652 | (mapc (lambda (cg) (add-to-list 'groups cg)) customg) |
| 654 | 653 | ||
| 655 | ;; anyone can have an accessor function. This creates a function | 654 | ;; Anyone can have an accessor function. This creates a function |
| 656 | ;; of the specified name, and also performs a `defsetf' if applicable | 655 | ;; of the specified name, and also performs a `defsetf' if applicable |
| 657 | ;; so that users can `setf' the space returned by this function | 656 | ;; so that users can `setf' the space returned by this function. |
| 658 | (if acces | 657 | (if acces |
| 659 | (progn | 658 | (progn |
| 660 | (eieio--defmethod | 659 | (eieio--defmethod |
| @@ -668,18 +667,26 @@ See `defclass' for more information." | |||
| 668 | ;; Else - Some error? nil? | 667 | ;; Else - Some error? nil? |
| 669 | nil))) | 668 | nil))) |
| 670 | 669 | ||
| 671 | ;; Provide a setf method. It would be cleaner to use | 670 | (if (fboundp 'gv-define-setter) |
| 672 | ;; defsetf, but that would require CL at runtime. | 671 | ;; FIXME: We should move more of eieio-defclass into the |
| 673 | (put acces 'setf-method | 672 | ;; defclass macro so we don't have to use `eval' and require |
| 674 | `(lambda (widget) | 673 | ;; `gv' at run-time. |
| 675 | (let* ((--widget-sym-- (make-symbol "--widget--")) | 674 | (eval `(gv-define-setter ,acces (eieio--store eieio--object) |
| 676 | (--store-sym-- (make-symbol "--store--"))) | 675 | (list 'eieio-oset eieio--object '',name |
| 677 | (list | 676 | eieio--store))) |
| 678 | (list --widget-sym--) | 677 | ;; Provide a setf method. It would be cleaner to use |
| 679 | (list widget) | 678 | ;; defsetf, but that would require CL at runtime. |
| 680 | (list --store-sym--) | 679 | (put acces 'setf-method |
| 681 | (list 'eieio-oset --widget-sym-- '',name --store-sym--) | 680 | `(lambda (widget) |
| 682 | (list 'getfoo --widget-sym--))))))) | 681 | (let* ((--widget-sym-- (make-symbol "--widget--")) |
| 682 | (--store-sym-- (make-symbol "--store--"))) | ||
| 683 | (list | ||
| 684 | (list --widget-sym--) | ||
| 685 | (list widget) | ||
| 686 | (list --store-sym--) | ||
| 687 | (list 'eieio-oset --widget-sym-- '',name | ||
| 688 | --store-sym--) | ||
| 689 | (list 'getfoo --widget-sym--)))))))) | ||
| 683 | 690 | ||
| 684 | ;; If a writer is defined, then create a generic method of that | 691 | ;; If a writer is defined, then create a generic method of that |
| 685 | ;; name whose purpose is to set the value of the slot. | 692 | ;; name whose purpose is to set the value of the slot. |
| @@ -702,7 +709,8 @@ See `defclass' for more information." | |||
| 702 | ) | 709 | ) |
| 703 | (setq slots (cdr slots))) | 710 | (setq slots (cdr slots))) |
| 704 | 711 | ||
| 705 | ;; Now that everything has been loaded up, all our lists are backwards! Fix that up now. | 712 | ;; Now that everything has been loaded up, all our lists are backwards! |
| 713 | ;; Fix that up now. | ||
| 706 | (aset newc class-public-a (nreverse (aref newc class-public-a))) | 714 | (aset newc class-public-a (nreverse (aref newc class-public-a))) |
| 707 | (aset newc class-public-d (nreverse (aref newc class-public-d))) | 715 | (aset newc class-public-d (nreverse (aref newc class-public-d))) |
| 708 | (aset newc class-public-doc (nreverse (aref newc class-public-doc))) | 716 | (aset newc class-public-doc (nreverse (aref newc class-public-doc))) |
| @@ -2544,11 +2552,14 @@ This is usually a symbol that starts with `:'." | |||
| 2544 | ;; | 2552 | ;; |
| 2545 | 2553 | ||
| 2546 | (defsetf eieio-oref eieio-oset) | 2554 | (defsetf eieio-oref eieio-oset) |
| 2547 | ;; FIXME: Not needed for Emacs>=24.2 since setf follows function aliases. | 2555 | |
| 2556 | (if (eval-when-compile (fboundp 'gv-define-expander)) | ||
| 2557 | ;; Not needed for Emacs>=24.2 since gv.el's setf expands macros and | ||
| 2558 | ;; follows aliases. | ||
| 2559 | nil | ||
| 2548 | (defsetf slot-value eieio-oset) | 2560 | (defsetf slot-value eieio-oset) |
| 2549 | 2561 | ||
| 2550 | ;; The below setf method was written by Arnd Kohrs <kohrs@acm.org> | 2562 | ;; The below setf method was written by Arnd Kohrs <kohrs@acm.org> |
| 2551 | ;; FIXME: Not needed for Emacs>=24.2 since setf expands macros. | ||
| 2552 | (define-setf-method oref (obj slot) | 2563 | (define-setf-method oref (obj slot) |
| 2553 | (with-no-warnings | 2564 | (with-no-warnings |
| 2554 | (require 'cl) | 2565 | (require 'cl) |
| @@ -2560,7 +2571,7 @@ This is usually a symbol that starts with `:'." | |||
| 2560 | (list store-temp) | 2571 | (list store-temp) |
| 2561 | (list 'set-slot-value obj-temp slot-temp | 2572 | (list 'set-slot-value obj-temp slot-temp |
| 2562 | store-temp) | 2573 | store-temp) |
| 2563 | (list 'slot-value obj-temp slot-temp))))) | 2574 | (list 'slot-value obj-temp slot-temp)))))) |
| 2564 | 2575 | ||
| 2565 | 2576 | ||
| 2566 | ;;; | 2577 | ;;; |