5

I want to open Emacs full-screen, with two windows split vertically. I want my todo.org file to open on the left and my agenda view to open on the right.

Something like this appears in a couple of other questions on this site, but they are not quite the same and/or I haven't been able to use/understand their answers to completely solve my challenge.

I have gotten very close with the following in my custom-init.el file:

;; Windows layout setup
(add-to-list 'default-frame-alist '(fullscreen . maximized))
(split-window-right)
(setq initial-buffer-choice "~/emacs/Org/todo.org")
(setq org-agenda-window-setup 'current-window)
(add-hook 'after-init-hook (lambda () (org-agenda nil "u")))
(add-hook 'after-init-hook (lambda () (org-agenda-list 1)))

This formats the screen correctly with the window locations and size showing as I want them. It also opens my todo file and places it on the left as I wanted, BUT I have the scratch buffer open on the right. The Agenda is created and formatted correctly and is the third item in the buffers list (scratch, todo.org, Agenda, then all the other org files I am opening on start-up.)

So close, but after several days of thinking and trying different things, I'm just not getting there.

Stefan
  • 27,908
  • 4
  • 53
  • 82
OldEnough
  • 117
  • 9
  • Further experimenting shows me that "(add-hook 'after-init-hook '(lambda () (org-agenda-list 1)))" appears to have no impact in the current version of my attempts and can be deleted without changing the results. – OldEnough Oct 26 '19 at 18:17

1 Answers1

6

Adding a hook to window-setup-hook should get the desired effect - taking into account your frame customizations.

(add-to-list 'default-frame-alist '(fullscreen . maximized))
(setq initial-buffer-choice "~/emacs/org/todo.org")

(defun my-init-hook ()
  (split-window-right)
  (let ((org-agenda-window-setup 'other-window))
    (org-agenda nil "a")))

(add-hook 'window-setup-hook #'my-init-hook)
Rorschach
  • 31,301
  • 5
  • 78
  • 129
  • That gives me 3 windows. One at the top that runs the full width which displays the Agenda view, and two windows split vertically below the Agenda, both of which have the todo.org file displayed. If I move the (split-window-right) up and outside of the function I get two windows, split horizontally (No idea why it does that. The code clearly says "right".) The top window shows the agenda view, and the bottom window displays the todo file. – OldEnough Oct 26 '19 at 19:40
  • If I run `emacs -Q -l ` where this code is exactly what I have above, I get a maximized window with 2 splits, org on left, agenda on right. My guess is there is either more relevant parts in your init, or perhaps this is an OS difference -- I'm on debian, but I remember long ago when I used windows that there were some startup differences, eg. with maximizing windows – Rorschach Oct 26 '19 at 20:12
  • I do use Windows 10, so perhaps that is the explanation. The code we are discussing appears very close to the top of the init file; right after all of the initialization required for packages and access to package libraries (melpa, etc). There are two other functions bound to keys that allow some windows manipulation. I did, just now, comment those out with no change in the results. – OldEnough Oct 26 '19 at 20:31
  • to truly test the code, you should run with emacs -Q. The actual position of the code in the file shouldn't matter here since `my-init-hook` runs after the code in the init (unless perhaps there are more additions to `window-setup-hook` -- best just to run with -Q to avoid the undeterminism). If you run `split-window-right` outside the hook, it is probably happening before the frame is setup which likely leads to the unexpected results you saw – Rorschach Oct 26 '19 at 20:36
  • Running just your code does work. Now I "just" need to figure out what is interfering with it's successful integration with the rest of the custom init file. – OldEnough Oct 27 '19 at 07:09
  • 1
    This comment chain is becoming quite long, but I don't know an alternative. The problem turned out to be a line in the init file that used org-agenda-list. The issue has been discussed in [Emacs org-agenda-list destroy my windows splits](https://stackoverflow.com/questions/10635989/emacs-org-agenda-list-destroy-my-windows-splits) – OldEnough Oct 28 '19 at 19:16