Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

session management with desktop and window configuration

4 views
Skip to first unread message

Kiwon Um

unread,
Dec 31, 2009, 5:08:18 AM12/31/09
to
Dear Emacs users:

I'm now using desktop.el for managing sessions. When I do desktop-
read, it restore all files opened before well. Then, I'm wondering if
there is any way to restore window configuration as well in easy way.
Firstly, I tried to add some functions to the desktop hooks as
follows:
(add-hook 'desktop-save-hook '(window-configuration-to-register ?0))
(add-hook 'desktop-after-read-hook '(jump-to-register ?0))
However, it didn't work at all.

The register-base window configuration save/restore are perfect to
what I want. But I don't know how to integrate it with desktop. Please
give me help.

martin rudalics

unread,
Dec 31, 2009, 6:31:55 AM12/31/09
to um.k...@gmail.com, help-gn...@gnu.org

You can't do this with desktop at the moment. The basic problem is that
we currently cannot read window configurations from a file - a window
configuration can only be saved in memory and retrieved from there.
This obviously means that when you exit Emacs your saved window
configurations are lost forever. In this context note also that you
can't cleanly restore a window configuration in one and the same session
if you have deleted its frame in the meantime.

Basically you should be able to write a configuration to a file as a
sequence of `split-window' functions (and some interspersed window
resizings) and execute these commands when you restart Emacs. But you
might end up getting only an approximation of the earlier configuration
partly due to the quite unpredictable behavior of the current window
resizing code which can, for example, deliberately delete windows when
they become too small.

I'm currently contemplating functions that write window configurations
to a file and read them from there. This way I can circumvent the
window splitting mechanism and directly construct a window-tree from the
information on the file. This should solve the problem for you.

Meanwhile you could try out ECB which does something similar to what you
want.

martin


Kiwon Um

unread,
Dec 31, 2009, 8:21:33 AM12/31/09
to martin rudalics, help-gn...@gnu.org
martin rudalics <ruda...@gmx.at> writes:

Thanks for your reply. So, I wrote some functions using revive.el:

(require 'revive)
(defun kiwon/save-window-configuration ()
(write-region (concat "(restore-window-configuration '"
(prin1-to-string (current-window-configuration-printable))
")")
nil ".emacs.restore-window.el"))
(defun kiwon/restore-window-configuration ()
(when (file-exists-p ".emacs.restore-window.el")
(load-file ".emacs.restore-window.el")))

(add-hook 'desktop-save-hook 'kiwon/save-window-configuration)
(add-hook 'desktop-after-read-hook 'kiwon/restore-window-configuration)

It seems to be enough to what I wanted. :)


Lennart Borgman

unread,
Dec 31, 2009, 8:33:09 AM12/31/09
to Kiwon Um, martin rudalics, help-gn...@gnu.org


Nice. I have seen revive but have not looked into it. There is also
winsav.el in nXhtml that can save and restore frames and windows.
(Martin, I am a bit surprised that you do not know about it. Didn't I
tell about this before?)


Richard Riley

unread,
Dec 31, 2009, 11:16:44 AM12/31/09
to help-gn...@gnu.org
Lennart Borgman <lennart...@gmail.com> writes:

windows.el does for me.


--

Lennart Borgman

unread,
Dec 31, 2009, 11:22:38 AM12/31/09
to Richard Riley, help-gn...@gnu.org
On Thu, Dec 31, 2009 at 5:16 PM, Richard Riley <riley...@gmail.com> wrote:
> Lennart Borgman <lennart...@gmail.com> writes:
>
>>>
>>> Thanks for your reply. So, I wrote some functions using revive.el:
>>>
>>> (require 'revive)
>>> (defun kiwon/save-window-configuration ()
>>>  (write-region (concat "(restore-window-configuration '"
>>>                        (prin1-to-string (current-window-configuration-printable))
>>>                        ")")
>>>                nil ".emacs.restore-window.el"))
>>> (defun kiwon/restore-window-configuration ()
>>>  (when (file-exists-p ".emacs.restore-window.el")
>>>    (load-file ".emacs.restore-window.el")))
>>>
>>> (add-hook 'desktop-save-hook 'kiwon/save-window-configuration)
>>> (add-hook 'desktop-after-read-hook 'kiwon/restore-window-configuration)
>>>
>>> It seems to be enough to what I wanted. :)
>>
>> Nice. I have seen revive but have not looked into it. There is also
>> winsav.el in nXhtml that can save and restore frames and windows.
>> (Martin, I am a bit surprised that you do not know about it. Didn't I
>> tell about this before?)
>>
>
> windows.el does for me.


What is windows.el, where can we find it?


Richard Riley

unread,
Dec 31, 2009, 11:32:44 AM12/31/09
to Lennart Borgman, Richard Riley, help-gn...@gnu.org
Lennart Borgman <lennart...@gmail.com> writes:

I googled it up when looking for a way to save window layout.

http://linux.about.com/cs/linux101/g/windows-el.htm

martin rudalics

unread,
Dec 31, 2009, 12:31:50 PM12/31/09
to Kiwon Um, help-gn...@gnu.org
> Thanks for your reply. So, I wrote some functions using revive.el:
[...]

> It seems to be enough to what I wanted. :)

When you encounter problems you can try Lennart's winsav.el which IIRC
is based on window-trees and doesn't have to make guesses from window
edges as revive.el. ECB records the entire story of window-splits in
order to reconstruct the window-tree which is not reasonable either.

martin


martin rudalics

unread,
Dec 31, 2009, 12:32:11 PM12/31/09
to Lennart Borgman, help-gn...@gnu.org, Kiwon Um
> Nice. I have seen revive but have not looked into it. There is also
> winsav.el in nXhtml that can save and restore frames and windows.
> (Martin, I am a bit surprised that you do not know about it. Didn't I
> tell about this before?)

I think winsave.el should do better than revive.el because it works on
the window-tree. But winsave.el is still based on splitting and
resizing which IMHO are liable to fail (otherwise there wouldn't be any
need for the `condition-case' in `bw-adjust-window'). And I dislike the
idea of calling `adjust-window-trailing-edge' repeatedly (every call of
this function means to allocate an entire window configuration).

martin


Vicente Hernando Ara

unread,
Dec 31, 2009, 12:33:22 PM12/31/09
to Richard Riley, Richard Riley, help-gn...@gnu.org
Hi,

may be I should start another thread but,

is it possible to save and restore not only windows but also processes
they were attached to? e.g: w3m or shell

On 31/12/2009, Richard Riley <riley...@googlemail.com> wrote:
> Lennart Borgman <lennart...@gmail.com> writes:
>
>> On Thu, Dec 31, 2009 at 5:16 PM, Richard Riley <riley...@gmail.com>
>> wrote:
>>> Lennart Borgman <lennart...@gmail.com> writes:
>>>
>>>>>

>>>>> Thanks for your reply. So, I wrote some functions using revive.el:
>>>>>

>>>>> (require 'revive)
>>>>> (defun kiwon/save-window-configuration ()
>>>>>  (write-region (concat "(restore-window-configuration '"
>>>>>                        (prin1-to-string
>>>>> (current-window-configuration-printable))
>>>>>                        ")")
>>>>>                nil ".emacs.restore-window.el"))
>>>>> (defun kiwon/restore-window-configuration ()
>>>>>  (when (file-exists-p ".emacs.restore-window.el")
>>>>>    (load-file ".emacs.restore-window.el")))
>>>>>
>>>>> (add-hook 'desktop-save-hook 'kiwon/save-window-configuration)
>>>>> (add-hook 'desktop-after-read-hook 'kiwon/restore-window-configuration)
>>>>>

>>>>> It seems to be enough to what I wanted. :)
>>>>

>>>> Nice. I have seen revive but have not looked into it. There is also
>>>> winsav.el in nXhtml that can save and restore frames and windows.
>>>> (Martin, I am a bit surprised that you do not know about it. Didn't I
>>>> tell about this before?)
>>>>
>>>

Lennart Borgman

unread,
Dec 31, 2009, 8:25:27 PM12/31/09
to Vicente Hernando Ara, Richard Riley, help-gn...@gnu.org, Richard Riley
On Thu, Dec 31, 2009 at 6:33 PM, Vicente Hernando Ara
<bize...@gmail.com> wrote:
> Hi,
>
> may be I should start another thread but,
>
> is it possible to save and restore not only windows but also processes
> they were attached to? e.g: w3m or shell


That is a job for desktop.el. At the moment I do not remember how
flexible it is, but if it is not it should be.

(winsav.el (and I guess the other variants too) remember which buffer
was shown in which window + buffer pos in window. But it is a job for
desktop to restore the buffers. winsav just binds them to the
windows.)


Lennart Borgman

unread,
Dec 31, 2009, 8:27:38 PM12/31/09
to martin rudalics, help-gn...@gnu.org, Kiwon Um
On Thu, Dec 31, 2009 at 6:32 PM, martin rudalics <ruda...@gmx.at> wrote:
>> Nice. I have seen revive but have not looked into it. There is also
>> winsav.el in nXhtml that can save and restore frames and windows.
>> (Martin, I am a bit surprised that you do not know about it. Didn't I
>> tell about this before?)
>
> I think winsave.el should do better than revive.el because it works on
> the window-tree.  But winsave.el is still based on splitting and
> resizing which IMHO are liable to fail (otherwise there wouldn't be any
> need for the `condition-case' in `bw-adjust-window').  And I dislike the
> idea of calling `adjust-window-trailing-edge' repeatedly (every call of
> this function means to allocate an entire window configuration).


Strange things happens during resizing. But as you know I wanted to
rewrite it. Sorry for not coming back to you about this. nXhtml did
take much longer time than I expected. (And there is still fundamental
problems. Some low level changes in Emacs are definitively needed IMO.
But it is a hard decision.)


Lennart Borgman

unread,
Dec 31, 2009, 8:29:45 PM12/31/09
to martin rudalics, help-gn...@gnu.org, Kiwon Um
On Thu, Dec 31, 2009 at 6:31 PM, martin rudalics <ruda...@gmx.at> wrote:
>> Thanks for your reply. So, I wrote some functions using revive.el:
> [...]

>> It seems to be enough to what I wanted. :)
>
> When you encounter problems you can try Lennart's winsav.el which IIRC
> is based on window-trees and doesn't have to make guesses from window
> edges as revive.el.  ECB records the entire story of window-splits in
> order to reconstruct the window-tree which is not reasonable either.


I have taken some care to support ECB in winsav.el.

That said I think the different versions should be merged. But it is a
quite difficult job. If someone is interested in doing it please try
to find the discussions between Martin and me about this. There are
some good points to start from.


martin rudalics

unread,
Jan 1, 2010, 9:55:08 AM1/1/10
to Lennart Borgman, help-gn...@gnu.org, Kiwon Um
> Strange things happens during resizing.

The inherent problem of resizing is that you can't specify _which_ other
windows may be affected when resizing a particular window. So you end
up doing what your and Stefan's balancing routines do: Adjusting the
size of one window may break the size of another one and ou have to go
on until the configuration converges to (a possibly suboptimal) one
which can't be improved by the algorithm.

> But as you know I wanted to
> rewrite it. Sorry for not coming back to you about this. nXhtml did
> take much longer time than I expected. (And there is still fundamental
> problems. Some low level changes in Emacs are definitively needed IMO.
> But it is a hard decision.)

My current code allows to specify the sizes of windows directly. It
only checks whether the sizes fit - if they do it applies them (in one
direction only though - so for resizing horizontally and vertically you
have to run the code twice). What I don't know yet is whether we should
keep the splitting concept of winsave.el. IIRC it's a bit tedious since
you have to make sure that the window you want to split is large enough.
OTOH writing some extra code to construct a window tree from a saved
description is not very funny either (especially because I would have to
write it in C.)

martin


Lennart Borgman

unread,
Jan 1, 2010, 10:04:30 AM1/1/10
to martin rudalics, help-gn...@gnu.org, Kiwon Um
On Fri, Jan 1, 2010 at 3:55 PM, martin rudalics <ruda...@gmx.at> wrote:
>> Strange things happens during resizing.
>
> The inherent problem of resizing is that you can't specify _which_ other
> windows may be affected when resizing a particular window.  So you end
> up doing what your and Stefan's balancing routines do: Adjusting the
> size of one window may break the size of another one and ou have to go
> on until the configuration converges to (a possibly suboptimal) one
> which can't be improved by the algorithm.
>
> My current code allows to specify the sizes of windows directly.  It
> only checks whether the sizes fit - if they do it applies them


Is there an elisp function to access it?


> (in one
> direction only though - so for resizing horizontally and vertically you
> have to run the code twice).


Don't you have to run it once for every node in the window tree?

martin rudalics

unread,
Jan 1, 2010, 10:18:40 AM1/1/10
to Lennart Borgman, help-gn...@gnu.org
>> My current code allows to specify the sizes of windows directly. It
>> only checks whether the sizes fit - if they do it applies them
>
> Is there an elisp function to access it?

Sure. I currently do practically all resizing in Elisp.

>> (in one
>> direction only though - so for resizing horizontally and vertically you
>> have to run the code twice).
>
> Don't you have to run it once for every node in the window tree?

I have a simple C routine which traverses the window tree and checks
whether the proposed new sizes fit together and don't violate the
absolute minimum sizes. If the test succeeds, I set the real sizes to
the proposed ones and assign the new top lines (or left columns).
Otherwise the resize operation fails.

martin


David Combs

unread,
Jan 6, 2010, 7:48:57 PM1/6/10
to
In article <mailman.476.126225912...@gnu.org>,

martin rudalics <ruda...@gmx.at> wrote:
> > I'm now using desktop.el for managing sessions. When I do desktop-
> > read, it restore all files opened before well. Then, I'm wondering if
> > there is any way to restore window configuration as well in easy way.
> > Firstly, I tried to add some functions to the desktop hooks as
> > follows:
> > (add-hook 'desktop-save-hook '(window-configuration-to-register ?0))
> > (add-hook 'desktop-after-read-hook '(jump-to-register ?0))
> > However, it didn't work at all.
> >
> > The register-base window configuration save/restore are perfect to
> > what I want. But I don't know how to integrate it with desktop. Please
> > give me help.
>
>You can't do this with desktop at the moment. The basic problem is that


For the short term, and if you can create your window-config without
too much fingerwork-hair, maybe C-x { and start building it, and
when done assign it into a register (as above), then via list-kbd-macro
and edit-kbd-macro save them in a file?

And if you screw up building the physical screen config, I suppose you
can just undo your mistake and fix it, still while in the C-x ( --

or, maybe if bold, use edit-kbd-macro and EDIT it?


Pretty easy to wrap a defun around it, the list-kbd-macro?


This have any chance of being a quick super-kludgy work-around?

Thanks!

David

PS: Note -- I have NOT read the rest of the thread yet, to see
likely far cooler ways.

0 new messages