pashinin / workgroups2

Workgroups2 - Emacs session manager
http://workgroups2.rtfd.org/
GNU General Public License v3.0
297 stars 43 forks source link

Split buffer with same file doesn't maintain both positions #114

Open chipschap opened 2 years ago

chipschap commented 2 years ago

Using workgroups2 from Melpa, Arch Linux, Emacs 27.2, with helm and save-place-mode.

My use case: the same file split into 2 windows, each window at a different position in the file. Save to a workgroup and next time around in Emacs, restore.

The file in question opens in 2 windows as expected but both windows are at the same file position rather than different positions as desired. The windows are in fact open at the save-place-mode saved position, not the workgroups saved position(s).

The cause appears to be that wg-restore-buffer is forced to return nil. This prevents point from being restored up in wg-restore-window. When I change 'nil' to 't' at the bottom of wg-restore-buffer, point is restored (to the two different places) as expected in my split window. (I don't see how point is ever restored at all, in fact, although I'm probably missing something.)

However forcing 't' is crude. The problem is in the 'when' clauses for debugging. A possible rewrite is this:

(defun wg-restore-buffer (buf &optional switch) "Restore BUF, return it and maybe SWITCH to it." (when buf (fset 'buffer-list wg-buffer-list-original) (cond ((wg-restore-existing-buffer buf switch)) ((wg-restore-special-buffer buf switch)) ((wg-restore-file-buffer buf switch)) (t (wg-restore-default-buffer switch)))))

This works fine for me but I'm not familiar enough with workspace2 code to see if there are unintended consequences.

redguardtoo commented 2 years ago

b4fb228 can restore marker position (Chen Bin)

chipschap commented 2 years ago

Thank you, a much nicer patch than mine!