7

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 M-x 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 M-x 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 M-X nrepl-jack-in and restart what I was doing.

2 Answers 2

4

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))
1
  • 1
    I get the following error in *Messages* when I type M-x my-nrepl-jack-in : my-nrepl-jack-in: Wrong number of arguments: #[(prompt-project) "ÄÅÆÇ! # ÈÉÊ #ËÌ\"ÍÎ\"ÏÐ#ÑÒ!*" [prompt-project nrepl-server-command cmd process format "cd %s && %s" ido-read-directory-name "Project: " start-process-shell-command "nrepl-server" ...] 4 nil "P"], 0 Oct 22, 2012 at 19:40
4

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))
1
  • The sentinel normally would ask you simply for confirmation to kill the underlying buffer process. Restarting worked for me when I tried it, but obviously I wouldn't go committing the code as is upstream ;-) Oct 23, 2012 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.