emacs - Kill the buffer with terminal emulator - emacs

I am aware of this option:
Kill the *terminal* buffer with C-d
But I am still a newbie in emacs, what is the original method to do this? I tried C-x k but it doesn't like it, C-x C-c kills all my windows and buffers...

I assume you're using a buffer in term-mode (M-x term). term-mode is a bit different than most modes in that it has two submodes, char and line. In char mode it acts more like a terminal than emacs, as in a lot of normal keybinds are not available. Put it in line mode with C-c C-j to put it in line mode, then you can run most normal keybinds including C-x k. You can put it back into char mode with C-c C-k.
I use the multi-term package, which I think has better defaults than plain term-mode and as the name suggests makes it easy to have many terminal buffers.

Related

How do I exit MELPA in emacs?

I'm trying to learn Emacs, and I've installed MELPA as a package manager. The only problem is that the only way I know how to exit MELPA is by quitting Emacs entirely. I'm sure there's a better way to do this. What is it?
Killing buffers with C-x k RET is generally good advice, but it is much easier to quit the package-list-packages screen by simply pressing q.
This also works to exit dired buffers, magit, and many other types of buffers that aren't text-oriented.
C-x C-f open file
C-x C-b open buffer list
C-x b open buffer
M-x execute command
C - ctrl and M - alt
Also take a tour here

Use Ctrl-X commands while in terminal in emacs?

When I'm running a terminal inside emacs (with M-x term) I can't seem to use commands that start with C-X, such as, say C-x o to switch panes or C-x C-c to exit. Instead it seems that the terminal itself is receiving these C-x signals. By contrast, C-c commands are received by emacs itself. How can I change this behavior?
term has two different input submodes. In the default (character) mode, C-x simply transmits a literal control x to the terminal. Many keybindings which are normally available in the C-x map are instead now in the C-c map, so you can switch to a different buffer in the other window with C-c 4 b. Or you can switch to line mode with C-c C-j (and back to character mode with C-c C-k).
See also the documentation.

In Cygwin emacs C-c is read as C-g

I recently installed cygwin and emacs, and when I try to exit the program (by pressing C-x C-c) the minibuffer reads "C-x C-g is undefined". When I type C-c the minibuffer reads "Quit" just like if I had typed C-g. To the best of my knowledge, it's just reading the c key as a g in the minibuffer. However, if I type c into a scratch buffer it correctly displays c. Or if I type M-x c, it correctly reads as c in the minibuffer.
Is this a common problem? How do I fix this?
Thanks so much for any help! It's driving me crazy. Right now, I have to exit out of Cygwin when I want to quit emacs because C-x C-c won't close the program!
This is a problem with the default Cygwin console, but it doesn't happen with other Cygwin terminals such as mintty, rxvt, or xterm, so you might want to try one of those. Also, I believe the issue with the console is fixed in recent Cygwin snapshots.

How to invoke the buffer list in Emacs

I usually type M-x buffer-menu to switch buffers in Emacs. How can I do this with a shorter command? Its quite a long string to type.
Thanks!
You can use C-x b to change buffers. You have to enter the first few letters of the buffer name, and of course you can use completion. If you press TAB (the most useful key in Emacs), a list of (matching) buffers appears. You can click in this list to switch to a buffer.
You can bind buffer-menu to a key. Pick a key that's not used for another command — let's say f12 — and add the following line to the file ~/.emacs:
(global-set-key (kbd "<f12>") 'buffer-menu)
There are many other interfaces to changing buffers in Emacs, and they can be significantly more efficient than C-x b and C-x C-b. Since this tends to be a very personal choice, I recommend you experiment with a few and keep the one(s) you feel most comfortable with.
C-x C-b
As stated here
I'd highly recommend switching to a mode designed for efficient buffer switching.
If your version of Emacs is recent enough (22+):
M-x ido-mode
and then:
C-x b
to switch buffers, with incremental substring matching, C-s and C-r rotate forward and backwards through the matches.
If you have an older version of Emacs, it should have:
M-x iswitchb-mode
and then, as with ido-mode:
C-x b
opens up the minibuffer to let you choose the buffer to switch to.
Bind C-x C-b to buffer-menu. There is no sense leaving it bound to list-buffers. list-buffers is just a eunuch version of buffer-menu. ;-)
And you might want to try this: http://www.emacswiki.org/emacs/BufferMenuPlus
Try bs-show (in my opinion a way better than C-x C-b). You can bind it to F9 by adding this to .emacs:
(global-set-key (kbd "<f9>") 'bs-show)

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.