Function: set-nested-alist

set-nested-alist is an autoloaded and byte-compiled function defined in mule-util.el.gz.

Signature

(set-nested-alist KEYSEQ ENTRY ALIST &optional LEN BRANCHES)

Documentation

Set ENTRY for KEYSEQ in a nested alist ALIST.

Optional 4th arg LEN non-nil means the first LEN elements in KEYSEQ
 are considered.
Optional 5th argument BRANCHES if non-nil is branches for a keyseq longer than KEYSEQ. See the documentation of nested-alist-p for more detail.

Source Code

;; Defined in /usr/src/emacs/lisp/international/mule-util.el.gz
;;;###autoload
(defun set-nested-alist (keyseq entry alist &optional len branches)
  "Set ENTRY for KEYSEQ in a nested alist ALIST.
Optional 4th arg LEN non-nil means the first LEN elements in KEYSEQ
 are considered.
Optional 5th argument BRANCHES if non-nil is branches for a keyseq
longer than KEYSEQ.
See the documentation of `nested-alist-p' for more detail."
  (or (nested-alist-p alist)
      (error "Invalid argument %s" alist))
  (let ((len (or len (length keyseq)))
	(i 0))
    (cond
     ((stringp keyseq)             ; We can use `assq' for characters.
      (while (< i len)
        (if (null (nested-alist-p alist))
            (error "Keyseq %s is too long for this nested alist" keyseq))
        (let* ((key-elt (aref keyseq i))
               (slot (assq key-elt (cdr alist))))
          (unless slot
            (setq slot (list key-elt t))
            (push slot (cdr alist)))
          (setq alist (cdr slot)))
        (setq i (1+ i))))
     ((arrayp keyseq)
      (while (< i len)
        (if (null (nested-alist-p alist))
            (error "Keyseq %s is too long for this nested alist" keyseq))
        (let* ((key-elt (aref keyseq i))
               (slot (assoc key-elt (cdr alist))))
          (unless slot
            (setq slot (list key-elt t))
            (push slot (cdr alist)))
          (setq alist (cdr slot)))
        (setq i (1+ i))))
     ((listp keyseq)
      (while (< i len)
        (if (null (nested-alist-p alist))
            (error "Keyseq %s is too long for this nested alist" keyseq))
        (let* ((key-elt (pop keyseq))
               (slot (assoc key-elt (cdr alist))))
          (unless slot
            (setq slot (list key-elt t))
            (push slot (cdr alist)))
          (setq alist (cdr slot)))
        (setq i (1+ i))))
     (t (signal 'wrong-type-argument (list keyseq))))
    (setcar alist entry)
    (if branches
	(setcdr (last alist) branches))))