The Stack Overflow podcast is back! Listen to an interview with our new CEO.
31

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 ...


16

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-...


12

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: (...


10

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 ...


9

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 [0]). If you enter line mode (C-c C-j [1]) M-x should work as usual. You can read more on both: [0] https://www.emacswiki.org/emacs/AnsiTerm [1] https://www.gnu.org/software/emacs/manual/html_node/emacs/Term-Mode....


6

You can use this snippet in your dotspacemacs/user-config function: (evil-set-initial-state 'term-mode 'emacs)


6

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 ...


6

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 ...


5

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 ...


5

It's an off by one error in term-handle-ansi-escape, I've posted a patch in Bug#31690. --- c/lisp/term.el +++ w/lisp/term.el @@ -3386,11 +3386,10 @@ term-handle-ansi-escape ;; \E[B - cursor down (terminfo: cud) ((eq char ?B) (let ((tcr (term-current-row))) - (unless (= tcr (1- term-scroll-end)) + (unless (>= tcr term-scroll-end) ...


4

Try something like this: (defun set-no-process-query-on-exit () (let ((proc (get-buffer-process (current-buffer)))) (when (processp proc) (set-process-query-on-exit-flag proc nil)))) (add-hook 'term-exec-hook 'set-no-process-query-on-exit)


4

This sort of thing? (defun my-foo-console () "Runs foo in a `term' buffer." (interactive) (require 'term) (let* ((cmd "foo") (args "--args for --command") (switches (split-string-and-unquote args)) (termbuf (apply 'make-term "foo console" cmd nil switches))) (set-buffer termbuf) (term-mode) (term-char-mode) ...


4

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: (require 'term) (defun jnm/term-toggle-mode () "Toggles term between line mode and char mode" (interactive) (if (term-in-...


4

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)) (...


4

This is a simplified version of a function in my .emacs file: (defun ml/bash () "Start a terminal emulator in a new window." (interactive) (split-window-sensibly) (other-window 1) (ansi-term (executable-find "bash"))) You can bind it to C-c a: (global-set-key (kbd "C-c a") #'ml/bash)


3

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." (cond ;; \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)))) ...


3

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") You ...


3

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 ...


3

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 . (term-paste) Insert the last stretch of killed text at point.


2

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), ...


2

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 ...


2

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) (let ((process ...


2

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 ...


2

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-...


2

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 ...


2

Paste this script into bash and you are ready to roll: #!/bin/bash EMAX_DIR=/usr/local/bin EMAX=$EMAX_DIR/emax mkdir -p $EMAX_DIR cat > $EMAX <<EOF #!/bin/bash exec emacs \$* --eval "(ansi-term \"/usr/bin/bash\")" EOF chmod +x $EMAX hash -r SHORTCUT=$HOME/.local/share/applications/emacs-with-ansi-term.desktop sed -e "s,EMAX,$EMAX," > $SHORTCUT &...


2

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 find-file file.txt 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 ...


2

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" https://github.com/atomontage/xterm-color


2

I used these functions for that ;; yank in term (kill-ing) (defun term-yank-kill-ring () (interactive) (flet ((insert-for-yank (string) (term-send-raw-string string))) (yank))) ;; yank-pop un term (kill-ring) (defun term-yank-pop-kill-ring () (interactive) (dotimes (i (- (point) (mark t))) (term-send-backspace)) (process-send-string (...


2

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, ...


Only top voted, non community-wiki answers of a minimum length are eligible