diff --git a/src/workgroups-commands.el b/src/workgroups-commands.el index a6dd2df3ba88f680bbefbcf8e41465e9fa62f6f0..419a97371488eb16a871e2b1e861f6cedaca1d8b 100644 --- a/src/workgroups-commands.el +++ b/src/workgroups-commands.el @@ -18,10 +18,17 @@ (defun wg-switch-to-workgroup (workgroup &optional noerror) "Switch to WORKGROUP." (interactive (list (wg-read-workgroup-name))) - ;; Set a parameter when using ECB + ;; Mark if ECB is active (if (wg-current-workgroup t) (wg-set-workgroup-parameter (wg-current-workgroup t) 'ecb (and (boundp 'ecb-minor-mode) ecb-minor-mode))) + ;;(wg-set-workgroup-parameter (wg-current-workgroup t) 'ecb-win-config (ecb-current-window-configuration)) + ;; (type-of (ecb-current-window-configuration)) + ;; (type-of (car (ecb-current-window-configuration))) + ;; (type-of (car (nthcdr 3 (ecb-current-window-configuration)))) + ;; (wg-pickelable-or-error (ecb-current-window-configuration)) + ;;(ecb-current-window-configuration) + ;;) (let ((workgroup (wg-get-workgroup-create workgroup)) (current (wg-current-workgroup t))) (when (and (eq workgroup current) (not noerror)) @@ -54,6 +61,8 @@ (wg-workgroup-parameter (wg-current-workgroup t) 'ecb nil)) (let ((ecb-split-edit-window-after-start 'before-deactivation)) (ecb-activate))) + ;;(ecb-last-window-config-before-deactivation + ;; (wg-workgroup-parameter (wg-current-workgroup t) 'ecb-win-config nil))) (run-hooks 'wg-switch-to-workgroup-hook) (wg-fontified-message @@ -674,6 +683,8 @@ Think of it as `write-file' for Workgroups sessions." (wg-perform-session-maintenance) (setf (wg-session-file-name (wg-current-session)) filename) (setf (wg-session-version (wg-current-session)) wg-version) + (if wg-control-frames + (wg-save-frames)) (wg-write-sexp-to-file (wg-pickel-all-session-parameters (wg-current-session)) filename) @@ -712,6 +723,21 @@ the session regardless of whether it's been modified." (wg-save-session) (wg-query-and-save-if-modified))))) +(defun wg-save-frames () + "Save opened frames as a session parameter. +Exclude `selected-frame' and daemon one (if any). +http://stackoverflow.com/questions/21151992/why-emacs-as-daemon-gives-1-more-frame-than-is-opened" + (interactive) + (let ((fl (frame-list))) + (mapc (lambda (frame) + (if (string-equal "initial_terminal" (terminal-name frame)) + (delete frame fl))) fl) + (setq fl (delete (selected-frame) fl)) + (if (wg-current-session t) + (wg-set-session-parameter (wg-current-session t) + 'frame-list + (mapcar 'wg-frame-to-wconfig fl))))) + (defun wg-find-session-file (filename) "Load a session visiting FILENAME, creating one if none already exists." (interactive "FFind session file: ") @@ -733,6 +759,8 @@ the session regardless of whether it's been modified." (wg-session-parameter (wg-current-session t) 'last-workgroup)) (wg-switch-to-workgroup (car it))) )) + (if wg-control-frames + (wg-restore-frames)) (wg-fontified-message (:cmd "Loaded: ") (:file filename))) (t (wg-query-and-save-if-modified) diff --git a/src/workgroups-pickel.el b/src/workgroups-pickel.el index 1a2af381319b972276e62f45cf6137f805871209..d52d2481f57c737711add53a4c68f0fd0d7d6e76 100644 --- a/src/workgroups-pickel.el +++ b/src/workgroups-pickel.el @@ -75,6 +75,7 @@ (v . wg-pickel-deserialize-vector) (h . wg-pickel-deserialize-hash-table) (b . wg-pickel-deserialize-buffer)) + ;; (f . wg-pickel-deserialize-frame)) "Alist mapping type keys to object deserialization functions.") (defvar wg-pickel-link-deserializers diff --git a/src/workgroups-restore.el b/src/workgroups-restore.el index 6773acf191fc88d4455e1cf2c3c527bf92116f8b..55f4eb1ec4388b7a0c7945fedc99489b61627322 100644 --- a/src/workgroups-restore.el +++ b/src/workgroups-restore.el @@ -131,15 +131,16 @@ a wtree." (wg-restore-window-tree-helper wtree) (wg-awhen wg-window-tree-selected-window (select-window it)))) -(defun wg-wconfig-restore-frame-position (wconfig) - "Restore `selected-frame's position from WCONFIG." +(defun wg-wconfig-restore-frame-position (wconfig &optional frame) + "Use WCONFIG to restore FRAME's position. +If frame is nil then `selected-frame'." (wg-when-let ((left (wg-wconfig-left wconfig)) (top (wg-wconfig-top wconfig))) ;; Check that arguments are integers ;; Problem: https://github.com/pashinin/workgroups2/issues/15 (if (and (integerp left) (integerp top)) - (set-frame-position (selected-frame) left top)))) + (set-frame-position frame left top)))) (defun wg-wconfig-restore-scroll-bars (wconfig) "Restore `selected-frame's scroll-bar settings from WCONFIG." @@ -162,20 +163,22 @@ Return a scaled copy of WCONFIG." (frame-parameter nil 'width) (frame-parameter nil 'height))) -(defun wg-frame-resize-and-position (wconfig) - "Resize and position a frame based on WCONFIG of current workgroup." +(defun wg-frame-resize-and-position (wconfig &optional frame) + "Apply WCONFIG's size and position to a FRAME." (interactive) + (unless frame + (setq frame (selected-frame))) (let* ((params (wg-wconfig-parameters wconfig)) fullscreen) - (set-frame-parameter nil 'fullscreen (if (assoc 'fullscreen params) - (cdr (assoc 'fullscreen params)) - nil)) + (set-frame-parameter frame 'fullscreen (if (assoc 'fullscreen params) + (cdr (assoc 'fullscreen params)) + nil)) (when (and wg-restore-frame-position - (not (frame-parameter nil 'fullscreen))) - (wg-wconfig-restore-frame-position wconfig)) + (not (frame-parameter frame 'fullscreen))) + (wg-wconfig-restore-frame-position wconfig frame)) )) -(defun wg-restore-frame-size-position (wconfig) +(defun wg-restore-frame-size-position (wconfig &optional fs) "Smart-restore of frame size and position. Depending on `wg-remember-frame-for-each-wg' frame parameters may @@ -195,9 +198,10 @@ ignored. (setq fullscreen (if (assoc 'fullscreen params) (cdr (assoc 'fullscreen params)) nil)) - (when (and fullscreen - (or wg-remember-frame-for-each-wg - (null (wg-current-workgroup t)))) + (when (and fs + fullscreen + (or wg-remember-frame-for-each-wg + (null (wg-current-workgroup t)))) (set-frame-parameter nil 'fullscreen fullscreen) ;; I had bugs restoring maximized frame: ;; Frame could be maximized but buffers are not scaled to fit it. @@ -213,17 +217,33 @@ ignored. (wg-wconfig-restore-frame-position wconfig)) )) -;; FIXME: throw a specific error if the restoration was unsuccessful -(defun wg-restore-wconfig (wconfig) - "Restore a workgroup configuration WCONFIG in `selected-frame'. +(defun wg-restore-frames () + "Try to recreate opened frames, take info from session's 'frame-list parameter." + (interactive) + (delete-other-frames) + (when (wg-current-session t) + (let ((fl (wg-session-parameter (wg-current-session t) 'frame-list nil)) + (frame (selected-frame))) + (mapc (lambda (wconfig) + (with-selected-frame (make-frame) + ;;(wg-frame-resize-and-position wconfig) + ;;(wg-restore-frame-size-position wconfig) + ;;(wg-wconfig-restore-frame-position wconfig) + (wg-restore-wconfig wconfig) + )) fl) + (select-frame-set-input-focus frame)))) +;; FIXME: throw a specific error if the restoration was unsuccessful +(defun wg-restore-wconfig (wconfig &optional frame) + "Restore a workgroup configuration WCONFIG in a FRAME. Runs each time you're switching workgroups." + (unless frame + (setq frame (selected-frame))) (let ((wg-record-incorrectly-restored-bufs t) (wg-incorrectly-restored-bufs nil) (params (wg-wconfig-parameters wconfig)) fullscreen wtree) (wg-barf-on-active-minibuffer) - (wg-restore-frame-size-position wconfig) (when wg-restore-scroll-bars (wg-wconfig-restore-scroll-bars wconfig)) (setq wtree (wg-scale-wconfig-to-frame wconfig)) ; scale wtree to frame size @@ -235,7 +255,7 @@ Runs each time you're switching workgroups." (when (and wg-restore-frame-position (not (frame-parameter nil 'fullscreen)) (null (wg-current-workgroup t))) - (wg-wconfig-restore-frame-position wconfig)) + (wg-wconfig-restore-frame-position wconfig frame)) (when wg-incorrectly-restored-bufs (message "Unable to restore these buffers: %S\ diff --git a/src/workgroups-structs.el b/src/workgroups-structs.el index 0f9cef180e0440297bd1220ba95195818c1cf12a..ee6ad82632e2f6b2569897b25234e6e22f77d300 100644 --- a/src/workgroups-structs.el +++ b/src/workgroups-structs.el @@ -61,10 +61,7 @@ (height) (vertical-scroll-bars) (scroll-bar-width) - (wtree) - ;;(fullscreen) - ) -;; wg-wconfig + (wtree)) (wg-defstruct wg workgroup (uid (wg-generate-uid)) diff --git a/src/workgroups-variables.el b/src/workgroups-variables.el index 0fe06cb68a2b18d339b55d6c63eaaec87dc2c996..aaf12c7081119a1c5d1d6c03aa8d350bc1458783 100644 --- a/src/workgroups-variables.el +++ b/src/workgroups-variables.el @@ -29,6 +29,11 @@ :group 'workgroups :type 'boolean) +(defcustom wg-control-frames t + "Save/restore frames." + :group 'workgroups + :type 'boolean) + ;; keybinding customization