aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBasil L. Contovounesios2020-06-03 17:35:59 +0100
committerBasil L. Contovounesios2020-06-06 17:24:00 +0100
commit8bcc781bc762b4082cfd678b88938e3d03465d91 (patch)
treec633ddabe6c442953e08f60eff889966d5214703
parentacd2cb28ef63188bff31fc167ab007a051f99c17 (diff)
downloademacs-8bcc781bc762b4082cfd678b88938e3d03465d91.tar.gz
emacs-8bcc781bc762b4082cfd678b88938e3d03465d91.zip
Un-deprecate oset and oset-default
For discussion see the following threads: https://lists.gnu.org/archive/html/emacs-devel/2020-05/msg00630.html https://lists.gnu.org/archive/html/emacs-devel/2020-05/msg00674.html https://lists.gnu.org/archive/html/emacs-devel/2020-06/msg00099.html * lisp/emacs-lisp/eieio.el (oset, oset-default): Un-deprecate. * lisp/emacs-lisp/eieio-core.el (eieio-oref): Declare gv-setter here instead of in lisp/emacs-lisp/eieio.el. Suggested by Stefan Monnier <monnier@iro.umontreal.ca>. (eieio-oref-default): Add gv-setter declaration. * etc/NEWS: Announce these changes. * doc/misc/eieio.texi (Accessing Slots): Document oref and oref-default as generalized variables. Consistently document getters before setters. * test/lisp/emacs-lisp/eieio-tests/eieio-tests.el: Use lexical-binding. (eieio-test-13-init-methods): Simplify. (eieio-test-33-instance-tracker): Declare IT-list as special.
-rw-r--r--doc/misc/eieio.texi32
-rw-r--r--etc/NEWS7
-rw-r--r--lisp/emacs-lisp/eieio-core.el4
-rw-r--r--lisp/emacs-lisp/eieio.el14
-rw-r--r--test/lisp/emacs-lisp/eieio-tests/eieio-tests.el5
5 files changed, 35 insertions, 27 deletions
diff --git a/doc/misc/eieio.texi b/doc/misc/eieio.texi
index 3943c544c7d..6e7d4386bec 100644
--- a/doc/misc/eieio.texi
+++ b/doc/misc/eieio.texi
@@ -698,6 +698,27 @@ and argument-order conventions are similar to those used for
698referencing vectors (@pxref{Vectors,,,elisp,GNU Emacs Lisp Reference 698referencing vectors (@pxref{Vectors,,,elisp,GNU Emacs Lisp Reference
699Manual}). 699Manual}).
700 700
701@defmac oref obj slot
702@anchor{oref}
703This macro retrieves the value stored in @var{obj} in the named
704@var{slot}. Slot names are determined by @code{defclass} which
705creates the slot.
706
707This is a generalized variable that can be used with @code{setf} to
708modify the value stored in @var{slot}. @xref{Generalized
709Variables,,,elisp,GNU Emacs Lisp Reference Manual}.
710@end defmac
711
712@defmac oref-default class slot
713@anchor{oref-default}
714This macro returns the value of the class-allocated @var{slot} from
715@var{class}.
716
717This is a generalized variable that can be used with @code{setf} to
718modify the value stored in @var{slot}. @xref{Generalized
719Variables,,,elisp,GNU Emacs Lisp Reference Manual}.
720@end defmac
721
701@defmac oset object slot value 722@defmac oset object slot value
702This macro sets the value behind @var{slot} to @var{value} in 723This macro sets the value behind @var{slot} to @var{value} in
703@var{object}. It returns @var{value}. 724@var{object}. It returns @var{value}.
@@ -716,17 +737,6 @@ changed, this can be arranged by simply executing this bit of code:
716@end example 737@end example
717@end defmac 738@end defmac
718 739
719@defmac oref obj slot
720@anchor{oref}
721Retrieve the value stored in @var{obj} in the slot named by @var{slot}.
722Slot is the name of the slot when created by @dfn{defclass}.
723@end defmac
724
725@defmac oref-default class slot
726@anchor{oref-default}
727Get the value of the class-allocated @var{slot} from @var{class}.
728@end defmac
729
730The following accessors are defined by CLOS to reference or modify 740The following accessors are defined by CLOS to reference or modify
731slot values, and use the previously mentioned set/ref routines. 741slot values, and use the previously mentioned set/ref routines.
732 742
diff --git a/etc/NEWS b/etc/NEWS
index ed4722b27f5..27e511047e6 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -112,7 +112,12 @@ setting the variable 'auto-save-visited-mode' buffer-locally to nil.
112** New bindings in occur-mode, 'next-error-no-select' bound to 'n' and 112** New bindings in occur-mode, 'next-error-no-select' bound to 'n' and
113'previous-error-no-select' bound to 'p'. 113'previous-error-no-select' bound to 'p'.
114 114
115** EIEIO: 'oset' and 'oset-default' are declared obsolete. 115** EIEIO
116
117+++
118*** The macro 'oref-default' can now be used with 'setf'.
119It is now defined as a generalized variable that can be used with
120'setf' to modify the value stored in a given class slot.
116 121
117** New minor mode 'cl-font-lock-built-in-mode' for `lisp-mode'. 122** New minor mode 'cl-font-lock-built-in-mode' for `lisp-mode'.
118The mode provides refined highlighting of built-in functions, types, 123The mode provides refined highlighting of built-in functions, types,
diff --git a/lisp/emacs-lisp/eieio-core.el b/lisp/emacs-lisp/eieio-core.el
index 1e53f30a2ae..3bc65d0d4c5 100644
--- a/lisp/emacs-lisp/eieio-core.el
+++ b/lisp/emacs-lisp/eieio-core.el
@@ -730,7 +730,8 @@ Argument FN is the function calling this verifier."
730 (guard (not (memq name eieio--known-slot-names)))) 730 (guard (not (memq name eieio--known-slot-names))))
731 (macroexp--warn-and-return 731 (macroexp--warn-and-return
732 (format-message "Unknown slot `%S'" name) exp 'compile-only)) 732 (format-message "Unknown slot `%S'" name) exp 'compile-only))
733 (_ exp))))) 733 (_ exp))))
734 (gv-setter eieio-oset))
734 (cl-check-type slot symbol) 735 (cl-check-type slot symbol)
735 (cl-check-type obj (or eieio-object class)) 736 (cl-check-type obj (or eieio-object class))
736 (let* ((class (cond ((symbolp obj) 737 (let* ((class (cond ((symbolp obj)
@@ -755,6 +756,7 @@ Argument FN is the function calling this verifier."
755(defun eieio-oref-default (obj slot) 756(defun eieio-oref-default (obj slot)
756 "Do the work for the macro `oref-default' with similar parameters. 757 "Do the work for the macro `oref-default' with similar parameters.
757Fills in OBJ's SLOT with its default value." 758Fills in OBJ's SLOT with its default value."
759 (declare (gv-setter eieio-oset-default))
758 (cl-check-type obj (or eieio-object class)) 760 (cl-check-type obj (or eieio-object class))
759 (cl-check-type slot symbol) 761 (cl-check-type slot symbol)
760 (let* ((cl (cond ((symbolp obj) (cl--find-class obj)) 762 (let* ((cl (cond ((symbolp obj) (cl--find-class obj))
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el
index ee5dd2cccdb..b75410ee220 100644
--- a/lisp/emacs-lisp/eieio.el
+++ b/lisp/emacs-lisp/eieio.el
@@ -513,8 +513,7 @@ The CLOS function `class-direct-subclasses' is aliased to this function."
513 "Set the value in OBJ for slot SLOT to VALUE. 513 "Set the value in OBJ for slot SLOT to VALUE.
514SLOT is the slot name as specified in `defclass' or the tag created 514SLOT is the slot name as specified in `defclass' or the tag created
515with in the :initarg slot. VALUE can be any Lisp object." 515with in the :initarg slot. VALUE can be any Lisp object."
516 (declare (obsolete "use (setf (oref ..) ..) instead" "28.1") 516 (declare (debug (form symbolp form)))
517 (debug (form symbolp form)))
518 `(eieio-oset ,obj (quote ,slot) ,value)) 517 `(eieio-oset ,obj (quote ,slot) ,value))
519 518
520(defmacro oset-default (class slot value) 519(defmacro oset-default (class slot value)
@@ -522,8 +521,7 @@ with in the :initarg slot. VALUE can be any Lisp object."
522The default value is usually set with the :initform tag during class 521The default value is usually set with the :initform tag during class
523creation. This allows users to change the default behavior of classes 522creation. This allows users to change the default behavior of classes
524after they are created." 523after they are created."
525 (declare (obsolete "use (setf (oref-default ..) ..) instead" "28.1") 524 (declare (debug (form symbolp form)))
526 (debug (form symbolp form)))
527 `(eieio-oset-default ,class (quote ,slot) ,value)) 525 `(eieio-oset-default ,class (quote ,slot) ,value))
528 526
529;;; CLOS queries into classes and slots 527;;; CLOS queries into classes and slots
@@ -647,14 +645,6 @@ If SLOT is unbound, do nothing."
647 nil 645 nil
648 (eieio-oset object slot (delete item (eieio-oref object slot))))) 646 (eieio-oset object slot (delete item (eieio-oref object slot)))))
649 647
650;;; Here are some CLOS items that need the CL package
651;;
652
653;; FIXME: Shouldn't this be a more complex gv-expander which extracts the
654;; common code between oref and oset, so as to reduce the redundant work done
655;; in (push foo (oref bar baz)), like we do for the `nth' expander?
656(gv-define-simple-setter eieio-oref eieio-oset)
657
658 648
659;;; 649;;;
660;; We want all objects created by EIEIO to have some default set of 650;; We want all objects created by EIEIO to have some default set of
diff --git a/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el b/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
index 34c20b2003f..21adc91e555 100644
--- a/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
+++ b/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
@@ -1,4 +1,4 @@
1;;; eieio-tests.el -- eieio tests routines 1;;; eieio-tests.el -- eieio test routines -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 1999-2003, 2005-2010, 2012-2020 Free Software 3;; Copyright (C) 1999-2003, 2005-2010, 2012-2020 Free Software
4;; Foundation, Inc. 4;; Foundation, Inc.
@@ -356,7 +356,7 @@ METHOD is the method that was attempting to be called."
356 (oset a test-tag 1)) 356 (oset a test-tag 1))
357 357
358 (let ((ca (class-a))) 358 (let ((ca (class-a)))
359 (should-not (/= (oref ca test-tag) 2)))) 359 (should (= (oref ca test-tag) 2))))
360 360
361 361
362;;; Perform slot testing 362;;; Perform slot testing
@@ -852,6 +852,7 @@ Subclasses to override slot attributes.")
852 "Instance Tracker test object.") 852 "Instance Tracker test object.")
853 853
854(ert-deftest eieio-test-33-instance-tracker () 854(ert-deftest eieio-test-33-instance-tracker ()
855 (defvar IT-list)
855 (let (IT-list IT1) 856 (let (IT-list IT1)
856 (should (setq IT1 (IT))) 857 (should (setq IT1 (IT)))
857 ;; The instance tracker must find this 858 ;; The instance tracker must find this