Function: vtable-update-object

vtable-update-object is a byte-compiled function defined in vtable.el.gz.

Signature

(vtable-update-object TABLE OBJECT &optional OLD-OBJECT)

Documentation

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.

TABLE must be at point in the current buffer.

Probably introduced at or before Emacs version 30.1.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/vtable.el.gz
(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.

TABLE must be at point in the current buffer."
  (unless old-object
    (setq old-object object))
  (let ((objects (vtable-objects table)))
    ;; First replace the object in the object storage.
    (if (eq old-object (car objects))
        ;; It's at the head, so replace it there.
        (setf (vtable-objects table)
              (cons object (cdr objects)))
      ;; Otherwise splice into the list.
      (while (and (cdr objects)
                  (not (eq (cadr objects) old-object)))
        (setq objects (cdr objects)))
      (unless (cdr objects)
        (error "Can't find the old object"))
      (setcar (cdr objects) object))
    ;; Then update the rendered vtable in its buffer.
    (if-let* ((cache (vtable--current-cache table))
              (line-number (seq-position (vtable--cache-lines cache)
                                         old-object
                                         (lambda (a b)
                                           (equal (car a) b))))
              (line (elt (vtable--cache-lines cache) line-number)))
        (with-current-buffer (vtable-buffer table)
          (let ((inhibit-read-only t)
                (inhibit-modification-hooks t))
            (setcar line object)
            (setcdr line (vtable--compute-cached-line table object))
            ;; ... and redisplay the line in question.
            (save-excursion
              (vtable-goto-object old-object)
              (let ((keymap (get-text-property (point) 'keymap))
                    (start (point)))
                (delete-line)
                (vtable--insert-line table line line-number
                                     (vtable--cache-widths cache)
                                     (vtable--spacer table))
                (add-text-properties start (point) (list 'keymap keymap
                                                         'vtable table))))
            ;; We may have inserted a non-numerical value into a previously
            ;; all-numerical table, so recompute.
            (vtable--recompute-numerical table (cdr line))))
      (error "Can't find cached object in vtable"))))