all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Karl Chen" <quarl.newsgroup@REMOVE_ME_quarl.org>
Subject: add-to-plist, add-plist-to-plist functions
Date: Sun, 28 Apr 2002 16:26:56 -0700	[thread overview]
Message-ID: <aai0g1$2cgo$1@agate.berkeley.edu> (raw)

Hi, I wrote these two functions which may be useful to others:

(defun add-to-plist (plist-var p)
  "Add an element to a plist symbol.

If the element is a cons:
  If there exists an element in the value of plist-var whose car matches the
new element's car, replace its cdr. Else prepend the whole element to the
list.

If the element is not a cons:
  If the element does not already exist, prepend it. (Equivalent to
`add-to-list' in this case.)"
  (if (consp p)
      (let ((plist (symbol-value plist-var))
            (pname (car p)))
        (when pname
          (while plist
            (let ((p0 (car plist)))
              (setq plist (cdr plist))
              (when (and (consp p0) (eq (car p0) pname))
                (setcdr p0 (cdr p))
            (setq plist nil)
            (setq pname nil))))
          (when pname
            (set plist-var (cons p (symbol-value plist-var)))
            )))
    (add-to-list plist-var p)))

(defun add-plist-to-plist (plist new-plist)
  "Apply NEW-PLIST on PLIST by calling `add-to-plist' on each entry."
  (while new-plist
    (add-to-plist 'plist (car new-plist))
    (setq new-plist (cdr new-plist))
    )
  plist)

--
Karl Chen

             reply	other threads:[~2002-04-28 23:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-28 23:26 Karl Chen [this message]
2002-04-28 23:38 ` add-to-plist, add-plist-to-plist functions Miles Bader
2002-04-28 23:45   ` Karl Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='aai0g1$2cgo$1@agate.berkeley.edu' \
    --to=quarl.newsgroup@remove_me_quarl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.