How to break out of an infinite loop in emacs lisp ? (environment: emacs)

emacs manual
emacs lisp
elisp occur
emacs for lisp
elisp let
emacs lisp manual
emacs options
elisp tutorial

I tried using ctrl-c then :a

But It doesn't work here.

My code is like:

(defun game-repl()
    (loop (print (eval (read)))))

then I run

(game-repl())
look()
(require 'cl)
(loop (setq x (read))
      (if (eq x 'exit)
        (return)
        (print (eval x))))

Infinite Loops - GNU Emacs Lisp Reference Manual, Buffer Walk Through, Exploring a few buffer-related functions. Most of the GNU Emacs integrated environment is written in the programming language This introduction to Emacs Lisp is designed to get you started: to guide you in learning attempt to repeat continually what it is doing for ever and ever in an infinite loop . This works when executing one at a time, but if you call from an emacs lisp function more than once, as below, then it goes into an infinite loop inserting |'s until it locks up or shows the message below. Update it now locks up when I do (test1) as below. Can dowload a full example of the code from pastebin here

Emacs modes often send an interruption signal to the inferior program only when you hit Ctrl-C twice in a row (i.e., the key sequence you are looking for is C-c C-c). In particular, this is true for SLIME.

This is because C-c is a prefix key that is usually combined with other keys to access a whole bunch of mode-specific features.

Programming in Emacs Lisp, When you run Emacs, it enters the editor command loop almost immediately. the pre-command-hook list could easily make Emacs go into an infinite loop of errors. the commands to exit the minibuffer do not exit if the current input is not valid. current buffer, default-directory (see section Operating System Environment). C-gworks by setting the variable quit-flagto tthe instant C-gis typed; Emacs Lisp checks this variable frequently and quits if it is non-nil. C-gis only actually executed as a command if you type it while Emacs is waiting for

[Reference http://www.psg.com/~dlamkins/sl/chapter05.html]

Most of the time you write a LOOP form, you'd like to have a way out. Fortunately, a RETURN form anywhere inside will cause control to leave the LOOP; any value you specify becomes the value of the LOOP form:

 ? (loop
     (print "Here I am.")
     (return 17)
     (print "I never got here."))
 "Here I am."
 17

RETURN is normally used in a conditional form, like this:

? (let ((n 0))
     (loop
       (when (> n 10) (return))
  (print n) (print (* n n))
  (incf n)))

0 0
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100
NIL
?

GNU Emacs Lisp Reference Manual, Aborting with C-] ( abort-recursive-edit ) is used to get out of a recursive editing level or when Emacs is stuck in a very tight endless loop (in C code, not in Lisp code). For possible display bugs, the terminal type (the value of environment  Meanwhile I would like to just continue using Emacs for other things, but I find the only way I can use M-x after running simple-rtm is to exit Emacs and run it again. My question therefore is: is there a simple Emacs command I can use to break out of the function indirection loop so I can use M-x again? Emacs version is 24.5.1 running on

This question can refer to:

  1. how to programmatically break out of a loop that would otherwise be infinite or
  2. how to manually stop an infinite loop that's already raging.

The 1st has satisfactorily been answered by @fred-foo (and it seems it was OP's actual question). The 2nd has been tackled by @matthias-benkard but his answer is not working for emacs lisp.

The actual answer to manually stop a running infinite emacs-lisp loop is Ctrl+g (C-g in emacs-speak).

There is a documentation page in the emacs lisp manual on this very topic.

Sorry, I don't have the reputation to just amend @matthias-benkard's answer and the question ranks high on search engines...

GNU Emacs Manual, If Emacs hangs, or seems to be stuck in some infinite loop, typing "kill -TSTP PID", where PID is To see the current value of a Lisp Variable, use `pv variable'. This is in fact what happens if you stop Emacs while it is waiting. To disable this protection you need to set the environment variable LD_POINTER_GUARD to 0. The entire cl-do loop is enclosed in an implicit nil block, so that you can use (cl-return) to break out of the loop at any time. If there are no result forms, the loop returns nil.

This Stack Exchange answer is the first hit on google for "break a never ending loop slime"

 C-c C-b

What is missing, is that different lisps handle this break differently. I found this answer because GNU Clisp just doesn't intercept SLIME's C-c C-b. Nor does it do what SBCL does which is intercept both C-c C-b and C-c C-c.

Debugging, GNU Emacs Lisp Reference Manual. GNU Emacs Version 19. for Unix Users. Revision 2.4, June 1995. by Bil Lewis, Dan LaLiberte, Richard Stallman. and the   The Lisp debugger provides the ability to suspend evaluation of a form. While evaluation is suspended (a state that is commonly known as a break), you may examine the run time stack, examine the values of local or global variables, or change those values. Since a break is a recursive edit, all the usual editing facilities of Emacs are available

GNU Emacs Lisp Reference Manual, 4.2 Files Lisp needs to start up 2: the Allegro directory 9.0 How to exit Lisp When starting in Emacs, you are asked for a `Lisp Image (dxl) file' and also for On Solaris 2 this means using the environment variable LD_LIBRARY_PATH; other infinite loop is in C or FORTRAN code loading into Lisp) and (2) when Lisp is  If deferred tasks fall into an infinite loop unexpectedly (but Emacs may not freeze), calling the command deferred:clear-queue, you can stop the deferred tasks immediately. If the errors occurred in deferred tasks are caught by no errorback functions, finally the deferred framework catches it and reports to the message buffer.

Allegro CL Startup, That kind of tight feedback loop will be useful while learning Clojure and, later, when Emacs is also great for working with any Lisp dialect; in fact, Emacs is written in a To get there, you'll start by installing Emacs and setting up a new- person-friendly But underlying Emacs is the elegant simplicity of Lisp and the infinite  21. Command Loop . When you run Emacs, it enters the editor command loop almost immediately. This loop reads key sequences, executes their definitions, and displays the results. In this chapter, we describe how these things are done, and the subroutines that allow Lisp programs to do them.

How to Use Emacs, an Excellent Clojure Editor, The following Emacs-specific functions are also setf -able. This cleanup happens even if the form s exit irregularly due to a throw or an error The argument env specifies the “environment” to be passed on to macroexpand if get- setf-method should simply creates an infinite loop executing the expressions over and over. All loops can stop using Esc or Ctrl+C or Break (the last two open dialog box to stop or continue). Using Escape Off we make Esc not work for breaking execution. If Esc works then Ctrl + Y (and other letters except C, A, Z, X, N, M. F, L), open Control form, which we can do: Next Step, Slow Flow, Stop, and we can show code,current stack

Comments
  • Often game loops will have a variable isDone or isNotDone, and will loop based on that, e.g. (while is-not-done ... ). Simply set is-not-done to false, and the loop will break on the next iteration.
  • Thank you @Merlyn, But my question is how to break this loop back to my Lisp programming enviroment,that is emacs.
  • Hence why a comment and not an answer :) But it would solve the problem... Just set is-not-done in your REPL. But yes I can see you are looking for an editor command, not a programmable solution.
  • Thank you Merlyn. I see. I searched some sources. You are right. I need to "tell" lisp when to get out. ;)
  • (Game-repl ()) should signal an error because of an invalid number of arguments (expects none, but gets one). Look is most likely not a defined variable. () evaluates to nil.
  • I've just confirmed that this is specific to Clisp on Windows.