Function: vtable-update-object

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

Signature

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

Documentation

Replace OLD-OBJECT in TABLE with OBJECT.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/vtable.el.gz
(defun vtable-update-object (table object old-object)
  "Replace OLD-OBJECT in TABLE with OBJECT."
  (let* ((objects (vtable-objects table))
         (inhibit-read-only t))
    ;; 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 objects
        (error "Can't find the old object"))
      (setcar (cdr objects) object))
    ;; Then update the cache...
    (let* ((line-number (seq-position old-object (car (vtable--cache table))))
           (line (elt (car (vtable--cache table)) line-number)))
      (unless line
        (error "Can't find cached object"))
      (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
                               (nth 1 (vtable--cache table))
                               (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)))))