From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juanma Barranquero Newsgroups: gmane.emacs.devel Subject: Re: How to restore the layout? Date: Thu, 27 Jun 2013 01:05:53 +0200 Message-ID: References: <51C5AA68.4000204@alice.it> <83ehbrju1d.fsf@gnu.org> <87r4frcq9v.fsf@rosalinde.fritz.box> <87vc5345t3.fsf@gmail.com> <51C8B2C8.4000803@gmx.at> <51C93CDB.2020301@gmx.at> <51C9C790.3020407@gmx.at> <51CA0D4C.7080204@alice.it> <0A6F5672-6149-41B7-B0FF-D4725076B271@mit.edu> <51CB3299.50004@gmx.at> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=047d7b5dbe6864671204e016b2cd X-Trace: ger.gmane.org 1372288001 18247 80.91.229.3 (26 Jun 2013 23:06:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 26 Jun 2013 23:06:41 +0000 (UTC) Cc: chad , Drew Adams , Emacs developers To: martin rudalics Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 27 01:06:41 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UrynR-000306-05 for ged-emacs-devel@m.gmane.org; Thu, 27 Jun 2013 01:06:41 +0200 Original-Received: from localhost ([::1]:42344 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrynQ-0005mW-Hl for ged-emacs-devel@m.gmane.org; Wed, 26 Jun 2013 19:06:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrynM-0005mG-Vf for emacs-devel@gnu.org; Wed, 26 Jun 2013 19:06:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UrynL-0006mu-FE for emacs-devel@gnu.org; Wed, 26 Jun 2013 19:06:36 -0400 Original-Received: from mail-ee0-x232.google.com ([2a00:1450:4013:c00::232]:60179) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrynL-0006ma-4v for emacs-devel@gnu.org; Wed, 26 Jun 2013 19:06:35 -0400 Original-Received: by mail-ee0-f50.google.com with SMTP id d49so23392eek.23 for ; Wed, 26 Jun 2013 16:06:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=noSetG0mxaK3nU8xtqnVxByT/0jepvkENeBTwmv+D9A=; b=mWbquGZ+Ta2Qm4PvABjTFrBQwctqbjZcMs5sv2vtI/p3GztTi2GshBofLl/fuOxR+i UXaSx3/TzQKKIb/9gWvT/WUGe+hrZJmUPHZFw9JKQrc3LMWEoHS6jgjhcKU0uJF+Xi1V TKnYLnrkgPtXR9oHYsdVCfDry9R8n4IZwZWPISHPeJgkMEuwVp4fHI05Zb9GCtGT08RM eJY7Zb90HcsxfsLr1/QdFI+8ce1Am4Aw7qzvojYvY+bfcfIdtjjFouDqUSnPfhDEc1ha Qm7n2XzDGgcRQ+u2veVTlCOPsg/N2R/04rvaK8ZSpISTXUo0Hn9ZL59ptHdLiGI6nxJq 5Bxg== X-Received: by 10.14.218.8 with SMTP id j8mr6061362eep.129.1372287993653; Wed, 26 Jun 2013 16:06:33 -0700 (PDT) Original-Received: by 10.14.142.4 with HTTP; Wed, 26 Jun 2013 16:05:53 -0700 (PDT) In-Reply-To: <51CB3299.50004@gmx.at> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c00::232 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:161118 Archived-At: --047d7b5dbe6864671204e016b2cd Content-Type: text/plain; charset=UTF-8 On Wed, Jun 26, 2013 at 8:27 PM, martin rudalics wrote: > The main application is to _restore_ the layout at the _beginning_ of a > session. This means that the one initial frame would get reused. I've implemented reusing all frames according to their displays (that is, if desktop wants to restore a frame, it will first look on the list of yet-unused frames for one on the right display; if found, it will reuse it and delete it from the list; otherwise it will create a new frame). It's a pity that, AFAIK, there's no way to delay creating the initial frame; initial-frame-alist is set after running .emacs, so you cannot really avoid the resizing / flickering. Other than setting X resources / Win32 registry settings just right for the initial frame (which will backfire as soon as you exit & save the initial frame at another position / size), the only way to make it more palatable is starting emacs with --iconic (or perhaps --daemon on POSIX systems?). > Let's ignore the next issues for the moment. Well, some of them are hardly ignorable, at least for users with many frames, minibuffer-only frames, etc. Also the maximized/fullscreen issue will bother people who usually works with maximized Emacs windows (assuming such people does exist). Another issue is at which point in the restore sequence should windows/frames be restored. Currently I'm doing it between desktop-delay-hook (which runs when all buffers are loaded) and desktop-after-read-hook (which happens after a "successful `desktop-read'"). That would allow the user to intercept the restoring, though desktop-delay-hook is for internal use. I can of course add hooks at some points in the save & restore sequences, but perhaps that's better left until the need arises. > Please do that. Let's hear from Stefan & Glenn. Meanwhile, here's the new patch. J === modified file 'lisp/desktop.el' --- lisp/desktop.el 2013-05-02 17:47:39 +0000 +++ lisp/desktop.el 2013-06-26 23:03:43 +0000 @@ -371,6 +371,12 @@ :type '(repeat symbol) :group 'desktop) +(defcustom desktop-save-windows t + "When non-nil, save window/frame configuration to desktop file." + :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: @@ -556,6 +562,9 @@ "Checksum of the last auto-saved contents of the desktop file. Used to avoid writing contents unchanged between auto-saves.") +(defvar desktop--saved-states nil + "Internal use only.") + ;; ---------------------------------------------------------------------------- ;; Desktop file conflict detection (defvar desktop-file-modtime nil @@ -858,6 +867,42 @@ ;; ---------------------------------------------------------------------------- +(defconst desktop--excluded-frame-parameters + '(buffer-list + buffer-predicate + buried-buffer-list + explicit-name + font-backend + minibuffer + name + outer-window-id + parent-id + window-id + window-system) + "Frame parameters not saved or restored.") + +(defun desktop--filter-frame-parms (frame) + "Return frame parameters of FRAME. +Parameters in `desktop--excluded-frame-parameters' are excluded. +Internal use only." + (let (params) + (dolist (param (frame-parameters frame)) + (unless (memq (car param) desktop--excluded-frame-parameters) + (push param params))) + params)) + +(defun desktop--save-windows () + "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 + (mapcar (lambda (frame) + (cons (desktop--filter-frame-parms frame) + (window-state-get (frame-root-window frame) t))) + (frame-list)))) + (desktop-outvar 'desktop--saved-states)) + ;;;###autoload (defun desktop-save (dirname &optional release auto-save) "Save the desktop in a desktop file. @@ -896,6 +941,9 @@ (save-excursion (run-hooks 'desktop-save-hook)) (goto-char (point-max)) (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) (mapc (function desktop-outvar) desktop-globals-to-save) (when (memq 'kill-ring desktop-globals-to-save) (insert @@ -954,6 +1002,37 @@ (defvar desktop-lazy-timer nil) ;; ---------------------------------------------------------------------------- +(defun desktop--find-frame-in-display (frames display) + (let (result) + (while (and frames (not result)) + (if (equal display (frame-parameter (car frames) 'display)) + (setq result (car frames)) + (setq frames (cdr frames)))) + result)) + +(defun desktop--restore-windows () + "Restore window/frame configuration. +Internal use only." + (when (and desktop-save-windows desktop--saved-states) + (condition-case nil + (let ((frames (frame-list))) + (dolist (state desktop--saved-states) + (let* ((fconfig (car state)) + (display (cdr (assq 'display fconfig))) + (frame (desktop--find-frame-in-display frames display))) + (if (not frame) + ;; no frames in the display -- make a new one + (setq frame (make-frame-on-display display fconfig)) + ;; found one -- reuse and remove from list + (setq frames (delq frame frames)) + (modify-frame-parameters frame fconfig)) + ;; restore windows + (window-state-put (cdr state) (frame-root-window frame) 'safe))) + ;; delete any remaining frames + (mapc #'delete-frame frames)) + (error + (message "Error loading window configuration from desktop file"))))) + ;;;###autoload (defun desktop-read (&optional dirname) "Read and process the desktop file in directory DIRNAME. @@ -1022,6 +1101,7 @@ (switch-to-buffer (car (buffer-list))) (run-hooks 'desktop-delay-hook) (setq desktop-delay-hook nil) + (desktop--restore-windows) (run-hooks 'desktop-after-read-hook) (message "Desktop: %d buffer%s restored%s%s." desktop-buffer-ok-count --047d7b5dbe6864671204e016b2cd Content-Type: application/octet-stream; name="desktop.patch" Content-Disposition: attachment; filename="desktop.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_hif4rwya0 PT09IG1vZGlmaWVkIGZpbGUgJ2xpc3AvZGVza3RvcC5lbCcNCi0tLSBsaXNwL2Rlc2t0b3AuZWwJ MjAxMy0wNS0wMiAxNzo0NzozOSArMDAwMA0KKysrIGxpc3AvZGVza3RvcC5lbAkyMDEzLTA2LTI2 IDIzOjAzOjQzICswMDAwDQpAQCAtMzcxLDYgKzM3MSwxMiBAQA0KICAgOnR5cGUgJyhyZXBlYXQg c3ltYm9sKQ0KICAgOmdyb3VwICdkZXNrdG9wKQ0KIA0KKyhkZWZjdXN0b20gZGVza3RvcC1zYXZl LXdpbmRvd3MgdA0KKyAgIldoZW4gbm9uLW5pbCwgc2F2ZSB3aW5kb3cvZnJhbWUgY29uZmlndXJh dGlvbiB0byBkZXNrdG9wIGZpbGUuIg0KKyAgOnR5cGUgJ2Jvb2xlYW4NCisgIDpncm91cCAnZGVz a3RvcA0KKyAgOnZlcnNpb24gIjI0LjQiKQ0KKw0KIChkZWZjdXN0b20gZGVza3RvcC1maWxlLW5h bWUtZm9ybWF0ICdhYnNvbHV0ZQ0KICAgIkZvcm1hdCBpbiB3aGljaCBkZXNrdG9wIGZpbGUgb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