unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#69666: [PATCH] (vtable-update-object): Make old-object argument optional
@ 2024-03-09  5:51 Adam Porter
  2024-03-14  9:00 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Adam Porter @ 2024-03-09  5:51 UTC (permalink / raw)
  To: 69666

[-- Attachment #1: Type: text/plain, Size: 225 bytes --]

Hi,

Please see the attached patch which makes `vtable-update-object' easier 
to use in the common case of updating an existing object's 
representation in a table (rather than replacing it with another object).

Thanks,
Adam

[-- Attachment #2: 0001-vtable-update-object-Make-old-object-argument-option.patch --]
[-- Type: text/x-patch, Size: 2337 bytes --]

From ebb5a2a6ea5bc0437fd39d0e87406fe723183e5a Mon Sep 17 00:00:00 2001
From: Adam Porter <adam@alphapapa.net>
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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-03-21 10:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-09  5:51 bug#69666: [PATCH] (vtable-update-object): Make old-object argument optional Adam Porter
2024-03-14  9:00 ` Eli Zaretskii
2024-03-16  0:41   ` Adam Porter
2024-03-16 10:29     ` Eli Zaretskii
2024-03-17  4:29       ` Adam Porter
2024-03-21 10:44         ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).