|
60 | 60 | (provide-public (ignore . l) (noop)) |
61 | 61 | (provide-public (negate pred?) (lambda x (not (apply pred? x)))) |
62 | 62 |
|
63 | | -(define-public (keyword->string x) |
64 | | - (symbol->string (keyword->symbol x))) |
65 | | -(define-public (string->keyword x) |
66 | | - (symbol->keyword (string->symbol x))) |
| 63 | +(define-public (keyword->string x) (symbol->string (keyword->symbol x))) |
| 64 | +(define-public (string->keyword x) (symbol->keyword (string->symbol x))) |
67 | 65 | (define-public (keyword->number x) |
68 | | - (string->number (string-tail (symbol->string (keyword->symbol x)) 1))) |
| 66 | + (string->number (string-tail (symbol->string (keyword->symbol x)) 1)) |
| 67 | +) ;define-public |
69 | 68 | (define-public (number->keyword x) |
70 | | - (symbol->keyword (string->symbol (string-append "%" (number->string x))))) |
| 69 | + (symbol->keyword (string->symbol (string-append "%" (number->string x)))) |
| 70 | +) ;define-public |
71 | 71 |
|
72 | 72 | (define-public (save-object file value) |
73 | | - (string-save |
74 | | - (let-temporarily (((*s7* 'print-length) 9223372036854775807)) |
75 | | - (object->string value)) |
76 | | - file)) |
| 73 | + (string-save (let-temporarily (((*s7* 'print-length) 9223372036854775807)) |
| 74 | + (object->string value) |
| 75 | + ) ;let-temporarily |
| 76 | + file |
| 77 | + ) ;string-save |
| 78 | +) ;define-public |
77 | 79 |
|
78 | 80 | (define-public (load-object file) |
79 | | - (with-input-from-string (string-load file) |
80 | | - (lambda () (read)))) |
| 81 | + (with-input-from-string (string-load file) (lambda () (read))) |
| 82 | +) ;define-public |
81 | 83 |
|
82 | 84 | (define-public (persistent-ref dir key) |
83 | | - (and (persistent-has? dir key) |
84 | | - (persistent-get dir key))) |
| 85 | + (and (persistent-has? dir key) (persistent-get dir key)) |
| 86 | +) ;define-public |
85 | 87 |
|
86 | 88 | (define-public (sourcify x) |
87 | | - (if (and (procedure? x) (procedure-source x)) (procedure-source x) x)) |
| 89 | + (if (and (procedure? x) (procedure-source x)) (procedure-source x) x) |
| 90 | +) ;define-public |
88 | 91 |
|
89 | 92 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
90 | 93 | ;; Common programming constructs |
91 | 94 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
92 | 95 |
|
93 | 96 | (define-public-macro (with var val . body) |
94 | 97 | (if (or (pair? var) (null? var)) |
95 | | - `(apply (lambda ,var ,@body) ,val) |
96 | | - `(let ((,var ,val)) ,@body))) |
| 98 | + `(apply (lambda ,var ,@body) ,val) |
| 99 | + `(let ((,var ,val)) ,@body) |
| 100 | + ) ;if |
| 101 | +) ;define-public-macro |
97 | 102 |
|
98 | 103 | (define-public-macro (with-define fun fun-body . body) |
99 | | - `(let ((,(car fun) (lambda ,(cdr fun) ,fun-body))) |
100 | | - ,@body)) |
| 104 | + `(let ((,(car fun) (lambda ,(cdr fun) ,fun-body))) ,@body) |
| 105 | +) ;define-public-macro |
101 | 106 |
|
102 | 107 | ;; handle multiple values in a way compatible with s7 (and backcompatible with guile) |
103 | 108 | (define-public-macro (with-global var val . body) |
104 | 109 | (let ((old (gensym)) (new (gensym))) |
105 | 110 | `(let ((,old ,var)) |
106 | 111 | (set! ,var ,val) |
107 | | - (call-with-values |
108 | | - (lambda () ,@body) |
109 | | - (lambda vals |
110 | | - (set! ,var ,old) |
111 | | - (apply values vals)))))) |
| 112 | + (call-with-values (lambda ,() ,@body) |
| 113 | + (lambda vals (set! ,var ,old) (apply values vals)))) |
| 114 | + ) ;let |
| 115 | +) ;define-public-macro |
112 | 116 |
|
113 | 117 | (define-public-macro (and-with var val . body) |
114 | | - `(with ,var ,val |
115 | | - (and ,var (begin ,@body)))) |
| 118 | + `(with ,var ,val (and ,var (begin ,@body))) |
| 119 | +) ;define-public-macro |
116 | 120 |
|
117 | 121 | (define-public-macro (with-result result . body) |
118 | | - `(let* ((return ,result) |
119 | | - (dummy (begin ,@body))) |
120 | | - return)) |
| 122 | + `(let* ((return ,result) (dummy (begin ,@body))) return) |
| 123 | +) ;define-public-macro |
121 | 124 |
|
122 | 125 | (define (range-list start end delta) |
123 | | - (if (< start end) |
124 | | - (cons start (range-list (+ start delta) end delta)) |
125 | | - '())) |
| 126 | + (if (< start end) (cons start (range-list (+ start delta) end delta)) '()) |
| 127 | +) ;define |
126 | 128 |
|
127 | 129 | (define (range-list* start end delta) |
128 | | - (if (<= start end) |
129 | | - (cons start (range-list* (+ start delta) end delta)) |
130 | | - '())) |
| 130 | + (if (<= start end) (cons start (range-list* (+ start delta) end delta)) '()) |
| 131 | +) ;define |
131 | 132 |
|
132 | 133 | (define-public (.. start end . delta) |
133 | | - (if (null? delta) |
134 | | - (range-list start end 1) |
135 | | - (range-list start end (car delta)))) |
| 134 | + (if (null? delta) (range-list start end 1) (range-list start end (car delta))) |
| 135 | +) ;define-public |
136 | 136 |
|
137 | 137 | (define-public (... start end . delta) |
138 | | - (if (null? delta) |
139 | | - (range-list* start end 1) |
140 | | - (range-list* start end (car delta)))) |
| 138 | + (if (null? delta) (range-list* start end 1) (range-list* start end (car delta))) |
| 139 | +) ;define-public |
141 | 140 |
|
142 | 141 | (define-public-macro (for what . body) |
143 | 142 | (let ((n (length what))) |
144 | 143 | (cond ((== n 2) |
145 | 144 | ;; range over values of a list |
146 | | - `(for-each (lambda (,(car what)) ,@body) |
147 | | - ,(cadr what))) |
| 145 | + `(for-each (lambda (,(car what)) ,@body) ,(cadr what)) |
| 146 | + ) ; |
148 | 147 | ((== n 3) |
149 | 148 | ;; range over values from start to end with step 1 |
150 | | - `(do ((,(car what) ,(cadr what) (+ ,(car what) 1))) |
151 | | - ((>= ,(car what) ,(caddr what)) (noop)) |
152 | | - ,@body)) |
| 149 | + `(do ((,(car what) ,(cadr what) (+ ,(car what) ,1))) |
| 150 | + ((>= ,(car what) ,(caddr what)) (noop)) |
| 151 | + ,@body) |
| 152 | + ) ; |
153 | 153 | ((== n 4) |
154 | 154 | ;; range over values from start to end with step |
155 | | - `(if (> ,(cadddr what) 0) |
156 | | - (do ((,(car what) ,(cadr what) (+ ,(car what) ,(cadddr what)))) |
157 | | - ((>= ,(car what) ,(caddr what)) (noop)) |
158 | | - ,@body) |
159 | | - (do ((,(car what) ,(cadr what) (+ ,(car what) ,(cadddr what)))) |
160 | | - ((<= ,(car what) ,(caddr what)) (noop)) |
161 | | - ,@body))) |
| 155 | + `(if (> ,(cadddr what) ,0) |
| 156 | + (do ((,(car what) ,(cadr what) (+ ,(car what) ,(cadddr what)))) |
| 157 | + ((>= ,(car what) ,(caddr what)) (noop)) |
| 158 | + ,@body) |
| 159 | + (do ((,(car what) ,(cadr what) (+ ,(car what) ,(cadddr what)))) |
| 160 | + ((<= ,(car what) ,(caddr what)) (noop)) |
| 161 | + ,@body)) |
| 162 | + ) ; |
162 | 163 | ((== n 5) |
163 | 164 | ;; range over values from start to end with step and comparison |
164 | 165 | `(do ((,(car what) ,(cadr what) (+ ,(car what) ,(cadddr what)))) |
165 | | - ((not (,(car (cddddr what)) ,(car what) ,(caddr what))) (noop)) |
166 | | - ,@body)) |
167 | | - (else '(noop))))) |
| 166 | + ((not (,(car (cddddr what)) ,(car what) ,(caddr what))) (noop)) |
| 167 | + ,@body) |
| 168 | + ) ; |
| 169 | + (else '(noop)) |
| 170 | + ) ;cond |
| 171 | + ) ;let |
| 172 | +) ;define-public-macro |
168 | 173 |
|
169 | 174 | (define-public-macro (repeat n . body) |
170 | 175 | (let ((x (gensym))) |
171 | | - `(for (,x 0 ,n) ,@body))) |
| 176 | + `(for (,x ,0 ,n) ,@body) |
| 177 | + ) ;let |
| 178 | +) ;define-public-macro |
172 | 179 |
|
173 | | -(define-public-macro (twice . body) |
174 | | - `(begin ,@body ,@body)) |
| 180 | +(define-public-macro (twice . body) `(begin ,@body ,@body)) |
175 | 181 |
|
176 | 182 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
177 | 183 | ;; Small rewritings on top of C++ interface |
178 | 184 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
179 | 185 |
|
180 | | -(define-public (path->tree p) |
181 | | - (and (path-exists? p) (cpp-path->tree p))) |
| 186 | +(define-public (path->tree p) (and (path-exists? p) (cpp-path->tree p))) |
182 | 187 |
|
183 | 188 | (define-public selection-active? selection-active-any?) |
184 | 189 |
|
185 | 190 | (define-public (selection-active-non-small?) |
186 | | - (and (selection-active?) |
187 | | - (not (selection-active-small?)))) |
| 191 | + (and (selection-active?) (not (selection-active-small?))) |
| 192 | +) ;define-public |
188 | 193 |
|
189 | 194 | (define-public (selection-active-large?) |
190 | 195 | (and (selection-active?) |
191 | | - (not (selection-active-small?)) |
192 | | - (not (selection-active-table?)))) |
| 196 | + (not (selection-active-small?)) |
| 197 | + (not (selection-active-table?)) |
| 198 | + ) ;and |
| 199 | +) ;define-public |
193 | 200 |
|
194 | 201 | (define-public (go-to p) |
195 | | - (let* ((r (buffer-path)) |
196 | | - (lp (length p)) |
197 | | - (lr (length r))) |
| 202 | + (let* ((r (buffer-path)) (lp (length p)) (lr (length r))) |
198 | 203 | (and (or (and (<= lr lp) (== (sublist p 0 lr) r)) |
199 | | - (and-with buf (path->buffer p) |
200 | | - (switch-to-buffer buf) #t)) |
201 | | - (go-to-path p)))) |
| 204 | + (and-with buf (path->buffer p) (switch-to-buffer buf) #t) |
| 205 | + ) ;or |
| 206 | + (go-to-path p) |
| 207 | + ) ;and |
| 208 | + ) ;let* |
| 209 | +) ;define-public |
202 | 210 |
|
203 | 211 | (define-public (choose-file fun title type . opts) |
204 | 212 | (when (null? opts) |
205 | | - (with prompt (cond ((string-starts? title "Save") "Save as:") |
206 | | - ((string-starts? title "Export") "Export as:") |
207 | | - ((== title "Select database") "Selected database:") |
208 | | - (else "")) |
209 | | - (set! opts (list prompt)))) |
| 213 | + (with prompt |
| 214 | + (cond ((string-starts? title "Save") "Save as:") |
| 215 | + ((string-starts? title "Export") "Export as:") |
| 216 | + ((== title "Select database") "Selected database:") |
| 217 | + (else "") |
| 218 | + ) ;cond |
| 219 | + (set! opts (list prompt)) |
| 220 | + ) ;with |
| 221 | + ) ;when |
210 | 222 | (when (null? (cdr opts)) |
211 | 223 | ;; Issue #327: Use last file dialog directory if current buffer is scratch |
212 | 224 | (let* ((master (buffer-get-master (current-buffer))) |
213 | 225 | (last-dir (and (url-scratch? master) |
214 | | - (defined? 'get-last-file-dialog-directory) |
215 | | - (get-last-file-dialog-directory)))) |
| 226 | + (defined? 'get-last-file-dialog-directory) |
| 227 | + (get-last-file-dialog-directory) |
| 228 | + ) ;and |
| 229 | + ) ;last-dir |
| 230 | + ) ; |
216 | 231 | (if (and last-dir (string? last-dir) (not (string-null? last-dir))) |
217 | | - (set! opts (list (car opts) (system->url last-dir))) |
218 | | - (set! opts (list (car opts) master))))) |
219 | | - (cpp-choose-file |
220 | | - (lambda (u) |
221 | | - ;; u is return from tm_frame_rep::choose_file in tm_dialogue.cpp |
222 | | - ;; make sure u is a url, or car of u is a url |
223 | | - ;; and that it does not contain a wildcard |
224 | | - (if (or (url? u) (and (pair? u) (url? (car u)))) |
225 | | - (let ((u-url (if (url? u) u (car u)))) |
226 | | - (if (and (not (url-none? u-url)) (url-contains-wildcard? u-url)) |
227 | | - (dialogue-window (message-widget "File name and path cannot contain ' * '") |
228 | | - (lambda () (choose-file fun title type (car opts) (cadr opts))) |
229 | | - "Invalid file name") |
230 | | - (fun u))) |
231 | | - (fun u))) |
232 | | - title type (car opts) (cadr opts))) |
233 | | - |
234 | | -(define-public (alt-windows-delete l) |
235 | | - (for-each alt-window-delete l)) |
| 232 | + (set! opts (list (car opts) (system->url last-dir))) |
| 233 | + (set! opts (list (car opts) master)) |
| 234 | + ) ;if |
| 235 | + ) ;let* |
| 236 | + ) ;when |
| 237 | + (cpp-choose-file (lambda (u) |
| 238 | + ;; u is return from tm_frame_rep::choose_file in tm_dialogue.cpp |
| 239 | + ;; make sure u is a url, or car of u is a url |
| 240 | + ;; and that it does not contain a wildcard |
| 241 | + (if (or (url? u) (and (pair? u) (url? (car u)))) |
| 242 | + (let ((u-url (if (url? u) u (car u)))) |
| 243 | + (if (and (not (url-none? u-url)) (url-contains-wildcard? u-url)) |
| 244 | + (dialogue-window (message-widget "File name and path cannot contain ' * '") |
| 245 | + (lambda () (choose-file fun title type (car opts) (cadr opts))) |
| 246 | + "Invalid file name" |
| 247 | + ) ;dialogue-window |
| 248 | + (fun u) |
| 249 | + ) ;if |
| 250 | + ) ;let |
| 251 | + (fun u) |
| 252 | + ) ;if |
| 253 | + ) ;lambda |
| 254 | + title |
| 255 | + type |
| 256 | + (car opts) |
| 257 | + (cadr opts) |
| 258 | + ) ;cpp-choose-file |
| 259 | +) ;define-public |
| 260 | + |
| 261 | +(define-public (alt-windows-delete l) (for-each alt-window-delete l)) |
236 | 262 |
|
237 | 263 | (define-public (qt4-gui?) (== (gui-version) "qt4")) |
238 | 264 | (define-public (qt4-or-later-gui?) (in? (gui-version) (list "qt4" "qt5" "qt6"))) |
|
0 commit comments