2

I want to ask something regarding making my own custom layout for spacemacs. I have read the documentation. They have an example like this:

This is the custom layout for ERC buffers.

(spacemacs|define-custom-layout "@ERC"
  :binding "E"
  :body
  (progn
    ;; hook to add all ERC buffers to the layout
    (defun spacemacs-layouts/add-erc-buffer-to-persp ()
      (persp-add-buffer (current-buffer)
                        (persp-get-by-name
                        erc-spacemacs-layout-name)))
    (add-hook 'erc-mode-hook #'spacemacs-layouts/add-erc-buffer-to-persp)
    ;; Start ERC
    (call-interactively 'erc)))

Since I am still beginner is Emacs Lisp, I don't really know what is happening here.

Let say I have four files in my home directory:

  1. ~/file1.org
  2. ~/file2.org
  3. ~/file3.org
  4. ~/file4.org

I want them automatically to be opened like this in my spacemacs:

|-----------+-----------|
| file1.org | file2.org |
|           |           |
|           |           |
|-----------+-----------|
| file3.org | file4.org |
|           |           |
|           |           |
|-----------+-----------|

Can anyone show me how can I achieve this (I am hoping that it comes with explanation since I am trying to learn through implementation)? Or at least can anyone tell me some keywords or Elisp functions that I can try to google on?

If it helps, I do regularly program in Python. So, a quite simple explanation is maybe enough for me.

3

You can easily save and load layouts in spacemacs:

  • create your layout with SPC l l
  • split and open the files you need, resize to taste etc.
  • press SPC l s. Choose a name for your layout and confirm

Next time you open spacemacs just press SPC l L and choose your layout.

1

I've created a few custom layout similar to this:

(spacemacs|define-custom-layout "My Python Layout"
  :binding "p"
  :body
  (find-file "*path to upper left file*")
  (split-window-right) ;; Create the right side but don't move focus
  (split-window-below-and-focus) ;; Split the left side into two and move focus
  (find-file "*path to lower left file*")
  (winum-select-window-3) ;; Go to the top right window
  (find-file "*path to upper right file*")
  (split-window-below-and-focus) ;; Split the right side into two and move focus
  (find-file "*path to lower right file*")
  (winum-select-window-1) ;; Move focus back to the first window (optional)
)

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.