Killing Racket Infinite Loops in Geiser - emacs

When I accidentally make an infinite loop by evaluating a form in emacs with geiser + racket, after a minute or so of waiting, eventually emacs will start to respond again. Unfortunately, every eval after that takes at least a minute. Usually, after the second or third eval, emacs will stop responding at all, and the fastest thing to do at that point it to restart the Ubuntu machine.
Is there some setting to prevent this in geiser, or a way to tell emacs to kill geiser?

Here's what I do when something hangs up.
Over the years, I don't recall Emacs being stuck in an unrecoverable state.
Use C-g. Repeatedly if needed. It calls keyboard-quit.
This should break any stuck loop and give you the ability to enter commands.
Now if geiser or any other process is misbehaving, just kill the buffers
that correspond to this process.
C-x C-b will give you the list of all buffers.
If you don't recognize the one that belongs to geiser, just restart Emacs
and open only geiser and see the buffer list again.
Now mark the misbehaving buffers with d.
Execute the deletion with x. That's it. You can
now restart geiser or whatever else. This approach is completely generic.
By the way, restarting the Ubuntu machine is too drastic.
When nothing works to stop the application with a window, but X still works,
use xkill utility. I've bound it to Ctrl-Alt-F12 for instance.
Then you just click on a window you don't like and it's gone.
If xkill doesn't work, switch to a virtual terminal with
Ctrl-Alt-F1 and use htop to kill the application.

According to the REPL documentation, you should be able to use C-c C-q to kill the REPL. From the link to the REPL documentation, go to the First Aids section; it's near the bottom of it.

Geiser hangs on loops here also. In emacs 24.3.1 running on Debian 7 updated two days ago; M-x run-geiser; Then one gets a window with a REPL prompt. All is good, but then say > (define f (* f (- n 1))), then > (f 3) and the process in the buffer is locked up. C-c C-c and C-c C-q do nothing. Killing the buffer, answering yes to the query of killing subprocesses, and then restarting does get one to a REPL prompt with all definitions gone.

Related

emacs kill process from list

