M-x shell is the standard interface to OS's shell. On linux, it calls bash (or whatever your default), on Windows, it calls cmd.exe. M-x shell is the most frequently used.
M-x eshell is a shell written in emacs lisp entirely. It has a syntax similar to bash, but is integrated with elisp well. e.g. you can eval elisp code right there. Eshell is especially ...
comint-derived modes (like shell, ielm, ...) support filter functions, the following snippet makes the output and prompt read-only:
(setq comint-prompt-read-only t)
(defun my-comint-preoutput-turn-buffer-read-only (text)
(propertize text 'read-only t))
(add-hook 'comint-preoutput-filter-functions 'my-comint-preoutput-turn-buffer-read-only)
As for ansi-...
I think the first part of your question can be done with dirtrack-mode. First, you set your shell prompt to include the present working directory. Next, you set dirtrack-list to a regex that tells dirtrack-mode how to extract it. Example: I set PS1 in Bash to be this:
export PS1="[\h:\w] $ "
and in Emacs I set dirtrack-list and turn on dirtrack-mode:
Apparently this issue is caused by missing terminfo for eterm-color. I managed to fix the issue by following the instructions in that answer to install an appropriate entry into the terminfo database. Specifically:
$ tic -o ~/.terminfo /usr/local/share/emacs/25.0.50/etc/e/eterm-color.ti
I'm still not sure why that is needed at all. term.el actually ...
Term mode has two input mode char mode and line mode. In char mode you would press C-x M-x (prefix your standard keyboard shortcuts with C-x ).
If you enter line mode (C-c C-j ) M-x should work as usual.
You can read more on both:
The bi-directional text support introduced in Emacs 24 interacts badly with term.el when large numbers of spaces or tabs are inserted, and many applications clear the screen (often drawing a new background colour) by writing WIDTHxHEIGHT spaces (which, if the terminal’s dimensions are sufficiently large, may take several seconds).
The workaround is to ...
The info reader in Emacs can be accessed with C-h i. There you can jump directly into the some-node node with g (some-node) RET.
Alternatively, you can go to the some-node node by eval'ing (info "some-node").
Note that the info reader on the terminal picks man pages when info nodes cannot be found. There is no "glibc" info node, but just a man page. To ...
In ansi-term's "char run mode", C-<left> & co are by default intercepted by emacs, which moves the point instead of telling the undelying terminal to do it. This leads to the situation you describe: the point moves in the emacs buffer, but the next insertion will use the real cursor position in the terminal, which hasn't changed.
You thus need to ...
C-c C-j to activate term-line-mode, then, the terminal buffer act more like a normal text-buffer. Switch back to character mode with C-c C-k.
You may be intersted by this function that will help you toggle, between the two modes:
(defun jnm/term-toggle-mode ()
"Toggles term between line mode and char mode"
A nice package that helps with setting up the environment is exec-path-from-shell (at MELPA or https://github.com/purcell/exec-path-from-shell). As the name suggests it sets the PATH variable to a more useful value, but it is also able to set any number of environment variables. I use it like this:
(when (and (memq window-system '(mac ns))
This is a simplified version of a function in my .emacs file:
(defun ml/bash ()
"Start a terminal emulator in a new window."
(ansi-term (executable-find "bash")))
You can bind it to C-c a:
(global-set-key (kbd "C-c a") #'ml/bash)
Given the pointer to term-handle-ansi-escape by @jch I was able to add support for CHA as follows:
(defun toolbear:term-handle-more-ansi-escapes (proc char)
"Handle additional ansi escapes."
;; \E[nG - Cursor Horizontal Absolute, e.g. move cursor to column n
((eq char ?G)
(let ((col (min term-width (max 0 term-terminal-parameter))))
Terminal.app and iTerm 2 set LANG based on the region selected in System Preferences (defaults read -g AppleLocale) by default unless the "Set locale environment variables on startup" setting is unchecked in Terminal or the "Set locale variables automatically" setting is unchecked in iTerm 2.
This changes LANG in Emacs:
(setenv "LANG" "en_US.UTF-8")
If you run bash in a term buffer, bash will do all of its normal bash initialisation things, just as it would when you run it inside any other terminal emulator.
So you can set your prompt in your ~/.bashrc file, no differently to the way you do it without Emacs.
If you particularly wish to detect that the shell is running inside Emacs (in order to set ...
A command to paste into an ansi-term is bound to S-insert (that's shift insert) by default.
runs the command term-paste (found in term-raw-map), which is an
interactive compiled Lisp function in ‘term.el’.
It is bound to .
Insert the last stretch of killed text at point.
When mixing term with shell-mode, the variable comint-use-prompt-regexp seems to get set occasionally. This causes behavior a bit like you've described: in shell-mode C-a will go to the beginning of the line, C-k will kill the whole line, including prompt.
A simple fix is to reset comint-use-prompt-regexp with C-: (setq comint-use-prompt-regexp nil), ...
The problem here is that Emacs is moving the cursor position in the buffer, but no input is being sent to the process running in the terminal, meaning that the apparent state does not match the actual state.
This should be reported as a term-char-mode bug, but you can fix it by binding the Ctrl- and Meta-modified left and right cursor keys in term-raw-map ...
You can use "process sentinel" mentioned in @steve-lorimer's answer if it is OK for you to get color AFTER the process is finished, otherwise you should use "process filter" instead.
Take command echo -e "\e[31mHello World\e[0m" as an example, you can simply use comint-output-filter (I learnt this by reading shell-command's source code)
iTerm2 and Terminal.app automatically set LANG and LC_* from the global language settings of OS X. For instance, if your OS X installation is configured for US language a shell in iTerm2 and Terminal.app automatically receives LANG=en_US.utf8 in its environment.
Emacs' ansi-term however does not do this. Hence you need to explicitly configure your ...
Terminal.app starts an interactive login shell, while Emacs starts interactive non-login shells. The Bash manual's section on startup files explains that for login shells, Bash will first source /etc/profile (and on Mac OS this file instructs Bash to source /etc/bashrc, which sets PS1) and then goes on to look for user-specific config files. Interactive non-...
Disclaimer: I assume this is in no way related to Spacemacs.
The evil-emacs-state-modes variable is initialized with a list of modes to start in Emacs state. This is a mishap as it makes it harder to customize it properly, any successful change to the variable will not take this value into account and Evil's code will not change it either because the ...
I'm assuming you mean in the same window, not buffer.
From eshell its simple. You can run emacs lisp functions by simply typing them into eshell. This means you can type
to open file.txt. You could also make a nicer alias to this so you could do something like type "emacs file.txt" to do the same thing. The emacs wiki page on eshell ...
It is correct that ansi-term only supports 8 colors, but, using xterm-color.el instead of ansi-color.el, you get 256 colors.
"ANSI & xterm-256 color text property translator for Emacs"
The \370\272 is Emacs trying to show the character using octal escapes. See the Emacs manual, node Text Display, and see the Elisp manual, node Usual Display.
You can set variable ctl-arrow to t to see the characters displayed otherwise, using face escape-glyph. But if your font does not enable showing those characters as you expect (Cyrillic) then, well, ...
Emacs supports sending the region/buffer to the interpreter. This is supported in various modes, including python, haskell, octave, and even in shell scripts. Unfortunately, they keybindings are different in every mode.
For shell scripts (sh-mode), you can use C-c C-n to send the current line, or the highlighted region to the inferior shell. Unfortunately, ...