Initial Commit
[packages] / xemacs-packages / ilisp / ilisp-snd.el
1 ;;; -*- Mode: Emacs-Lisp -*-
2
3 ;;; ilisp-snd.el --
4 ;;; ILISP send and support.
5 ;;;
6 ;;; This file is part of ILISP.
7 ;;; Please refer to the file COPYING for copyrights and licensing
8 ;;; information.
9 ;;; Please refer to the file ACKNOWLEGDEMENTS for an (incomplete) list
10 ;;; of present and past contributors.
11 ;;;
12 ;;; $Id: ilisp-snd.el,v 1.6 2009-08-13 16:47:39 aidan Exp $
13
14
15 ;;;%% Package / Symbol support
16
17 ;;;---------------------------------------------------------------------------
18 ;;; Package hacks by Martin Atzmueller
19 ;;;
20 ;;; 19990824 Marco Antoniotti
21
22 ;; Have compiled 21.4 code also work on XEmacs binaries with real support
23 ;; for multiple values, by avoiding runtime calls to #'values: 
24 (eval-when-compile (when (eq 'list (symbol-function 'values))
25                      (define-compiler-macro values (&rest args)
26                        `(list ,@args))))
27
28 (defvar *ILISP-default-package* "COMMON-LISP-USER")
29
30 (defun ilisp-add-set-package-hook ()    ; Was: add-set-package-hook
31   (interactive)
32   (add-hook 'lisp-mode-hook
33             '(lambda ()
34                ;; ilisp-buffer must exist and be ready
35                (if (and (boundp 'ilisp-buffer)
36                         (not (equal ilisp-buffer "*nil*"))
37                         (not (ilisp-value 'ilisp-initializing t))
38                         (ilisp-value 'ilisp-status) " :ready")
39
40                    ;; and check the Package when in ILISP
41                    (lisp-buffer-package)))))
42
43 ;;; ilisp-check-package-advanced --
44 ;;; treat DEFPACKAGE before IN-PACKAGE.
45
46 (defun ilisp-check-package-advanced (hash-defpackage-forms-list 
47                                      hash-in-package-forms-list)
48   "Advanced check for packages in buffer.
49 It hanldes the special case of read-time conditionals - i.e. hash plus
50 or minus forms - as well as normal IN-PACKAGE or DEFPACKAGE forms."
51   (let* ((string
52           (apply #'concat (nconc hash-defpackage-forms-list
53                                  hash-in-package-forms-list)))
54          (string
55           (format (ilisp-value 'ilisp-package-command)
56                   (format (ilisp-value 'ilisp-block-command) string)))
57          (package
58              ;;; (string &optional message status and-go handler)
59            (let ((the-package
60                    (ilisp-send
61                     string "Finding Buffer package with hash-forms" 'pkg nil t)))
62              ;; there may have been an error: fix it.
63              (if (string-match (ilisp-value 'ilisp-error-regexp t) the-package)
64                (progn
65                  (comint-send (ilisp-process) (ilisp-value 'comint-fix-error) t t 'fix "Fixing erroneous package-situation in inferior-lisp." t nil)
66                  "nil")
67                (if the-package
68                  the-package
69                  "nil"))))
70          (case-fold-search t)
71          (npic-regexp (ilisp-value 'ilisp-no-package-in-core-regexp t)))
72     (if (and npic-regexp (string-match npic-regexp package))
73       (progn
74         (message (format "Buffer package not found. Using fallback-package: %s"
75                          (ilisp-value 'ilisp-fallback-package)))
76         (values (ilisp-value 'ilisp-fallback-package) t))
77       (progn
78         (message "Buffer package: %s" package)
79         (values package nil)))))
80
81 ;;;
82 (defun lisp-find-hash-form ()           ; Was: find-hash-form.
83   "Tries to find either an hash-form, e.g. #{+|-}-form, or a regular
84  in-package or defpackage form."
85   (let ((hash-form-regexp (ilisp-value 'ilisp-hash-form-regexp))
86         (in-package-regexp (ilisp-value 'ilisp-in-package-command-string t))
87         (defpackage-regexp (ilisp-value 'ilisp-defpackage-command-string t)))
88     (ignore-errors (backward-char))
89     (and (re-search-forward hash-form-regexp)
90          (let ((found (buffer-substring
91                        (progn
92                          (match-end 0)  ; this is due to problems with
93                          (backward-char) ; the #{+|-}-regexp.
94                          (backward-sexp) ; now we are in front of the exp
95                          (point))
96                        (match-end 0))))
97            
98            (cond ((or (prog1
99                           (string-match in-package-regexp found)
100                         (setq in-package-found-p t))
101                       (string-match defpackage-regexp found))
102                   (backward-char)
103                   (buffer-substring (point) (progn (forward-sexp) (point))))
104                  (t
105                   (buffer-substring
106                    (point)
107                    (progn
108                      (let ((post-form (buffer-substring (point)
109                                                         (progn
110                                                           (forward-sexp)
111                                                           (point))))
112                            )
113                        ;; This is for the case  '#{+|-}({'and'|'or'} expr*)'
114                        (unless (string-match "^\\(#+[^(].\\)\\|\\(#-[^(].\\)"
115                                              post-form)
116                          (forward-sexp))) ; after the #{+|-}-form
117                      (forward-sexp)     ; after the *real* Lisp-exp
118                      (point)))))))))
119
120
121 ;;; lisp-buffer-package-internal -- This function does not work well
122 ;;; for Scheme yet.  After all the module system of Scheme is a system
123 ;;; of very high  entropy.
124 ;;;
125 ;;; 19990824 Marco Antoniotti
126
127 (defun lisp-buffer-package-internal ()
128   "Returns the package of the buffer.
129 If SEARCH-FROM-START is T then will search from the beginning of the
130 buffer, otherwise will search backwards from current point.  This
131 function also tries to correctly handle read-time
132 conditionals and the relative order of DEFPACKAGE and IN-PACKAGE for
133 Common Lisp."
134   (interactive)
135   (setq mode-line-process 'ilisp-status)
136   (let* ((lisp-buffer-package t)
137          (case-fold-search t)
138          (hash-form-regexp (ilisp-value 'ilisp-hash-form-regexp t))
139          (in-package-regexp (ilisp-value 'ilisp-in-package-command-string t))
140          (defpackage-regexp (ilisp-value 'ilisp-defpackage-command-string t))
141          (hash-in-package-forms-list nil)
142          (hash-defpackage-forms-list nil)
143          (in-package-found-p nil)
144          (package nil)
145          (should-not-cache-p nil))
146     (if (not hash-form-regexp)
147         (values nil nil)
148       (save-excursion
149         (goto-char (point-min))
150
151         (while
152             (let* ((hash-expr
153                     (ignore-errors (lisp-find-hash-form)))
154                    (sub-expr
155                     (and hash-expr
156                          (string-match hash-form-regexp hash-expr)
157                          (substring hash-expr (match-beginning 0)))))
158               (when hash-expr
159                 (cond ((string-match "(in-package\\s-*)" hash-expr)
160                        (setq should-not-cache-p t)
161                        nil)
162                       (t
163                        (when (and sub-expr (string-match in-package-regexp sub-expr))
164                          (setq in-package-found-p t)
165                          (push hash-expr hash-in-package-forms-list))
166                        (when (and sub-expr (string-match defpackage-regexp sub-expr))
167                          (push hash-expr hash-defpackage-forms-list))
168                         t)))))
169
170         (multiple-value-bind (package package-not-in-core-p)
171             (ilisp-check-package-advanced
172              (nreverse hash-defpackage-forms-list) 
173              (nreverse hash-in-package-forms-list))
174           (let ((should-not-cache-p (or should-not-cache-p package-not-in-core-p)))
175           ;;; RED? (when (ilisp-value 'comint-errorp t)
176           ;;;  (lisp-display-output package)
177           ;;;  (error "No package"))
178           
179             (when (and package
180                        ;; There was a bug here, used to have the second *
181                        ;; outside of the parens.
182                        ;; CMUCL needs just that WITHIN the double-quotes
183                        ;; the old regexp is (string-match "[ \n\t:\"]*\\([^
184                        ;; \n\t\"]*\\)" package))
185                        (string-match "\\([\"].[^\"]*[\"]\\)" package))
186           
187               (setq package
188                     (substring package
189                                (1+ (match-beginning 1)) (1- (match-end 1)))))
190             ;; => without double-quotes
191
192             (values package should-not-cache-p)))))))
193
194 ;;;
195 (defun set-package-lisp-always ()
196   "Set inferior LISP to a named package.
197 The package is set whether the buffer has a package or not!"
198   (interactive)
199   (let* ((default *ILISP-default-package*)
200          (name
201           (read-string
202            (format "Package [%s]: " (lisp-buffer-package)) ""))
203          (package (and (equal name "") default name)))
204     
205     (if package
206         (ilisp-send (format (ilisp-value 'ilisp-in-package-command) package)
207                     (format "Set %s's package to %s" 
208                             (buffer-name (ilisp-buffer))
209                             package)
210                     'pkg 'dispatch)
211       (error "No package"))))
212               
213 ;;; Martin Atzmueller code ends here.
214 ;;; --------------------------------------------------------------------------
215
216 ;;;
217 (defun lisp-buffer-package ()
218   "Return the package for this buffer.
219 The package name is a string. If there is none, return NIL.  This
220 caches the package unless 'ILISP-DONT-CACHE-PACKAGE' is non-nil, so
221 calling this more than once is cheap."
222   (cond ((and (not (eq buffer-package 'not-yet-computed))
223               (null lisp-dont-cache-package))
224          buffer-package)
225         (ilisp-completion-package ilisp-completion-package)
226         ((or lisp-buffer-package 
227              (memq major-mode ilisp-modes)
228              (not (memq major-mode lisp-source-modes)))
229          nil)
230         (t
231          (make-local-variable 'buffer-package)
232          (make-local-variable 'buffer-mode-name)
233          (multiple-value-bind (package should-not-cache-p)
234              (lisp-buffer-package-internal)
235            (setq buffer-package (if (or should-not-cache-p lisp-dont-cache-package)
236                                     'not-yet-computed package))
237            ;; Display package in mode line
238            (when package 
239              (setq mode-name
240                    (concat (or buffer-mode-name
241                                (setq buffer-mode-name mode-name))
242                            ":" package)))
243            package))))
244
245
246 ;;;
247 (defun package-lisp ()
248   "Show current inferior LISP package."
249   (interactive)
250   (message "Inferior LISP package is %s"
251            (ilisp-send (ilisp-value 'ilisp-package-name-command)
252                        "Finding inferior LISP package" 'pkg)))
253
254 ;;; set-package-lisp --
255 ;;; Left the original version, instead of M. Atzmueller's.
256 ;;;
257 ;;; 19990824 Marco Antoniotti
258 (defun set-package-lisp (package)
259   "Set inferior LISP to package of buffer or a named package with prefix."
260   (interactive 
261    (let ((default (lisp-buffer-package)))
262      (if (or current-prefix-arg (null default))
263          (let ((name
264                 (read-string
265                  (format "Package [%s]: " (lisp-buffer-package)) "")))
266            (list (if (equal name "") default name)))
267        (list default))))
268   (if package
269       (ilisp-send (format (ilisp-value 'ilisp-in-package-command) package)
270                   (format "Set %s's package to %s" 
271                           (buffer-name (ilisp-buffer))
272                           package)
273                   'pkg 'dispatch)
274     (error "No package")))
275
276 ;;;
277 (defun set-buffer-package-lisp (package)
278   "Reset the current package of the current buffer.
279 With prefix specify manually."
280   (interactive (if current-prefix-arg
281                    (list (read-from-minibuffer "Package: " ))
282                  (list nil)))
283   (if package
284       (setq buffer-package package
285             mode-name (concat (or buffer-mode-name mode-name) ":" package))
286     (setq buffer-package 'not-yet-computed)
287     (lisp-buffer-package)))
288
289
290 ;;;%Interface functions
291 ;;;%%Symbols
292 (defun lisp-string-to-symbol (string)
293   "Convert STRING to a symbol, (package delimiter symbol).
294 'package' is either package:symbol or from the current buffer."
295   (let* ((start (if (ilisp-value 'ilisp-package-separator-regexp t)
296                     (string-match (ilisp-value 'ilisp-package-separator-regexp t)
297                                   string)))
298          (end (if start (match-end 0))))
299     (if start
300         (lisp-symbol
301          (if (= start 0)
302              ""
303            (substring string 0 start))
304          (substring string start end)
305          (substring string end))
306       (let ((package (lisp-buffer-package)))
307         (lisp-symbol package (if package "::") string)))))
308
309 ;;;
310 (defun lisp-symbol-to-string (symbol)
311   "Convert SYMBOL to a string."
312   (apply 'concat symbol))
313
314 ;;;
315 (defun lisp-buffer-symbol (symbol)
316   "Return SYMBOL as a string qualified for the current buffer."
317   (let ((symbol-name (lisp-symbol-name symbol))
318         (pkg (lisp-symbol-package symbol))
319         (delimiter (lisp-symbol-delimiter symbol)))
320     (cond ((string= pkg (lisp-buffer-package)) symbol-name)
321           ((string= pkg "") (concat ":" symbol-name))
322           (pkg (concat pkg delimiter symbol-name))
323           (t symbol-name))))
324
325 ;;;
326 (defun lisp-previous-symbol (&optional stay)
327   "Return the immediately preceding symbol encoding.
328 The result is encoded as ((package delimiter symbol) function-p start end).
329 If STAY is T, the end of the symbol will be point."
330   (save-excursion
331     (if (or (and (memq major-mode ilisp-modes)
332                  (= (point) (process-mark (get-buffer-process
333                                            (current-buffer)))))
334             (progn
335               (skip-chars-backward " \t\n")
336               (or (bobp) (memq (char-after (1- (point))) '(?\) ?\")))))
337         nil
338       (let* ((delimiters (ilisp-value 'ilisp-symbol-delimiters))
339              (end (progn
340                     (if (not stay) (skip-chars-forward delimiters))
341                     (point)))
342              (start (progn
343                       (skip-chars-backward delimiters)
344                       (point)))
345              (prefix (if (not (bobp)) (1- start)))
346              (function-p
347               (and prefix
348                    (or (eq (char-after prefix) ?\()
349                        (and (eq (char-after prefix) ?')
350                             (not (bobp))
351                             (eq (char-after (1- prefix)) ?#)))
352                    (not (looking-at "[^: \t\n]*:*\\*[^ \t\n]")))))
353         (cons (lisp-string-to-symbol (buffer-substring start end))
354               (list function-p start end))))))
355
356
357 ;;;
358 (defun lisp-function-name ()
359   "Return the previous function symbol.
360 This is either after a #' or at the start of the current sexp.  If there
361 is no current sexp, return NIL."
362   (save-excursion
363     (let ((symbol (lisp-previous-symbol)))
364       (if (car (cdr symbol))
365           (car symbol)
366         (condition-case ()
367             (if (and (memq major-mode ilisp-modes)
368                      (= (point)
369                         (process-mark 
370                          (get-buffer-process (current-buffer)))))
371                 nil
372               (backward-up-list 1)
373               (down-list 1)
374               (lisp-string-to-symbol
375                (buffer-substring (point) 
376                                  (progn (forward-sexp 1) (point)))))
377           (error nil))))))
378
379 ;;;
380 (defun lisp-defun-name ()
381   "Return the name of the current defun."
382   (save-excursion
383     (lisp-defun-begin)
384     (lisp-string-to-symbol (lisp-def-name t))))
385
386
387 ;;;%% ILISP initializations
388 ;;;
389 (defun ilisp-initialized ()
390   "Return T if the current inferior LISP has been initialized."
391   (memq (buffer-name (ilisp-buffer)) ilisp-initialized))
392
393 ;;;
394 (defun ilisp-load-init (dialect file)
395   "Add FILE to the files to be loaded into the inferior LISP.
396 The file(s) are 'init' files to be loaded when dialect is initialized.
397 If FILE is NIL, the entry will be removed."
398   (let ((old (assoc dialect ilisp-load-inits)))
399     (if file
400         (if old
401             (rplacd old file)
402           (setq ilisp-load-inits (nconc ilisp-load-inits 
403                                         (list (cons dialect file)))))
404       (when old
405         (setq ilisp-load-inits (delq old ilisp-load-inits))))))
406
407 ;;;
408 (defun ilisp-binary (init var)
409   "Initialize VAR to the result of INIT if VAR is NIL."
410   (if (not (ilisp-value var t))
411       (let ((binary (ilisp-value init t)))
412         (if binary
413             (comint-send 
414              (ilisp-process) binary
415              t nil 'binary nil 
416              (` (lambda (error wait message output last)
417                   (if (or error
418                           (not (string-match "\"[^\"]*\"" output)))
419                       (progn
420                         (lisp-display-output output)
421                         (abort-commands-lisp "No binary"))
422                     (setq (, var)
423                           (substring output
424                                      (1+ (match-beginning 0))
425                                      (1- (match-end 0))))))))))))
426
427 ;;;
428 (defun ilisp-done-init ()
429   "Make sure that initialization is done, and, if not, dispatch another check."
430   (if ilisp-load-files
431       (comint-send-code (get-buffer-process (current-buffer))
432                         'ilisp-done-init)
433     (when ilisp-initializing
434       (unless comint-errorp
435         (message "Finished initializing %s" (car ilisp-dialect)))
436       (setq ilisp-initializing nil
437             ilisp-initialized
438             (cons (buffer-name (current-buffer)) ilisp-initialized)))))
439
440 ;;;
441
442 (defun comint-send-code-init-function ()
443   "Stuff that is executed for initialization in the ilisp process buffer."
444   (let ((files ilisp-load-inits)
445         (done nil))
446     (unwind-protect
447       (progn
448         (when (not ilisp-init-binary-extension)
449           (setq ilisp-init-binary-extension 
450                   ilisp-binary-extension))
451
452         (dolist (file files)
453           (let ((load-file 
454                   (let ((source
455                           (expand-file-name (cdr file)
456                                             ilisp-*directory*))
457                         (binary
458                           (expand-file-name
459                            (lisp-file-extension (cdr file)
460                                                 ilisp-binary-extension)
461                            ilisp-*directory*)))
462                     (if (file-newer-than-file-p binary source)
463                       binary
464                       source))))
465             (ilisp-load-or-send (file-name-hack load-file))))
466         (comint-send-code (ilisp-process)
467                           'ilisp-done-init)
468         (setq done t))                         
469       (unless done
470         (setq ilisp-initializing nil)
471         (abort-commands-lisp)))))
472
473 (defun ilisp-init-internal (&optional sync)
474   "Send all of the stuff necessary to initialize."
475   (unwind-protect
476       (progn
477         (when sync
478           (comint-sync (ilisp-process)
479                        "\"Start sync\""  "[ \t\n]*\"Start sync\""
480                        "\"End sync\""    "\"End sync\""))
481         (ilisp-binary 'ilisp-binary-command 'ilisp-binary-extension)
482         (ilisp-binary 'ilisp-init-binary-command 
483                       'ilisp-init-binary-extension)
484
485         ;; This gets executed in the process buffer
486         (comint-send-code
487          (ilisp-process)
488          (function comint-send-code-init-function))
489         (set-ilisp-value 'ilisp-initializing t)) ; progn
490     
491     (unless (ilisp-value 'ilisp-initializing t)
492       (abort-commands-lisp))))
493
494 ;;;
495 (defun ilisp-init (&optional waitp forcep sync)
496   "Initialize the current inferior LISP.
497 If necessary load the files in 'ilisp-load-inits'.  Optional WAITP
498 waits for initialization to finish.  When called interactively, force
499 reinitialization.  With a prefix, get the binary extensions again."
500   (interactive 
501    (list (if current-prefix-arg
502              (progn
503                (set-ilisp-value 'ilisp-init-binary-extension nil)
504                (set-ilisp-value 'ilisp-binary-extension nil)
505                nil))
506          t))
507   (when (or forcep (not (ilisp-initialized)))
508     (message "Started initializing ILISP")
509     (unless ilisp-*directory*
510       (setq ilisp-*directory* (or (ilisp-directory "ilisp.elc" load-path)
511                                   (ilisp-directory "ilisp.el" load-path))))
512     (unless (ilisp-value 'ilisp-initializing t)
513       (ilisp-init-internal sync))
514     (when waitp
515       (while (ilisp-value 'ilisp-initializing t)
516         (accept-process-output)
517         (sit-for 0)))))
518
519 ;;;
520 (defun ilisp-init-and-sync ()
521   "Synchronize with the inferior LISP and then initialize."
522   (ilisp-init nil nil t))
523
524 ;;;
525 (defun call-defun-lisp (arg)
526   "Put a call of the current defun in the inferior LISP and go there.
527 If it is a \(def* name form, look up reasonable forms of name in the
528 input history unless called with prefix ARG. If not found, use \(name
529 or *name* as the call.  If is not a def* form, put the whole form in
530 the buffer."
531   (interactive "P")
532   (if (save-excursion (lisp-defun-begin) (looking-at "(def"))
533       (let* ((symbol (lisp-defun-name))
534              (name (lisp-symbol-name symbol))
535              (package (if (lisp-symbol-package symbol)
536                           (concat "\\("
537                                   (lisp-symbol-package symbol) ":+\\)?")))
538              (variablep (string-match "^\\*" name))
539              (setfp (string-match "(setf \\([^\)]+\\)" name))
540              )
541         (switch-to-lisp t t)
542         (cond (setfp 
543                (setq name 
544                      (substring name (match-beginning 1) (match-end 1)))
545                (lisp-match-ring (if (not arg)
546                                     (concat "(setf[ \t\n]*(" 
547                                             package name "[ \t\n]"))
548                                 (concat "(setf (" name)))
549               (variablep (lisp-match-ring (if (not arg) 
550                                               (concat package name))
551                                           name))
552               (t
553                (let ((fun (concat "(" name)))
554                  (setq name (regexp-quote name))
555                  (or (lisp-match-ring 
556                       (if (not arg) (concat "(" package name "[ \t\n\)]"))
557                       fun 
558                       (not arg))
559                      (lisp-match-ring (concat "(" package
560                                               "[^ \t\n]*-*" name)
561                                       fun))))))
562     (let ((form 
563            (save-excursion
564              (buffer-substring (lisp-defun-begin) 
565                                (lisp-end-defun-text t)))))
566       (switch-to-lisp t t)
567       (comint-kill-input)
568       (insert form))))
569
570 ;;;
571 (defun ilisp-send (string &optional message status and-go handler)
572   "Send STRING to the ILISP buffer.
573 Also print MESSAGE set STATUS and return the result if AND-GO is NIL,
574 otherwise switch to ilisp if and-go is T and show message and results.
575 If AND-GO is 'dispatch, then the command will be executed without
576 waiting for results.  If AND-GO is 'call, then a call will be
577 generated. If this is the first time an ilisp command has been
578 executed, the lisp will also be initialized from the files in
579 ilisp-load-inits.  If there is an error, comint-errorp will be T and
580 it will be handled by HANDLER."
581   (ilisp-init t)
582   (let ((process (ilisp-process))
583         (dispatch (eq and-go 'dispatch)))
584     (when message
585       (message "%s" (if dispatch
586                         (concat "Started " message)
587                       message)))
588     ;; No completion table
589     (setq ilisp-original nil)
590
591     (cond ((memq and-go '(t call))
592            (comint-send process string nil nil status message handler)
593            (if (eq and-go 'call)
594                (call-defun-lisp nil)
595              (switch-to-lisp t t))
596            nil)
597           (t
598            (let* ((save (ilisp-value 'ilisp-save-command t))
599                   (result
600                    (comint-send 
601                     process
602                     (if save (format save string) string)
603                     ;; Interrupt without waiting
604                     t (unless dispatch 'wait) status message handler)))
605              (when save
606                (comint-send
607                 process
608                 (ilisp-value 'ilisp-restore-command t)
609                 ;; Martin Atzmueller 2000-01-22
610                 ;; this was necessary to have it work in Emacs 20.3 smoothly
611                 ;; old one: t nil 'restore "Restore" t t
612                 ;; mew experimental:
613                 ;; t (unless dispatch 'wait) 'restore "Restore" t t))
614                 t (unless dispatch 'wait) 'restore "Restore" t t))           
615              (unless dispatch
616                (while (not (cdr result))
617                  ;; (sit-for 0)  ; 19990912 Pretty useless.
618                  (accept-process-output))
619                (comint-remove-whitespace (car result))))))))
620
621
622 ;;;
623 (defun ilisp-load-or-send (file)
624   "Try to load FILE into the inferior LISP.
625 If the file is not accessible in the inferior LISP as determined by
626 ilisp-load-or-send-command, then visit the file and send the file over
627 the process interface."
628
629   (let* ((command
630           (format (ilisp-value 'ilisp-load-or-send-command) 
631                   (lisp-file-extension
632                    file 
633                    (ilisp-value 'ilisp-init-binary-extension t))
634                   file)))
635     (set-ilisp-value 'ilisp-load-files 
636                      (nconc (ilisp-value 'ilisp-load-files t) (list file)))
637     (comint-send
638      (ilisp-process) command t nil 'load
639      (format "Loading %s" file)
640      (function
641       (lambda (error wait message output last)
642         (let* ((file (first (last ilisp-load-files)))
643                (process (get-buffer-process (current-buffer)))
644                (case-fold-search t))
645           (if (and output 
646                    (string-match "nil" (car (lisp-last-line output))))
647               (let* ((old-buffer (get-file-buffer file))
648                      (buffer (find-file-noselect file))
649                      (string (save-excursion
650                                (set-buffer buffer)
651                                (buffer-string))))
652                 (unless old-buffer (kill-buffer buffer))
653                 (if (string= "" string)
654                     (abort-commands-lisp (format "Can't find file %s" file))
655                   (comint-send
656                    process
657                    (format ilisp-block-command string)
658                    t nil 'send (format "Sending %s" file)
659                    (function (lambda (error wait message output last)
660                                (if error
661                                    (progn 
662                                      (comint-display-error output)
663                                      (abort-commands-lisp
664                                       (format "Error sending %s"
665                                               (first (last ilisp-load-files)))
666                                       ))
667                                  (setq ilisp-load-files
668                                        (delq (first (last ilisp-load-files))
669                                              ilisp-load-files))))))))
670             (when error (ilisp-handler error wait message output last))
671             (setq ilisp-load-files (delq file ilisp-load-files)))))))))
672
673 ;;; end of file -- ilisp-snd.el --