all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Save and load window states
@ 2011-12-20 16:00 Michael Bach
  2011-12-20 18:53 ` Drew Adams
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Bach @ 2011-12-20 16:00 UTC (permalink / raw
  To: help-gnu-emacs

I am trying to get saving and loading window states to work.  I am using
the new `window-state-get' and `window-state-put' functions from emacs
24:

--8<---------------cut here---------------start------------->8---
(defun my-save-frame ()
  (interactive)
  (let ((buf (find-file-noselect (concat *emacs-path* ".emacs-layout"))))
    (set-buffer buf)
    (erase-buffer)
    (print (window-state-get) buf)
    (save-buffer)
    (kill-buffer)))

(defun my-load-frame ()
  (interactive)
  (let ((buf (find-file-noselect (concat *emacs-path* ".em1acs-layout"))))
    (set-buffer buf)
    (window-state-put (read buf))))
--8<---------------cut here---------------end--------------->8---

Saving works this way.  The file has the same contents shown in the
*Messages* buffer when doing a manual `window-state-get'.  On loading, I
get either "Invalid read syntax #" or "End of file during parsing".  In
the documentation of the `window-state-get' function it says:

"The return value can be used as argument for `window-state-put' to put
the state recorded here into an arbitrary window.  The value can be also
stored on disk and read back in a new session."

I am thinking that this has something to do with how emacs reads and
evaluates objects.

Can someone give me a hint on how to make it work?

Best Regards,
Michael Bach



^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: Save and load window states
  2011-12-20 16:00 Michael Bach
@ 2011-12-20 18:53 ` Drew Adams
  0 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2011-12-20 18:53 UTC (permalink / raw
  To: 'Michael Bach', help-gnu-emacs

> I am trying to get saving and loading window states to work.  
> I am using the new `window-state-get' and `window-state-put'
> functions from emacs 24:...
> Saving works this way.  The file has the same contents shown in the
> *Messages* buffer when doing a manual `window-state-get'.  On 
> loading, I get either "Invalid read syntax #" or "End of file
> during parsing".  In the documentation of the `window-state-get'
> function it says:

Sounds like a bug: `M-x report-emacs-bug'.  My guess is it's trying to read
something like this, contained your overall sexp, and is choking on the #<window
syntax. 

(parameters (clone-of . #<window 16 on *Help*>))




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Save and load window states
@ 2011-12-21 15:29 martin rudalics
  2011-12-21 20:13 ` Michael Bach
  0 siblings, 1 reply; 10+ messages in thread
