Bad-ptr / persp-mode.el

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

Switching perspectives misbehaving when a window is dedicated #26

Closed bmag closed 8 years ago

bmag commented 8 years ago

Invoking persp-switch (C-c p s) from a dedicated window results in a wrong window configuration after perspective is switched. This seems to be a problem with calling window-state-put when the current window is a dedicated window, similar to https://github.com/wasamasa/eyebrowse/issues/36

For example, consider neotree. When I open neotree, neotree creates a dedicated window and selects it. If I then switch to a different perspective, then neotree's window remains visible and the original window configuration of the perspective is ruined. More details in the reproduction recipes.

Adding (set-window-dedicated-p nil nil) right after (delete-other-windows) here seems to fix the error described in recipe 2.


Recipe 1: creating a new perspective when current window is dedicated:

  1. start emacs: emacs -Q -l /path/to/persp-mode.el
  2. disable auto-resume: M-: (setq persp-auto-resume-time -1)
  3. activate persp-mode: M-x persp-mode
  4. switch to a new buffer: C-x b foo
  5. make window dedicated: M-: (set-window-dedicated-p nil t)
  6. switch to a new perspective: C-c p s bar

Observed result: new perspective is created, the frame has two windows: one for buffer foo and one for the scratch buffer.

Expected result: new perspective is created, the frame has one window: for the scratch buffer. The buffer foo is not visible.


Recipe 2: switching to an existing perspective when current window is dedicated:

  1. start emacs: emacs -Q -l /path/to/persp-mode.el
  2. disable auto-resume: M-: (setq persp-auto-resume-time -1)
  3. activate persp-mode: M-x persp-mode
  4. switch to a new perspective: C-c p s bar
  5. switch to a new buffer: C-c p s baz
  6. switch back to previous perspective: C-c p s none
  7. switch to a new buffer: C-x b foo
  8. make window dedicated: M-: (set-window-dedicated-p nil t)
  9. switch to the other perspective: C-c p s bar

Observed result: current perspective is now bar, but the displayed buffer remains foo. The echo area shows the message "Window is dedicated to foo'". In theMessagesbuffer: "window-state-put: Window is dedicated tofoo'"

Expected result: current perspective is now bar, the displayed buffer is baz.

Bad-ptr commented 8 years ago

uhu. Looks like we must store a per perspective dedicated window list, and undedicate/rededicate windows when switching.

bmag commented 8 years ago

Looks like we must store a per perspective dedicated window list, and undedicate/rededicate windows when switching.

Actually window-state-get and window-state-put do take care of saving and restoring the dedicated status, so unless I'm missing something that shouldn't be necessary.

The error in recipe 2 happens when window-state-put tries to change the buffer of a dedicated window. It's a bug in window-state-put that affects persp-mode. The bug is fixed in Emacs 25 and can be worked around in Emacs 24, details here.

Thanks for the quick reply.

Bad-ptr commented 8 years ago

Aha, OK. Thanks for the explanation.)

Bad-ptr commented 8 years ago

Should be fixed bf36bf8811a5b2a8f828e22ad387ed8368c94965

bmag commented 8 years ago

Thanks, but that fixes only the scenario described in recipe 2. Running the 1st recipe still gives me the same result. Do you get a different result on your machine?

Maybe I wasn't clear enough. There are two different scenarios that I reported in the original comment. The first is about creating a new perspective, and the second is about switching to an existing perspective. The latter is indeed fixed, the former is not.

Bad-ptr commented 8 years ago

Maybe I wasn't clear enough.

No, this is because of my laziness. Now it really should be fixed c6074ce3b61aca3e1ca1104ef5a751028357badf (i hope :p)

bmag commented 8 years ago

Yeah, that did it :smile: