Hot answers tagged

41

IPython 5 has a new terminal interface, which is not compatible with Emacs' inferior shells. To fix it, add the --simple-prompt flag to the IPython command: (setq python-shell-interpreter "ipython" python-shell-interpreter-args "--simple-prompt -i") From the documentation: The new interface is not compatible with Emacs ‘inferior-shell’ feature. To ...


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


21

You can start background processes with start-process, which shouldn't pop up a buffer: (start-process "process-name" "buffer-name" "program") Process names are modified to avoid duplication as necessary, so don't worry about that. Just give it a name useful for debugging in the future! If you give a "buffer-name", a buffer will be created but not shown ...


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


15

I think you're looking for comint-prompt-read-only. E.g. (setq comint-prompt-read-only t) should take care of it.


14

Turns out it was projectile that was causing the problems. As soon as I disabled projectile-mode TRAMP was buttery smooth and I began to understand the hype behind it. Hopefully this helps out someone else who has exhausted all other options. Another solution I found if you don't want to disable projectile constantly is to put this command in your init.el ...


14

This is the correct behaviour. .bash_profile is for so-called login shells. Like when you log in to your computer in text mode, or in a terminal emulator to a different computer via ssh or telnet or ... .bashrc is meant for non-login shells, like when you are already logged in and start a new xterm, or in this case emacs' shell mode. Usually the ....


12

You can clean up the *Messages* buffer the same way you always could, with the kill-buffer command. The next time a message is signaled, the buffer will be recreated anew. The reason that this buffer is read-only now, is that it has been granted its own major-mode, which inherits from special-mode, which is read-only. The advantages behind that are several. ...


12

You can also install exec-path-from-shell package and add this to your init file: (exec-path-from-shell-initialize)


11

