From 2addf9226a04194010742975a2203e53aa8d7c79 Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Mon, 1 Jul 2013 05:29:46 +0200 Subject: [PATCH] lisp/desktop.el: More fixes to frame restoration. (desktop-restore-frames): Rename from desktop-save-windows. (desktop-restore-in-current-display): New customization option. (desktop--excluded-frame-parameters): Add `font'. (desktop--save-frames): Rename from desktop--save-windows. (desktop--restore-in-this-display-p): New function. (desktop--make-full-frame): Remove unwanted width/height from full(width|height) frames. (desktop--restore-frames): Rename from desktop--restore-windows. Obey desktop-restore-current-display. Do not delete old frames or select a new frame unless we were able to restore at least one frame. --- etc/NEWS | 2 +- lisp/ChangeLog | 13 +++++++++++++ lisp/desktop.el | 60 +++++++++++++++++++++++++++++++++++++-------------------- 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 3a8ef2314a8..f83d82417dd 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -252,7 +252,7 @@ on the given date. *** `desktop-auto-save-timeout' defines the number of seconds between auto-saves of the desktop. -*** `desktop-save-windows' enables saving and restoring the window/frame +*** `desktop-restore-frames enables saving and restoring the window/frame configuration. ** Dired diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2a8649006dc..b27eb32246f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,16 @@ +2013-07-01 Juanma Barranquero + + * desktop.el (desktop-restore-frames): Rename from desktop-save-windows. + (desktop-restore-in-current-display): New customization option. + (desktop--excluded-frame-parameters): Add `font'. + (desktop--save-frames): Rename from desktop--save-windows. + (desktop--restore-in-this-display-p): New function. + (desktop--make-full-frame): Remove unwanted width/height from + full(width|height) frames. + (desktop--restore-frames): Rename from desktop--restore-windows. + Obey desktop-restore-current-display. Do not delete old frames or + select a new frame unless we were able to restore at least one frame. + 2013-06-30 Michal Nazarewicz * files.el (find-file-noselect): Simplify conditional expression. diff --git a/lisp/desktop.el b/lisp/desktop.el index 7d4ea20c210..2f4c2a8589c 100644 --- a/lisp/desktop.el +++ b/lisp/desktop.el @@ -371,12 +371,19 @@ modes are restored automatically; they should not be listed here." :type '(repeat symbol) :group 'desktop) -(defcustom desktop-save-windows nil +(defcustom desktop-restore-frames nil "When non-nil, save window/frame configuration to desktop file." :type 'boolean :group 'desktop :version "24.4") +(defcustom desktop-restore-in-current-display nil + "When non-nil, frames are restored in the current display. +Otherwise they are restored, if possible, in their original displays." + :type 'boolean + :group 'desktop + :version "24.4") + (defcustom desktop-file-name-format 'absolute "Format in which desktop file names should be saved. Possible values are: @@ -872,6 +879,7 @@ DIRNAME must be the directory in which the desktop file will be saved." buffer-predicate buried-buffer-list explicit-name + font font-backend minibuffer name @@ -891,12 +899,12 @@ Internal use only." (push param params))) params)) -(defun desktop--save-windows () +(defun desktop--save-frames () "Save window/frame state, as a global variable. Intended to be called from `desktop-save'. Internal use only." (setq desktop--saved-states - (and desktop-save-windows + (and desktop-restore-frames (mapcar (lambda (frame) (cons (desktop--filter-frame-parms frame) (window-state-get (frame-root-window frame) t))) @@ -944,7 +952,7 @@ and don't save the buffer if they are the same." (insert "\n;; Global section:\n") ;; Called here because we save the window/frame state as a global ;; variable for compatibility with previous Emacsen. - (desktop--save-windows) + (desktop--save-frames) (mapc (function desktop-outvar) desktop-globals-to-save) (when (memq 'kill-ring desktop-globals-to-save) (insert @@ -1003,6 +1011,10 @@ This function also sets `desktop-dirname' to nil." (defvar desktop-lazy-timer nil) ;; ---------------------------------------------------------------------------- +(defun desktop--restore-in-this-display-p () + (or desktop-restore-in-current-display + (and (eq system-type 'windows-nt) (not (display-graphic-p))))) + (defun desktop--find-frame-in-display (frames display) (let (result) (while (and frames (not result)) @@ -1017,47 +1029,53 @@ This function also sets `desktop-dirname' to nil." (params '((visibility))) frame) (when width - (setq params (append `((user-size . t) (width . ,width)) params))) + (setq params (append `((user-size . t) (width . ,width)) params) + config (assq-delete-all 'height config))) (when height - (setq params (append `((user-size . t) (height . ,height)) params))) + (setq params (append `((user-size . t) (height . ,height)) params) + config (assq-delete-all 'width config))) (setq frame (make-frame-on-display display params)) (modify-frame-parameters frame config) frame)) -(defun desktop--restore-windows () +(defun desktop--restore-frames () "Restore window/frame configuration. Internal use only." - (when (and desktop-save-windows desktop--saved-states) + (when (and desktop-restore-frames desktop--saved-states) (let ((frames (frame-list)) + (current (frame-parameter nil 'display)) (selected nil)) (dolist (state desktop--saved-states) (condition-case err - (let* ((fconfig (car state)) - (display (cdr (assq 'display fconfig))) - (full (cdr (assq 'fullscreen fconfig))) + (let* ((config (car state)) + (display (if (desktop--restore-in-this-display-p) + (setcdr (assq 'display config) current) + (cdr (assq 'display config)))) + (full (cdr (assq 'fullscreen config))) (frame (and (not full) (desktop--find-frame-in-display frames display)))) (cond (full ;; treat fullscreen/maximized frames specially - (setq frame (desktop--make-full-frame full display fconfig))) + (setq frame (desktop--make-full-frame full display config))) (frame ;; found a frame in the right display -- reuse (setq frames (delq frame frames)) - (modify-frame-parameters frame fconfig)) + (modify-frame-parameters frame config)) (t ;; no frames in the display -- make a new one - (setq frame (make-frame-on-display display fconfig)))) + (setq frame (make-frame-on-display display config)))) ;; restore windows (window-state-put (cdr state) (frame-root-window frame) 'safe) (unless selected (setq selected frame))) (error (message "Error restoring frame: %S" (error-message-string err))))) - ;; make sure the original selected frame is visible and selected - (unless (or (frame-parameter selected 'visibility) (daemonp)) - (modify-frame-parameters selected '((visibility . t)))) - (select-frame-set-input-focus selected) - ;; delete any remaining frames - (mapc #'delete-frame frames)))) + (when selected + ;; make sure the original selected frame is visible and selected + (unless (or (frame-parameter selected 'visibility) (daemonp)) + (modify-frame-parameters selected '((visibility . t)))) + (select-frame-set-input-focus selected) + ;; delete any remaining frames + (mapc #'delete-frame frames))))) ;;;###autoload (defun desktop-read (&optional dirname) @@ -1127,7 +1145,7 @@ Using it may cause conflicts. Use it anyway? " owner))))) (switch-to-buffer (car (buffer-list))) (run-hooks 'desktop-delay-hook) (setq desktop-delay-hook nil) - (desktop--restore-windows) + (desktop--restore-frames) (run-hooks 'desktop-after-read-hook) (message "Desktop: %d buffer%s restored%s%s." desktop-buffer-ok-count -- 2.11.4.GIT