2

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 Aug 25 '16 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. – lawlist Aug 25 '16 at 13:40
2

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 RET term ? – Chakravarthy Raghunandan Nov 21 '16 at 13:27
  • It opens the native Mac Terminal program in a separate window. – John Kitchin Nov 23 '16 at 0:25
1

M-x eshell works. If you have helm M-x will show a list of possible completions when you start typing.

  • 2
    What's the link between helm and eshell? – JeanPierre Sep 20 '16 at 14:56
1

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.