3

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)

or

(defun check-server ...)

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

3
  • 1
    Show da codz. Make the question more specific, please.
    – Drew
    Jan 22, 2016 at 5:47
  • @Drew, thanks for your comment, updated.
    – netawater
    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
    Jan 22, 2016 at 9:14

2 Answers 2

4

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.

2
  • Yes. In the buffer that shows the backtrace, press c. 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
    Jan 26, 2016 at 6:51
1

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)
    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 that you have read and understand our privacy policy and code of conduct.

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