I'm taking a class that assumes you have emacs set up to have a Scheme interpreter running in a buffer in the background, so I have the following in my .emacs file:
Code:
(require 'cmuscheme)
(load "cmuscheme")
(setq scheme-program-name "stk")
(define-key scheme-mode-map "\r" 'newline-and-indent)
(defun run-stk () "
Remove the *scheme* buffer unless it is running Stk. If there is no
*scheme* buffer running Stk, create one. Switch to the *scheme* buffer."
(interactive)
(set-buffer (get-buffer-create "*scheme*"))
(let ((proc (get-buffer-process "*scheme*")))
(if (and proc (not (string-match
"stk$" (car (process-command proc)))))
(progn
(set-process-buffer proc nil)
(kill-process proc))))
(run-scheme "stk-simply"))
(defun run-half-scheme () "
Run Scheme in half a window."
(interactive)
(split-window-vertically nil)
(other-window 1)
(call-interactively 'run-scheme))
(run-stk)
(global-set-key "\M-s" 'run-half-scheme)
(defun scheme-load-file-and-go (file-name)
"Load Scheme file FILE-NAME into the inferior Scheme process and then go to Scheme buffer."
(interactive (comint-get-source "Load Scheme file: " scheme-prev-l/c-dir/file scheme-source-modes t))
(scheme-load-file file-name)
(split-window-vertically nil)
(other-window 1)
(switch-to-scheme t))
(define-key (lookup-key scheme-mode-map [menu-bar scheme])
[scheme-load-file-and-go] '("Send Scheme File & Go" . scheme-load-file-and-go))
(global-unset-key "\C-r")
(define-key scheme-mode-map "\C-r" 'scheme-load-file-and-go)
This is probably excessively messy and redundant, but it does almost what I want it to and I don't really understand Lisp well enough at this point to see how everything works. There's a couple of things that would be handy to change, so I thought I'd ask here and see if anyone has any ideas.
1. With it set up as it currently is, I can work on a file, hit Ctrl-r, a half-window will pop up with the interpreter. However, if I then switch back to my original buffer without closing the other, fix something, and do Ctrl-r again, I get a quarter-window with another interpreter. Is there a way to check and see what the current status is and only open an additional window if none is already open? (In other words, if you are working on a file taking up the whole screen, it will open an interpreter in a half-window, but if you're working on a file with a half-interpreter already open, then it will simply load that file into the already running and open buffer). If this is too specific of a question to ask in a general forum like this, does anyone know where I could look to figure out how to do this?
2. With the interpreter running in the background, every time I close emacs, I get the message:
Code:
Active processes exist; kill them and exit anyway? (yes or no)
Is there a way to either automatically answer yes to this and not display the message or have Ctrl-x c switch to the Scheme buffer and run "(exit)" (killing it the right way) before closing emacs?
Thanks in advance.