为什么不在 clojure 模式的钩子中进行 clojure-jack-in 呢?
我正在使用 https://github.com/technomancy/swank-clojure 中的 swank-clojure 。
我想在 emacs 中打开 clojure 文件时自动运行 clojure-jack-in 。我所有的项目都使用 lein,所以它应该总是合适的。
想必您应该检查它是否尚未被调用。 ~/.emacs.d/init.el 中类似的东西似乎有效,但是是否有缺点或更好的方法来达到相同的效果?
(defun clojure-jack-in-once ()
"clojure-jack-in if it hasn't been run already,
as indicated by presence of *swank* buffer"
(if (eq nil (get-buffer "*swank*"))
(clojure-jack-in)))
(add-hook 'clojure-mode-hook 'clojure-jack-in-once)
I'm using swank-clojure from https://github.com/technomancy/swank-clojure.
I'd like to run clojure-jack-in automatically when a clojure file is opened in emacs. All my projects use lein, so it should always be appropriate.
Presumably you should check that it hasn't been called already. Something like this in ~/.emacs.d/init.el seems to work, but is there a downside or a better way to achieve the same effect?
(defun clojure-jack-in-once ()
"clojure-jack-in if it hasn't been run already,
as indicated by presence of *swank* buffer"
(if (eq nil (get-buffer "*swank*"))
(clojure-jack-in)))
(add-hook 'clojure-mode-hook 'clojure-jack-in-once)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能希望使用
process-status
和get-buffer-process
扩展它来检查进程的活跃度,但没有根本原因您不能这样做那。elisp 的一个稍微好一点的地方是:
添加检查:
应该检查进程是否仍在运行,并在需要时自动重新启动。
You might want to extend that to check the liveness of the process, using
process-status
andget-buffer-process
, but there is no fundamental reason you can't do that.A slightly nicer bit of elisp would be:
Adding the check:
That should check if the process is still running and automatically restart if required.
(slime-connected-p) 就是您要找的。
或者(和(featurep 'slime)(slime-connected-p))以确保安全。
(slime-connected-p) is what you're looking for.
Or (and (featurep 'slime) (slime-connected-p)) to be safe.