From ebb5a2a6ea5bc0437fd39d0e87406fe723183e5a 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 * lisp/emacs-lisp/vtable.el (vtable-update-object): Make 'old-object' argument optional. * doc/misc/vtable.texi (Interface Functions): Update documentation. 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 foo) Instead of like this: (vtable-update-object table foo foo) --- doc/misc/vtable.texi | 7 ++++--- lisp/emacs-lisp/vtable.el | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/misc/vtable.texi b/doc/misc/vtable.texi index a4f2ed29d93..f6a2ae05818 100644 --- a/doc/misc/vtable.texi +++ b/doc/misc/vtable.texi @@ -554,9 +554,10 @@ 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 +Change @var{old-object} into @var{object} in @var{table}; or, without +@var{old-object}, update existing @var{object} in @var{table}. This +also updates the displayed table. This has the same effect as calling @code{vtable-remove-object} and then @code{vtable-insert-object}, but is more efficient. diff --git a/lisp/emacs-lisp/vtable.el b/lisp/emacs-lisp/vtable.el index 02020552e7f..ae6a5296cef 100644 --- a/lisp/emacs-lisp/vtable.el +++ b/lisp/emacs-lisp/vtable.el @@ -283,8 +283,11 @@ 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) + "Replace OLD-OBJECT in TABLE with OBJECT. +Without OLD-OBJECT, just update existing OBJECT in TABLE." + (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