Cleanup robe processes killing last ruby buffer

Experimental?
This commit is contained in:
Henrik Lissner 2018-07-06 23:11:26 +02:00
parent f5f87ee0a3
commit 00d6e7b9ca
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 19 additions and 3 deletions

View file

@ -0,0 +1,15 @@
;;; lang/ruby/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +ruby|cleanup-robe-servers ()
"Clean up dangling inf robe processes if there are no more `enh-ruby-mode'
buffers open."
;; FIXME This should wait X seconds before cleaning up
(unless (or (not robe-mode) (doom-buffers-in-mode 'enh-ruby-mode))
(let (inf-buffer kill-buffer-query-functions)
(while (setq inf-buffer (robe-inf-buffer))
(let ((process (get-buffer-process inf-buffer))
confirm-kill-processes)
(when (processp process)
(kill-process (get-buffer-process inf-buffer))
(kill-buffer inf-buffer)))))))

View file

@ -78,9 +78,10 @@ environment variables."
;; robe-start errors if you hit no. ;; robe-start errors if you hit no.
(defun +ruby|init-robe () (defun +ruby|init-robe ()
(when (executable-find "ruby") (when (executable-find "ruby")
(cl-letf (((symbol-function #'yes-or-no-p) (cl-letf (((symbol-function #'yes-or-no-p) (lambda (_) t)))
(lambda (&rest _) t))) (ignore-errors (robe-start))
(ignore-errors (robe-start))))) (when (robe-running-p)
(add-hook 'kill-buffer-hook #'+ruby|cleanup-robe-servers nil t)))))
(add-hook 'enh-ruby-mode-hook #'+ruby|init-robe) (add-hook 'enh-ruby-mode-hook #'+ruby|init-robe)
:config :config
(set-company-backend! 'robe-mode 'company-robe)) (set-company-backend! 'robe-mode 'company-robe))