1 ;; Common Lisp bindings for GTK+ v2.0
2 ;; Copyright (C) 1999-2000 Espen S. Johnsen <espejohn@online.no>
4 ;; This library is free software; you can redistribute it and/or
5 ;; modify it under the terms of the GNU Lesser General Public
6 ;; License as published by the Free Software Foundation; either
7 ;; version 2 of the License, or (at your option) any later version.
9 ;; This library is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;; Lesser General Public License for more details.
14 ;; You should have received a copy of the GNU Lesser General Public
15 ;; License along with this library; if not, write to the Free Software
16 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ;; $Id: gutils.lisp,v 1.9 2001/10/21 16:53:13 espen Exp $
23 (defun type-expand-1 (form)
24 (let ((def (cond ((symbolp form)
25 (info type expander form))
26 ((and (consp form) (symbolp (car form)))
27 (info type expander (car form)))
30 (values (funcall def (if (consp form) form (list form))) t)
36 (defun type-expand-to (type form)
37 (labels ((expand (form0)
38 (if (eq (first (mklist form0)) type)
40 (multiple-value-bind (expanded-form expanded-p)
43 (expand expanded-form)
44 (error "~A can not be expanded to ~A" form type))))))
47 (defmacro with-gc-disabled (&body body)
48 (let ((gc-inhibit (make-symbol "GC-INHIBIT")))
50 (let ((,gc-inhibit lisp::*gc-inhibit*))
58 (if (atom obj) (list obj) obj))
61 (and (symbolp obj) (not (member obj '(t nil)))))
63 (defun all-equal (&rest objects)
68 (equal (first objects) (second objects))
69 (apply #'all-equal (rest objects)))))
71 (defun neq (obj1 obj2)
74 (defmacro return-if (form)
75 (let ((result (make-symbol "RESULT")))
76 `(let ((,result ,form))
80 (defun make-pointer (address)
83 (defun null-pointer-p (pointer)
84 (zerop (sap-int pointer)))
87 (defmacro when-bind ((var expr) &body body)
93 (defmacro assoc-ref (key alist &key (test #'eq))
94 `(cdr (assoc ,key ,alist :test ,test)))
97 (defmacro assoc-lref (key alist &key (test #'eq))
98 `(cadr (assoc ,key ,alist :test ,test)))
101 (defun assoc-rem (key alist &key (test #'eq))
102 (remove-if #'(lambda (element) (funcall test key (car element))) alist))
105 (defun assoc-delete (key alist &key (test #'eq))
106 (delete-if #'(lambda (element) (funcall test key (car element))) alist))
109 (defun funcallable (object)
114 (defun intersection-p (list1 list2 &key (test #'eq))
115 (dolist (obj list1 nil)
116 (when (member obj list2 :test test)
117 (return-from intersection-p t))))
120 (defun split-string (string delimiter)
121 (declare (simple-string string) (character delimiter))
122 (check-type string string)
123 (check-type delimiter character)
124 (let ((pos (position delimiter string)))
128 (subseq string 0 pos)
129 (split-string (subseq string (1+ pos)) delimiter)))))
131 (defun split-string-if (string predicate)
132 (declare (simple-string string))
133 (check-type string string)
134 (check-type predicate (or symbol function))
135 (let ((pos (position-if predicate string :start 1)))
139 (subseq string 0 pos)
140 (split-string-if (subseq string pos) predicate)))))
142 (defun concatenate-strings (strings &optional delimiter)
143 (if (not (rest strings))
148 (if delimiter (string delimiter) "")
149 (concatenate-strings (rest strings) delimiter))))
151 (defun string-prefix-p (prefix string)
153 (>= (length string) (length prefix))
154 (string= prefix string :end2 (length prefix))))
156 (defun get-all (plist property)
157 (multiple-value-bind (property value tail)
158 (get-properties plist (list property))
160 (cons value (get-all (cddr tail) property)))))
162 (defun plist-remove (plist property)
164 (if (eq (first plist) property)
165 (plist-remove (cddr plist) property)
167 (first plist) (second plist) (plist-remove (cddr plist) property)))))