OldEnough
OldEnough

Reputation: 125

Start Emacs with org file on left and agenda on right

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.

Upvotes: 5

Views: 2115

Answers (1)

Rorschach
Rorschach

Reputation: 32446

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)

Upvotes: 6

Related Questions