How to gracefully exit SLIME and Emacs?
Asked Answered
N

10

14

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.

Nieberg answered 25/2, 2010 at 20:57 Comment(1)
Who cares about shortcut keys? We want something to paste into .emacs that quits SLIME when emacs ends.Statampere
G
28

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.

Goat answered 4/8, 2010 at 2:40 Comment(3)
I prefer 'quit' to 'sayoonara'. It's shorter :-)Almoner
This terminates my stumpwm session. :) I think I only need (slime-disconnect).Situated
The function is slime-repl-sayoonara. There is also slime-repl-quit.Squatter
A
5

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).

Auricle answered 16/11, 2010 at 17:49 Comment(0)
A
3

The problem is the check for active processes (and the query for confirmation to kill) would be activated before kill-emacs-hooks had a chance to do its job.

A very kludgy solution:

(defadvice save-buffers-kill-terminal (before slime-quit activate)
  (slime-smart-quit)
  (sleep-for 1))

The function slime-quit-lisp is asynchronous; it needs time to finish after returning, hence the sleep-for.

Ame answered 16/11, 2010 at 13:16 Comment(0)
W
2

One way to debug the problem is to debug the function.

Place your cursor inside the 'slime-smart-quit routine and type M-x edebug-defun. Then exit Emacs as you normally would. You should then be prompted by the Emacs lisp debugger edebug. It's a pretty easy debugger to use (type ? for help).

Step through the code and see where it doesn't do what you expect it to do.

Use q to quit out of the debugger, then make changes, and M-x edebug-defun again to debug the new version.

Repeat until you find success, or have a little more information for the question.

Westernize answered 25/2, 2010 at 21:38 Comment(0)
D
2

@Alex - I found your method to be the cleanest way to quit SLIME. However the config file needs to be edited in this fashion for it to be used.

(require 'slime-autoloads)
(slime-setup '(slime-fancy)) ; load contrib packages

Once it's setup this way then:

  1. press comma (,) to bring up the minibuffer
  2. type quit or sayoonara to cleanly exit.

PS: Check this for SLIME config at startup - http://common-lisp.net/project/slime/doc/html/Loading-Contribs.html

Duhl answered 6/12, 2010 at 22:1 Comment(0)
S
1

I find it annoying to have to agree to kill all processes every time I close the Emacs so I come up with this function

(defun emacs-forget-buffer-process ()
  "Emacs will not query about this process when killing."
  (let ((p (get-buffer-process (current-buffer))))
    (when p
      (set-process-query-on-exit-flag p nil))))

which makes process die silently when Emacs is closed. Use it like this

(add-hook 'slime-inferior-process-start-hook #'emacs-forget-buffer-process)
(add-hook 'slime-repl-mode-hook #'emacs-forget-buffer-process)

I use it for all repl-like buffers that I have, which includes octave, python, scheme, shell and haskell's ghci. So far nothing bad happened when these repls get killed silently so I assume this solution isn't bad though may not be graceful.

Sudderth answered 19/4, 2012 at 19:32 Comment(0)
C
0

This is a more general solution that I use. It works not just for SLIME, but for other stuff, e.g. python, terminal, lisp etc.

(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate)
  "Prevent annoying \"Active processes exist\" query when you quit Emacs."
  (flet ((process-list ())) ad-do-it))
Casefy answered 4/5, 2012 at 13:48 Comment(0)
O
0

This took me forever. If you have two windows opened up, switch to the slime window and hit c-x 0 to kill that window. Then you can kill the emacs window normally through c-x c-c.

Olenolin answered 17/10, 2019 at 5:22 Comment(0)
C
0

Here's what I feel is a better solution that specifically ignores only SLIME buffers. It doesn't actually kill the processes if the user aborts the kill-emacs command, nor does it require waiting for slime to asynchronously exit gracefully.

(defun process-ignore-on-exit (regexp)
  (cl-loop for proc in (process-list)
           when (s-matches-p regexp (process-name proc))
           do
           (progn (message "disabling query-on-exit for '%s'" proc)
                  (set-process-query-on-exit-flag proc nil))))

(defun slime-ignore-processes-on-exit (&rest r)
  (process-ignore-on-exit "SLIME"))

(advice-add #'save-some-buffers :before #'slime-ignore-processes-on-exit)
Coastland answered 29/3, 2022 at 19:46 Comment(0)
P
-1

No, no, no. https://mcmap.net/q/420797/-make-emacs-stop-asking-quot-active-processes-exist-kill-them-and-exit-anyway-quot ; any other way of killing a process buffer is at best rude, if not plain dangerous to children and puppies.

Parabolic answered 1/6, 2012 at 19:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.