I'm very new to emacs and am currently using it to edit files on mac os x. How do I open instances of the shell from inside emacs so that I can execute the code I'm working on?
-
Welcome to Emacs.SE! Please have a look at this search for "emacs shell" for links to the manual and tutorials on using a shell within Emacs.– Dan ♦Commented Aug 25, 2016 at 12:30
-
Press the escape key, then press the letter x, then type the word shell, then press the return key. Try that out and see if you like it. Then, instead of typing the word shell, you can type the word eshell in the above example. Then instead of typing the words shell or eshell, you can type the word term in the above example. None are as good as Terminal.app, but you can do most things inside of Emacs once you learn a few tricks like configuring the $PATH variable to your liking.– lawlistCommented Aug 25, 2016 at 13:40
3 Answers
I wrote this terminal command to open a terminal in the current working directory:
(defun terminal ()
(interactive)
(shell-command
(format "open -b com.apple.terminal \"%s\""
(if (buffer-file-name)
(file-name-directory (buffer-file-name))
(expand-file-name default-directory)))))
its not an emacs shell, but it is convenient for me.
-
what's the difference between this and
M-x
RETterm
? Commented Nov 21, 2016 at 13:27 -
It opens the native Mac Terminal program in a separate window. Commented Nov 23, 2016 at 0:25
M-x eshell
works. If you have helm M-x will show a list of possible completions when you start typing.
-
2
This is a really nice overview of various shell options in emacs. Which shell you use depends on what you need. Sane term is a nice basic terminal emulator. You can also look at the various settings I use if you like. I tend to use eshell for most things, but occasionally use sane term for more computation heavy tasks.
And here is another way to call a terminal, if you use iterm (which you should) on OS X.
(defun open-dir-in-iterm ()
"Open the current directory of the buffer in iTerm."
(interactive)
(let* ((iterm-app-path "/Applications/iTerm.app")
(iterm-brew-path "/opt/homebrew-cask/Caskroom/iterm2/2.1.4/iTerm.app")
(iterm-path (if (file-directory-p iterm-app-path)
iterm-app-path
iterm-brew-path)))
(shell-command (concat "open -a " iterm-path " ."))))
(global-set-key (kbd "C-x t") 'open-dir-in-iterm)