'vtable-update-object' can now be called with one argument
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.
This commit is contained in:
parent
fe24a8c3c0
commit
393f58c85a
3 changed files with 32 additions and 5 deletions
|
@ -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))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue