5

I want such functionality from emacs (gnu 25), I press key in any buffer with source code, and instead of one buffer I got 3 buffers on the screen:

source code buffer
------------------
*eshell* | *compilation*

*eshell* should be created if not exists, and if no *compilation* buffer around, should *scratch* be shown, but should be replaced with *compilation* after first compilation.

I read about sessions, but as I understand it was not I want. I want this windows split for any source code buffers, not for specific, that I save in session and restore from session.

How can I achieve, any known extension/package with such functionality?

3
  • @Dan I read about sessions, persp-mode.el and perspective-el. But all of them (according to documentation) are not what I want. They deal with existing buffers, and before get functionality that I want, you have to add buffers to session/perspective. While I want this functionality for any buffers. Commented Jul 25, 2017 at 0:43
  • Do you want a dedicated *eshell* session for each source file, or just one global one? (or one per folder, or one per "project", or ....?)
    – deprecated
    Commented Jul 27, 2017 at 3:01
  • @deprecated Global one *eshell* and global one *compilation* Commented Jul 27, 2017 at 7:00

1 Answer 1

4
+50

Here is a bare-bones minimum viable function, which I hope does what you want.

(defun wjh3pane-create-3pane-layout ()
  "Create 3-pane layout of windows in the current frame.

Layout is as follows:

    |--------------------------------------|
    |          source code buffer          |
    |          source code buffer          |
    |          source code buffer          |
    |--------------------------------------|
    |     *eshell*     |   *compilation*   |
    |--------------------------------------|

The height of the bottom windows can be changed by customizing
the `compilation-window-height' variable.  The function does
nothing if selected buffer is not visiting a file.
"
  (interactive)
  (when (buffer-file-name)
    (delete-other-windows)
    (save-selected-window
      (split-window-vertically (- (or compilation-window-height 10)))
      (select-window (next-window) t)
      (switch-to-buffer (eshell))
      (split-window-horizontally)
      (select-window (next-window) t)
      (switch-to-buffer (or (get-buffer "*compilation*")
                            (get-buffer "*scratch*"))))))

(global-set-key (kbd "s-3") 'wjh3pane-create-3pane-layout)

I have bound it to "Super 3" (I have super mapped to the caps lock key), but you can adjust that to taste. As it stands, you need to invoke the function manually, before or after calling compile. That could be automated with a bit more effort, for example, using advice. (I tried using a compilation hook, but that looked like it would be tricky). Also, it currently does nothing to save/restore the previous window configuration.

1
  • great, thanks a lot, I will try it in the next hours. Commented Jul 27, 2017 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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