Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting in org-agenda view doesn't work with persp-mode enabled #91

Open
rieje opened this issue May 19, 2018 · 6 comments
Open

Starting in org-agenda view doesn't work with persp-mode enabled #91

rieje opened this issue May 19, 2018 · 6 comments

Comments

@rieje
Copy link

rieje commented May 19, 2018

I have a simple function that starts Emacs with 2 windows split vertically--a todo.org buffer on the left and an org-agenda view on the right:

(defun my-todo-buffers ()
(interactive)
(setq initial-buffer-choice nil)
(find-file "~/notes/todo.org")
(split-window-horizontally)
(org-agenda-list))

I launch it by launching Emacs through emacs -f my-todo-buffers and it works fine when persp-mode is not enabled. However, if persp-mode is enabled, then for some reason not only does both the todo.org buffer and the org agenda view buffer not show up, but a specific org file gets shown instead. That specific org file is not mentioned in any of my settings but it's a file for my org-agenda-files.

How can I have an org agenda view buffer shown on Emacs launch with persp-mode enabled?

Any help is much appreciated--I really depend on persp-mode.

Thanks.

@Bad-ptr
Copy link
Owner

Bad-ptr commented May 26, 2018

Try to run your code in persp-after-load-state-functions(maybe it will require to run with delay(using timer) to work properly) :

(with-eval-after-load "persp-mode"
(defun persp-restore-org-agenda-after-init (file phash &rest _args)
  (when (and (eq phash *persp-hash*)
             (string= file (concat (or (file-name-directory file)
                                       (expand-file-name persp-save-dir))
                                   (file-name-nondirectory file))))
    (my-todo-buffers)
    (remove-hook 'persp-after-load-state-functions
                 #'persp-restore-org-agenda-after-init)))

(add-hook 'persp-after-load-state-functions
          #'persp-restore-org-agenda-after-init))

@rieje
Copy link
Author

rieje commented May 27, 2018

By using a timer for delay, did you mean specifically using sleep-for like (sleep-for 4)`? It doesn't work without it, but I'm hoping there might be a better method to sleep that doesn't freeze Emacs for 4 seconds on startup every time. Even better, would it be possible to not sleep an arbitrary amount of time and instead check and wait for a certain thing to complete instead?

Thanks.

@Bad-ptr
Copy link
Owner

Bad-ptr commented Jun 4, 2018

By using a timer for delay, did you mean specifically using sleep-for

I mean run-at-time:

(run-at-time seconds nil #'(lambda () (your-code-here)))

I did a mistake in the code in my previous post, now it's fixed. Actually you can wrap this code in a function and call it like emacs -f function-with-persp-mode-settings-for-org-agenda.

Alternatively you can manually check the commandline arguments:

(let ((org-agenda (member "-org-agenda" command-line-args)))
        (when org-agenda
         (setq command-line-args (remove "-org-agenda" command-line-args))
	 (add-hook 'persp....)))

@rieje
Copy link
Author

rieje commented Jun 5, 2018

I think I found the problem, it's described here. (Edit: Someone was able to reproduce what I'm experiencing and has a guess on what might be the issue). Also, further information here.

So is there a viable solution? I tried your code and it doesn't seem to do anything.

@rieje
Copy link
Author

rieje commented Jun 13, 2018

Solution posted here.

@rieje rieje closed this as completed Jun 13, 2018
@rieje rieje reopened this Jun 13, 2018
@rieje
Copy link
Author

rieje commented Jun 13, 2018

Actually, I'll leave it open for you to decide whether it's worth closing. The original problem is dealt with, but the underlying issue of org-agenda-files which apparently visits each org agenda file alphabetically so the last file becomes the focused window after a previous perspective is restored is most likely undesirable. I think there should be a way for persp-mode to deal with this, as it's not a behavior people would expect using org-agenda-files and persp-mode.

As you can tell, it took a while to figure out what's the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants