Changeset - 3edbfb87fe7d
[Not reviewed]
0 5 0
Sergey Pashinin - 11 years ago 2014-07-01 19:44:58
sergey@pashinin.com
Save/restore frames (#11)

Probably works (for me) with usual file buffers
5 files changed with 75 insertions and 24 deletions:
0 comments (0 inline, 0 general)
src/workgroups-commands.el
Show inline comments
 
@@ -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)
src/workgroups-pickel.el
Show inline comments
 
@@ -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
src/workgroups-restore.el
Show inline comments
 
@@ -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\
src/workgroups-structs.el
Show inline comments
 
@@ -61,10 +61,7 @@
 
  (height)
 
  (vertical-scroll-bars)
 
  (scroll-bar-width)
 
  (wtree)
 
  ;;(fullscreen)
 
  )
 
;; wg-wconfig
 
  (wtree))
 

	
 
(wg-defstruct wg workgroup
 
  (uid (wg-generate-uid))
src/workgroups-variables.el
Show inline comments
 
@@ -29,6 +29,11 @@
 
  :group 'workgroups
 
  :type 'boolean)
 

	
 
(defcustom wg-control-frames t
 
  "Save/restore frames."
 
  :group 'workgroups
 
  :type 'boolean)
 

	
 

	
 
;; keybinding customization
 

	
0 comments (0 inline, 0 general)