[comp.emacs] Saving window configurations

Ram-Ashwin@cs.yale.edu (Ashwin Ram) (10/28/88)

Is there a way to save the current window configuration (as returned by
(current-window-configuration)) in a file, such that loading that file would
restore that window configuration?  I know I can save it in a variable and
later use set-window-configuration to restore it in the same session, but I'd
like to be able to restore a particular window configuration in later
sessions too.

Thanks.

-- Ashwin.

ARPA:    Ram-Ashwin@cs.yale.edu
UUCP:    {decvax,ucbvax,harvard,cmcl2,...}!yale!Ram-Ashwin
BITNET:  Ram@yalecs

daveemme@amdahl.uts.amdahl.com (Dave Emme) (10/28/88)

In article <41546@yale-celray.yale.UUCP> Ram-Ashwin@cs.yale.edu (Ashwin Ram) writes:
 >Is there a way to save the current window configuration (as returned by
 >(current-window-configuration)) in a file, such that loading that file would
 >restore that window configuration?  I know I can save it in a variable and
 >later use set-window-configuration to restore it in the same session, but I'd
 >like to be able to restore a particular window configuration in later
 >sessions too.

I realize that the following isn't what was asked for (I'd like that
ability, too!), but here is some code I've put together to support saving
and restoring of Gnu Emacs window configurations *within* a session.  You can
push and pop configurations, or give them names and restore by name (in any
order). 

- Dave

------------------------------ Cut Here ------------------------------

(defvar window-configuration-stack nil
  "The stack used by functions `push-window-configuration' and
`pop-window-configuration'.")

(defun push-window-configuration ()
  "Push the current window configuration onto the configuration stack.
It can be retrieved later using `pop-window-configuration'."
  (interactive)
  (setq window-configuration-stack
	(cons (current-window-configuration) window-configuration-stack)))

(defun pop-window-configuration ()
  "Pop the top window configuration off of the stack and adjust windows
accordingly.
Window configurations are saved on the stack using 
`push-window-configuration'."
  (interactive)
  (if window-configuration-stack
      (progn (set-window-configuration (car window-configuration-stack))
	     (setq window-configuration-stack (cdr window-configuration-stack)))

    (error "The window configuration stack is empty.")))


(defvar named-window-configurations nil
  "List of named window configurations used by commands
`save-window-configuration' and `restore-window-configuration'.")

(defun save-window-configuration (name)
  "Save the current window configuration as NAME.
It can be later retrieved using `restore-window-configuration'."
  (interactive "sName for window configuration: ")
  (let ((x (assoc name named-window-configurations)))
    (if (or (null x)
	    (if (y-or-n-p "Name is currently used; reassign? ")
		(progn
		  (setq named-window-configurations
			(delq x named-window-configurations))
		  t)))
	(setq named-window-configurations
	      (cons (cons name (current-window-configuration))
		    named-window-configurations)))
    (message "")))


(defun restore-window-configuration ()
  "Restore (make current) the window configuration NAME, which was
saved using `save-window-configuration'."
  (interactive)
  (set-window-configuration
   (cdr (assoc (completing-read "Window configuration name: "
				named-window-configurations
				nil 'force)
	       named-window-configurations))))
-- 
------------------------------------------------------------------------------
	(Insert disclaimer of your choice here)

Dave Emme  (M/S 316)                    daveemme@uts.amdahl.com
Amdahl Corporation            {ames, decwrl, sun, uunet}!amdahl!daveemme
1250 E. Arques Ave.
Sunnyvale, CA 94088

grunwald@m.cs.uiuc.edu (10/28/88)

Check to see if you have ``saveconf.el'' in your Gnuemacs lisp directory.
This does something similar to what you want. Be warned -- you should
put the `recover-context' call at the very end.

I've also define the following, which doesn't save the context of
files in /tmp or RMAIL related files (since recovering RMAIL files
doesn't work).

BTW: does anyone know how to occasionally save the configuration incase
you don't exit cleanly?

(setq save-context-predicate
      (function
       (lambda (w)
	 (and
	  ; nil?
	  (buffer-file-name (window-buffer w))
	  ; /usr/tmp or /tmp?
	  (not (string-match "^\\(/usr\\)?/tmp/"
			       (buffer-file-name (window-buffer w))))
	  ; rmail mode?
	  (let
	      ((isok t))
	    (save-excursion
	      (set-buffer (window-buffer w))
	      (setq isok
		    (not (or (eq major-mode 'rmail-mode)
			     (eq major-mode 'mail-mode)))))
	    isok))
	  )))

jcgs@harlqn.UUCP (John Sturdy) (10/31/88)

(save-window-excursion <body>) is useful for this, if you are always
stacking the window configurations rather than picking them in random
order.

-- 
__John            The Lord bless you and watch over you, The Lord make his face
         shine upon you and be gracious to you, The Lord look kindly on you and
   give you peace; My brothers, my sisters, God bless you. Amen.  (St. Francis)
         jcgs@uk.co.harlqn Harlequin Ltd,Barrington,Cambridge,UK +44-223-872522

kjones@talos.UUCP (Kyle Jones) (10/31/88)

In article <4300020@m.cs.uiuc.edu> grunwald@m.cs.uiuc.edu writes:
>BTW: does anyone know how to occasionally save the configuration incase
>you don't exit cleanly?

If you've installed my recently posted `timer' package, you can say

(start-timer "auto-save-context" 'save-context 300 300)

to get the context saved every five minutes (300 seconds).