When using M-x list-processes I get a list of processes.
Is there a way to kill them interactively ? For instance by selecting one in the list, then pressing q or something similar ?
In case it matters, I am using emacs 24.5.1 on osx with emacs prelude.
Note : it is different from this question I want to do it interactively, not from the mini-buffer (as understood by #legoscia already).
In Emacs 25, you can do what you'd expect: in the process list, hit d to "delete" the process under point.
For earlier Emacs versions, I've been using this little function that works using the minibuffer, not the process list:
(defun delete-process-i(p)
(interactive `(,(completing-read"Kill proc: "(mapcar 'process-name(process-list))()t)))
(delete-process p))
After defining it, you can type M-x delete-process-i, and type the name of the process you want to kill, with tab completion.
(I originally wrote it to fit in 140 characters; thus the non-standard layout.)

What happens in emacs if exiting emacsclient with C-x C-c?

I've been trying to get used to using emacsclient because the load time is so much quicker than always running a full-fledged emacs process every time I want to open a file. I noticed in the emacs manual, it's suggested that I use C-x # to exit emacsclient. I'm so used to C-x C-c to exit that I often forget.
Is this a problem if I use C-x C-c to exit? Is there anything bad that can happen (e.g. corrupted files, zombie processes, etc.)
Is this a problem if I use C-x C-c to exit?
No, is this not a problem.

Failure to send buffer region to REPL in sml-mode

Recently I have started dabbling in the sml-mode Emacs package for running SML code. The problem I'm facing is when I try to send across a region of my SML code/file to the REPL (which I think is the only logical way of writing multi-line functions in SML without getting troubled by the primitive REPL). Here is my workflow:
Open up an SML file (the SML mode shows in the bottom part of the window)
Open up the REPL if it isn't already running (C-c C-s)
Again get back to the SML file and write a function
Select the entire function and then press C-C C-r. I get an error "Not a `sml-prog-proc` buffer"
Now instead of selecting a region, just try to send the entire file to the REPL using C-C C-l; again the same error in the mini-buffer
Can someone please help me out in understand why this occurs and how to actually send across code from a script/file to the REPL when using SML? If it matters, I'm using SML/NJ.
TIA,
sasuke
This was bugging me as well, as it worked on some occasions but not on others.
If the sml process is killed with C-d (as recommended when issuing 'use' commands) and immediately restarted from the same buffer (C-c C-s), the error will occur whenever any of the 'send-to-repl' operations are performed.
The correct way (after killing the repl) is to switch back to the buffer containing the .sml file that is being edited and restart the repl from there (C-c C-s) or by either of (C-c C-r) or (C-c C-l).
HTH.

Yanking text into a terminal running in Emacs

I am unable to yank text into a terminal running in Emacs.
This is my procedure:
I killed the string "date" from one buffer and yanked it into the terminal in another buffer and hit return.
The terminal behaves as if I typed nothing. It just returns the prompt back.
I am using OS X 10.5.8 and Emacs 23.1. I have tried this procedure on Aquamacs, Carbon Emacs, and the release from http://emacsformacosx.com/. They all show this weird behaviour even in their default configurations with my .emacs file empty. What could possibly be causing this?
By "in a terminal" I assume you mean you're running Emacs's built-in terminal emulator. Ordinarily, the terminal emulator transmits most keys exactly as typed to the shell process. Type C-c C-j in the terminal buffer to put it into a state where ordinary Emacs key bindings are available. You'll see the mode line change from (Term: char run) to (Term: line run).
Addendum:
Yanking text without leaving char mode is a little tricky; the relevant function, however, is term-paste (not yank, which merely inserts the text into the terminal buffer without sending it to the inferior process). term-paste will immediately send the most recent kill to the inferior process, but doesn't provide the fancy yank functionality you're probably used to (like M-y to cycle through prior kills). You could run term-paste as an extended command: C-c M-x term-paste RET.
Probably the easiest solution is just to temporarily go into line mode (C-c C-j) when you have something to paste, and then immediately go back into char mode (C-c C-k). Or even easier, just stay in line mode all the time. I often do this when I have a terminal logged into an Oracle SQL*Plus session. I rarely notice the difference, but I get all sorts of convenient Emacs functionality, like being able to type M-p to cycle through a long, previously-typed SQL statement.
I would have assumed that you could always start off in line mode like this:
(add-hook 'term-mode-hook 'term-line-mode)
...but it doesn't work for me. Don't know why.
In the buffer with the terminal running, put the terminal into line mode with C-c C-j. To paste in your text, now press S-Insert (that's Shift-Insert). If you need the terminal to go back to char mode afterwards, it's C-c C-k.
When all else fails I just highlight the text and click Edit->Copy then right click in the other emacs buffer and click paste.

Is there a (repeat-last-command) in Emacs?

Frequently, I've dug into apropos and docs looking for something like the following only to give up to get back to the task at hand:
(repeat-last-command)
do the last C- or M- command I just executed (to be rebound to a fn key)
or sometimes the related:
(describe-last-function)
what keystroke did I just mistakenly issue, the effect of which I'd like to add to my bag of tricks. describe-key is close, but requires knowing what I typed.
Am I simply asking too much from my trusty sidekick?
Repeat functionality is provided by the repeat.el Emacs Lisp package, which is included with standard Emacs distributions. From repeat.el's documentation:
This package defines a command that
repeats the preceding command,
whatever that was, including its
arguments, whatever they were. This
command is connected to the key C-x z.
To repeat the previous command once,
type C-x z. To repeat it a second time
immediately after, type just z. By
typing z again and again, you can
repeat the command over and over.
To see additional information about the repeat command, type C-h F repeat RET from within Emacs.
Repeat last command
C-xz
Once you pressed it, just press only
z
after that and it will repeat (without having to press C-x again).
Yes, there is a repeat command. It's called repeat:
You can repeat commands with C-x z, and hit z to keep repeating.
A bit shocking nobody mentioned repeat-complex-command, available from the key binding C-x ESC ESC.
with regards to 'describe-last-function':
There's a variable last-command which is set to a symbol representative of the last thing you did. So this elisp snippet - (describe-function last-command) - ought to bring up the documentation for the thing that immediately happened.
So you could make a trivial working describe-last-function like so
(defun describe-last-function()
(interactive)
(describe-function last-command))
Put that elisp in .emacs or equivalent, and you'll have a M-x describe-last-function.
If you've banged on a few keys or done something that modified last-command since the thing you're interested in, the command-history function might be of interest. You can get that by M-x command-history
Also, M-x view-lossage shows you the last hundred(?) keystrokes you entered. So, you'll be able to see where the command is. It's what i used until i just right now found out about M-x command-history which i think i'll be using with C-h w now.
I'm not really sure, but maybe you are searching for this one?
The command C-xz (repeat) provides another way to repeat an
Emacs command many times. This command repeats the previous Emacs
command, whatever that was. Repeating a command uses the same arguments
that were used before; it does not read new arguments each time.
Emacs Manual, 8.11 Repeating a Command
May be this would help too...
From emacs Help verbatim:
C-x M-ESC runs the command repeat-complex-command
which is an interactive compiled Lisp function in `simple.el'.
It is bound to <again>, <redo>, C-x M-:, C-x M-ESC.
(repeat-complex-command ARG)
Edit and re-evaluate last complex command, or ARGth from last.
A complex command is one which used the minibuffer.
The command is placed in the minibuffer as a Lisp form for editing.
The result is executed, repeating the command as changed.
If the command has been changed or is not the most recent previous command
it is added to the front of the command history.
You can use the minibuffer history commands M-n and M-p
to get different commands to edit and resubmit.
Personally I found Sebastian's idea useful. Here is a working version
(global-set-key "\C-r" #'(lambda () (interactive)
(eval (car command-history))))
This is old, but Google pops post this up first when I was looking to retrieve the last command I typed at the Emacs prompt. None of these answers worked for me so I decided to put in my two cents for those who might stumble upon this later on as I did. I'm using Portacle, but I found what I was looking for in here so I'm hoping it's generic enough to work with different setups. Anyway, what worked for me is using C-&uparrow; and C-&downarrow; to cycle through the history. Using M-p and M-n worked as well, but I prefer using the arrows since I use Bash quite a bit.
dot-mode is a way to repeat the last command(s).
From its commentary:
It emulates the vi `redo' command, repeating the
immediately preceding sequence of commands. This is done by
recording input commands which change the buffer, i.e. not motion
commands.