From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Karl Chen" Newsgroups: gmane.emacs.bugs Subject: add-to-plist, add-plist-to-plist functions Date: Sun, 28 Apr 2002 16:26:56 -0700 Organization: University of California, Berkeley Sender: bug-gnu-emacs-admin@gnu.org Message-ID: NNTP-Posting-Host: localhost.gmane.org X-Trace: main.gmane.org 1020036469 20681 127.0.0.1 (28 Apr 2002 23:27:49 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 28 Apr 2002 23:27:49 +0000 (UTC) Return-path: Original-Received: from fencepost.gnu.org ([199.232.76.164]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 171y57-0005NK-00 for ; Mon, 29 Apr 2002 01:27:49 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 171y4v-0003eI-00; Sun, 28 Apr 2002 19:27:37 -0400 Original-Received: from agate.berkeley.edu ([128.32.206.40]) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 171y4J-0003be-00 for ; Sun, 28 Apr 2002 19:26:59 -0400 Original-Received: (from news@localhost) by agate.berkeley.edu (8.11.6/8.11.3) id g3SNQvT78362 ; Sun, 28 Apr 2002 16:26:57 -0700 (PDT) (envelope-from news) Original-To: gnu-emacs-bug@prep.ai.mit.edu Original-Path: not-for-mail Original-Newsgroups: gnu.emacs.bug Original-Lines: 42 Original-NNTP-Posting-Host: star.cs.berkeley.edu Original-X-Trace: agate.berkeley.edu 1020036417 78360 128.32.42.27 (28 Apr 2002 23:26:57 GMT) Original-X-Complaints-To: usenet@agate.berkeley.edu Original-NNTP-Posting-Date: Sun, 28 Apr 2002 23:26:57 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Errors-To: bug-gnu-emacs-admin@gnu.org X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.0.9 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.bugs:1012 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:1012 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