32

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


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


7

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


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


5

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


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

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

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


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

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

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


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

Solved it by myself. Just needed to add the following lines to ~/.emacs.d/init.el: (eval-after-load "term" '(progn ;; ensure that scrolling doesn't break on output (setq term-scroll-to-bottom-on-output t)))


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

From my point of view you should accept Cyberbisson's most useful answer. I'll give you a formal one and the way to determine that information for yourself. Why can't I use this key (global-set-key (kbd "M-o") 'other-window) defined in my emacs config, in ansi-term char mode? Are all meta keybindings simply passed raw to the terminal process? F1 ...


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

Saving the last value of (point) and restoring it with goto-char should do the trick: (defun toggle-maximize-buffer () "Toggle maximize buffer" (interactive) (if (= 1 (length (window-list))) (progn (set-window-configuration my-saved-window-configuration) (goto-char my-saved-point)) (setq my-saved-window-configuration (current-...


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

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

So, after reading excellent commentary for the original question, I was able to solve my problem in this way: (defun my-term-hook () (define-key term-raw-map (kbd "<M-left>") (lambda () (interactive) (term-send-raw-string "\e[1;3D"))) (define-key term-raw-map (kbd "<M-right>") (lambda () (interactive) (term-send-raw-string "\e[1;3C"))...


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