abrochard / kubel

Emacs extension for controlling Kubernetes with limited permissions
GNU General Public License v3.0
259 stars 41 forks source link

Add optional callback arg to kubel--exec function #129

Closed risset closed 3 months ago

risset commented 3 months ago

Hi,

I've been using this package for a while (thanks for creating it!), and it always bugged me that when I describe resources via RET in the list view, the point always starts at the bottom of the buffer rather than the top. I took a look at the code to see if I could tweak it somehow, and saw that there was actually a (goto-char (point-min) call, which suggested that was the intended behaviour. It seemed however that because make-process is async, things weren't guaranteed to happen in the correct order.

My lisp skills are not the best just yet and getting this working what somewhat tricky for me, so please feel free to suggest/make changes.

abrochard commented 3 months ago

Thank you for submitting this! (and for using my package). It always bothered me too and I'm so glad you have a solution. I left two minor nitpick comments but the rest looks good. I plan to test and merge on Monday-ish

d1egoaz commented 3 months ago

It seems there were several of us bothered by this :)

I've been using my private version of Kubel, and a patch for this issue, which I think is simpler. My fork has diverged significantly from the upstream, and I plan to sync it someday.

I noticed that multiple versions of Kubel are now supported. Although I've been using my fork without any issues, I should try the new versions.

The patch consist in modify the sentinel, get the associated buffer name, and then if the buffer exists go to the first line.

(defun kubel--sentinel (process _)
  "Sentinel function for PROCESS."
  (let ((process-name (process-name process))
        (exit-status (process-exit-status process))
        (output-buffer (process-buffer process))) ;; <------------ NEW
    (kubel--append-to-process-buffer (format "[%s]\nexit-code: %s" process-name exit-status))
    (unless (eq 0 exit-status)
      (let ((err (with-current-buffer (kubel--process-error-buffer process-name)
                   (buffer-string))))
        (kubel--append-to-process-buffer (format "error: %s" err))
        (error (format "Kubel process %s error: %s" process-name err))))
    ;; Move point to the beginning of the output buffer
    (when (buffer-live-p output-buffer) ;; <------------ NEW
      (with-current-buffer output-buffer
        (goto-char (point-min))))))

It works with tail too, when it's not following changes, it goes to the first line, otherwise it'll go to the tail.