简体   繁体   中英

kill previous nrepl sessions when nrepl-jack-in called?

At this moment in time, I am using nrepl primarily to talk to Clojurescript apps. I like to use nrepl from within emacs. I start nrepl by typing Mx nrepl-jack-in .

Unfortunately, my nrepl session often gets completely hung. When this happens, I dutifully kill the 3 buffers related to nrepl. These buffers are:

  1. *nrepl*
  2. *nrepl-connection*
  3. *nrepl-server*

*nrepl-server* also has an active process, it ask me if I want to close it, and I say yes.

I then type Mx nrepl-jack-in again.

This is a pain.

I would like to overload nrepl-jack-in so that it automatically checks if any of these 3 buffers exist. If any of them do exist, it will kill these buffers and any active processes associated with these bufers. After doing this, the overloaded nrepl-jack-in will proceed as usual. I would like this because then, whenever I detect that nrepl has decided to hang itself again, I could just type MX nrepl-jack-in and restart what I was doing.

This should get the job done:

(defun my-nrepl-jack-in ()
  (interactive)
  (dolist (buffer (buffer-list))
    (when (string-prefix-p "*nrepl" (buffer-name buffer))
      (kill-buffer buffer)))
  (nrepl-jack-in nil))

The chosen answer didn't quite work for me... The nrepl process sentinel threw an error, preventing it from restarting. I played with it a bit and came up with the following (which also gives a separate kill-nrepl function)

;; Disable prompt on killing buffer with a process
(setq kill-buffer-query-functions
      (remq 'process-kill-buffer-query-function
            kill-buffer-query-functions))

(defun nrepl-kill ()
  "Kill all nrepl buffers and processes"
  (interactive)
  (when (get-process "nrepl-server")
    (set-process-sentinel (get-process "nrepl-server")
                          (lambda (proc evt) t)))
  (dolist (buffer (buffer-list))
    (when (string-prefix-p "*nrepl" (buffer-name buffer))
      (kill-buffer buffer))))

(defun nrepl-me ()
  (interactive)
  (nrepl-kill)
  (nrepl-jack-in nil))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM