Skip to content

Commit

Permalink
Merge pull request #14 from syohex/improve-window-history
Browse files Browse the repository at this point in the history
Improve window history management
  • Loading branch information
knu committed Oct 26, 2015
2 parents e918ae9 + ee1fd7e commit 249653a
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions elscreen.el
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,32 @@ Return the modified ALIST."
(delq pair alist)
alist)))

(defun elscreen-window-history-supported-p ()
(and (fboundp 'window-prev-buffers)
(fboundp 'window-next-buffers)
(fboundp 'set-window-prev-buffers)
(fboundp 'set-window-next-buffers)))

(defun elscreen-get-all-window-history-alist ()
(when (elscreen-window-history-supported-p)
(mapcar (lambda (window)
(let ((prevs (window-prev-buffers window))
(nexts (window-next-buffers window)))
(cons window (cons prevs nexts))))
(window-list))))

(defun elscreen-restore-all-window-history-alist (history-alist)
(when (elscreen-window-history-supported-p)
(mapc (lambda (entry)
(let* ((window (car entry))
(histories (cdr entry))
(prevs (car histories))
(nexts (cdr histories)))
(when (window-valid-p window)
(set-window-prev-buffers window prevs)
(set-window-next-buffers window nexts))))
history-alist)))

(defun elscreen--remove-alist (symbol key)
"Delete an element whose car equals KEY from the alist bound to SYMBOL."
(and (boundp symbol)
Expand Down Expand Up @@ -374,7 +400,8 @@ Return the value of the last form in BODY."
(original-buffer-live-p nil)
(original-elscreen-window-configuration
(elscreen-current-window-configuration))
(original-frame-confs (elscreen-copy-tree elscreen-frame-confs)))
(original-frame-confs (elscreen-copy-tree elscreen-frame-confs))
(original-window-histories (elscreen-get-all-window-history-alist)))
(unwind-protect
(save-window-excursion ,@body)
(setq elscreen-frame-confs original-frame-confs)
Expand All @@ -388,7 +415,8 @@ Return the value of the last form in BODY."
original-buffer-list)
(when original-buffer-live-p
(while (not (memq (car (buffer-list)) original-buffer-list))
(bury-buffer (car (buffer-list))))))))
(bury-buffer (car (buffer-list)))))
(elscreen-restore-all-window-history-alist original-window-histories))))

(defsubst elscreen-get-frame-confs (frame)
(assoc-default frame elscreen-frame-confs))
Expand Down

0 comments on commit 249653a

Please sign in to comment.