I have a elisp program which check server in a endless loop, like

(while t
  (let ((status (check-server)))
     (case status
     (sleep-for 100))

and I want to debug or update code in ielm, like

(print status)


(defun check-server ...)

However when I run it, I can't enter any code in ielm. Is there a method to finish my purpose?

  • 1
    Show da codz. Make the question more specific, please.
    – Drew
    Commented Jan 22, 2016 at 5:47
  • @Drew, thanks for your comment, updated.
    – netawater
    Commented Jan 22, 2016 at 8:39
  • Do you really want to block your emacs?? Isn't it better to run your check-server with run-with-idle-timer?
    – Tobias
    Commented Jan 22, 2016 at 9:14

2 Answers 2


In the menus, enable:

Options -> Enter debugger on Quit/C-g

and then press C-g when your code is running and you want to debug.

  • Yes. In the buffer that shows the backtrace, press c. Commented Jan 25, 2016 at 8:06
  • It works very well for me, and it can be done by set debug-on-quit to true. Thanks so much!
    – netawater
    Commented Jan 26, 2016 at 6:51

Run your server with run-with-timer. In this way you can do anything you like with it. For an instance you can instrument check-server for edebug or redefine check-server while it is still running.

An example how to run the check-server with run-with-timer. Each started server has its own buffer. The variable my-server-status is buffer local to this buffer. If you want to see its value first switch to this buffer.

(defun check-server ()
  (let ((time (current-time)))
    (message "Running server at %s" time)

(defun my-server-start (time fun)
  "Run `fun' with timer for every time seconds."
  (interactive "nTime in seconds:\naServer to run:")
  (let ((buf (generate-new-buffer (concat "*my-server(" (symbol-name fun) ")"))))
    (with-current-buffer buf
      (setq-local my-server-fun fun)
      (setq-local my-server-timer (run-with-timer 0 time `(lambda () (with-current-buffer ,buf (setq-local my-server-status (funcall my-server-fun))))))
      (add-hook 'kill-buffer-hook (lambda () (cancel-timer my-server-timer)) t t))))

EDIT: You get rid of the server timer when you kill the server buffer.

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.