[英]How to gracefully exit SLIME and Emacs?
I have a question regarding how to "gracefully exit SLIME", when I quit Emacs. 我退出Emacs时,有一个关于如何“正常退出SLIME”的问题。 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. 据我所知,每当我退出Emacs时,它都将自动杀死SLIME及其关联的进程。 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. 您可以执行SLIME命令退出,这样就剩下一个漂亮,干净的emacs。
In a SLIME buffer, type in , (comma). 在SLIME缓冲区中,输入, (逗号)。 You're placed in the minibuffer and SLIME asks which command to execute. 您被放置在迷你缓冲区中,SLIME询问要执行哪个命令。 Type in sayoonara and hit Enter . 输入 sayoonara,然后按Enter 。 You should see SLIME exiting, the minibuffer mentions that "Connection closed." 您应该看到SLIME正在退出,微型缓冲区中提到“连接已关闭”。 and you're placed in the *scratch* buffer. 然后将您放在* scratch *缓冲区中。
I wonder if there's some way to simply invoke this "sayoonara" command from your .emacs, as opposed to manually unwiring everything. 我想知道是否有某种方法可以从.emacs中简单地调用此“ sayoonara”命令,而不是手动取消所有连接。
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." 根据此手册的页面 ,“一旦完成save-buffers-kill-emacs的所有文件保存和确认操作,它就会调用kill-emacs来运行此挂钩中的功能。” 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 可行的解决方案是制作自己的kill-emacs命令,例如
(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). (我假设您的函数正确退出了SLIME并关闭了它的缓冲区,但我尚未对其进行测试)。
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. 问题是在kill-emacs-hooks
有机会执行工作之前,将激活活动进程的检查(以及用于确认终止的查询)。
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; 功能slime-quit-lisp
是异步的; it needs time to finish after returning, hence the sleep-for
. 返回后需要一些时间才能完成,因此需要sleep-for
。
One way to debug the problem is to debug the function. 调试问题的一种方法是调试功能。
Place your cursor inside the 'slime-smart-quit
routine and type Mx edebug-defun . 将光标置于'slime-smart-quit
例程内,然后键入Mx edebug-defun 。 Then exit Emacs as you normally would. 然后像往常一样退出Emacs。 You should then be prompted by the Emacs lisp debugger edebug . 然后,应该由Emacs lisp调试器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 Mx edebug-defun again to debug the new version. 使用q退出调试器,然后进行更改,然后再次使用Mx edebug-defun调试新版本。
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. @Alex-我发现您的方法是退出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: 一旦以这种方式设置,则:
PS: Check this for SLIME config at startup - http://common-lisp.net/project/slime/doc/html/Loading-Contribs.html PS:在启动时检查此为泥配置- 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 我发现每次关闭Emacs都要同意杀死所有进程很烦,所以我想出了这个功能
(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. 当关闭Emacs时,使进程无声地死掉。 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. 我将它用于我拥有的所有类似于repl的缓冲区,其中包括八度,python,scheme,shell和haskell的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, eg python, terminal, lisp etc. 它不仅适用于SLIME,而且适用于其他内容,例如python,terminal,lisp等。
(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 cx 0 to kill that window. 如果您打开了两个窗口,请切换到史莱姆窗口,然后按cx 0终止该窗口。 Then you can kill the emacs window normally through cx cc. 然后,您可以通过cx cc正常终止emacs窗口。
No, no, no. 不不不。 https://stackoverflow.com/a/10780124/539797 ; 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. 杀死进程缓冲区的任何其他方式,即使对孩子和幼犬来说都不是危险的,至多也是无礼的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.