Codebase list ilisp / debian/5.12.0+cvs.2003.04.02 ilisp-hi.el
debian/5.12.0+cvs.2003.04.02

Tree @debian/5.12.0+cvs.2003.04.02 (Download .tar.gz)

ilisp-hi.el @debian/5.12.0+cvs.2003.04.02raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
;;; -*- Mode: Emacs-Lisp -*-

;;; ilisp-hi.el --
;;; ILISP high level interface functions Lisp <-> Emacs
;;;
;;; This file is part of ILISP.
;;; Please refer to the file COPYING for copyrights and licensing
;;; information.
;;; Please refer to the file ACKNOWLEGDEMENTS for an (incomplete) list
;;; of present and past contributors.
;;;
;;; $Id: ilisp-hi.el,v 1.18 2003/01/02 08:39:18 amoroso Exp $

;;;%Eval/compile
(defun lisp-send-region (start end switch message status format
			       &optional handler)
  "Sends a region to the lisp buffer and execute a 'command' on it.
Given START, END, SWITCH, MESSAGE, STATUS, FORMAT and optional
HANDLER send the region between START and END to the lisp buffer and
execute the command defined by FORMAT on the region, its package and
filename.  If called with a positive prefix, the results will be
inserted at the end of the region.  If SWITCH is T, the command will
be sent and the buffer switched to the inferior LISP buffer.  if
SWITCH is 'call, a call will be inserted.  If SWITCH is 'result the
result will be returned without being displayed.  Otherwise the
results will be displayed in a popup window if lisp-wait-p is T and
the current-prefix-arg is not '- or if lisp-wait-p is nil and the
current-prefix-arg is '-.  If not displayed in a pop-up window then
comint-handler will display the results in a pop-up window if they are
more than one line long, or they are from an error.  STATUS will be
the process status when the command is actually executing.  MESSAGE is
a message to let the user know what is going on."
  (if (= start end) (error "Region is empty"))
  (let ((sexp (lisp-count-pairs start end ?\( ?\)))
	(string (buffer-substring-no-properties start end)))
    (setq string
	  (format (ilisp-value format)
		  (lisp-slashify
		   (if (= sexp 1)
		       string
		       (format (ilisp-value 'ilisp-block-command) string)))
		  (lisp-buffer-package)
		  (buffer-file-name) 
		  (save-excursion	; start line
		    (goto-char (min start end))
		    (beginning-of-line)
		    (1+ (count-lines 1 (min start end))))))
    (let ((result 
	   (ilisp-send
	    string message status
	    (cond ((memq switch '(t call)) switch)
		  ((or (not (eq lisp-wait-p (lisp-minus-prefix))) 
		       current-prefix-arg
		       (eq switch 'result)) nil)
		  (t 'dispatch))
	    handler)))

      (if (and result
               (not (eq switch 'result)))
	  (if current-prefix-arg
	      (save-excursion
		(goto-char end)
		(insert ?\n)
		(insert result))
	    ;; Display the output in the usual way.
	    (lisp-display-output result)))
      result)))

;;;%%Eval
(defun eval-region-lisp (start end &optional switch message status handler)
  "Evaluate the current region."
  (interactive "r")
  (setq message (or message 
		    (concat "Evaluate " (lisp-region-name start end))))
  (let ((defvar (ilisp-value 'ilisp-defvar-regexp t)))
    (if (and defvar
	     (save-excursion
	       (goto-char start)
	       (skip-chars-forward " \t\n")
	       (and (let ((case-fold-search t)) (looking-at defvar))
		    (progn (forward-sexp) (skip-chars-forward " \t\n" end)
			   (= (point) end)))))
	(lisp-send-region start end switch message (or status 'defvar)
			  'ilisp-defvar-command handler)
	(lisp-send-region start end switch message (or status 'eval)
			  'ilisp-eval-command handler))))

;;;
(defun eval-next-sexp-lisp (&optional switch)
  "Evaluate the next sexp."
  (interactive)
  (let (start end)
    (save-excursion
      (setq start (point))
      (forward-sexp)
      (setq end (point)))
    (eval-region-lisp start end switch
		      (format "Evaluate %s" (buffer-substring-no-properties start end)))))

;;;
(defun eval-defun-lisp (&optional switch)
  "Evaluate the current form."
  (interactive)
  (let* ((form (lisp-defun-region-and-name))
	 (result
	  (eval-region-lisp (car form) (car (cdr form)) (or switch 'result)
			    (format "Evaluating %s" (car (cdr (cdr form)))))))
    ;; Display the returned value. -fmw
    (lisp-display-output result)))


;;;%%%And go
(defun eval-region-and-go-lisp (start end)
  "Evaluate the current region and switch to the current ILISP buffer."
  (interactive "r")
  (eval-region-lisp start end t))

(defun eval-next-sexp-and-go-lisp (&optional switch)
  "Evaluate the next sexp and switch to the current ILISP buffer."
  (interactive)
  (eval-next-sexp-lisp t))

(defun eval-defun-and-go-lisp ()
  "Evaluate the current defun and switch to the current ILISP buffer.
With prefix, insert a call as well."
  (interactive)
  (eval-defun-lisp (if current-prefix-arg 
		       (progn
			 (setq current-prefix-arg nil)
			 'call)
		       t)))

;;;%%Compile
(defun compile-region-lisp (start end &optional switch message status handler)
  "Compile the current region."
  (interactive "r")
  (lisp-send-region
   start end
   (or switch 'result)			; Default to return the result.
   (or message (concat "Compile " (lisp-region-name start end)))
   (or status 'compile)
   'ilisp-compile-command 
   handler))


;;; ilisp-compile-buffer --
;;;
;;; 19990806 Martin Atzmueller

(defun ilisp-compile-buffer ()
  (interactive)
  (let ((old-point (point)))
    (mark-whole-buffer)
    (unwind-protect
      (let ((result
              (compile-region-lisp (point) (mark) 'result
                                   (format "Compiling Buffer %s"
                                           (buffer-name (current-buffer))))))
        (lisp-display-output result))
      (goto-char old-point)
      (set-mark old-point)
      (or (and (fboundp 'deactivate-mark)
               (deactivate-mark))
          (and (fboundp 'zmacs-deactivate-region)
               (zmacs-deactivate-region)))
      ;; ... and go implicitly -> you see what's going on!
      (switch-to-lisp t))))


;;; ilisp-eval-buffer --
;;;
;;; 19990806 Martin Atzmueller

(defun ilisp-eval-buffer ()
  (interactive)
  (mark-whole-buffer)
  (eval-region-lisp (point) (mark)))

    
;;;
(defun compile-defun-lisp (&optional switch)
  "Compile the current defun.
If no current defun compile  the last command in the input-ring of
an ILISP buffer."
  (interactive)
  (let* ((form (lisp-defun-region-and-name))
	 (start (car form))
	 (end (car (cdr form))))
    (if (and (= start end) (memq major-mode ilisp-modes))
	(save-excursion
	  (let ((form (ring-ref (ilisp-get-input-ring) 
				(ilisp-input-ring-index))))
	    (set-buffer "*ilisp-send*")
	    (delete-region (point-min) (point-max))
	    (insert form)
	    (compile-defun-lisp)))
      ;; Display the value returned by the compilation. -fmw
      ;; [and fake it if the compiler was silent.  -- rgr, 23-Aug-02.]
      (let* ((thing (car (cdr (cdr form))))
	     (result (compile-region-lisp start end (or switch 'result)
					  (format "Compiling %s" thing))))
	(lisp-display-output (if (equal result "")
				 (format "Compiled %s" thing)
				 result))))))

;;;%%%And-go
(defun compile-region-and-go-lisp (start end)
  "Compile the current region and switch to the current ILISP buffer."
  (interactive "r")
  (compile-region-lisp start end t))

(defun compile-defun-and-go-lisp ()
  "Compile the current defun and switch to the current ILISP buffer."
  (interactive)
  (compile-defun-lisp 
   (if current-prefix-arg
       (progn
	 (setq current-prefix-arg nil)
	 'call)
       t)))

;;; 2002-05-20 09:38:07 rurban
;;; Ivan's ange-ftp hack: "/user@server:~/xx.lisp" => "~/xx.lisp"  
;;; Reini's cygwin hack: "/cygdrive/r/xx.lisp"     => "r:/xx.lisp"
(defun file-name-hack (file-name)
  "Strip ange-ftp and cygwin pathnames prefixes for the native local lisp"
  (cond ((string-match "/.*?@.*:" file-name)
	 (substring file-name (match-end 0)))
	((not (eq system-type 'cygwin32)) file-name) ; verified on XEmacs
	;; assume cygwin clisp on cygwin (X)Emacs
	((eq ilisp-dialect 'clisp-hs) file-name)
	;; => w32 path for non-cygwin lisps only.
	((string-equal "/cygdrive/" (subseq file-name 0 10))
	 (concat (subseq file-name 10 11) ":" (subseq file-name 11)))
	(t file-name)))

;;;
(defun compile-file-lisp (file-name &optional extension)
  "Compile a Lisp file in the current inferior LISP and go there."
  (interactive (comint-get-source
		"Compile Lisp file: " lisp-prev-l/c-dir/file
		lisp-source-modes nil))
  (comint-check-source file-name)	; Check to see if buffer needs saved.
  (setq lisp-prev-l/c-dir/file (cons (file-name-directory    file-name)
				     (file-name-nondirectory file-name)))
  (ilisp-init t)
  (let ((file-name (file-name-hack file-name)))
    (ilisp-send
     (format (ilisp-value 'ilisp-compile-file-command) file-name
	     (or extension (ilisp-value 'ilisp-binary-extension)))
     (concat "Compile " file-name) 'compile
     t)))


;;;
(defun ilisp-compile-inits ()
  "Compile the initialization files for the current inferior LISP dialect."
  (interactive)
  (ilisp-init t)
  (let ((files (ilisp-value 'ilisp-load-inits t)))
    (dolist (f files)
      (compile-file-lisp 
       (expand-file-name (cdr f) ilisp-*directory*)
       (ilisp-value 'ilisp-init-binary-extension t)))))


;;;
(defun close-and-send-lisp ()
  "Close and indent the current sexp then send it to the inferior
LISP." 
  (interactive)
  (reindent-lisp)
  (if (memq major-mode ilisp-modes)
      (return-ilisp)
      (eval-defun-lisp)))

;;;%Special commands
(defun describe-lisp (sexp)
  "Describe the current sexp using ilisp-describe-command.
With a negative prefix, prompt for the expression.  If in an ILISP
buffer, and there is no current sexp, describe ilisp-last-command."
  (interactive
   (list
    (if (lisp-minus-prefix)
	(ilisp-read "Describe: " (lisp-previous-sexp t))
	(if (memq major-mode ilisp-modes)
	    (if (= (point)
		   (process-mark (get-buffer-process (current-buffer))))
		(or (ilisp-value 'ilisp-last-command t)
		    (error "No sexp to describe."))
		(lisp-previous-sexp t))
	    (lisp-previous-sexp t)))))
  (let ((result
	 (ilisp-send
	  (format (ilisp-value 'ilisp-describe-command) 
		  (lisp-slashify sexp) (lisp-buffer-package))
	  (concat "Describe " sexp)
	  'describe)))
    (lisp-display-output result)))

;;;
(defun inspect-lisp (sexp)
  "Inspect the current sexp using ilisp-inspect-command.
With a prefix, prompt for the expression.  If in an ILISP buffer, and
there is no current sexp, inspect ilisp-last-command."
  (interactive
   (list
    (if current-prefix-arg
	(ilisp-read "Inspect: " (lisp-previous-sexp t))
	(if (memq major-mode ilisp-modes)
	    (if (= (point)
		   (process-mark (get-buffer-process (current-buffer))))
		(or (ilisp-value 'ilisp-last-command t)
		    (error "No sexp to inspect."))
		(lisp-previous-sexp t))
	    (lisp-previous-sexp t)))))
  (ilisp-send
   (format (ilisp-value 'ilisp-inspect-command) 
	   (lisp-slashify sexp) (lisp-buffer-package))
   (concat "Inspect " sexp)
   'inspect t))

;;;
(defun arglist-lisp (symbol)
  "Return the arglist of the currently looked at function.
With a numeric prefix, the arglist will be inserted.  With a negative
one, the symbol will be prompted for."
  (interactive
   (let* ((function (lisp-function-name)))
     (list (if (lisp-minus-prefix)
	       (ilisp-read-symbol
		(format "Arglist [%s]: " (lisp-buffer-symbol function))
		function t)
	     function))))
  (if (null symbol)
      (error "No symbol")
    (let* ((arglist
	    (ilisp-send
	     (format (ilisp-value 'ilisp-arglist-command)
		     (lisp-symbol-name symbol) 
		     (lisp-symbol-package symbol))
	     nil
	     'args))
	   (position (string-match "(" arglist)))
      ;; Insert just the stuff after the open paren,
      ;; but display everything the inferior lisp prints.
      (cond ((and (not (ilisp-value 'comint-errorp t))
		  current-prefix-arg position)
	     (let ((temp (point)))
	       (insert (substring arglist (1+ position)))
	       (goto-char temp)))

	    (t
	     (lisp-display-output arglist))))))


;;;
(defun documentation-lisp (symbol type)
  "Return the documentation of the previous symbol.
It uses 'ilisp-documentation-command'.  If the symbol is at the start
of a list, it is assumed to be a function, otherwise variable
documentation is searched for.  With a minus prefix, prompt for the
symbol and type. With a numeric prefix always return the current
function call documentation."
  (interactive
   (if (lisp-minus-prefix)
       (let* ((symbol-info (lisp-previous-symbol))
	      (symbol (car symbol-info))
	      (doc (ilisp-read-symbol 
		    (format "Documentation [%s]: " 
			    (lisp-buffer-symbol symbol))
		    symbol))
	      (default (if (car (cdr symbol-info))
			   'function
			   'variable))
	      (types (ilisp-value 'ilisp-documentation-types t))
	      (type
	       (if types
		   (ilisp-completing-read
		    (if default
			(format "Type [%s]: " default)
			"Type: ")
		    types
		    default))))
	 (list doc (if (stringp type) (read type) type)))
       (if current-prefix-arg
	   (list (lisp-function-name) 'function)
	   (let* ((symbol-info (lisp-previous-symbol)))
	     (list (car symbol-info)
		   (if (car (cdr symbol-info))
		       'function
		       'variable))))))
  (lisp-display-output
   (ilisp-send
    (format (ilisp-value 'ilisp-documentation-command)
	    (lisp-symbol-name symbol) (lisp-symbol-package symbol) type)
    (format "Documentation %s %s" type (lisp-buffer-symbol symbol))
    'doc)))

;;;%%Macroexpand
(defun lisp-macroexpand-form ()
  "Return the next form for macroexpanding."
  (save-excursion
    (skip-chars-forward " \t\n")
    (let* ((begin (point))
	   (end (progn (forward-sexp) (point)))
	   (form (buffer-substring-no-properties begin end)))
      (list
       (if (lisp-minus-prefix)
	   (ilisp-read "Macroexpand: " form)
	   form)))))

;;;
(defun macroexpand-lisp (form &optional top)
  "Macroexpand the next sexp until it is no longer a macro.
With a prefix, insert into buffer."
  (interactive (lisp-macroexpand-form))
  (if (string-match "(\\([^ \t\n)]*\\)" form)
      (let ((message (concat "Macroexpand"
			     (if top "-1 " " ")
			     (substring form
					(match-beginning 1)
					(match-end 1))))
	    result)
	(setq result
	      (ilisp-send
	       (format
		(ilisp-value
		 (if top
		     'ilisp-macroexpand-1-command
		     'ilisp-macroexpand-command))
		(lisp-slashify form)
		(lisp-buffer-package)
		(buffer-file-name))
	       message 'expand))
	(if current-prefix-arg
	    (save-excursion (forward-sexp) (insert ?\n) (insert result))
	    (lisp-display-output result)))
      (error "Not a form: %s" form)))

(defun macroexpand-1-lisp (form)
  "Macroexpand the next sexp once.  With a prefix, insert into buffer."
  (interactive (lisp-macroexpand-form))
  (macroexpand-lisp form t))



;;;%%Trace
(defun trace-defun-lisp-break (function)
  "Trace FUNCTION without arg, untrace with.
Prompt for function with negative prefix.  Default function is the
current defun.
Trace with :break set."
  (interactive
   (let ((function (lisp-defun-name)))
     (if (lisp-minus-prefix)
	 (list (ilisp-read-symbol
		(format (if current-prefix-arg 
			    "Untrace [%s]: "
			    "Trace [%s]: ")
			(lisp-buffer-symbol function))
		function
		t))
	 (list function))))
  (trace-defun-lisp-internal function (not current-prefix-arg)))

(defun trace-defun-lisp (function)
  "Trace FUNCTION without arg, untrace with.
Prompt for function with negative prefix.  Default function is the
current defun."
  (interactive
   (let ((function (lisp-defun-name)))
     (if (lisp-minus-prefix)
	 (list (ilisp-read-symbol
		(format (if current-prefix-arg 
			    "Untrace [%s]: "
			    "Trace [%s]: ")
			(lisp-buffer-symbol function))
		function
		t))
	 (list function))))
  (trace-defun-lisp-internal function nil))

(defun trace-defun-lisp-internal (function breakp)
  (cond (function
	  (let ((result
		  (ilisp-send
		    (if current-prefix-arg
			(format (ilisp-value 'ilisp-untrace-command)
				(lisp-symbol-name function)
				(lisp-symbol-package function))
		      (format (ilisp-value 'ilisp-trace-command)
			      (lisp-symbol-name function)
			      (lisp-symbol-package function)
			      breakp))
		    (format "%srace %s" (if current-prefix-arg "Unt" "T") 
			    (lisp-buffer-symbol function))
		    (if current-prefix-arg 'untrace 'trace)
		    ;; Change to always wait, so we can see the
		    ;; result.  -fmw, 10/13/93
		    ;; (if lisp-wait-p nil 'dispatch)
		    nil)))
	    ;; Display the value returned -fmw
	    (lisp-display-output result)))
	(t
	  (error "No function to %strace" (if current-prefix-arg "un" "")))))



;;;%%Default-directory
(defun default-directory-lisp (&optional buffer)
  "Set the inferior LISP default directory.
The default directory of the optional BUFFER is used is available.  If
you are in an inferior LISP buffer, set the default directory to the
current directory of the LISP."
  (interactive)
  (if (and (not buffer)
	   (memq major-mode ilisp-modes)
           (ilisp-value 'ilisp-directory-command))
      (let ((dir (ilisp-send
		  (ilisp-value 'ilisp-directory-command)
		  (format "Getting LISP directory")
		  'dir)))
	(if (ilisp-value 'comint-errorp t)
	    (progn
	      (lisp-display-output dir)
	      (error "Error getting directory"))
	    (setq default-directory (read dir)
		  lisp-prev-l/c-dir/file (cons default-directory nil))
	    (message "Default directory is %s" default-directory)))
      (let ((directory
	     (expand-file-name (save-excursion
				 (set-buffer (or buffer (current-buffer)))
				 default-directory))))
	(ilisp-send
	 (format (ilisp-value 'ilisp-set-directory-command) directory)
	 (format "Set %s's directory to %s" 
		 (buffer-name (ilisp-buffer))
		 directory)
	 'dir
	 ;; (if lisp-wait-p nil 'dispatch)
	 ;; The above line might cause problems with Lispworks.
	 ;; I just set the default to 'nil'. It shouldn't harm.
	 ;; Marco Antoniotti: Jan 2 1995.
	 ))))
  

;;;
(defun load-file-lisp (file-name)
  "Load a lisp file into the current inferior LISP and go there."
  (interactive (comint-get-source "Load Lisp file: " lisp-prev-l/c-dir/file
				  lisp-source-modes nil))
  (comint-check-source file-name)	; Check to see if buffer needs saved.
  (setq lisp-prev-l/c-dir/file (cons (file-name-directory    file-name)
				     (file-name-nondirectory file-name)))
  (ilisp-init t)
  (let* ((extension (ilisp-value 'ilisp-binary-extension t))
	 (binary (lisp-file-extension file-name extension)))
    (save-excursion
      (set-buffer (ilisp-buffer))
      (unless (eq comint-send-queue comint-end-queue)
        (if (y-or-n-p "Abort commands before loading? ")
            (abort-commands-lisp)
          (message "Waiting for commands to finish")
          (while (not (eq comint-send-queue comint-end-queue))
            (accept-process-output)
            (sit-for 0))))
      (when (and (car (comint-send-variables (car comint-send-queue)))
                 (y-or-n-p "Interrupt top level? "))
        (let ((result (comint-send-results (car comint-send-queue))))
          (interrupt-subjob-ilisp)
          (while (not (cdr result))
            (accept-process-output)
            (sit-for 0)))))
    (unless (string= "system" (file-name-extension file-name))
      (if (file-newer-than-file-p file-name binary)
          (when (and (not ilisp-load-no-compile-query)
                     extension (y-or-n-p "Compile first? "))
            ;; Load binary if just compiled
            (message "")
            (compile-file-lisp file-name)
            (setq file-name binary))
        ;; Load binary if it is current
        (when (file-readable-p binary)
          (setq file-name binary))))
    (switch-to-lisp t t)
    (let ((file-name (file-name-hack file-name)))
      (comint-sender
       (ilisp-process)
       (format (ilisp-value 'ilisp-load-command) file-name))
      (message "Loading %s" file-name))))


;;;%Source
;;;%File operations
;;;
(defun lisp-find-file (file &optional pop no-name)
  "Find FILE, optionally POPping.
The optional NO-NAME arg is obsolete."
  ;; [Formerly, if NO-NAME is nil and there is a buffer with a name that is the
  ;; same as the final pathname component, lisp-find-file selected that buffer
  ;; instead of reading the file associated with the full path name.  This
  ;; feature was used only by edit-definitions-lisp (via lisp-locate-definition)
  ;; and replace-lisp, where it may have helped for remote lisps without shared
  ;; file access, but only if you happen not to have duplicate file names.  In
  ;; the 21st century, remote file access is more common; by the same token, so
  ;; are duplicate file names.  -- rgr, 26-Aug-02.]
  (if pop
      (lisp-pop-to-buffer (find-file-noselect file))
      (find-file file)))

;;;
(defun find-file-lisp (file-name)
  "Find a file.
If point is on a string that points to an existing
file, that will be the default.  If the buffer is one of
lisp-source-modes, the buffer file will be the default.  Otherwise,
the last file used in a lisp-source-mode will be used."
  (interactive
   (comint-get-source "Find file: "
		      lisp-prev-l/c-dir/file
		      lisp-source-modes nil))
  (setq lisp-prev-l/c-dir/file (cons (file-name-directory    file-name)
				     (file-name-nondirectory file-name)))
  (lisp-find-file file-name nil t))


;;; ilisp-arglist-message-lisp-space --
;;;
;;; 19990806 Martin Atzmueller

(defun ilisp-arglist-message-lisp-space ()
  "Displays the value of the argument list of a symbol followed by #\\Space.
This function is intended to be bound to the #\\Space key so that,
after being enabled it will display the arglist or value of a specific
symbol after the symbol has been typed in followed by #\\Space."
  (interactive)
  (when (and ilisp-*arglist-message-lisp-space-p* ; only if enabled and...
             (ignore-errors             ; we can print info
               (ilisp-value 'ilisp-print-info-message-command t))
	     (ignore-errors
	       (or (equal (ilisp-value 'ilisp-status) " :ready")
		   (equal (ilisp-value 'ilisp-status) " :error")))
	     (or (eql (current-buffer) (ilisp-buffer)) ; if in
					; ILISP-Buffer, or else 
		 (ignore-errors (lisp-buffer-package))))
    (let* ((old-point (point))
	   (last-char (progn (ignore-errors (backward-char))
			     (unless (eql (point) old-point)
			       (buffer-substring-no-properties old-point (point)))))

	   (string
             (buffer-substring-no-properties old-point
                               (progn
                                 (goto-char old-point)
                                 (ignore-errors (backward-sexp))
                                 (point))))
	   (prefix-char 
             (let ((save (ignore-errors
                           (goto-char old-point)
                           (backward-sexp)
                           (backward-char)
                           (point))))
               (when save
                 (buffer-substring-no-properties save (1+ save)))))
	   (double-quote-pos (and string (string-match "\"" string)))
	   (paren-pos (and string
			   (string-match "(" string)))
	   (ilisp-symbol-avec-package
             (unless (eql paren-pos 0)
               (lisp-string-to-symbol
                (if (and double-quote-pos (eql double-quote-pos 0)
                         string (ignore-errors (elt string 2)))
                  (substring string 1 -1)
                  string))))
	   (symbol (lisp-symbol-name ilisp-symbol-avec-package))
           (package (lisp-symbol-package ilisp-symbol-avec-package)))
      (flet ((no-arglist-output-p ()
               (or (and last-char 
                        (or;; don't do silly things after comment character
                          (equal last-char ";")
                          ;; do something only if directly after a sexp.
                          (equal last-char " ")))
		   ;; could be something like #+foo, #-foo, or #:foo, any of
		   ;; which is likely to lose.
		   (and string
			(string-match "^#" string))
                   double-quote-pos;; there is no output  for strings only.
                   (not (and symbol (stringp symbol) (> (length symbol) 0)))
                   (string-match "^\. " symbol)
                   (string-match "^\\\\" symbol))))

        (goto-char old-point)
        (unless (no-arglist-output-p)
          ;; only output for functions within brackets; too much lisp-traffic!
          ;; or ilisp-*arglist-message-lisp-space-p* has to be set to 'all
          (when (or (equal prefix-char "(")
                    (eql ilisp-*arglist-message-lisp-space-p* 'all))
            (ilisp-arglist-message-lisp ilisp-symbol-avec-package))))))
  (self-insert-command (prefix-numeric-value current-prefix-arg)))
    

;;; ilisp-arglist-message-lisp --
;;;
;;; Notes:
;;; 19990806 Martin Atzmueller
;;; created
;;;
;;; 19991218 Marco Antoniotti
;;; The double quote processing is very dubious. Basically we want to
;;; strip the double quotes when the resulting string in 'arglist' is
;;; *just* a double-quoted string.  But the current code does not do
;;; that. As a matter of fact it may remove a lot of initial non white
;;; characters.  Hence the fix (i.e. the removal).

;;; arglist functions

(defun ilisp-arglist-message-lisp (symbol)
  "Returns the arglist of the currently looked at function as Message.
With a numeric prefix, the arglist will be inserted.  With a negative one,
the symbol will be prompted for."
  (interactive
   (let* ((function (lisp-function-name)))
     (list (if (lisp-minus-prefix)
	       (ilisp-read-symbol
		(format "Arglist [%s]: " (lisp-buffer-symbol function))
		function t)
	     function))))

  (if (null symbol)
      (error "ilisp-arglist-message-lisp: null symbol")
    (let* ((arglist
	    (ilisp-send
	     (format (ilisp-value 'ilisp-print-info-message-command)
		     (lisp-symbol-name symbol) 
		     (lisp-symbol-package symbol))
             ""
	     'args
	     nil))
	   (output arglist))

      ;; Insert just the stuff after the double-quotes
      ;; but display everything the inferior lisp prints.
      (cond ((and (not (ilisp-value 'comint-errorp t))
		  current-prefix-arg)
	     (let ((temp (point)))
	       (insert output)
	       (goto-char temp)))
	    (t
	     ;; display output only if it is _not_ the empty string!
	     (when (and output (stringp output) (> (length output) 0))
	       (if (equal lisp-no-popper t)
		   (message "%s" output)
                   (lisp-display-output output))))))))

;;; Original version

;;; (defun ilisp-arglist-message-lisp (symbol)
;;;   "Returns the arglist of the currently looked at function as Message.
;;; With a numeric prefix, the arglist will be inserted.  With a negative one,
;;; the symbol will be prompted for."
;;;   (interactive
;;;    (let* ((function (lisp-function-name)))
;;;      (list (if (lisp-minus-prefix)
;;; 	       (ilisp-read-symbol
;;; 		(format "Arglist [%s]: " (lisp-buffer-symbol function))
;;; 		function t)
;;; 	     function))))

;;;   ;; (message "ilisp-arglist-message-lisp: symbol = %s\n" symbol)
;;;   (if (null symbol)
;;;       (error "ilisp-arglist-message-lisp: null symbol")
;;;     (let* ((arglist
;;; 	    (ilisp-send
;;; 	     (format (ilisp-value 'ilisp-print-info-message-command)
;;; 		     (lisp-symbol-name symbol) 
;;; 		     (lisp-symbol-package symbol))
;;; 	     nil
;;; 	     'args))
;;; 	   (position (string-match "\"" arglist))
;;; 	   (output (if position
;;; 		       (substring arglist (1+ position) -1)
;;; 		     arglist)))

;;;       ;; (message ">>> '%s'\n>>> '%s'\n" arglist output)

;;;       ;; Insert just the stuff after the double-quotes
;;;       ;; but display everything the inferior lisp prints.
;;;       (cond ((and (not (ilisp-value 'comint-errorp t))
;;; 		  current-prefix-arg position)
;;; 	     (let ((temp (point)))
;;; 	       (insert output)
;;; 	       (goto-char temp)))
;;; 	    ((string-match "ILisp-Message" arglist)
;;; 	     ;; don't do anything
;;; 	     nil)
;;; 	    (t
;;; 	     (if (equal lisp-no-popper t)
;;; 		 (message "%s" output)
;;; 	       (lisp-display-output output)))))))


;;; end of file -- ilisp-hi.el --