annotate lisp/alist.el @ 384:bbff43aa5eb7 r21-2-7

Import from CVS: tag r21-2-7
author cvs
date Mon, 13 Aug 2007 11:08:24 +0200
parents cc15677e0335
children 6719134a07c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 337
diff changeset
1 ;;; alist.el --- utility functions about assoc-list
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
2
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 337
diff changeset
3 ;; Copyright (C) 1993,1994,1995,1996 Free Software Foundation, Inc.
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
4
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 337
diff changeset
6 ;; Version:
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 337
diff changeset
7 ;; $Id: alist.el,v 1.1 1997/11/29 20:37:43 steve Exp $
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
8 ;; Keywords: alist
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
9
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 337
diff changeset
10 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
11
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
12 ;; This program is free software; you can redistribute it and/or
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
13 ;; modify it under the terms of the GNU General Public License as
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
14 ;; published by the Free Software Foundation; either version 2, or (at
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
15 ;; your option) any later version.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
16
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
17 ;; This program is distributed in the hope that it will be useful, but
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
20 ;; General Public License for more details.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
21
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
26
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
27 ;;; Code:
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
28
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
29 (defun put-alist (item value alist)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
30 "Modify ALIST to set VALUE to ITEM.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
31 If there is a pair whose car is ITEM, replace its cdr by VALUE.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
32 If there is not such pair, create new pair (ITEM . VALUE) and
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
33 return new alist whose car is the new pair and cdr is ALIST.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
34 \[tomo's ELIS like function]"
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
35 (let ((pair (assoc item alist)))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
36 (if pair
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
37 (progn
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
38 (setcdr pair value)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
39 alist)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
40 (cons (cons item value) alist)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
41 )))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
42
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
43 (defun del-alist (item alist)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
44 "If there is a pair whose key is ITEM, delete it from ALIST.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
45 \[tomo's ELIS emulating function]"
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
46 (if (equal item (car (car alist)))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
47 (cdr alist)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
48 (let ((pr alist)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
49 (r (cdr alist))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
50 )
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
51 (catch 'tag
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
52 (while (not (null r))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
53 (if (equal item (car (car r)))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
54 (progn
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
55 (rplacd pr (cdr r))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
56 (throw 'tag alist)))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
57 (setq pr r)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
58 (setq r (cdr r))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
59 )
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
60 alist))))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
61
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
62 (defun set-alist (symbol item value)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
63 "Modify a alist indicated by SYMBOL to set VALUE to ITEM."
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
64 (or (boundp symbol)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
65 (set symbol nil)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
66 )
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
67 (set symbol (put-alist item value (symbol-value symbol)))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
68 )
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
69
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
70 (defun remove-alist (symbol item)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
71 "Remove ITEM from the alist indicated by SYMBOL."
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
72 (and (boundp symbol)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
73 (set symbol (del-alist item (symbol-value symbol)))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
74 ))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
75
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
76 (defun modify-alist (modifier default)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
77 "Modify alist DEFAULT into alist MODIFIER."
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
78 (mapcar (function
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
79 (lambda (as)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
80 (setq default (put-alist (car as)(cdr as) default))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
81 ))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
82 modifier)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
83 default)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
84
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
85 (defun set-modified-alist (sym modifier)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
86 "Modify a value of a symbol SYM into alist MODIFIER.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
87 The symbol SYM should be alist. If it is not bound,
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
88 its value regard as nil."
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
89 (if (not (boundp sym))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
90 (set sym nil)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
91 )
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
92 (set sym (modify-alist modifier (eval sym)))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
93 )
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
94
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
95
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
96 ;;; @ end
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
97 ;;;
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
98
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
99 (provide 'alist)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
100
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents:
diff changeset
101 ;;; alist.el ends here