1 ;;; knode.el --- Generic nodes for use as elements in data structures.
3 ;; Copyright (C) 1993-1995, Free Software Foundation, Inc.
4 ;; Developed with support from Motorola Inc.
6 ;; Author: Bob Weiner, Brown U.
8 ;; Maintainer: Mats Lidell <matsl@contactor.se>
9 ;; Keywords: extensions, hypermedia, outlines
11 ;; This file is part of GNU Hyperbole.
13 ;; GNU Hyperbole is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 3, or (at
16 ;; your option) any later version.
18 ;; GNU Hyperbole is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
40 (defun knode:create (contents &optional prop-list)
41 "Return a new knode which stores CONTENTS and optional PROP-LIST."
46 (defun knode:contents (knode)
47 "Return KNODE's contents."
48 (if (knode:is-p knode)
49 (car (cdr (memq 'contents knode)))
50 (error "(knode:contents): Argument must be a knode.")))
52 (fset 'knode:copy 'copy-tree)
54 (defun knode:is-p (object)
56 (and (listp object) (eq (car object) 'knode)))
58 (defun knode:set-contents (knode contents)
59 "Set KNODE's CONTENTS."
60 (if (knode:is-p knode)
61 (setcar (cdr (memq 'contents knode)) contents)
62 (error "(knode:set-contents): First arg must be a knode.")))
68 (defun knode:get-attr (obj attribute)
69 "Return the value of OBJECT's ATTRIBUTE."
70 (car (cdr (memq attribute obj))))
72 (defun knode:remove-attr (obj attribute)
73 "Remove OBJECT's ATTRIBUTE, if any, and return modified OBJECT.
74 Use (setq object (knode:remove-attr object attribute)) to ensure that OBJECT
80 (while (and sym (eq sym attribute))
81 (setq tail (cdr (cdr tail))
85 tail (cdr (cdr tail)))
88 (if (eq sym attribute)
89 (setcdr (cdr prev) (cdr (cdr tail))))
91 tail (cdr (cdr tail))))
94 (defun knode:set-attr (obj attribute value)
95 "Set OBJECT's ATTRIBUTE to VALUE and return OBJECT."
96 (let ((attr (memq attribute obj)))
98 (setcar (cdr attr) value)
99 (setq obj (nconc obj (list attribute value)))))
103 ;;; Private variables
108 ;;; knode.el ends here