Download
(require 'cmuscheme)
(defcustom duck-scheme-commands '("scheme48" "scsh")
"*The possible commands to run as Scheme interpreters.
This is used by `run-scheme' for the completion."
:type 'string
:group 'scheme)
(defun run-scheme (&optional cmd)
"Run an inferior Scheme process, input and output via buffer *scheme*.
If there is a process already running in *scheme*, switch to that buffer.
If no process is running, ask for a Scheme interpreter to run.
Allow completion on `duck-scheme-commands'.
Runs the hooks `inferior-scheme-mode-hook' (after the
`comint-mode-hook' is run).
\(Type \\[describe-mode] in the process buffer for a list of commands.)"
(interactive)
(let ((cmd (when (not (comint-check-proc "*scheme*"))
(or cmd
(duck-completing-read (format "Run Scheme (default %S): "
(car duck-scheme-commands))
duck-scheme-commands
(car duck-scheme-commands))))))
(when cmd
(let ((cmdlist (scheme-args-to-list cmd)))
(set-buffer (apply 'make-comint "scheme" (car cmdlist)
nil (cdr cmdlist)))
(inferior-scheme-mode)))
(setq scheme-program-name cmd)
(setq scheme-buffer "*scheme*")
(pop-to-buffer "*scheme*")))
(defun duck-tidy-buffer ()
"Tidy up the code in the current buffer."
(interactive)
(save-excursion
(goto-char (point-min))
(while (re-search-forward "\n\n\\(\n+\\)" nil t)
(replace-match "\n\n"))
(delete-trailing-whitespace)
(goto-char (point-min))
(while (looking-at "\n")
(delete-char 1))
(goto-char (1- (point-max)))
(while (looking-at "\n")
(delete-char 1)
(backward-char))
(goto-char (point-max))
(when (not (looking-at "\n"))
(insert "\n"))
(indent-region (point-min) (point-max))
(untabify (point-min) (point-max))))
(defun duck-completing-read (prompt table default)
"Like `completing-read', only allow spaces in the input."
(let ((map (make-sparse-keymap)))
(set-keymap-parent map
minibuffer-local-completion-map)
(define-key map (kbd "<SPC>") 'self-insert-command)
(let ((minibuffer-local-completion-map map))
(completing-read prompt table nil nil nil nil default))))
(provide 'duck)