Since mention that the command is running asynchronously I am assuming you mean the command async-shell-command bound to M-&. You can follow the advice in documentation of async-shell-command (you can read it by doing C-hfasync-shell-commandRET) customize display-buffer-alist as follows (add-to-list 'display-buffer-alist (cons "\\*Async Shell Command\\*....


11

In Shell mode, Emacs detects password prompts based on the prompt. If it sees Password: (or Enter new password:, or Passwort:, or Wachtwoord: or a number of variations), it assumes that you're prompted to enter a password and reads a string from the minibuffer (repeating the prompt); this string is not echoed and is not entered in any history list. If Emacs ...


11

In addition to the points made by @pingi, you can also use a separate configuration file that will be loaded only for the emacs shell (M-x shell): From the manual page (emacs) Interactive Shell: Emacs sends the new shell the contents of the file ‘~/.emacs_SHELLNAME’ as input, if it exists, where SHELLNAME is the name of the file that the shell was ...


10

The ^[] noise is coming from various terminal control characters in your shell prompt. Try echo $PS1 to see the full sequence, and try e.g. export PS1='$ ' to see that a simpler prompt string removes that particular problem. For the encoding, you might try making utf-8 your preferred encoding: (prefer-coding-system 'utf-8) Setting up the prompt Emacs ...


9

Well, as @dshepherd mentioned, you are missing /usr/local/bin in PATH. git is working probably only because there is symlink in /bin. Try export PATH=$PATH:/usr/local/bin in emacs terminal. You can also check this out: https://stackoverflow.com/questions/8606954/path-and-exec-path-set-but-emacs-does-not-find-executable In the future, in case of similar ...


8

The "problem" is that with M-x shell (or M-x eshell btw), Emacs uses a very limited terminal emulator, so that TERM is correctly set to dumb Fancy pagers cannot operate under such limited constraints, which is why you have to use cat instead. Now, when you open an ssh connection from that shell, TERM is still dumb, but PAGER is reset to whatever the other ...


8

Like Tikhon mentioned, (start-process) is the way to go. In case you don't want to create a buffer but would still like to react to the background process status, you can also employ (set-process-sentinel). Here's a modified example I'm taking from my projector package: (set-process-sentinel (start-process "process-name" nil "command") #'output-message-...


8

This is an OSX annoying environment issue, the $PATH appearing in Emacs is coming from /etc/paths file, which then gets appended with whatever I've set in the shell. I added /Users/g/Library/Haskell/bin to the top of the /etc/paths file and it then worked fine. Going into shell and calling echo $PATH in Emacs shows now: /Users/g/Library/Haskell/bin:/usr/...


8

The canonical way of altering the display behaviour for a buffer is to customize display-buffer-alist: (setq display-buffer-alist '(("\\`\\*e?shell" display-buffer-pop-up-window))) (setq display-buffer-alist '(("\\`\\*e?shell" display-buffer-pop-up-frame))) It's a bit easier with my shackle package though: (setq shackle-rules '(("\\`\\*e?shell" :regexp t :...


8

save-window-excursion is a macro for running a piece of code without altering the window configuration. Something like this should work: (defun my-view-pdf () (interactive) (save-window-excursion (async-shell-command (concat "SumatraPDF " (file-name-base (buffer-file-name)) ".pdf"))))


8

If you just would like to spawn a process in the background you don't need all the bells an whistles that shell command functions provide. Instead, you can use the function call-process. For example: (call-process "a_command" nil 0 ; <- Discard and don't wait nil "arg1" "arg2") Concretely, this mean that you can ...


8

Interactively, C-u M-! (i.e., shell-command with the universal argument prefix) will prompt you for a shell command and insert the output in the current buffer. To do this from elisp code, see the comment from @lawlist org-mode also has fairly sophisticated methods of its own for evaluating code, including both inline code and code blocks. First, you need ...


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


7

Use display-buffer-alist with the display-buffer-no-window if you're on Emacs 24.4 or later. (setq display-buffer-alist '(("\\`\\*Async Shell Command\\*\\'" display-buffer-no-window))) Alternatively, use shackle: (setq shackle-rules '(("*Async Shell Command*" :ignore t)))


7

Did you successfully fix the problem? Sure! ob-shell was flipping out and you stopped loading it. That is, in some sense, a fix! That said: the chunk of code you found and commented out controls which languages are loaded by org babel, which is a pretty powerful function within org. If you've got any interest in using/evaluating shell code blocks, you'll ...


7

You need to change the option shell-file-name. (setenv "SHELL" "/bin/bash") This doesn't work since Emacs is already running thus it's too late, Emacs initializes shell-file-name according to SHELL during startup. Something like $ SHELL=/bin/bash emacs should work. (setq explicit-shell-file-name "/bin/bash") This is for M-x shell, not M-x shell-...


7

This is an ancient version of emacs that came preinstalled with macOS. To find out where the version of emacs that you installed is, start it by clicking on the icon and then evaluate (expand-file-name invocation-name invocation-directory). Then post that into a shell.


6

You can modify dired-after-readin-hook to send an appropriate command to your shell buffer. The following code creates a shell called dired-synced-shell if one doesn't already exist, and every time you change a directory in dired, runs a cd on the shell running in buffer dired-synced-shell. (add-hook 'dired-after-readin-hook (lambda() (...


6

As Gilles mentioned in the comment above, emacs does not read the local env settings unless specifically asked to. The easiest way to keep variables in shell terminals inside and outside Emacs is to use a package, such as the Steve Purcell's package exec-path-from-shell. Once installed, this package ensures each time you start a shell in emacs, it reads ...


6

You can run one-off commands using the magit-run-popup bound to !. For example, !!ls-files will run git ls-files in the top-level directory of the repo and output the results to the Magit process buffer for that repo. For writing your own commands, you can use one of Magit's functions for calling Git, picking the variant depending on the type of Git command ...


6

My Emacs (GNU Emacs 24.5.1) sets TERM=dumb in startup.el and my ls from GNU coreutils 8.24 checks TERM even with --color=always. dumb is not a terminal type recognized by dircolors (the utility used by ls to decide how to color the output), so running TERM=ansi ls --color=always in a *shell* buffer works as expected, while ls --color=always does not. So, I ...


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