cmuscheme48.el 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. (if (and (> (length file) len)
  32. (string-equal scheme-dir (substring file 0 len)))
  33. (substring file len)
  34. (if *scheme48-home-directory-kludge*
  35. (let* ((home-dir (expand-file-name "~/"))
  36. (len (length home-dir)))
  37. (if (and (> (length file) len)
  38. (string-equal home-dir (substring file 0 len)))
  39. (concat "~/" (substring file len))
  40. file))
  41. file))))
  42. (defvar *scheme48-home-directory-kludge* t)
  43. (defun scheme48-send-definition (losep)
  44. "Send the current definition to the inferior Scheme48 process."
  45. (interactive "P")
  46. (save-excursion
  47. (end-of-defun)
  48. (let ((end (point)))
  49. (beginning-of-defun)
  50. (if losep
  51. (let ((loser "/tmp/s48lose.tmp"))
  52. (write-region (point) end loser)
  53. (scheme48-load-file loser))
  54. (scheme48-send-region (point) end)))))
  55. (defun scheme48-send-last-sexp ()
  56. "Send the previous sexp to the inferior Scheme process."
  57. (interactive)
  58. (scheme48-send-region (save-excursion (backward-sexp) (point)) (point)))
  59. (defun scheme48-send-region-and-go (start end)
  60. "Send the current region to the inferior Scheme48 process,
  61. and switch to the process buffer."
  62. (interactive "r")
  63. (scheme48-send-region start end)
  64. (switch-to-scheme t))
  65. (defun scheme48-send-definition-and-go (losep)
  66. "Send the current definition to the inferior Scheme48,
  67. and switch to the process buffer."
  68. (interactive "P")
  69. (scheme48-send-definition losep)
  70. (switch-to-scheme t))
  71. (defun scheme48-load-file (file-name)
  72. "Load a Scheme file into the inferior Scheme48 process."
  73. (interactive (comint-get-source "Load Scheme48 file: "
  74. scheme-prev-l/c-dir/file
  75. scheme-source-modes t)) ; T because LOAD
  76. ; needs an exact name
  77. (comint-check-source file-name) ; Check to see if buffer needs saved.
  78. (setq scheme-prev-l/c-dir/file (cons (file-name-directory file-name)
  79. (file-name-nondirectory file-name)))
  80. (comint-send-string (scheme-proc)
  81. (concat ",load "
  82. (enough-scheme-file-name file-name)
  83. "\n")))
  84. ; For Pertti Kellom\"aki's debugger.
  85. ; Cf. misc/psd-s48.scm.
  86. (defvar psd-using-slib nil "Scheme 48, not SLIB.")