3

I tried adding this snippet to my ~/.emacs, but the resulting buffer/window mapping is weird.

;; Open split shell on launch
(add-hook 'after-init-hook
  (lambda ()
    (let ((w (split-window-below 2)))
      (select-window w)
      (sh))
      (switch-to-buffer "*shell*")))

Example:

$ emacs .

Expected:

  • top window is dired
  • bottom window is shell

Observed:

  • top window is scratch
  • bottom window is dired
  • My suggestion would be to make a new function to create a noselect shell buffer that is not displayed in any particular window, and then display it wherever you want using something like my-display-buffer: emacs.stackexchange.com/a/19858/2287 To locate the shell buffer function, just type: M-x find-function RET shell RET The pop-to-buffer is what is causing your difficulties, similar to what the poster suffered from in the above-mentioned link. If the area of code that follows pop-to-buffer requires that the *shell* buffer be set, consider using with-current-buffer. – lawlist Feb 2 '16 at 6:42
  • 1
    You may also wish to look at the emacs-startup-hook to let Emacs startup.el finish its nonsense, and then you can go about your business. Trying to go about your business before the nonsense ends will eventually make you learn how to create your own custom startup.el when building Emacs. :) – lawlist Feb 2 '16 at 9:13
2

Thanks to @lawlist:

;; Open split shell on launch
(add-hook 'emacs-startup-hook
  (lambda ()
    (let ((w (split-window-below 2)))
      (select-window w)
      (sh))
      (switch-to-buffer "*shell*")))
  • for some reason, it opens 3 buffers (identical) of either the 'scratch' or of the file initially focused upon. – Vass Oct 13 '18 at 16:02
  • changing line 4 to 'split-window-below 1' helped. – Vass Oct 13 '18 at 16:08

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.