rejeep / prodigy.el

Manage external services from within Emacs
GNU General Public License v3.0
550 stars 39 forks source link

Restart process direcly from Prodigy-view #98

Closed FrancescElies closed 7 years ago

FrancescElies commented 7 years ago

Hi,

This is rather a question than a bug

when I am using prodigy I can restart a process using prodigy-restart but once I call prodigy-display-process and I am inside a buffer with prodigy-view-mode having a look at the process output I can't call prodigy-restart without going back to the prodigy overview buffer.

Is there an easy way of calling prodigy-restart directly from the output process buffer(prodigy-view-mode)?

All best & thanks for your advice

FrancisMurillo commented 7 years ago

I don't think there is an explicit command for that. Thus this quick shiv:

(defun prodigy-find-service-by-buffer (&optional buffer)
  "Find `prodigy' service based on BUFFER name."
  (let* ((this-prodigy-buffer-name (buffer-name buffer))
           (service (-find
                (lambda (service)
                  (string= (prodigy-buffer-name service)
                           this-prodigy-buffer-name))
                (prodigy-services))))
    service))

(defun prodigy-restart-view ()
  "Restart a `prodigy-view-mode' buffer."
  (interactive)
  (-if-let (service (prodigy-find-service-by-buffer))
      (prodigy-with-refresh
       (prodigy-restart-service service))
    (error "Current buffer is not a prodigy view buffer.")))

(define-key prodigy-view-mode-map (kbd "C-c r") #'prodigy-restart-view)

It may not be perfect but it might be a base I think. When I have the time, I'll re-test and improve the snippet.

FrancescElies commented 7 years ago

Thanks @FrancisMurillo, I'll try to play around a bit with the code you wrote and if I do any improvements I'll report them back. In the meanwhile I'll close this one

FrancescElies commented 7 years ago

I noticed that if I comment out the s-exp that kills the buffer in prodigy-maybe-kill-process-buffer when I restart the process with prodigy-restart-view you don't need to reopen the buffer again, but in the *prodigy* buffer it says process Failed though it' has only been restarted.

FrancisMurillo commented 7 years ago

About removing the kill-buffer in prodigy-maybe-kill-process-buffer, that was an issue I was resolving with :kill-process-buffer-on-stop whether to switch to that buffer when the process is restarted but it might be intrusive via prodigy-switch-to-process-buffer.

For the failed status, how about adding an extra refresh after restarting

(prodigy-restart-service
    service
  (lambda ()
    (prodigy-refresh)))