From 4b762015ebb82d1861c2efe51c1e902ac329bc8e Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Fri, 8 Mar 2024 23:43:14 -0600 Subject: [PATCH] (vtable-update-object): Make old-object argument optional (Bug#69666) * lisp/emacs-lisp/vtable.el (vtable-update-object): Make 'old-object' argument optional. * doc/misc/vtable.texi (Interface Functions): Update documentation. * etc/NEWS: Add news entry. It's often necessary to update the representation of a single object in a table (e.g a struct, whose identity does not change when its slots' values are changed). To do so, now the function may be called like this: (vtable-update-object table object) Instead of like this: (vtable-update-object table object object) --- doc/misc/vtable.texi | 9 ++++++--- etc/NEWS | 9 +++++++++ lisp/emacs-lisp/vtable.el | 9 +++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/doc/misc/vtable.texi b/doc/misc/vtable.texi index a4f2ed29d93..6881e9663c4 100644 --- a/doc/misc/vtable.texi +++ b/doc/misc/vtable.texi @@ -554,9 +554,12 @@ Interface Functions also updates the displayed table. @end defun -@defun vtable-update-object table object old-object -Change @var{old-object} into @var{object} in @var{table}. This also -updates the displayed table. +@defun vtable-update-object table object &optional old-object +Update @var{object}'s representation in @var{table}. Optional argument +@var{old-object}, if non-@code{nil}, means to replace @var{old-object} +with @var{object} and redisplay the associated row in the table. In +either case, if the existing object is not found in the table (being +compared with @code{equal}), signal an error. This has the same effect as calling @code{vtable-remove-object} and then @code{vtable-insert-object}, but is more efficient. diff --git a/etc/NEWS b/etc/NEWS index a654d2d8d79..85751074aaa 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2175,6 +2175,15 @@ aforementioned functions: (and (arrayp executing-kbd-macro) (>= executing-kbd-macro-index (length executing-kbd-macro)))) ++++ +** 'vtable-update-object' updates an existing object with just two arguments. +It is now possible to update the representation of an object in a vtable +by calling 'vtable-update-object' with just the vtable and the object as +arguments. (Previously the 'old-object' argument was required which, in +this case, would mean repeating the object in the argument list.) When +replacing an object with a different one, passing both the new and old +objects is still necessary. + * Changes in Emacs 30.1 on Non-Free Operating Systems diff --git a/lisp/emacs-lisp/vtable.el b/lisp/emacs-lisp/vtable.el index 15a430f5c26..dfcfa434135 100644 --- a/lisp/emacs-lisp/vtable.el +++ b/lisp/emacs-lisp/vtable.el @@ -283,8 +283,13 @@ vtable-goto-column (goto-char (prop-match-beginning match)) (end-of-line))) -(defun vtable-update-object (table object old-object) - "Replace OLD-OBJECT in TABLE with OBJECT." +(defun vtable-update-object (table object &optional old-object) + "Update OBJECT's representation in TABLE. +When OLD-OBJECT is non-nil, replace OLD-OBJECT with OBJECT and display +it. In either case, if the existing object is not found in the +table (being compared with `equal'), signal an error." + (unless old-object + (setq old-object object)) (let* ((objects (vtable-objects table)) (inhibit-read-only t)) ;; First replace the object in the object storage. -- 2.30.2