cmuscheme48.el 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. ;;; cmuscheme48.el -- Scheme process in a buffer. Adapted from cmuscheme.el.
  2. (provide 'cmuscheme48)
  3. (require 'cmuscheme)
  4. (define-key scheme-mode-map "\M-\C-x" 'scheme48-send-definition);gnu convention
  5. (define-key scheme-mode-map "\C-x\C-e" 'scheme48-send-last-sexp);gnu convention
  6. (define-key scheme-mode-map "\C-ce" 'scheme48-send-definition)
  7. (define-key scheme-mode-map "\C-c\C-e" 'scheme48-send-definition-and-go)
  8. (define-key scheme-mode-map "\C-cr" 'scheme48-send-region)
  9. (define-key scheme-mode-map "\C-c\C-r" 'scheme48-send-region-and-go)
  10. (define-key scheme-mode-map "\C-cl" 'scheme48-load-file)
  11. (defun scheme48-send-region (start end)
  12. "Send the current region to the inferior Scheme process."
  13. (interactive "r")
  14. (comint-send-string (scheme-proc)
  15. (concat ",from-file "
  16. (enough-scheme-file-name
  17. (buffer-file-name (current-buffer)))
  18. "\n"))
  19. (comint-send-region (scheme-proc) start end)
  20. (comint-send-string (scheme-proc) " ,end\n"))
  21. ; This assumes that when you load things into Scheme 48, you type
  22. ; names of files in your home directory using the syntax "~/".
  23. ; Similarly for current directory. Maybe we ought to send multiple
  24. ; file names to Scheme and let it look at all of them.
  25. (defun enough-scheme-file-name (file)
  26. (let* ((scheme-dir
  27. (save-excursion
  28. (set-buffer scheme-buffer)
  29. (expand-file-name default-directory)))
  30. (len (length scheme-dir))
  31. (raw
  32. (cond
  33. ((and (> (length file) len)
  34. (string-equal scheme-dir (substring file 0 len)))
  35. (substring file len))
  36. (*scheme48-home-directory-kludge*
  37. (let* ((home-dir (expand-file-name "~/"))
  38. (len (length home-dir)))
  39. (if (and (> (length file) len)
  40. (string-equal home-dir (substring file 0 len)))
  41. (concat "~/" (substring file len))
  42. file)))
  43. (t file))))
  44. (subst-char-in-string ?\\ ?/ raw)))
  45. (defvar *scheme48-home-directory-kludge* t)
  46. (defun scheme48-send-definition (losep)
  47. "Send the current definition to the inferior Scheme48 process."
  48. (interactive "P")
  49. (save-excursion
  50. (end-of-defun)
  51. (let ((end (point)))
  52. (beginning-of-defun)
  53. (if losep
  54. (let ((loser (make-temp-file "s48lose")))
  55. (write-region (point) end loser)
  56. (scheme48-load-file loser))
  57. (scheme48-send-region (point) end)))))
  58. (defun scheme48-send-last-sexp ()
  59. "Send the previous sexp to the inferior Scheme process."
  60. (interactive)
  61. (scheme48-send-region (save-excursion (backward-sexp) (point)) (point)))
  62. (defun scheme48-send-region-and-go (start end)
  63. "Send the current region to the inferior Scheme48 process,
  64. and switch to the process buffer."
  65. (interactive "r")
  66. (scheme48-send-region start end)
  67. (switch-to-scheme t))
  68. (defun scheme48-send-definition-and-go (losep)
  69. "Send the current definition to the inferior Scheme48,
  70. and switch to the process buffer."
  71. (interactive "P")
  72. (scheme48-send-definition losep)
  73. (switch-to-scheme t))
  74. (defun scheme48-load-file (file-name)
  75. "Load a Scheme file into the inferior Scheme48 process."
  76. (interactive (comint-get-source "Load Scheme48 file: "
  77. scheme-prev-l/c-dir/file
  78. scheme-source-modes t)) ; T because LOAD
  79. ; needs an exact name
  80. (comint-check-source file-name) ; Check to see if buffer needs saved.
  81. (setq scheme-prev-l/c-dir/file (cons (file-name-directory file-name)
  82. (file-name-nondirectory file-name)))
  83. (comint-send-string (scheme-proc)
  84. (concat ",load "
  85. (enough-scheme-file-name file-name)
  86. "\n")))
  87. ; For Pertti Kellom\"aki's debugger.
  88. ; Cf. misc/psd-s48.scm.
  89. (defvar psd-using-slib nil "Scheme 48, not SLIB.")