unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Adam Porter <adam@alphapapa.net>
To: 69666@debbugs.gnu.org
Subject: bug#69666: [PATCH] (vtable-update-object): Make old-object argument optional
Date: Fri, 8 Mar 2024 23:51:33 -0600	[thread overview]
Message-ID: <29c23366-b37c-422e-81f0-f0508e79460f@alphapapa.net> (raw)

[-- 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


             reply	other threads:[~2024-03-09  5:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-09  5:51 Adam Porter [this message]
2024-03-14  9:00 ` bug#69666: [PATCH] (vtable-update-object): Make old-object argument optional 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=29c23366-b37c-422e-81f0-f0508e79460f@alphapapa.net \
    --to=adam@alphapapa.net \
    --cc=69666@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).