Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to gracefully exit SLIME and Emacs?

I have a question regarding how to "gracefully exit SLIME", when I quit Emacs. Here is the relevant portion of my config file:

;; SLIME configuration

(setq inferior-lisp-program "/usr/local/bin/sbcl")
(add-to-list 'load-path "~/Scripts/slime/")
(require 'slime)
(slime-setup)

;; configure SLIME to gracefully quit when emacs
;; terminates

(defun slime-smart-quit ()
  (interactive)
  (when (slime-connected-p)
    (if (equal (slime-machine-instance) "Gregory-Gelfonds-MacBook-Pro.local")
 (slime-quit-lisp)
      (slime-disconnect)))
  (slime-kill-all-buffers))

(add-hook 'kill-emacs-hook 'slime-smart-quit)

To my knowledge this should automatically kill SLIME and it's associated processes whenever I exit Emacs. However, every time I exit, I still get the prompt:

Proc       Status   Buffer  Command
----       ------   ------  -------
SLIME Lisp    open      *cl-connection* (network stream connection to 127.0.0.1)
inferior-lisp run      *inferior-lisp* /usr/local/bin/sbcl


Active processes exist; kill them and exit anyway? (yes or no) 

Can someone shed some insight as to what I'm missing from my config?

Thanks in advance.

like image 235
Gregory Gelfond Avatar asked Feb 25 '10 20:02

Gregory Gelfond


People also ask

How to exit Emacs debugger?

If the debugger was entered due to a C-g but you really want to quit, and not debug, use the q command. Return a value from the debugger. The value is computed by reading an expression with the minibuffer and evaluating it.

How do I use slime in Emacs?

emacs. d/ . The first lisp file you load you may need to perform M-x slime , which means holding down either Alt or Escape, then hitting the letter 'x'. A prompt will appear at the bottom of the editor (in the minibuffer) where you type "slime" and hit enter.


2 Answers

I know it's not exactly what you asked for, but maybe this will be helpful to other noobs like me.

You can execute a SLIME command to exit, so you'll have a nice, clean emacs left over.

In a SLIME buffer, type in , (comma). You're placed in the minibuffer and SLIME asks which command to execute. Type in sayoonara and hit Enter. You should see SLIME exiting, the minibuffer mentions that "Connection closed." and you're placed in the *scratch* buffer.

I wonder if there's some way to simply invoke this "sayoonara" command from your .emacs, as opposed to manually unwiring everything.

like image 167
Alex Beynenson Avatar answered Sep 20 '22 05:09

Alex Beynenson


According to the manual page on this, "once save-buffers-kill-emacs is finished with all file saving and confirmation, it calls kill-emacs which runs the functions in this hook." So the check for active processes is done before the hook is called.

A working solution would be to make your own kill-emacs command, for example

(defun kill-emacs-slime ()
  (interactive)
  (when (slime-connected-p)
    (if (equal (slime-machine-instance) "Gregory-Gelfonds-MacBook-Pro.local")
        (slime-quit-lisp)
      (slime-disconnect)))
  (slime-kill-all-buffers)
  (save-buffers-kill-emacs))

And then bind this to your quit key

(global-set-key (kbd "C-x C-c") 'kill-emacs-slime)

(I am assuming your function correctly quit SLIME and closes its buffers, I haven't tested it).

like image 39
Borbus Avatar answered Sep 22 '22 05:09

Borbus