From: martin rudalics @ 2011-12-21 15:29 UTC (permalink / raw
  To: phaebz; +Cc: help-gnu-emacs

 > Saving works this way.  The file has the same contents shown in the
 > *Messages* buffer when doing a manual `window-state-get'.  On loading, I
 > get either "Invalid read syntax #"

This is a bug.  Please report it as Drew suggested.

 > or "End of file during parsing".

This is probably due to the fact that you called `my-load-frame' twice
in a row and you were already at the end of the buffer in the second
call so there was nothing more to read.

 > I am thinking that this has something to do with how emacs reads and
 > evaluates objects.

Partly, yes.

 > Can someone give me a hint on how to make it work?

Please comment out the two code lines

                 (unless (window-parameter window 'clone-of)
                   ;; Make a clone-of parameter.
                   (setq list (cons (cons 'clone-of window) list)))

in the function `window--state-get-1' and recompile window.el (possibly
twice - I'm somewhat confused by Stefan's backquote syntax here).  These
lines are currently for internal use only, their absence should not harm
you.  If you still see problems, please tell me.

Thanks, martin



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Save and load window states
  2011-12-21 15:29 Save and load window states martin rudalics
@ 2011-12-21 20:13 ` Michael Bach
  2011-12-21 21:20   ` martin rudalics
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Bach @ 2011-12-21 20:13 UTC (permalink / raw
  To: martin rudalics; +Cc: help-gnu-emacs

martin rudalics <rudalics@gmx.at> writes:

>> Saving works this way.  The file has the same contents shown in the
>> *Messages* buffer when doing a manual `window-state-get'.  On loading, I
>> get either "Invalid read syntax #"
>
> This is a bug.  Please report it as Drew suggested.
>

Will do.


>> or "End of file during parsing".
>
> This is probably due to the fact that you called `my-load-frame' twice
> in a row and you were already at the end of the buffer in the second
> call so there was nothing more to read.
>

Yep, that was the reason.  I adapted `my-load-frame' accordingly.


>> Can someone give me a hint on how to make it work?
>
> Please comment out the two code lines
>
>                 (unless (window-parameter window 'clone-of)
>                   ;; Make a clone-of parameter.
>                   (setq list (cons (cons 'clone-of window) list)))
>
> in the function `window--state-get-1' and recompile window.el (possibly
> twice - I'm somewhat confused by Stefan's backquote syntax here).  These
> lines are currently for internal use only, their absence should not harm
> you.  If you still see problems, please tell me.
>

Unfortunately, that did not work.  Tried it compiled once and twice.
Same as before.

Thanks so far

michael



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Save and load window states
  2011-12-21 20:13 ` Michael Bach
@ 2011-12-21 21:20   ` martin rudalics
  2011-12-23 11:02     ` Michael Bach
  0 siblings, 1 reply; 10+ messages in thread
From: martin rudalics @ 2011-12-21 21:20 UTC (permalink / raw
  To: Michael Bach; +Cc: help-gnu-emacs

 >> Please comment out the two code lines
 >>
 >>                 (unless (window-parameter window 'clone-of)
 >>                   ;; Make a clone-of parameter.
 >>                   (setq list (cons (cons 'clone-of window) list)))
 >>
 >> in the function `window--state-get-1' and recompile window.el (possibly
 >> twice - I'm somewhat confused by Stefan's backquote syntax here).  These
 >> lines are currently for internal use only, their absence should not harm
 >> you.  If you still see problems, please tell me.
 >>
 >
 > Unfortunately, that did not work.  Tried it compiled once and twice.
 > Same as before.

It works here.  Make sure your file does not contain a `clone-of' entry.
(And note that window.el is preloaded.  So after commenting out these
lines you have to rebuild Emacs if you want it to work right after
starting Emacs.)  If it still doesn't work, send me the file contents.

martin



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Save and load window states
  2011-12-21 21:20   ` martin rudalics
@ 2011-12-23 11:02     ` Michael Bach
  2011-12-23 11:13       ` martin rudalics
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Bach @ 2011-12-23 11:02 UTC (permalink / raw
  To: martin rudalics; +Cc: help-gnu-emacs

martin rudalics <rudalics@gmx.at> writes:

> It works here.  Make sure your file does not contain a `clone-of' entry.
> (And note that window.el is preloaded.  So after commenting out these
> lines you have to rebuild Emacs if you want it to work right after
> starting Emacs.)  If it still doesn't work, send me the file contents.
>

It took me a while to figure out how to patch the source.  The bzr
snapshot is built automatically via a PKGBUILD (I am on Arch Linux
here).

Rebuilt with your suggested patch and it works now.

Thanks a lot for the professional support!

Michael



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Save and load window states
  2011-12-23 11:02     ` Michael Bach
@ 2011-12-23 11:13       ` martin rudalics
  2011-12-23 12:24         ` Michael Bach
  0 siblings, 1 reply; 10+ messages in thread
From: martin rudalics @ 2011-12-23 11:13 UTC (permalink / raw
  To: Michael Bach; +Cc: help-gnu-emacs

 > It took me a while to figure out how to patch the source.  The bzr
 > snapshot is built automatically via a PKGBUILD (I am on Arch Linux
 > here).

I was afraid that something simlar interferred.  Once you changed this
and rebuilt, the change should remain persistent, though.

In any case: When you look at your file and it contains hash ("#")
notation, be assured that `read' breaks.

 > Rebuilt with your suggested patch and it works now.

I hope I can fix this so `read' works out of the box for Emacs 24.1.

BTW what do you use for "resurrecting" buffers - desktop.el?

martin



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Save and load window states
  2011-12-23 11:13       ` martin rudalics
@ 2011-12-23 12:24         ` Michael Bach
  2011-12-23 13:46           ` martin rudalics
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Bach @ 2011-12-23 12:24 UTC (permalink / raw
  To: martin rudalics; +Cc: help-gnu-emacs

martin rudalics <rudalics@gmx.at> writes:

> BTW what do you use for "resurrecting" buffers - desktop.el?
>

I do not know whether I understand correctly, but I am using
`(desktop-save-mode t)' for saving my buffers across sessions.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Save and load window states
  2011-12-23 12:24         ` Michael Bach
@ 2011-12-23 13:46           ` martin rudalics
  2011-12-28 14:10             ` Michael Bach
  0 siblings, 1 reply; 10+ messages in thread
From: martin rudalics @ 2011-12-23 13:46 UTC (permalink / raw
  To: Michael Bach; +Cc: help-gnu-emacs

 > I do not know whether I understand correctly, but I am using
 > `(desktop-save-mode t)' for saving my buffers across sessions.

That's what I wanted to know.  Does establishing the window-buffer
correspondence work as intended?  That is, does running `desktop-read'
first and `my-load-frame' afterwards show the right buffers in the right
windows?

martin



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Save and load window states
  2011-12-23 13:46           ` martin rudalics
@ 2011-12-28 14:10             ` Michael Bach
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Bach @ 2011-12-28 14:10 UTC (permalink / raw
  To: martin rudalics; +Cc: help-gnu-emacs

martin rudalics <rudalics@gmx.at> writes:

> That is, does running `desktop-read' first and `my-load-frame'
> afterwards show the right buffers in the right windows?

Sorry for being late, christmas and all.  Yes, it works satisfactory for
me.  Again, much obliged.

michael




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-12-28 14:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-21 15:29 Save and load window states martin rudalics
2011-12-21 20:13 ` Michael Bach
2011-12-21 21:20   ` martin rudalics
2011-12-23 11:02     ` Michael Bach
2011-12-23 11:13       ` martin rudalics
2011-12-23 12:24         ` Michael Bach
2011-12-23 13:46           ` martin rudalics
2011-12-28 14:10             ` Michael Bach
  -- strict thread matches above, loose matches on Subject: below --
2011-12-20 16:00 Michael Bach
2011-12-20 18:53 ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.