emacs cancel the last action ,the ctrl+g is not very effective - emacs

Emacs usually use Ctrl+G to cancel the operation ,but when i use the GUD mode to debug a program ,the Ctrl+G is usually not working so well as i expected.
For example, if i wanna to set a break point at the source test.cpp, line 223,
if i input
"b test.c:" ,then i use the TAB to auto complete it then will try to list all the possible result , then the emacs cannot respond to any input.
if i use Ctrl+G to cancel this, the result continue to output all result to the screen, this may take a long time.
is there a way to cancel this action more effectively?

Ctrl+G is for cancelling Emacs commands, but that output is coming from the debugger that's being run in the comint buffer. The Emacs command has already completed, it just sent the TAB to the debugger process.
Try Ctrl+C Ctrl+C, which sends an interrupt to the subprocess. However, it's possible that the subprocess has already finished sending the list of results, and it's all in the pty buffer.

Related

Checking start up error messages in Emacs

When I invoke Emacs, I see some error messages which are replaced by the main window (startup screen) pretty soon. How can I access these error messages?
The error messages are stored in the *Messages* buffer. There is a command to open it: C-h e. You can also just click on the echo area in the bottom of the window.
By default, the last 1000 lines of messages are saved. You can change this by setting the variable message-log-max.

Get tab completion in custom comint mode

I usually try to start CLI's (might not be defining it properly) using commands like:
(make-comint-in-buffer "PUTTY" nil "./plink.exe" nil "dbserver")
(make-comint-in-buffer "Python" nil "c:/Python26/python.exe" nil "-i")
(make-comint-in-buffer "Python" nil "c:/Python27/python.exe" nil "-i")
(make-comint-in-buffer "git" nil "C:/Program Files (x86)/Git/bin/sh.exe" nil "--login" "-i")
Starting the above specially the first and the last in command prompt provides the facility of tab completion. But in comint-mode I don't seem to get this feature.
Entering tab adds a simple tab character under the point instead of passing it to the process and getting back the completion candidates. comint-dynamic-complete and C-qtab doesn't produce the desired result.
How can I utilize in above said feature in comint-mode running different processes?
Short answer
You need to write your own completion functions inside Emacs. These may pull info in from the external program, but you can't have direct access to the tab-completion provided by python or git etc.
Long answer:
When you run make-comint-in-buffer, you are setting up the most basic setup for interactively sending and receiving data from an external process. Whenever you press enter, Emacs sends the current line to the underlying process, and then prints back the output from the process. The external process doesn't know what you're doing until Emacs sends a full line to it - no single characters are passed directly.
This is different from running the external program directly in a terminal. When you run python in a terminal, it interprets every character as you type it (or at least it can). So when you hit tab it knows to try to complete something. When you run python inside Emacs, Emacs is processing all of your input until you hit enter. Which means when you hit tab, Emacs just inserts a tab character, and python doesn't know to try and complete something.
Emacs can provide tab-completion for comint modes, but you need to build the completion targets on the Emacs side, you can't rely on the native completion of the external program. To get an idea of how this works, take a look at the completion functions in shell.el, which you can open with M-x find-library shell.
This isn't something you can do with a line or two of elisp. It's an important part of major-modes written to interact with external processes - things like ESS for R http://ess.r-project.org/
That said, if you dig into the guts of shell.el you may find enough code you can modify to get you started.

How to kill minibuffer after period of inactivity?

I usually encounter situation when I enter minibuffer command such as open file or change buffer and instead of completing it in a minibuffer, I start doing something else, usually editing the buffer. I would like that minibuffer simply forget the command if it was not completed after some period of inactivity in a minibuffer. Is it possible?
If it would be possible to make the minibuffer simply flush itself after losing focus it would be great too. Now frequently I get the queue of minibuffer commands waiting for me and it is annoying as hell, since when I C-g them, emacs changes the buffers in the frames.
I wouldn't really advise doing anything of the sort, but would suggest instead that you provide a visual clue to yourself when the minibuffer is active. But since you asked for it...
You can put a function to exit the minibuffer on a suitable hook or in a timer. The function could check the value of (active-minibuffer-window) and call, say, (top-level) to return to the top level whenever it is nil. (Function abort-recursive-edit will exit the current minibuffer, but that can return to a parent (shallower) minibuffer, not necessarily `top-level'.
What hook or timer to use? You could use `post-command-hook', which is run after each command (e.g., each key press). That is perhaps overkill, but it won't miss a chance. There is perhaps another, more pertinent hook; dunno.
You could use an idle timer, which kicks in only after Emacs has been idle for a specified time. Or you could use a regular timer, just checking periodically. A timer could be started on minibuffer-setup-hook and then canceled on minibuffer-exit-hook.

How to view history of various commands in Emacs

Commands entered after pressing M-x can be viewed using the up/down arrow keys.
How can I get a list of all the commands including menu bar invocation, commands
triggered using mouse clicks, etc. in Emacs?
For a complete list of history, type C-h l (lowercase "L").
Note: this list is complete in the sense that it keeps all events and commands that happened recently, but it's not complete in the sense that it only keeps track of the last 300 or so events (and corresponding commands).
I've used mwe-log-commands to make screencasts. It shows events and the commands they trigger as you work in Emacs.
command-log-mode
I've just forked it and made it into a proper minor-mode and global-minor-mode along with some other improvements as command-log-mode.
Give it a shot and file issues against me if the documentation is unclear or if you find any bugs.
So you want the history of of all commands, regardless of where they are executed? I don't know if emacs provides this by default, but you can add your own function to post-command-hook which is executed after every command, so you can use it to collect all the executed commands.
M-x view-lossage
From emacs documentation
(view-lossage)
Display last few input keystrokes and the commands run. For
convenience this uses the same format as edit-last-kbd-macro. See
lossage-size to update the number of recorded keystrokes.
To record all your input, use open-dribble-file.
(open-dribble-file FILE)
Start writing input events to a dribble file called FILE. Any
previously open dribble file will be closed first. If FILE is nil,
just close the dribble file, if any. If the file is still open when
Emacs exits, it will be closed then.
The events written to the file include keyboard and mouse input
events, but not events from executing keyboard macros. The events are
written to the dribble file immediately without line buffering.
Be aware that this records all characters you type! This may include
sensitive information such as passwords.

pause shell output

In windows shell it's possible to pause the output just by selecting a text in the shell window (a QuickEdit mode must be enabled). The same is possible in the cygwin shell (again with a QuickEdit mode).
How can I pause the output in emacs shell?
I need to pause it because some tasks are very verbose and it's difficult to search the necessary text in a big buffer.
When I execute M-x comint-stop-subjob I get a message "No SIGTSTP support"
As an example try to pause the following:
find . -type f -name "*.txt" -exec cat {} ';'
Not exactly what you asked for, but clone-buffer will get you close to what you want. After binding it to a convenient key and running your find command, calling clone-buffer will copy the contents of the buffer to a new buffer. The find command in the original buffer keeps running, but the cloned buffer contains only the output of find up to the point that you cloned it.
You can invoke this command multiple times in the original window, giving you a series of stop points to examine. I don't know how to actually pause the original window though.
Note that the newly cloned buffers are fully functional shell buffers.
You can stop the job by pressing C-c C-z. Then just enter fg to make it work again.
I don't know about pausing the output, but you can presumably just narrow the buffer?
C-xnn to narrow-to-region
C-xnn to narrow-to-page
C-xnw to widen to full buffer