It's possible to start emacs with an eshell buffer focused using the -f flag as described in this question.

> emacs -nw -f "eshell"

I'm wondering if there's a way of launching eshell and focusing its buffer using just the .emacs file.

Using the following files, I've been able to start eshell automatically, but not to shift focus to its corresponding buffer, named *eshell* by default.

; .emacs.d/init.el


; .emacs.d/init.el
(switch-to-buffer "*eshell*)

Is there a way to switch focus to the eshell buffer from the .emacs file without using a command line argument?


A major obstacle is that startup.el is hard-coded into the Emacs executable and that file does some buffer switching that varies depending upon certain things. People also load things like restoring the prior desktop using desktop.el, which uses the after-init-hook and does some buffer switching. There are probably a lot of other popular startup options and libraries that do some buffer switching. The last hook to load is the emacs-startup-hook, so the O.P. may wish to use something like this:

(add-hook 'emacs-startup-hook 'eshell)
  • I shortened the example to eliminate switch-to-buffer because eshell contains pop-to-buffer-same-window. – lawlist Jul 15 '18 at 19:17
  • Do commands like eshell normally contain pop-to-buffer-same-window calls? It might be worth having the more verbose/explicit version as an option in case someone wants to try this with not-eshell. – Gregory Nisbet Jul 15 '18 at 19:28
  • The authors of the various Emacs libraries make decisions regarding how/where to display a particular buffer. There is no rule of thumb. The most common approach is to use the display-buffer-alist to control how certain buffers are displayed. There are also libraries that assist users to control how buffers are displayed. I personally prefer the create/locate approach and then I display buffers however/wherever I want. Here are two examples of how I do it: emacs.stackexchange.com/a/28730/2287 and emacs.stackexchange.com/a/28924/2287 . – lawlist Jul 15 '18 at 19:37

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.