Function: vtable-insert-object

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

Signature

(vtable-insert-object TABLE OBJECT &optional AFTER-OBJECT)

Documentation

Insert OBJECT into TABLE after AFTER-OBJECT.

If AFTER-OBJECT is nil (or doesn't exist in the table), insert OBJECT at the end. This also updates the displayed table.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/vtable.el.gz
(defun vtable-insert-object (table object &optional after-object)
  "Insert OBJECT into TABLE after AFTER-OBJECT.
If AFTER-OBJECT is nil (or doesn't exist in the table), insert
OBJECT at the end.
This also updates the displayed table."
  ;; First insert into the objects.
  (let (pos)
    (if (and after-object
             (setq pos (memq after-object (vtable-objects table))))
        ;; Splice into list.
        (setcdr pos (cons object (cdr pos)))
      ;; Append.
      (nconc (vtable-objects table) (list object))))
  ;; Then adjust the cache and display.
  (save-excursion
    (vtable-goto-table table)
    (let* ((cache (vtable--cache table))
           (inhibit-read-only t)
           (keymap (get-text-property (point) 'keymap))
           (ellipsis (if (vtable-ellipsis table)
                         (propertize (truncate-string-ellipsis)
                                     'face (vtable-face table))
                       ""))
           (ellipsis-width (string-pixel-width ellipsis))
           (elem (and after-object
                      (assq after-object (car cache))))
           (line (cons object (vtable--compute-cached-line table object))))
      (if (not elem)
          ;; Append.
          (progn
            (setcar cache (nconc (car cache) (list line)))
            (vtable-end-of-table))
        ;; Splice into list.
        (let ((pos (memq elem (car cache))))
          (setcdr pos (cons line (cdr pos)))
          (unless (vtable-goto-object after-object)
            (vtable-end-of-table))))
      (let ((start (point)))
        ;; FIXME: We have to adjust colors in lines below this if we
        ;; have :row-colors.
        (vtable--insert-line table line 0
                             (nth 1 cache) (vtable--spacer table)
                             ellipsis ellipsis-width)
        (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)))))