Function: savehist--merge

savehist--merge is a byte-compiled function defined in savehist.el.gz.

Signature

(savehist--merge OLD NEW)

Documentation

Merge the OLD history we had with the NEW history we just loaded.

Source Code

;; Defined in /usr/src/emacs/lisp/savehist.el.gz
(defun savehist--merge (old new)
  "Merge the OLD history we had with the NEW history we just loaded."
  ;; We don't know the relative age of the various entries in OLD and
  ;; NEW; it's possible that most entries in NEW are much older than
  ;; those in OLD or vice versa, or anything in-between.  Maybe we should
  ;; export the `lib/diffseq.h' to Elisp and use it here, but in the mean
  ;; time we interleave the two lists, which should usually be tolerable.
  (let ((res ()))
    (while (and old new)
      (push (pop old) res) ;; Keep the first element first.
      (push (pop new) res))
    ;; In order to avoid problems when merging repeatedly, we want to be
    ;; idempotent, i.e. (merge (merge OLD NEW) NEW) = (merge OLD NEW).
    (delete-dups (nconc (nreverse res) old new))))