]> git.eshelyaron.com Git - emacs.git/commitdiff
'vtable-update-object' can now be called with one argument
authorAdam Porter <adam@alphapapa.net>
Sat, 9 Mar 2024 05:43:14 +0000 (23:43 -0600)
committerEshel Yaron <me@eshelyaron.com>
Sun, 24 Mar 2024 14:15:12 +0000 (15:15 +0100)
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)

This also documents the behavior of the just-discovered limitation filed
as bug#69837.
* lisp/emacs-lisp/vtable.el (vtable-update-object): Make 'old-object'
argument optional.  (Bug#69666)

* doc/misc/vtable.texi (Interface Functions): Update documentation.

* etc/NEWS: Add news entry.

(cherry picked from commit 393f58c85aeb78f814866ccaad9ae7efd3fa6766)

doc/misc/vtable.texi
etc/NEWS
lisp/emacs-lisp/vtable.el

index a4f2ed29d93036dd4342c072ac29e1465b3f3c1e..dd5b70cf32f759612af6f4f77e4154b32cbb84c9 100644 (file)
@@ -554,12 +554,19 @@ the object after this object; otherwise append to @var{table}.  This
 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.
+
+Note a limitation: if the table's buffer is not in a visible window, or
+if its window has changed width since it was updated, updating the table
+is not possible, and an error is signaled.
 @end defun
 
 @defun vtable-column table index
index 58c348679a199e0dff5440a3dfd809b890445753..e4453291fffece91d2a70994827e00367692f4d1 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2353,6 +2353,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.
+
 \f
 * Changes in Emacs 30.1 on Non-Free Operating Systems
 
index 5f7d3ae5210f82dd51ba9faf324bd919cbb47c35..d8e5136c6662f0c61b3a707d14034df32551395b 100644 (file)
@@ -283,8 +283,16 @@ If it can't be found, return nil and don't move point."
       (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.
+If 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.  Note a limitation: if TABLE's
+buffer is not in a visible window, or if its window has changed width
+since it was updated, updating the TABLE is not possible, and an error
+is signaled."
+  (unless old-object
+    (setq old-object object))
   (let* ((objects (vtable-objects table))
          (inhibit-read-only t))
     ;; First replace the object in the object storage.
@@ -300,6 +308,9 @@ If it can't be found, return nil and don't move point."
         (error "Can't find the old object"))
       (setcar (cdr objects) object))
     ;; Then update the cache...
+    ;; FIXME: If the table's buffer has no visible window, or if its
+    ;; width has changed since the table was updated, the cache key will
+    ;; not match and the object can't be updated.  (Bug #69837).
     (if-let ((line-number (seq-position (car (vtable--cache table)) old-object
                                         (lambda (a b)
                                           (equal (car a) b))))