Skip to content

Commit

Permalink
Prevent propagation of window parameters when switching perspectives (#…
Browse files Browse the repository at this point in the history
…75)

`current-window-configuration` and `set-current-window-configuration` do not
care about window parameters so ensure that they are not in any of the windows
when creating new perspectives.

This is important because certain commands like `delete-other-windows` and
`split-window` take into account window parameters like `window-side` that
may inhibit these commands. We may want this behavior on the current
perspective, but not in any windows on the new perspective.
  • Loading branch information
Nathaniel Nicandro authored and nex3 committed Nov 1, 2018
1 parent 874aa41 commit 1358ba2
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions perspective.el
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,29 @@ REQUIRE-MATCH can take the same values as in `completing-read'."
(when ,old (persp-switch ,old)))
(set-frame-parameter nil 'persp--last last-persp-cache)))))

(defun persp-reset-windows ()
"Remove all windows, ensure the remaining one has no window parameters.
This prevents the propagation of reserved window parameters like
window-side creating perspectives."
(let ((ignore-window-parameters t))
(delete-other-windows)
(when (ignore-errors
;; Create a fresh window without any window parameters, the
;; selected window is still in a window that may have window
;; parameters we don't want.
(split-window))
;; Delete the selected window so that the only window left has no window
;; parameters.
(delete-window))))

(defun persp-new (name)
"Return a new perspective with name NAME.
The new perspective will start with only an `initial-major-mode'
buffer called \"*scratch* (NAME)\"."
(make-persp :name name
(switch-to-buffer (concat "*scratch* (" name ")"))
(funcall initial-major-mode)
(delete-other-windows)))
(persp-reset-windows)))

(defun persp-reactivate-buffers (buffers)
"Raise BUFFERS to the top of the most-recently-selected list.
Expand Down Expand Up @@ -459,6 +474,7 @@ perspective's local variables are set."
(check-persp persp)
(persp-save)
(set-frame-parameter nil 'persp--curr persp)
(persp-reset-windows)
(persp-set-local-variables (persp-local-variables persp))
(persp-reactivate-buffers (persp-buffers persp))
(setq buffer-name-history (persp-buffer-history persp))
Expand Down Expand Up @@ -698,10 +714,10 @@ is non-nil or with prefix arg, don't switch to the new perspective."
(if (null buffers)
(persp-error "Perspective `%s' doesn't exist in another frame" name))
(setq persp (make-persp :name name :buffers buffers
(switch-to-buffer (cl-loop for buffer in buffers
if (buffer-live-p buffer)
return buffer))
(delete-other-windows)))
(switch-to-buffer (cl-loop for buffer in buffers
if (buffer-live-p buffer)
return buffer))
(persp-reset-windows)))
(if dont-switch
(persp-update-modestring)
(persp-activate persp))))
Expand Down

0 comments on commit 1358ba2

Please sign in to comment.