jcubic
jcubic

Reputation: 66488

How to send every command to Emacs Term?

Is it possible to configure emacs term to send everything (maybe exception M-x) as raw commands. This will allow for instance run emacs -nw inside terminal and every command will work for emacs inside terminal now the one outside.

I want something like this because I sometimes run nano from terminal or screen, I also use ssh and this will alow me to run emacs on the server. Right now when I run nano I need to call C-c x that send C-x.

Upvotes: 0

Views: 1882

Answers (1)

jpkotta
jpkotta

Reputation: 9417

I'd first suggest using tramp to edit remote files. I prefer it to opening an editor on the remote machine. If you try to run emacs inside a term-mode buffer, you're going to be fighting it all the time.

If you must run emacs inside a term-mode buffer, you can use term-send-raw and term-send-raw-string. For example:

(defun term-send-backward-word ()
  "Move backward word in term mode."
  (interactive)
  (term-send-raw-string "\eb"))

<Escape> b is what the terminal (which is eterm-color) expects when you press C-<left>. This is not necessarily the same as binding C-<left> to term-send-raw. The best thing to do is probably to try binding whatever key to term-send-raw, and if that doesn't work, make a function with term-send-raw-string and bind that. You can figure out what the string should be if you have a shell in the term-mode buffer, send a quote, and then type the key. You can send a quote with

(defun term-send-quote ()
  "Quote the next character in term-mode.
Similar to how `quoted-insert' works in a regular buffer."
  (interactive)
  (term-send-raw-string "\C-v"))

It's just like typing C-v in a normal terminal.

Finally, I'll mention multi-term. It's available in melpa. It provides the functions I listed above, and has better defaults than term-mode IMO. But it's probably further from what you want, because it tries to integrate term-mode with the rest of emacs instead of just passing things through.

Upvotes: 6

Related Questions