Hot answers tagged

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


15

In term-mode, there are two input modes. In the default input mode -- char-mode -- all keypresses (except C-c) are sent to the terminal to do what it wishes with. If you change the input mode to line-mode, then regular Emacs commands work. You can switch to line-mode with C-c C-j. You can switch back to char-mode with C-c C-k.


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


12

Like most terminals, Emacs' term has a scrollback limit -- which will naturally mess with the consistency of linum's counting, as lines will be deleted from the beginning of the buffer. The term-buffer-maximum-size variable controls this, and sure enough it has a default value of 2048. So linum was telling you the truth: the terminal buffer was never more ...


9

There are a few answers here. Quitting Emacs without C-x C-c First, you can quit emacs by running the command that C-x C-c is bound to: M-x save-buffers-kill-terminal. Alternatives to recursive Emacs Emacs is able to edit files on remote servers, so you don't even need to ssh into the remote server, and you won't need an Emacs inside a term inside your ...


7

shell is the oldest of the two. It uses Emacs's comint-mode to run a subshell (e.g. bash). In this mode, you're using Emacs to edit a command line. The subprocess doesn't see any input until you press Enter. Emacs is acting like a dumb terminal. It does support color codes, but not things like moving the cursor around, so you can't run curses-based ...


6

maybe using ansi-term instead would be slightly less annoying, since it exposes a C-x prefix, allowing you to use, say, C-x o or C-x k without any special trick. If that's not sufficient, you can use the following approach: (defun expose-global-binding-in-term (binding) (define-key term-raw-map binding (lookup-key (current-global-map) binding))) (...


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


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

Looking at term.el it seems char mode is enabled right after running term-mode (and hence term-mode-hook) as such enabling term-line-mode in term-mode-hook would not work. The only option I can think of is advicing the function term and ansi-term, like so (defun my-enable-term-line-mode (&rest ignored) (term-line-mode)) (advice-add 'ansi-term :after #...


5

In term-mode, any regular C-x whatever keybinding becomes C-c whatever instead. Courtesy of Josh Matthews Now to define keybindings that will be active only in term mode, try this: (add-hook 'term-mode-hook (lambda () (define-key term-raw-map (kbd "M-J") 'other-window) (define-key term-raw-map (kbd "M-k") 'kill-buffer)))


5

TERM is an environment variable, you set it in your environment. This could be the environment of a particular shell that you've opened, by running export TERM=foo, or all of your shells by adding the same command to your .bashrc (or a similar file for your shell, if you don't use bash. but you probably do use bash). terminfo and termcap are databases ...


5

There is a way! The problem with using term is that term doesn't understand some of the escape sequences Julia sends, which causes term to put a bunch of extra prompts on the screen that make it unusable. This method should also work for more or less any REPL or terminal application you could want to run. There is a ridiculously useful terminal application ...


5

Quoting startup.el: ;; Subprocesses of Emacs do not have direct access to the terminal, so ;; unless told otherwise they should only assume a dumb terminal. ;; We are careful to do it late (after term-setup-hook), although the ;; new multi-tty code does not use $TERM any more there anyway. (setenv "TERM" "dumb") If Emacs didn't set TERM=dumb then every ...


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

(defun my-applescript-fn () "Open the Terminal.app, wait a second, and CD to the Emacs default-directory of current buffer." (interactive) (do-applescript (format "tell application \"Terminal\" activate delay 1 try do script with command \"cd %s\" in window 1 on error beep end try end tell" default-directory)))


4

I did this: (defun shell-hook () (text-scale-decrease 1.1)) (add-hook 'term-mode-hook 'shell-hook) and it worked beautifully


4

Yes, with defalias. Put this code in your init file: (defalias 'term 'multi-term) This will make it so calling M-x term calls the same function as M-x multi-term.


4

Such initialization might (I guess) looks like the following: (require 'multi-term) (defun init-multi-term (new-name dir) (let ((mt-buffer-name "*terminal*")) (multi-term) (comint-send-string (get-buffer-process mt-buffer-name) (format "cd %s\n" dir)) (with-current-buffer mt-buffer-name (rename-buffer new-name)))) (defun init-multi-...


4

I use ansi-term almost exclusively, so I would say "almost". Speed is your main concern -- anything which rapidly generates large amounts of output is going to cause some pain, as Emacs won't keep up with it. If I know I'm about to issue such a shell command, I pull up a dedicated terminal emulator. If you're using Emacs 24 then https://www.emacswiki.org/...


4

In my .emacs I first define a function like so (defun my-bash-on-windows-shell () (let ((explicit-shell-file-name "C:/Windows/System32/bash.exe")) (shell))) and I call at the bottom using: (my-bash-on-windows-shell) Note that Emacs shell mode does not handle the default colored prompt very well, however changing my PS1 to: PS1='\u@\h:\w\$ ' in my ...


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

Technical explanation: that's because emacs-startup-hook is run after the init file is processed, therefore your call to multi-term is run after you do the rename operation. Now, you don't need emacs-startup-hook at all, what you really want is to run those things in sequence, right from your init file. And you don't need to call get-buffer (which needs a ...


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

This is a helpful overview of ways to use the various shells and terminals in emacs. I use eshell for most things (here's my config for eshell) if you care to take a look. But as the other answer notes, if you're going to be dumping a lot of text in a terminal, emacs will likely be too slow.


3

Perhaps (evil-set-initial-state 'term-mode 'normal) will do what you want.


3

This should now be fixed in the master branch. As mentioned in the comments, bugs should be reported to the bug tracker. If you are not sure if something is a bug, testing with emacs -Q is a good indicator (and you should do that anyway, before reporting). 4c33ad4a24: Fix line-wrapping for term.el (Bug#30775)


3

Start with Eshell: (setq initial-buffer-choice #'eshell) Start with running Bash in Term: (setq initial-buffer-choice (lambda () (term "bash"))) C-h v initial-buffer-choice If the value is a function, call it with no arguments and switch to the buffer that it returns.


2

As correctly guessed by Tyler, what's happening is that ps is truncating the output to the width of the terminal when it's running in Emacs Term, but not when it's running elsewhere. You can see that in the line where you grep for 13109. Note that it's ps doing the truncation, not the terminal. The reason this happens is that Term sets the COLUMNS ...


2

I think the Emacs shell is telling ps what the column width is, and that causes ps to truncate its output. You can explicitly set the output width to unlimited by setting the -w argument twice: ps -ef -w -w. This overrides whatever settings Emacs is setting in shell mode.


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