0d07716f |
1 | ;; Common Lisp bindings for GTK+ v2.0 |
2 | ;; Copyright (C) 1999-2000 Espen S. Johnsen <espejohn@online.no> |
3 | ;; |
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. |
8 | ;; |
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. |
13 | ;; |
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 |
17 | |
eef2c0f1 |
18 | ;; $Id: gutils.lisp,v 1.4 2001/04/29 20:01:54 espen Exp $ |
0d07716f |
19 | |
20 | |
21 | (in-package "KERNEL") |
22 | |
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))) |
28 | (t nil)))) |
29 | (if def |
30 | (values (funcall def (if (consp form) form (list form))) t) |
31 | (values form nil)))) |
32 | |
33 | |
34 | (in-package "GLIB") |
35 | |
36 | |
37 | (defun type-expand-to (type form) |
38 | (labels ((expand (form0) |
39 | (if (eq (first (mklist form0)) type) |
40 | form0 |
41 | (multiple-value-bind (expanded-form expanded-p) |
42 | (type-expand-1 form0) |
43 | (if expanded-p |
44 | (expand expanded-form) |
45 | (error "~A can not be expanded to ~A" form type)))))) |
46 | (expand form))) |
47 | |
48 | (defmacro with-gc-disabled (&body body) |
49 | (let ((gc-inhibit (make-symbol "GC-INHIBIT"))) |
50 | `(progn |
51 | (let ((,gc-inhibit lisp::*gc-inhibit*)) |
52 | (ext:gc-off) |
53 | (unwind-protect |
54 | ,@body |
55 | (unless ,gc-inhibit |
56 | (ext:gc-on))))))) |
57 | |
58 | (defun mklist (obj) |
59 | (if (atom obj) (list obj) obj)) |
60 | |
61 | (defun namep (obj) |
62 | (and (symbolp obj) (not (member obj '(t nil))))) |
63 | |
64 | (defun all-equal (&rest objects) |
65 | (or |
66 | (null objects) |
67 | (null (rest objects)) |
68 | (and |
69 | (equal (first objects) (second objects)) |
70 | (apply #'all-equal (rest objects))))) |
71 | |
72 | (defun neq (obj1 obj2) |
73 | (not (eq obj1 obj2))) |
74 | |
75 | (defmacro return-if (form) |
76 | (let ((result (make-symbol "RESULT"))) |
77 | `(let ((,result ,form)) |
78 | (when ,result |
79 | (return ,result))))) |
80 | |
81 | (defun make-pointer (address) |
82 | (int-sap address)) |
83 | |
84 | (defun null-pointer-p (pointer) |
85 | (zerop (sap-int pointer))) |
eef2c0f1 |
86 | |
b94247b5 |
87 | |
88 | (defmacro when-bind ((var expr) &body body) |
89 | `(let ((,var ,expr)) |
90 | (when ,var |
91 | ,@body))) |
92 | |
93 | |
94 | (defmacro assoc-ref (key alist &key (test #'eq)) |
95 | `(cdr (assoc ,key ,alist :test ,test))) |
96 | |
97 | |
98 | (defmacro assoc-lref (key alist &key (test #'eq)) |
99 | `(cadr (assoc ,key ,alist :test ,test))) |
100 | |
101 | |
102 | (defun assoc-rem (key alist &key (test #'eq)) |
103 | (remove-if #'(lambda (element) (funcall test key (car element))) alist)) |
104 | |
105 | |
106 | (defun assoc-delete (key alist &key (test #'eq)) |
107 | (delete-if #'(lambda (element) (funcall test key (car element))) alist)) |
5ab32e1f |
108 | |
109 | |
110 | (defun funcallable (object) |
111 | (if (consp object) |
112 | (fdefinition object) |
113 | object)) |
114 | |
eef2c0f1 |
115 | |
116 | (defun split-string (string delimiter) |
117 | (declare (simple-string string) (character delimiter)) |
118 | (check-type string string) |
119 | (check-type delimiter character) |
120 | (let ((pos (position delimiter string))) |
121 | (if (not pos) |
122 | (list string) |
123 | (cons |
124 | (subseq string 0 pos) |
125 | (split-string (subseq string (1+ pos)) delimiter))))) |
126 | |
127 | (defun split-string-if (string predicate) |
128 | (declare (simple-string string)) |
129 | (check-type string string) |
130 | (check-type predicate (or symbol function)) |
131 | (let ((pos (position-if predicate string :start 1))) |
132 | (if (not pos) |
133 | (list string) |
134 | (cons |
135 | (subseq string 0 pos) |
136 | (split-string-if (subseq string pos) predicate))))) |
137 | |
138 | (defun concatenate-strings (strings &optional delimiter) |
139 | (if (not (rest strings)) |
140 | (first strings) |
141 | (concatenate |
142 | 'string |
143 | (first strings) |
144 | (if delimiter (string delimiter) "") |
145 | (concatenate-strings (rest strings))))) |