Bad-ptr / persp-mode.el

named perspectives(set of buffers/window configs) for emacs
400 stars 44 forks source link

New terminal frame flashes other frame's buffer before opening specified buffer #64

Closed aaronjensen closed 7 years ago

aaronjensen commented 7 years ago

When using emacs in client/server mode, if I have one client frame with a single window visiting file A, when I run emacsclient --tty B from the terminal, a new frame will open, I will briefly see A flash in emacs before it loads B.

Bad-ptr commented 7 years ago

This happens because there is no way(or I don't know any) to distinguish the creation of a frame with a file argument and without a file argument. When you create a frame by emacsclient --tty B it will first fire the before/after-make-frame-hook/functions by which persp-mode will restore a window configuration for the frame and only then it will come to the server-switch-hook. Only in the server-switch-hook persp-mode can see that you created the frame with intention to edit some other files and so it will show them. Hm... actually I think that for now it shows only the first file and others stay in background which is not good but I don't know how to do it better.

aaronjensen commented 7 years ago

Which window configuration is it restoring? Can I configure persp-mode to not restore configurations for anything but my first frame? To be honest, I don't really understand what persp-mode is doing, I have auto resume layouts turned off, so it doesn't actually resume layouts when I start emacs, so I'm not sure what/why it is restoring anything in a new frame.

Bad-ptr commented 7 years ago

Can I configure persp-mode to not restore configurations for anything but my first frame?

Yes, I believe you can. See persp-init-frame-behaviour, persp-init-new-frame-behaviour-override, persp-interactive-init-frame-behaviour-override, persp-emacsclient-init-frame-behaviour-override, persp-server-switch-behaviour variables.

To be honest, I don't really understand what persp-mode is doing, I have auto resume layouts turned off, so it doesn't actually resume layouts when I start emacs, so I'm not sure what/why it is restoring anything in a new frame.

Then why don't you just M-x package-delete RET persp-mode RET or just switch persp-mode off then? Anyway you can remove persp-mode functions from emacs hooks:

    (remove-hook 'find-file-hook               #'persp-add-or-not-on-find-file)
    (remove-hook 'kill-buffer-query-functions  #'persp-kill-buffer-query-function)
    (remove-hook 'kill-buffer-hook             #'persp-kill-buffer-h)
    (remove-hook 'before-make-frame-hook       #'persp-before-make-frame)
    (remove-hook 'after-make-frame-functions   #'persp-init-new-frame)
    (remove-hook 'delete-frame-functions       #'persp-delete-frame)
    (remove-hook 'kill-emacs-query-functions   #'persp-kill-emacs-query-function)
    (remove-hook 'kill-emacs-hook              #'persp-kill-emacs-h)
    (remove-hook 'server-switch-hook           #'persp-server-switch)
    (remove-hook 'after-change-major-mode-hook #'persp-after-change-major-mode-h)
aaronjensen commented 7 years ago

Ok, I'll take a look at those variables, thank you.

I use spacemacs, which uses persp-mode to manage its layouts, which I do use (and appreciate) extensively.

Bad-ptr commented 7 years ago

May be this is related https://github.com/Bad-ptr/persp-mode.el/issues/36

aaronjensen commented 7 years ago

Awesome, thanks, (setq persp-emacsclient-init-frame-behaviour-override nil) did the trick for me.