开发者

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))
开发者_StackOverflow
(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.


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.


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


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.


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.


@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


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.


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


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.


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)


No, no, no. https://stackoverflow.com/a/10780124/539797 ; any other way of killing a process buffer is at best rude, if not plain dangerous to children and puppies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