all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* desktop.el: autosave?
@ 2007-11-30 14:08 Reuben Thomas
  2007-11-30 23:35 ` Richard Stallman
  0 siblings, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2007-11-30 14:08 UTC (permalink / raw)
  To: bug-emacs

desktop.el is great; I've used it since before it became part of Emacs.

However, I sometimes lose my Emacs session for various reasons (hardly ever 
because of Emacs itself, usually for some stupid reason like updating a 
kernel, and then suspending instead of rebooting). When I come back, I get 
my old Emacs session. Of course, the files I'm editing all have auto-saved 
copies, if I need them. It would be nice if desktop mode could similarly 
write a desktop save file from time to time during the editing session so 
that if like me, you leave Emacs running all the time, you don't risk going 
back to a collection of files days or weeks out of date should you lose your 
Emacs session.

Since desktop already does things when Emacs is idle, it seems to me (I admit I 
know nothing about this area of programming Emacs, I've only dabbled in elisp 
to the extent I need to to customize Emacs) that it should be fairly simple to 
add the ability to save out a new desktop save file from time to time when 
Emacs is idle. I imagine the period would be customizable, but every half hour 
or so would seem to be the right order of default.

-- 
http://rrt.sc3d.org/ | The Next Station Is Oval (Anon)




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

* Re: desktop.el: autosave?
  2007-11-30 14:08 desktop.el: autosave? Reuben Thomas
@ 2007-11-30 23:35 ` Richard Stallman
  2007-12-01  0:35   ` Juri Linkov
  0 siblings, 1 reply; 57+ messages in thread
From: Richard Stallman @ 2007-11-30 23:35 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: emacs-devel

auto-save-hook could do this job.

Date: Fri, 30 Nov 2007 14:08:07 +0000 (GMT)
From: Reuben Thomas <rrt@sc3d.org>
To: bug-emacs@gnu.org
Message-ID: <alpine.DEB.0.99999.0711301407250.4037@localhost.localdomain>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
Cc: 
Subject: desktop.el: autosave?

desktop.el is great; I've used it since before it became part of Emacs.

However, I sometimes lose my Emacs session for various reasons (hardly ever 
because of Emacs itself, usually for some stupid reason like updating a 
kernel, and then suspending instead of rebooting). When I come back, I get 
my old Emacs session. Of course, the files I'm editing all have auto-saved 
copies, if I need them. It would be nice if desktop mode could similarly 
write a desktop save file from time to time during the editing session so 
that if like me, you leave Emacs running all the time, you don't risk going 
back to a collection of files days or weeks out of date should you lose your 
Emacs session.

Since desktop already does things when Emacs is idle, it seems to me (I admit I 
know nothing about this area of programming Emacs, I've only dabbled in elisp 
to the extent I need to to customize Emacs) that it should be fairly simple to 
add the ability to save out a new desktop save file from time to time when 
Emacs is idle. I imagine the period would be customizable, but every half hour 
or so would seem to be the right order of default.

-- 
http://rrt.sc3d.org/ | The Next Station Is Oval (Anon)

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

* Re: desktop.el: autosave?
  2007-11-30 23:35 ` Richard Stallman
@ 2007-12-01  0:35   ` Juri Linkov
  2007-12-01 23:41     ` Richard Stallman
  2007-12-03 21:14     ` Reuben Thomas
  0 siblings, 2 replies; 57+ messages in thread
From: Juri Linkov @ 2007-12-01  0:35 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel, Reuben Thomas

> auto-save-hook could do this job.

I use in .emacs:

  (defun my-desktop-save ()
    (interactive)
    ;; `desktop-owner' is a new function in Emacs 22.1.50 to check
    ;; for conflicts between two running Emacs instances.
    ;; We don't want automatic saving in the second Emacs process.
    (if (and (fboundp 'desktop-owner) (eq (desktop-owner) (emacs-pid)))
        (desktop-save "~")))

  ;; Save the desktop every hour
  (run-at-time 3600 3600 'my-desktop-save)

But maybe instead of requiring putting this code in .emacs for
every user who want to save the desktop periodically, we should
add a new user option to desktop.el that specifies time interval
of auto-saving?  I think the default value of `auto-save-timeout'
is too frequent for a heavy function `desktop-save'.  And also
standard auto-saving mechanism works on files, but the desktop
doesn't keep the desktop file permanently visited.

> Date: Fri, 30 Nov 2007 14:08:07 +0000 (GMT)
> From: Reuben Thomas <rrt@sc3d.org>
> To: bug-emacs@gnu.org
> Message-ID: <alpine.DEB.0.99999.0711301407250.4037@localhost.localdomain>
> MIME-Version: 1.0
> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
> Cc:
> Subject: desktop.el: autosave?
>
> desktop.el is great; I've used it since before it became part of Emacs.
>
> However, I sometimes lose my Emacs session for various reasons (hardly ever
> because of Emacs itself, usually for some stupid reason like updating a
> kernel, and then suspending instead of rebooting). When I come back, I get
> my old Emacs session. Of course, the files I'm editing all have auto-saved
> copies, if I need them. It would be nice if desktop mode could similarly
> write a desktop save file from time to time during the editing session so
> that if like me, you leave Emacs running all the time, you don't risk going
> back to a collection of files days or weeks out of date should you lose your
> Emacs session.
>
> Since desktop already does things when Emacs is idle, it seems to me (I admit I
> know nothing about this area of programming Emacs, I've only dabbled in elisp
> to the extent I need to to customize Emacs) that it should be fairly simple to
> add the ability to save out a new desktop save file from time to time when
> Emacs is idle. I imagine the period would be customizable, but every half hour
> or so would seem to be the right order of default.
>
> --
> http://rrt.sc3d.org/ | The Next Station Is Oval (Anon)

--
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-01  0:35   ` Juri Linkov
@ 2007-12-01 23:41     ` Richard Stallman
  2007-12-03 22:57       ` Juri Linkov
  2007-12-03 21:14     ` Reuben Thomas
  1 sibling, 1 reply; 57+ messages in thread
From: Richard Stallman @ 2007-12-01 23:41 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rrt, emacs-devel

    But maybe instead of requiring putting this code in .emacs for
    every user who want to save the desktop periodically, we should
    add a new user option to desktop.el that specifies time interval
    of auto-saving?

I agree, we should add some such feature.

		     I think the default value of `auto-save-timeout'
    is too frequent for a heavy function `desktop-save'.

Maybe so, but auto-saving based on idle time is an important feature.
Whatever we write for automatically saving the desktop should also
include a feature to do it after a certain amount of idle time,
perhaps 5 mins by default.  That way, if you occasionally take typing
breaks, Emacs will never interrupt your actual work to save the desktop.

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

* Re: desktop.el: autosave?
  2007-12-01  0:35   ` Juri Linkov
  2007-12-01 23:41     ` Richard Stallman
@ 2007-12-03 21:14     ` Reuben Thomas
  2007-12-03 22:57       ` Juri Linkov
  1 sibling, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2007-12-03 21:14 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rms, emacs-devel

On Sat, 1 Dec 2007, Juri Linkov wrote:

> I use in .emacs:
>
>  (defun my-desktop-save ()
>    (interactive)
>    ;; `desktop-owner' is a new function in Emacs 22.1.50 to check
>    ;; for conflicts between two running Emacs instances.
>    ;; We don't want automatic saving in the second Emacs process.
>    (if (and (fboundp 'desktop-owner) (eq (desktop-owner) (emacs-pid)))
>        (desktop-save "~")))

Why did you not use desktop-save-in-desktop-dir?

I use stable Emacs so I won't get the benefit of desktop-owner, but thanks 
for writing it so I will automagically as soon as it exists in stable!

-- 
http://rrt.sc3d.org/ | The yak is slow but the earth is patient (LucasArts)

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

* Re: desktop.el: autosave?
  2007-12-03 21:14     ` Reuben Thomas
@ 2007-12-03 22:57       ` Juri Linkov
  2007-12-06 14:56         ` Reuben Thomas
  0 siblings, 1 reply; 57+ messages in thread
From: Juri Linkov @ 2007-12-03 22:57 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: rms, emacs-devel

>> I use in .emacs:
>>  (defun my-desktop-save ()
>>    (interactive)
>>    ;; `desktop-owner' is a new function in Emacs 22.1.50 to check
>>    ;; for conflicts between two running Emacs instances.
>>    ;; We don't want automatic saving in the second Emacs process.
>>    (if (and (fboundp 'desktop-owner) (eq (desktop-owner) (emacs-pid)))
>>        (desktop-save "~")))
>
> Why did you not use desktop-save-in-desktop-dir?

This was enough for .emacs, but for desktop.el a proper variable
to save the desktop in is surely `desktop-dirname'.  Even though
`desktop-save-in-desktop-dir' is a method that does this, I think we
can't use it, because when `desktop-dirname' is nil initially, it asks
in the minibuffer where to save the desktop (by using `call-interactively'),
but this is not a good thing to do in a function called by a timer.
Perhaps it should do nothing when called by a timer and `desktop-dirname'
is nil.

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-01 23:41     ` Richard Stallman
@ 2007-12-03 22:57       ` Juri Linkov
  2007-12-04  7:39         ` martin rudalics
                           ` (2 more replies)
  0 siblings, 3 replies; 57+ messages in thread
From: Juri Linkov @ 2007-12-03 22:57 UTC (permalink / raw)
  To: rms; +Cc: rrt, emacs-devel

>     But maybe instead of requiring putting this code in .emacs for
>     every user who want to save the desktop periodically, we should
>     add a new user option to desktop.el that specifies time interval
>     of auto-saving?
>
> I agree, we should add some such feature.
>
> 		     I think the default value of `auto-save-timeout'
>     is too frequent for a heavy function `desktop-save'.
>
> Maybe so, but auto-saving based on idle time is an important feature.
> Whatever we write for automatically saving the desktop should also
> include a feature to do it after a certain amount of idle time,
> perhaps 5 mins by default.  That way, if you occasionally take typing
> breaks, Emacs will never interrupt your actual work to save the desktop.

I'm not sure an idle timer is good for this feature.  I want to auto-save
the desktop at quite long time intervals (an hour or so), but usually
Emacs is not idle for this time.  So it seems we need a non-idle timer.

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-03 22:57       ` Juri Linkov
@ 2007-12-04  7:39         ` martin rudalics
  2007-12-05  2:57           ` Richard Stallman
  2007-12-04 16:55         ` Richard Stallman
  2007-12-06 14:58         ` Reuben Thomas
  2 siblings, 1 reply; 57+ messages in thread
From: martin rudalics @ 2007-12-04  7:39 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel, rms, rrt

> I'm not sure an idle timer is good for this feature.  I want to auto-save
> the desktop at quite long time intervals (an hour or so), but usually
> Emacs is not idle for this time.  So it seems we need a non-idle timer.

Two timers?  The non-idle one triggers (after an hour or so) an idle one.

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

* Re: desktop.el: autosave?
  2007-12-03 22:57       ` Juri Linkov
  2007-12-04  7:39         ` martin rudalics
@ 2007-12-04 16:55         ` Richard Stallman
  2007-12-06 14:58         ` Reuben Thomas
  2 siblings, 0 replies; 57+ messages in thread
From: Richard Stallman @ 2007-12-04 16:55 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rrt, emacs-devel

    I'm not sure an idle timer is good for this feature.  I want to auto-save
    the desktop at quite long time intervals (an hour or so), but usually
    Emacs is not idle for this time.  So it seems we need a non-idle timer.

I think we need an idle timer and a clock timer both,
just as we have for auto-save.

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

* Re: desktop.el: autosave?
  2007-12-04  7:39         ` martin rudalics
@ 2007-12-05  2:57           ` Richard Stallman
  2007-12-05  9:02             ` martin rudalics
  0 siblings, 1 reply; 57+ messages in thread
From: Richard Stallman @ 2007-12-05  2:57 UTC (permalink / raw)
  To: martin rudalics; +Cc: juri, emacs-devel, rrt

    > I'm not sure an idle timer is good for this feature.  I want to auto-save
    > the desktop at quite long time intervals (an hour or so), but usually
    > Emacs is not idle for this time.  So it seems we need a non-idle timer.

    Two timers?  The non-idle one triggers (after an hour or so) an idle one.

That's a strange idea.  My idea is that they both trigger saving.

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

* Re: desktop.el: autosave?
  2007-12-05  2:57           ` Richard Stallman
@ 2007-12-05  9:02             ` martin rudalics
  2007-12-05 22:28               ` Juri Linkov
  2007-12-06  2:11               ` Richard Stallman
  0 siblings, 2 replies; 57+ messages in thread
From: martin rudalics @ 2007-12-05  9:02 UTC (permalink / raw)
  To: rms; +Cc: juri, emacs-devel

>     > I'm not sure an idle timer is good for this feature.  I want to auto-save
>     > the desktop at quite long time intervals (an hour or so), but usually
>     > Emacs is not idle for this time.  So it seems we need a non-idle timer.
> 
>     Two timers?  The non-idle one triggers (after an hour or so) an idle one.
> 
> That's a strange idea.  

It occurred to me because Juri wanted to auto-save the desktop only
every hour.  Hence, I'd first wait for an hour and then until Emacs
has become idle for at least five minutes.

> My idea is that they both trigger saving.

Wouldn't it be sufficient to have one idle timer which triggers
auto-saving only if some timeout has elapsed sine the last auto-save
of the desktop?

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

* Re: desktop.el: autosave?
  2007-12-05  9:02             ` martin rudalics
@ 2007-12-05 22:28               ` Juri Linkov
  2007-12-05 23:09                 ` martin rudalics
  2007-12-06  2:11               ` Richard Stallman
  1 sibling, 1 reply; 57+ messages in thread
From: Juri Linkov @ 2007-12-05 22:28 UTC (permalink / raw)
  To: martin rudalics; +Cc: rms, emacs-devel

>>     > I'm not sure an idle timer is good for this feature.  I want to
>>     > auto-save the desktop at quite long time intervals (an hour or
>>     > so), but usually Emacs is not idle for this time.  So it seems
>>     > we need a non-idle timer.
>>
>>     Two timers?  The non-idle one triggers (after an hour or so) an idle one.
>>
>> That's a strange idea.
>
> It occurred to me because Juri wanted to auto-save the desktop only
> every hour.  Hence, I'd first wait for an hour and then until Emacs
> has become idle for at least five minutes.

Yes, having two parallel timers with an idle timer run with a short delay
will save the desktop too often which is undesirable.  So your idea is
reasonable unless there is a more suitable solution with using just one timer.

>> My idea is that they both trigger saving.
>
> Wouldn't it be sufficient to have one idle timer which triggers
> auto-saving only if some timeout has elapsed since the last auto-save
> of the desktop?

It seems this is not possible with idle timers because they use timeout
elapsed since the last user input, not the last time they run.

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-05 22:28               ` Juri Linkov
@ 2007-12-05 23:09                 ` martin rudalics
  2007-12-05 23:41                   ` Juri Linkov
  0 siblings, 1 reply; 57+ messages in thread
From: martin rudalics @ 2007-12-05 23:09 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rms, emacs-devel

>>Wouldn't it be sufficient to have one idle timer which triggers
>>auto-saving only if some timeout has elapsed since the last auto-save
>>of the desktop?
> 
> 
> It seems this is not possible with idle timers because they use timeout
> elapsed since the last user input, not the last time they run.

Ahh no.  I meant using an extra variable which records the last autosave
date.  Whenever the routine triggered by the idle timer detects that the
period (one hour ...) has elapsed (by comparing that variable's value
with the present time) it does autosave and reset that variable.  This
would only fail when an idle time starts before the autosave timeout has
expired and terminates long after that.

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

* Re: desktop.el: autosave?
  2007-12-05 23:09                 ` martin rudalics
@ 2007-12-05 23:41                   ` Juri Linkov
  2007-12-06 15:12                     ` Richard Stallman
  0 siblings, 1 reply; 57+ messages in thread
From: Juri Linkov @ 2007-12-05 23:41 UTC (permalink / raw)
  To: martin rudalics; +Cc: rms, emacs-devel

>>>Wouldn't it be sufficient to have one idle timer which triggers
>>>auto-saving only if some timeout has elapsed since the last auto-save
>>>of the desktop?
>>
>> It seems this is not possible with idle timers because they use timeout
>> elapsed since the last user input, not the last time they run.
>
> Ahh no.  I meant using an extra variable which records the last autosave
> date.  Whenever the routine triggered by the idle timer detects that the
> period (one hour ...) has elapsed (by comparing that variable's value
> with the present time) it does autosave and reset that variable.  This
> would only fail when an idle time starts before the autosave timeout has
> expired and terminates long after that.

Yes, this is not a reliable solution since an idle timer may fail to run
at the requested time.  I think your first idea is better.

I wonder why standard timers don't do something like that: run a function
after a long timeout (e.g. several minutes) but only if Emacs is idle for
a few seconds.  This looks like an useful behavior.

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-05  9:02             ` martin rudalics
  2007-12-05 22:28               ` Juri Linkov
@ 2007-12-06  2:11               ` Richard Stallman
  2007-12-06 23:29                 ` Juri Linkov
  1 sibling, 1 reply; 57+ messages in thread
From: Richard Stallman @ 2007-12-06  2:11 UTC (permalink / raw)
  To: martin rudalics; +Cc: juri, emacs-devel

    It occurred to me because Juri wanted to auto-save the desktop only
    every hour.  Hence, I'd first wait for an hour and then until Emacs
    has become idle for at least five minutes.

One cannot argue with tastes, but one drawback is that if he never
takes a 5-minute break, it will never auto-save the desktop.

That's why I suggest auto-saving whenever Emacs is idle for N minutes
_or_ H hours have elapsed since the last save.  If you take breaks
often enough, it will save in the breaks and only in the breaks.
But if you don't take breaks, it will eventually save anyway.

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

* Re: desktop.el: autosave?
  2007-12-03 22:57       ` Juri Linkov
@ 2007-12-06 14:56         ` Reuben Thomas
  0 siblings, 0 replies; 57+ messages in thread
From: Reuben Thomas @ 2007-12-06 14:56 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rms, emacs-devel

On Tue, 4 Dec 2007, Juri Linkov wrote:

>>> I use in .emacs:
>>>  (defun my-desktop-save ()
>>>    (interactive)
>>>    ;; `desktop-owner' is a new function in Emacs 22.1.50 to check
>>>    ;; for conflicts between two running Emacs instances.
>>>    ;; We don't want automatic saving in the second Emacs process.
>>>    (if (and (fboundp 'desktop-owner) (eq (desktop-owner) (emacs-pid)))
>>>        (desktop-save "~")))
>>
>> Why did you not use desktop-save-in-desktop-dir?
>
> This was enough for .emacs, but for desktop.el a proper variable
> to save the desktop in is surely `desktop-dirname'.  Even though
> `desktop-save-in-desktop-dir' is a method that does this, I think we
> can't use it, because when `desktop-dirname' is nil initially, it asks
> in the minibuffer where to save the desktop (by using `call-interactively'),
> but this is not a good thing to do in a function called by a timer.

> Perhaps it should do nothing when called by a timer and `desktop-dirname'
> is nil.

Seems sensible, but can't you achieve this result by having the timer call 
my-desktop-save non-interactively?

-- 
http://rrt.sc3d.org/ | Astrophysics: it's not exactly rocket science

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

* Re: desktop.el: autosave?
  2007-12-03 22:57       ` Juri Linkov
  2007-12-04  7:39         ` martin rudalics
  2007-12-04 16:55         ` Richard Stallman
@ 2007-12-06 14:58         ` Reuben Thomas
  2007-12-06 15:38           ` tomas
  2 siblings, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2007-12-06 14:58 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rms, emacs-devel

On Tue, 4 Dec 2007, Juri Linkov wrote:

> I'm not sure an idle timer is good for this feature.  I want to auto-save
> the desktop at quite long time intervals (an hour or so), but usually
> Emacs is not idle for this time.  So it seems we need a non-idle timer.

Why do you want to save at such long intervals? Is there a performance 
problem with just using the idle timer? I can't say I've noticed the impact 
on my fairly modest system (1GHz laptop) by simply autosave-hook. Or is 
there some positive reason for wanting to save at much longer intervals?

-- 
http://rrt.sc3d.org/ | maxim, n.  wisdom for fools

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

* Re: desktop.el: autosave?
  2007-12-05 23:41                   ` Juri Linkov
@ 2007-12-06 15:12                     ` Richard Stallman
  0 siblings, 0 replies; 57+ messages in thread
From: Richard Stallman @ 2007-12-06 15:12 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rudalics, emacs-devel

    I wonder why standard timers don't do something like that: run a function
    after a long timeout (e.g. several minutes) but only if Emacs is idle for
    a few seconds.  This looks like an useful behavior.

What standard timers do now is a basic and useful behavior.
It would not be right to replace that with something more
complex which can be implemented on top of the existing behavior.

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

* Re: desktop.el: autosave?
  2007-12-06 14:58         ` Reuben Thomas
@ 2007-12-06 15:38           ` tomas
  2007-12-06 15:47             ` Reuben Thomas
  2007-12-07 17:18             ` Richard Stallman
  0 siblings, 2 replies; 57+ messages in thread
From: tomas @ 2007-12-06 15:38 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: Juri Linkov, rms, emacs-devel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, Dec 06, 2007 at 02:58:42PM +0000, Reuben Thomas wrote:
> On Tue, 4 Dec 2007, Juri Linkov wrote:
> 
> >I'm not sure an idle timer is good for this feature.  I want to auto-save
> >the desktop at quite long time intervals [...]

> Why do you want to save at such long intervals? Is there a performance 
> problem with just using the idle timer? [...]

Disk spin-up on laaptops comes to mind. The longer the intervals the
longer bettery (and disk!) life.

Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFHWBdeBcgs9XrR2kYRAu4FAJ96TJ6xjgYP7qxE39oUtwJRgWUavgCfWyFl
v/4WF/cpxps1ESvZoIkY1LA=
=2oyb
-----END PGP SIGNATURE-----

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

* Re: desktop.el: autosave?
  2007-12-06 15:38           ` tomas
@ 2007-12-06 15:47             ` Reuben Thomas
  2007-12-06 23:28               ` Juri Linkov
  2007-12-07 17:18             ` Richard Stallman
  1 sibling, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2007-12-06 15:47 UTC (permalink / raw)
  To: tomas; +Cc: Juri Linkov, rms, emacs-devel

On Thu, 6 Dec 2007, tomas@tuxteam.de wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Thu, Dec 06, 2007 at 02:58:42PM +0000, Reuben Thomas wrote:
>> On Tue, 4 Dec 2007, Juri Linkov wrote:
>>
>>> I'm not sure an idle timer is good for this feature.  I want to auto-save
>>> the desktop at quite long time intervals [...]
>
>> Why do you want to save at such long intervals? Is there a performance
>> problem with just using the idle timer? [...]
>
> Disk spin-up on laaptops comes to mind. The longer the intervals the
> longer bettery (and disk!) life.

That argument applies to any auto-save, not just desktop. I'm trying to work 
out why one would want one interval for auto-save and another for desktop 
save.

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

* Re: desktop.el: autosave?
  2007-12-06 15:47             ` Reuben Thomas
@ 2007-12-06 23:28               ` Juri Linkov
  2007-12-06 23:44                 ` Reuben Thomas
  2007-12-07  2:47                 ` Stefan Monnier
  0 siblings, 2 replies; 57+ messages in thread
From: Juri Linkov @ 2007-12-06 23:28 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: tomas, rms, emacs-devel

>>>> I'm not sure an idle timer is good for this feature.  I want to auto-save
>>>> the desktop at quite long time intervals [...]
>>
>>> Why do you want to save at such long intervals? Is there a performance
>>> problem with just using the idle timer? [...]
>>
>> Disk spin-up on laaptops comes to mind. The longer the intervals the
>> longer bettery (and disk!) life.
>
> That argument applies to any auto-save, not just desktop. I'm trying to
> work out why one would want one interval for auto-save and another for
> desktop save.

Saving a buffer's file is fast operation comparing to saving the desktop
that takes more time because it is a cpu-intensive task that collects
information from all buffers and some possibly long lists and writes
to the usually large desktop file.  The default timeout for auto-save
is 30 sec which is ok for auto-saving normal files, but I don't see a
need to waste resources to save the desktop so often.

I have no serious problems with short intervals, but some users may have
for various reasons (low memory that causes reading from the swap space
when collecting data to save to the desktop file, slow disk access, etc.).
So users may want to increase the timeout for the idle timer.  But the main
problem with idle timers is that with long intervals they may never run.

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-06  2:11               ` Richard Stallman
@ 2007-12-06 23:29                 ` Juri Linkov
  0 siblings, 0 replies; 57+ messages in thread
From: Juri Linkov @ 2007-12-06 23:29 UTC (permalink / raw)
  To: rms; +Cc: martin rudalics, emacs-devel

>     It occurred to me because Juri wanted to auto-save the desktop only
>     every hour.  Hence, I'd first wait for an hour and then until Emacs
>     has become idle for at least five minutes.
>
> One cannot argue with tastes, but one drawback is that if he never
> takes a 5-minute break, it will never auto-save the desktop.

Martin's idea would work if the idle timer's timeout is proportional to
the time required to save the desktop (a few seconds).  So the algorithm
would be the following: at large intervals (tens of minutes) a non-idle
timer will start an idle timer to wait for appropriate time within the
next few seconds of idle time.  The reason is that when saving the desktop
requires e.g. 1 sec then after 5 sec of idle time it is likely that it
finishes saving before the user notices the delay caused by saving.

> That's why I suggest auto-saving whenever Emacs is idle for N minutes
> _or_ H hours have elapsed since the last save.  If you take breaks
> often enough, it will save in the breaks and only in the breaks.
> But if you don't take breaks, it will eventually save anyway.

If the idea above is not acceptable then having two separate timers with
separately configured timeouts is not bad, because when necessary the user
can disable one of the two timers.

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-06 23:28               ` Juri Linkov
@ 2007-12-06 23:44                 ` Reuben Thomas
  2007-12-07  0:03                   ` Juri Linkov
  2007-12-07  2:47                 ` Stefan Monnier
  1 sibling, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2007-12-06 23:44 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, rms, emacs-devel

On Fri, 7 Dec 2007, Juri Linkov wrote:

> Saving a buffer's file is fast operation comparing to saving the desktop
> that takes more time because it is a cpu-intensive task that collects
> information from all buffers and some possibly long lists and writes
> to the usually large desktop file.  The default timeout for auto-save
> is 30 sec which is ok for auto-saving normal files, but I don't see a
> need to waste resources to save the desktop so often.

It's easy to argue about this, but numbers are more convincing. I don't know 
anything about instrumenting functions in Emacs; how can I find out how long 
Emacs spends running desktop-save over a particular time period?

> But the main problem with idle timers is that with long intervals they may 
> never run.

So don't use long intervals: if the computer is idle anyway, why does it 
matter if Emacs does some work? Or does "idle" only apply to Emacs?

-- 
http://rrt.sc3d.org/ | Travail broadens the behind

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

* Re: desktop.el: autosave?
  2007-12-06 23:44                 ` Reuben Thomas
@ 2007-12-07  0:03                   ` Juri Linkov
  2007-12-07  2:48                     ` Stefan Monnier
  2007-12-09 20:35                     ` Reuben Thomas
  0 siblings, 2 replies; 57+ messages in thread
From: Juri Linkov @ 2007-12-07  0:03 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: tomas, rms, emacs-devel

>> Saving a buffer's file is fast operation comparing to saving the desktop
>> that takes more time because it is a cpu-intensive task that collects
>> information from all buffers and some possibly long lists and writes
>> to the usually large desktop file.  The default timeout for auto-save
>> is 30 sec which is ok for auto-saving normal files, but I don't see a
>> need to waste resources to save the desktop so often.
>
> It's easy to argue about this, but numbers are more convincing. I don't
> know anything about instrumenting functions in Emacs; how can I find out
> how long Emacs spends running desktop-save over a particular time period?

You can evaluate:

(let ((start (float-time))) (desktop-save desktop-dirname) (- (float-time) start))

that returns a number of seconds spent for desktop saving.

>> But the main problem with idle timers is that with long intervals they
>> may never run.
>
> So don't use long intervals: if the computer is idle anyway, why does it
> matter if Emacs does some work? Or does "idle" only apply to Emacs?

"Idle" applies only to Emacs.  And if the user changes nothing in Emacs
during long idle periods it is redundant to write the same desktop file
without changes every 30 sec.

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-06 23:28               ` Juri Linkov
  2007-12-06 23:44                 ` Reuben Thomas
@ 2007-12-07  2:47                 ` Stefan Monnier
  1 sibling, 0 replies; 57+ messages in thread
From: Stefan Monnier @ 2007-12-07  2:47 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, emacs-devel, rms, Reuben Thomas

> Saving a buffer's file is fast operation comparing to saving the desktop
> that takes more time because it is a cpu-intensive task that collects
> information from all buffers and some possibly long lists and writes
> to the usually large desktop file.  The default timeout for auto-save
> is 30 sec which is ok for auto-saving normal files, but I don't see a
> need to waste resources to save the desktop so often.

I have a hard time believing that it's so "CPU intensive".
Collecting info about 100 buffers is a no brainer that should be done in
a tiny fraction of a second even on a 10 year old CPU.  As for "large
desktop file", how large are we talking about? anything smaller than
100KB is not large nowadays.

> I have no serious problems with short intervals, but some users may have
> for various reasons (low memory that causes reading from the swap space
> when collecting data to save to the desktop file, slow disk access, etc.).

When swapping, you might be better off using a short idle interval so as
to reduce the risk of the pages having been swapped out while "idling"
(i.e. while some other process ran).

> So users may want to increase the timeout for the idle timer.  But the main
> problem with idle timers is that with long intervals they may never run.

Worse yet: long interval means it will be run right when the machine is
idle, i.e. when the disk was spun down.  Better run it when the machine
is still "active" so there's a better chance that the drive is
already spinning.

On top of that, writing to a file does not necessarily imply spinning up
the disk, because the actual write might be delayed by the OS to save power.


        Stefan

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

* Re: desktop.el: autosave?
  2007-12-07  0:03                   ` Juri Linkov
@ 2007-12-07  2:48                     ` Stefan Monnier
  2007-12-09 20:35                     ` Reuben Thomas
  1 sibling, 0 replies; 57+ messages in thread
From: Stefan Monnier @ 2007-12-07  2:48 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, emacs-devel, rms, Reuben Thomas

> And if the user changes nothing in Emacs during long idle periods it
> is redundant to write the same desktop file without changes every
> 30 sec.

That's a more serious issue, indeed.


        Stefan

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

* Re: desktop.el: autosave?
  2007-12-06 15:38           ` tomas
  2007-12-06 15:47             ` Reuben Thomas
@ 2007-12-07 17:18             ` Richard Stallman
  1 sibling, 0 replies; 57+ messages in thread
From: Richard Stallman @ 2007-12-07 17:18 UTC (permalink / raw)
  To: tomas; +Cc: juri, emacs-devel, rrt

    > Why do you want to save at such long intervals? Is there a performance 
    > problem with just using the idle timer? [...]

    Disk spin-up on laaptops comes to mind. The longer the intervals the
    longer bettery (and disk!) life.

That is a valid argument.  So I guess it makes sense to have a certain
minimum time between saves, as well as a certain maximum time.
The minimum time could be implemented by a real time timer
which activates the idle timer.  The maximum time could be implemented
by another real time timer which directly causes a save.
When a save happens it should reinitialize all the timers

    That argument applies to any auto-save, not just desktop. I'm trying to work 
    out why one would want one interval for auto-save and another for desktop 
    save.

That is true.  Should we have this feature for auto-saves too?

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

* Re: desktop.el: autosave?
  2007-12-07  0:03                   ` Juri Linkov
  2007-12-07  2:48                     ` Stefan Monnier
@ 2007-12-09 20:35                     ` Reuben Thomas
  2007-12-10  0:27                       ` Juri Linkov
  1 sibling, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2007-12-09 20:35 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, rms, emacs-devel

On Fri, 7 Dec 2007, Juri Linkov wrote:

>>> Saving a buffer's file is fast operation comparing to saving the desktop
>>> that takes more time because it is a cpu-intensive task that collects
>>> information from all buffers and some possibly long lists and writes
>>> to the usually large desktop file.  The default timeout for auto-save
>>> is 30 sec which is ok for auto-saving normal files, but I don't see a
>>> need to waste resources to save the desktop so often.
>>
>> It's easy to argue about this, but numbers are more convincing. I don't
>> know anything about instrumenting functions in Emacs; how can I find out
>> how long Emacs spends running desktop-save over a particular time period?
>
> You can evaluate:
>
> (let ((start (float-time))) (desktop-save desktop-dirname) (- (float-time) start))

After about 30 hours, saving the desktop had accumulated about 50s of time 
this way. That seems a reasonable amount to me. I have 137 buffers in my 
session, and my desktop file is about 38,000 bytes long. Hence, I suggest 
that a simple feature "Auto-save desktop" which adds 
desktop-save-in-desktop-dir to auto-save-hook, would satisfy most people 
likely to use this feature. Furthermore those concerned about power usage 
and disk spin-up only have to worry about the same Emacs feature 
(auto-save-hook), and not add another hook or function to their list of 
things to tweak.

To ensure that this doesn't make auto-save-hook ask for input interactively, 
desktop-save-in-desktop-dir should be made only to prompt for the 
desktop-dir (when it's not set) if it's being run interactively.

-- 
http://rrt.sc3d.org/ | priest, n.  an unpaid lawyer (q.v.)

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

* Re: desktop.el: autosave?
  2007-12-09 20:35                     ` Reuben Thomas
@ 2007-12-10  0:27                       ` Juri Linkov
  2007-12-10  0:35                         ` Reuben Thomas
  2007-12-10  3:03                         ` Stefan Monnier
  0 siblings, 2 replies; 57+ messages in thread
From: Juri Linkov @ 2007-12-10  0:27 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: tomas, rms, emacs-devel

> After about 30 hours, saving the desktop had accumulated about 50s of time
> this way. That seems a reasonable amount to me. I have 137 buffers in my
> session, and my desktop file is about 38,000 bytes long. Hence, I suggest
> that a simple feature "Auto-save desktop" which adds
> desktop-save-in-desktop-dir to auto-save-hook, would satisfy most people
> likely to use this feature. Furthermore those concerned about power usage
> and disk spin-up only have to worry about the same Emacs feature
> (auto-save-hook), and not add another hook or function to their list of
> things to tweak.

For users with small desktop files this simple solution could be
satisfactory.  Who doesn't like it, can disable auto-saving and
add a pair of lines to .emacs with an explicit non-idle timer.

A separate question is whether to auto-save the desktop using
auto-save-hook by default or not.  Perhaps not if it can cause
potential problems for users.

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-10  0:27                       ` Juri Linkov
@ 2007-12-10  0:35                         ` Reuben Thomas
  2007-12-10  0:50                           ` Drew Adams
  2007-12-10  0:59                           ` Juri Linkov
  2007-12-10  3:03                         ` Stefan Monnier
  1 sibling, 2 replies; 57+ messages in thread
From: Reuben Thomas @ 2007-12-10  0:35 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, rms, emacs-devel

On Mon, 10 Dec 2007, Juri Linkov wrote:

>> After about 30 hours, saving the desktop had accumulated about 50s of time
>> this way. That seems a reasonable amount to me. I have 137 buffers in my
>> session, and my desktop file is about 38,000 bytes long. Hence, I suggest
>> that a simple feature "Auto-save desktop" which adds
>> desktop-save-in-desktop-dir to auto-save-hook, would satisfy most people
>> likely to use this feature. Furthermore those concerned about power usage
>> and disk spin-up only have to worry about the same Emacs feature
>> (auto-save-hook), and not add another hook or function to their list of
>> things to tweak.
>
> For users with small desktop files this simple solution could be
> satisfactory.

How much bigger than mine do you think it's going to get?

> A separate question is whether to auto-save the desktop using
> auto-save-hook by default or not.  Perhaps not if it can cause
> potential problems for users.

I think this is a nice default if desktop is active. Of course, desktop 
itself is not switched on by default. I don't think it will cause problems 
for many users; those who don't like it can switch it off, of course. It 
seems reasonable to have it on by defaut, just like auto-save for files is 
on by default.

-- 
http://rrt.sc3d.org/ | aphorism, n.  a wise lie

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

* RE: desktop.el: autosave?
  2007-12-10  0:35                         ` Reuben Thomas
@ 2007-12-10  0:50                           ` Drew Adams
  2007-12-10  0:59                           ` Juri Linkov
  1 sibling, 0 replies; 57+ messages in thread
From: Drew Adams @ 2007-12-10  0:50 UTC (permalink / raw)
  To: Reuben Thomas, Juri Linkov; +Cc: tomas, rms, emacs-devel

> I think this is a nice default if desktop is active. Of course, desktop
> itself is not switched on by default. I don't think it will cause
> problems for many users; those who don't like it can switch it off,
> of course. It seems reasonable to have it on by defaut, just like
> auto-save for files is on by default.

I don't use it. How does it work if you have multiple Emacs sessions open at
the same time, perhaps using different Emacs versions. And then you close
them at various times. Is there a separate desktop saved for each? How is
this handled and configured?

This is likely documented, but since a change is being proposed to the
default behavior, perhaps someone could summarize here the behavior and
consequences for users who don't currently use desktop. Thx.

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

* Re: desktop.el: autosave?
  2007-12-10  0:35                         ` Reuben Thomas
  2007-12-10  0:50                           ` Drew Adams
@ 2007-12-10  0:59                           ` Juri Linkov
  2007-12-10  1:10                             ` Reuben Thomas
  1 sibling, 1 reply; 57+ messages in thread
From: Juri Linkov @ 2007-12-10  0:59 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: tomas, rms, emacs-devel

>>> After about 30 hours, saving the desktop had accumulated about 50s of time
>>> this way. That seems a reasonable amount to me. I have 137 buffers in my
>>> session, and my desktop file is about 38,000 bytes long. Hence, I suggest
>>> that a simple feature "Auto-save desktop" which adds
>>> desktop-save-in-desktop-dir to auto-save-hook, would satisfy most people
>>> likely to use this feature. Furthermore those concerned about power usage
>>> and disk spin-up only have to worry about the same Emacs feature
>>> (auto-save-hook), and not add another hook or function to their list of
>>> things to tweak.
>>
>> For users with small desktop files this simple solution could be
>> satisfactory.
>
> How much bigger than mine do you think it's going to get?

Mine is ~700 kilobytes long with ~400 buffers and unlimited history lists.
So far I had no problems with such a large desktop: I rarely restart Emacs;
desktop reading is quite fast (a few seconds); desktop saving takes 0.2 sec.
I could try using auto-save-hook and see what problems it causes.

>> A separate question is whether to auto-save the desktop using
>> auto-save-hook by default or not.  Perhaps not if it can cause
>> potential problems for users.
>
> I think this is a nice default if desktop is active. Of course, desktop
> itself is not switched on by default. I don't think it will cause problems
> for many users; those who don't like it can switch it off, of course. It
> seems reasonable to have it on by defaut, just like auto-save for files is
> on by default.

In any case, there should be an option to easily switch it off.

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-10  0:59                           ` Juri Linkov
@ 2007-12-10  1:10                             ` Reuben Thomas
  0 siblings, 0 replies; 57+ messages in thread
From: Reuben Thomas @ 2007-12-10  1:10 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, rms, emacs-devel

On Mon, 10 Dec 2007, Juri Linkov wrote:

> Mine is ~700 kilobytes long with ~400 buffers and unlimited history lists.

Heh. Fair enough. I should take more limits off myself.

> So far I had no problems with such a large desktop: I rarely restart Emacs;
> desktop reading is quite fast (a few seconds); desktop saving takes 0.2 sec.

i.e. faster than me! (I am using a laptop with a slow disk, plus a fairly 
slow CPU, so it's not a surprise.)

> In any case, there should be an option to easily switch it off.

Of course. If there were a customize option, desktop-auto-save or similar, 
that were on by default, then it could easily be switched off too.

-- 
http://rrt.sc3d.org/
memoir, n.  a lie that flatters the author's ego and the reader's intellect

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

* Re: desktop.el: autosave?
  2007-12-10  0:27                       ` Juri Linkov
  2007-12-10  0:35                         ` Reuben Thomas
@ 2007-12-10  3:03                         ` Stefan Monnier
  2007-12-10 22:01                           ` Reuben Thomas
  2007-12-10 22:02                           ` Reuben Thomas
  1 sibling, 2 replies; 57+ messages in thread
From: Stefan Monnier @ 2007-12-10  3:03 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, emacs-devel, rms, Reuben Thomas

>> likely to use this feature. Furthermore those concerned about power usage
>> and disk spin-up only have to worry about the same Emacs feature
>> (auto-save-hook), and not add another hook or function to their list of
>> things to tweak.

BTW, how 'bout optimizing disk writes like savehist does: only save the
new desktop file if it's different from the previous one.  That doesn't
save you from generating the new file's content in a buffer, of course,
but still.


        Stefan

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

* Re: desktop.el: autosave?
  2007-12-10  3:03                         ` Stefan Monnier
@ 2007-12-10 22:01                           ` Reuben Thomas
  2007-12-10 23:55                             ` Juri Linkov
  2007-12-10 22:02                           ` Reuben Thomas
  1 sibling, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2007-12-10 22:01 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Juri Linkov, tomas, rms, emacs-devel

On Sun, 9 Dec 2007, Stefan Monnier wrote:

>>> likely to use this feature. Furthermore those concerned about power usage
>>> and disk spin-up only have to worry about the same Emacs feature
>>> (auto-save-hook), and not add another hook or function to their list of
>>> things to tweak.
>
> BTW, how 'bout optimizing disk writes like savehist does: only save the
> new desktop file if it's different from the previous one.  That doesn't
> save you from generating the new file's content in a buffer, of course,
> but still.

That sounds like a good idea. I think we can now collect the changes that 
need to be made:

1. A customizable preference, desktop-auto-save, which indicates whether 
desktop-save-in-desktop-dir should be added to auto-save-hook or not. Is the 
easiest way to do this to add a private function that desktop mode always 
adds to auto-save-hook and then have that private function test a boolean 
which is itself the customizable preference when it runs, to see whether to 
proceed or not?

2. Change desktop-save-in-desktop-dir so that it only prompts for a 
directory if it is called interactively. The normal way seems to be to add 
an optional argument as described in the help for interactive-p.

3. Change desktop-save-in-desktop-dir to be like savehist-mode, only 
actually writing the file when the history has changed since the last time.

Does that sounds about right?

-- 
http://rrt.sc3d.org/ | Brevity is the soul

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

* Re: desktop.el: autosave?
  2007-12-10  3:03                         ` Stefan Monnier
  2007-12-10 22:01                           ` Reuben Thomas
@ 2007-12-10 22:02                           ` Reuben Thomas
  2007-12-10 22:12                             ` Drew Adams
  1 sibling, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2007-12-10 22:02 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Juri Linkov, tomas, rms, emacs-devel

On Sun, 9 Dec 2007, Stefan Monnier wrote:

>>> likely to use this feature. Furthermore those concerned about power usage
>>> and disk spin-up only have to worry about the same Emacs feature
>>> (auto-save-hook), and not add another hook or function to their list of
>>> things to tweak.
>
> BTW, how 'bout optimizing disk writes like savehist does: only save the
> new desktop file if it's different from the previous one.  That doesn't
> save you from generating the new file's content in a buffer, of course,
> but still.

I was previously unaware of savehist-mode. What's the point of having both 
it and the history-saving functionality of desktop? Wouldn't it be better 
to remove that functionality from desktop and let users use savehist-mode 
instead? (Or vice versa.)

-- 
http://rrt.sc3d.org/ | author, n.  one who parades ignorance in public

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

* RE: desktop.el: autosave?
  2007-12-10 22:02                           ` Reuben Thomas
@ 2007-12-10 22:12                             ` Drew Adams
  2007-12-10 22:16                               ` Reuben Thomas
  0 siblings, 1 reply; 57+ messages in thread
From: Drew Adams @ 2007-12-10 22:12 UTC (permalink / raw)
  To: Reuben Thomas, Stefan Monnier; +Cc: Juri Linkov, tomas, rms, emacs-devel

> I was previously unaware of savehist-mode. What's the point of
> having both it and the history-saving functionality of desktop?
> Wouldn't it be better to remove that functionality from desktop
> and let users use savehist-mode instead? (Or vice versa.)

Certainly not vice versa. A user might want to save histories but not all
the rest.

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

* RE: desktop.el: autosave?
  2007-12-10 22:12                             ` Drew Adams
@ 2007-12-10 22:16                               ` Reuben Thomas
  2007-12-10 23:57                                 ` Juri Linkov
  0 siblings, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2007-12-10 22:16 UTC (permalink / raw)
  To: Drew Adams; +Cc: Juri Linkov, tomas, emacs-devel, Stefan Monnier, rms

On Mon, 10 Dec 2007, Drew Adams wrote:

>> I was previously unaware of savehist-mode. What's the point of
>> having both it and the history-saving functionality of desktop?
>> Wouldn't it be better to remove that functionality from desktop
>> and let users use savehist-mode instead? (Or vice versa.)
>
> Certainly not vice versa. A user might want to save histories but not all
> the rest.

That's configurable, of course: you could use desktop to save only your 
histories. I agree, though, that from where we stand now it'd be easier to 
make desktop not save minibuffer histories than to make it easy to configure 
to save only minibuffer histories. I suspect that there are more users using 
savehist to save their histories too. It would be easy to point desktop 
users at savehist-mode.

-- 
http://rrt.sc3d.org/ | The old cliches are the best

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

* Re: desktop.el: autosave?
  2007-12-10 22:01                           ` Reuben Thomas
@ 2007-12-10 23:55                             ` Juri Linkov
  2007-12-11  0:10                               ` Reuben Thomas
  0 siblings, 1 reply; 57+ messages in thread
From: Juri Linkov @ 2007-12-10 23:55 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: tomas, emacs-devel

> 1. A customizable preference, desktop-auto-save, which indicates whether
> desktop-save-in-desktop-dir should be added to auto-save-hook or not. Is
> the easiest way to do this to add a private function that desktop mode
> always adds to auto-save-hook and then have that private function test
> a boolean which is itself the customizable preference when it runs, to see
> whether to proceed or not?

No need for a separate function.  You could just change desktop-save-mode
as follows:

(define-minor-mode desktop-save-mode
  :global t
  :group 'desktop
  (if desktop-save-mode
      (if desktop-auto-save
	  (add-hook 'auto-save-hook 'desktop-save-in-desktop-dir))
    (remove-hook 'auto-save-hook 'desktop-save-in-desktop-dir)))

But please note that I still think it would be better to use a timer.
You can look in savehist.el that it uses a separate non-idle timer.
It seems reasonable to do the same in desktop.el.

> 2. Change desktop-save-in-desktop-dir so that it only prompts for
> a directory if it is called interactively. The normal way seems to be to
> add an optional argument as described in the help for interactive-p.

I think it should be replaced with:

(defun desktop-save-in-desktop-dir (&optional dirname)
  "Save the desktop in directory `desktop-dirname'."
  (interactive
   (list (or desktop-dirname
	     (read-directory-name "Directory to save desktop file in: "))))
  (when (and (null dirname) desktop-dirname)
    (setq dirname desktop-dirname))
  (when dirname
    (desktop-save dirname)
    (message "Desktop saved in %s" dirname)))

> 3. Change desktop-save-in-desktop-dir to be like savehist-mode, only
> actually writing the file when the history has changed since the
> last time.

This is easy to do once we will decide what auto-saving method to use.

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-10 22:16                               ` Reuben Thomas
@ 2007-12-10 23:57                                 ` Juri Linkov
  2007-12-11  0:02                                   ` Reuben Thomas
  0 siblings, 1 reply; 57+ messages in thread
From: Juri Linkov @ 2007-12-10 23:57 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: tomas, drew.adams, emacs-devel

>>> I was previously unaware of savehist-mode. What's the point of
>>> having both it and the history-saving functionality of desktop?
>>> Wouldn't it be better to remove that functionality from desktop
>>> and let users use savehist-mode instead? (Or vice versa.)
>>
>> Certainly not vice versa. A user might want to save histories but not all
>> the rest.
>
> That's configurable, of course: you could use desktop to save only your
> histories. I agree, though, that from where we stand now it'd be easier to
> make desktop not save minibuffer histories than to make it easy to
> configure to save only minibuffer histories. I suspect that there are more
> users using savehist to save their histories too. It would be easy to
> point desktop users at savehist-mode.

There is no sense to remove history saving from desktop.el if there
happens to exist a package that duplicates a part of its functionality.
Why put an additional hassle on users of desktop.el with more configuration?

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-10 23:57                                 ` Juri Linkov
@ 2007-12-11  0:02                                   ` Reuben Thomas
  2007-12-11  0:23                                     ` Juri Linkov
  0 siblings, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2007-12-11  0:02 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, drew.adams, emacs-devel

On Tue, 11 Dec 2007, Juri Linkov wrote:

> There is no sense to remove history saving from desktop.el if there
> happens to exist a package that duplicates a part of its functionality.
> Why put an additional hassle on users of desktop.el with more configuration?

What's the point of having two completely different ways of doing exactly 
the same thing? This is confusing. ISn't there some way to resolve that?

-- 
http://rrt.sc3d.org/ | sane, a.  not unnerved by children

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

* Re: desktop.el: autosave?
  2007-12-10 23:55                             ` Juri Linkov
@ 2007-12-11  0:10                               ` Reuben Thomas
  2007-12-11  0:23                                 ` Juri Linkov
  0 siblings, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2007-12-11  0:10 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, emacs-devel

On Tue, 11 Dec 2007, Juri Linkov wrote:

>> 1. A customizable preference, desktop-auto-save, which indicates whether
>> desktop-save-in-desktop-dir should be added to auto-save-hook or not. Is
>> the easiest way to do this to add a private function that desktop mode
>> always adds to auto-save-hook and then have that private function test
>> a boolean which is itself the customizable preference when it runs, to see
>> whether to proceed or not?
>
> No need for a separate function.  You could just change desktop-save-mode
> as follows:
>
> (define-minor-mode desktop-save-mode
>  :global t
>  :group 'desktop
>  (if desktop-save-mode
>      (if desktop-auto-save
> 	  (add-hook 'auto-save-hook 'desktop-save-in-desktop-dir))
>    (remove-hook 'auto-save-hook 'desktop-save-in-desktop-dir)))

Is that how other similar features work? If you change the desktop-auto-save 
preference while desktop-save-mode is active, it won't actually stop saving.

> But please note that I still think it would be better to use a timer. You 
> can look in savehist.el that it uses a separate non-idle timer. It seems 
> reasonable to do the same in desktop.el.

Fair enough.

-- 
http://rrt.sc3d.org/ | traddutore, v.t.  traditore (Anon)

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

* Re: desktop.el: autosave?
  2007-12-11  0:10                               ` Reuben Thomas
@ 2007-12-11  0:23                                 ` Juri Linkov
  2007-12-11  0:42                                   ` Reuben Thomas
  0 siblings, 1 reply; 57+ messages in thread
From: Juri Linkov @ 2007-12-11  0:23 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: tomas, emacs-devel

>>> 1. A customizable preference, desktop-auto-save, which indicates whether
>>> desktop-save-in-desktop-dir should be added to auto-save-hook or not. Is
>>> the easiest way to do this to add a private function that desktop mode
>>> always adds to auto-save-hook and then have that private function test
>>> a boolean which is itself the customizable preference when it runs, to see
>>> whether to proceed or not?
>>
>> No need for a separate function.  You could just change desktop-save-mode
>> as follows:
>>
>> (define-minor-mode desktop-save-mode
>>  :global t
>>  :group 'desktop
>>  (if desktop-save-mode
>>      (if desktop-auto-save
>> 	  (add-hook 'auto-save-hook 'desktop-save-in-desktop-dir))
>>    (remove-hook 'auto-save-hook 'desktop-save-in-desktop-dir)))
>
> Is that how other similar features work? If you change the
> desktop-auto-save preference while desktop-save-mode is active, it won't
> actually stop saving.

This is how other modes work: when you want a configuration change to
take effect, you should disable and re-enable this mode.

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-11  0:02                                   ` Reuben Thomas
@ 2007-12-11  0:23                                     ` Juri Linkov
  2007-12-11  0:48                                       ` Reuben Thomas
  2007-12-11 19:01                                       ` Richard Stallman
  0 siblings, 2 replies; 57+ messages in thread
From: Juri Linkov @ 2007-12-11  0:23 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: tomas, drew.adams, emacs-devel

> On Tue, 11 Dec 2007, Juri Linkov wrote:
>
>> There is no sense to remove history saving from desktop.el if there
>> happens to exist a package that duplicates a part of its functionality.
>> Why put an additional hassle on users of desktop.el with more configuration?
>
> What's the point of having two completely different ways of doing exactly
> the same thing? This is confusing. ISn't there some way to resolve that?

There are many packages in Emacs that have similar functionality.
But there are no problems with that.  Every package has its own users.

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-11  0:23                                 ` Juri Linkov
@ 2007-12-11  0:42                                   ` Reuben Thomas
  2013-04-10  1:36                                     ` Reuben Thomas
  0 siblings, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2007-12-11  0:42 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, emacs-devel

On Tue, 11 Dec 2007, Juri Linkov wrote:

> This is how other modes work: when you want a configuration change to
> take effect, you should disable and re-enable this mode.

Fair enough, then.

-- 
http://rrt.sc3d.org/
C++, n.  an octopus made by nailing extra legs onto a dog (Anon)

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

* Re: desktop.el: autosave?
  2007-12-11  0:23                                     ` Juri Linkov
@ 2007-12-11  0:48                                       ` Reuben Thomas
  2007-12-11 19:01                                       ` Richard Stallman
  1 sibling, 0 replies; 57+ messages in thread
From: Reuben Thomas @ 2007-12-11  0:48 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, drew.adams, emacs-devel

On Tue, 11 Dec 2007, Juri Linkov wrote:

>> On Tue, 11 Dec 2007, Juri Linkov wrote:
>>
>>> There is no sense to remove history saving from desktop.el if there
>>> happens to exist a package that duplicates a part of its functionality.
>>> Why put an additional hassle on users of desktop.el with more configuration?
>>
>> What's the point of having two completely different ways of doing exactly
>> the same thing? This is confusing. ISn't there some way to resolve that?
>
> There are many packages in Emacs that have similar functionality.
> But there are no problems with that.  Every package has its own users.

This is a different question from the rest, but it seems that here (and in 
other places, doubtless) there is the opportunity to reduce duplication and 
make Emacs simpler for everyone to understand. Sometimes, there is an 
obvious reason for having two packages that perform a similar task, as for 
example with different modes for editing the same language that have a 
different approach. In other cases, there's little obvious reason, the 
reason seems to be mainly historical, and if duplicate functionality can be 
merged then we make Emacs better for everyone.

Or is the general attitude that once a feature gets into Emacs, then it 
should stay there to avoid annoying users who rely on it? I understand this 
too, but I think it's a pity if it becomes a reason never to remove 
anything.

-- 
http://rrt.sc3d.org/ | Enlightenment is understanding becoming belief

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

* Re: desktop.el: autosave?
  2007-12-11  0:23                                     ` Juri Linkov
  2007-12-11  0:48                                       ` Reuben Thomas
@ 2007-12-11 19:01                                       ` Richard Stallman
  2007-12-12  0:50                                         ` Reuben Thomas
  1 sibling, 1 reply; 57+ messages in thread
From: Richard Stallman @ 2007-12-11 19:01 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, emacs-devel, drew.adams, rrt

    There are many packages in Emacs that have similar functionality.
    But there are no problems with that.  Every package has its own users.

Actually I wish we had fewer duplicate packages.  They are added complexity.

When duplications have existed for a long time we don't have to get
rid of the duplicates, but I would like to make one of them clearly
superior, so it can be the only one we recommend.

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

* Re: desktop.el: autosave?
  2007-12-11 19:01                                       ` Richard Stallman
@ 2007-12-12  0:50                                         ` Reuben Thomas
  2007-12-12 22:53                                           ` Richard Stallman
  0 siblings, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2007-12-12  0:50 UTC (permalink / raw)
  To: Richard Stallman; +Cc: Juri Linkov, tomas, drew.adams, emacs-devel

On Tue, 11 Dec 2007, Richard Stallman wrote:

>    There are many packages in Emacs that have similar functionality.
>    But there are no problems with that.  Every package has its own users.
>
> Actually I wish we had fewer duplicate packages.  They are added complexity.
>
> When duplications have existed for a long time we don't have to get
> rid of the duplicates, but I would like to make one of them clearly
> superior, so it can be the only one we recommend.

So what do you think about this case? Presumably one of desktop and 
savehist-mode should be marked as the preferred way of saving history.

-- 
http://rrt.sc3d.org/ | poetry, n.  platitude made obscure

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

* Re: desktop.el: autosave?
  2007-12-12  0:50                                         ` Reuben Thomas
@ 2007-12-12 22:53                                           ` Richard Stallman
  2007-12-12 23:59                                             ` Juri Linkov
  0 siblings, 1 reply; 57+ messages in thread
From: Richard Stallman @ 2007-12-12 22:53 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: juri, tomas, drew.adams, emacs-devel

    So what do you think about this case? Presumably one of desktop and 
    savehist-mode should be marked as the preferred way of saving history.

Looking at desktop.el I don't think it saves minibuffer history
variables.  I can't find any code that would do so.  It seems that
desktop.el and savehist.el are complementary, not duplicates at all.

Where did the idea come from that desktop.el saves minibuffer history?


The real duplicates in that area are saveplace.el and desktop.el.

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

* Re: desktop.el: autosave?
  2007-12-12 22:53                                           ` Richard Stallman
@ 2007-12-12 23:59                                             ` Juri Linkov
  2007-12-14 10:10                                               ` Richard Stallman
  0 siblings, 1 reply; 57+ messages in thread
From: Juri Linkov @ 2007-12-12 23:59 UTC (permalink / raw)
  To: rms; +Cc: tomas, emacs-devel, drew.adams, Reuben Thomas

>     So what do you think about this case? Presumably one of desktop and
>     savehist-mode should be marked as the preferred way of saving history.
>
> Looking at desktop.el I don't think it saves minibuffer history
> variables.  I can't find any code that would do so.  It seems that
> desktop.el and savehist.el are complementary, not duplicates at all.
>
> Where did the idea come from that desktop.el saves minibuffer history?

desktop.el allows saving any global variable listed in the option
`desktop-globals-to-save'.  I use it to save history lists in addition
to the default global variables in this list.

> The real duplicates in that area are saveplace.el and desktop.el.

desktop.el saves file positions restored once the whole desktop is restored
while positions stored by saveplace.el get restored on every file visit.

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: desktop.el: autosave?
  2007-12-12 23:59                                             ` Juri Linkov
@ 2007-12-14 10:10                                               ` Richard Stallman
  0 siblings, 0 replies; 57+ messages in thread
From: Richard Stallman @ 2007-12-14 10:10 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, emacs-devel, drew.adams, rrt

    > Where did the idea come from that desktop.el saves minibuffer history?

    desktop.el allows saving any global variable listed in the option
    `desktop-globals-to-save'.  I use it to save history lists in addition
    to the default global variables in this list.

Yes, you could use it for that, but desktop doesn't have a feature which
actually duplicates savehist.

    > The real duplicates in that area are saveplace.el and desktop.el.

    desktop.el saves file positions restored once the whole desktop is restored
    while positions stored by saveplace.el get restored on every file visit.

I see.  It would be nice to document that contrast in both files.
Could you do that?

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

* Re: desktop.el: autosave?
  2007-12-11  0:42                                   ` Reuben Thomas
@ 2013-04-10  1:36                                     ` Reuben Thomas
  2013-04-10  7:05                                       ` Juri Linkov
  0 siblings, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2013-04-10  1:36 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2491 bytes --]

On 11 December 2007 00:42, Reuben Thomas <rrt@sc3d.org> wrote:

> On Tue, 11 Dec 2007, Juri Linkov wrote:
>
>  This is how other modes work: when you want a configuration change to
>> take effect, you should disable and re-enable this mode.
>>
>
> Fair enough, then.


[Some time passed]

I have just revisited this. Nothing much seems to have changed in
desktop.el in the mean time.

I have gathered together what was agreed on earlier in the thread, and
implemented it:

(defun desktop-save-in-desktop-dir (&optional dirname)
  "Save the desktop in directory `desktop-dirname'."
  (interactive
   (list (or desktop-dirname
             (read-directory-name "Directory to save desktop file in: "))))
  (when (and (null dirname) desktop-dirname)
    (setq dirname desktop-dirname))
  (when dirname
    (desktop-save dirname)
    (when (called-interactively-p 'interactive)
        (message "Desktop saved in %s" (abbreviate-file-name dirname)))))

(defun desktop-owner-save-in-desktop-dir ()
  "Save the desktop if we are its owner."
  (if (eq (desktop-owner) (emacs-pid))
      (desktop-save-in-desktop-dir)))

(define-minor-mode desktop-save-mode
  "Toggle desktop saving (Desktop Save mode).
With a prefix argument ARG, enable Desktop Save mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
the mode if ARG is omitted or nil.

If Desktop Save mode is enabled, the state of Emacs is saved from
one session to another.  See variable `desktop-save' and function
`desktop-read' for details."
  :global t
  :group 'desktop
  (if desktop-save-mode
      (if desktop-auto-save
          (add-hook 'auto-save-hook 'desktop-owner-save-in-desktop-dir))
    (remove-hook 'auto-save-hook 'desktop-owner-save-in-desktop-dir)))

Remaining issues:

1. Here I have added the function desktop-owner-save-in-desktop-dir which
only saves the desktop if the current process owns it.

2. There was some discussion over whether by default we should use a
separate timer or auto-save-hook. For now I've used the latter.

3. It was desired to save the desktop only when it changed. Juri Linkov
previously said "This is easy to do once we will decide what auto-saving
method to use", so, since I don't know how to do it anyway, and since the
auto-saving method is not yet decided, I didn't implement that yet.

I've been happily using essentially the above code (mostly Juri's, with a
handful of lines by me) since this thread went quiet over five years ago.

-- 
http://rrt.sc3d.org

[-- Attachment #2: Type: text/html, Size: 3481 bytes --]

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

* Re: desktop.el: autosave?
  2013-04-10  1:36                                     ` Reuben Thomas
@ 2013-04-10  7:05                                       ` Juri Linkov
  2013-04-10 10:57                                         ` Reuben Thomas
  0 siblings, 1 reply; 57+ messages in thread
From: Juri Linkov @ 2013-04-10  7:05 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: tomas, emacs-devel

> I've been happily using essentially the above code (mostly Juri's, with a
> handful of lines by me) since this thread went quiet over five years ago.

The problem is that the time interval to run auto-save-hook is
not configurable exclusively for desktop mode.  If a user wants
to auto-save the desktop less often than to auto-save files
there is no way to do this.

OTOH, I like the simplicity of the auto-saving feature in savehist
that uses just one option `savehist-autosave-interval' to configure the
interval between autosaves, or nil to disable timer-based auto-saving.

Savehist uses `run-with-timer'.  Why not to do the same in desktop mode?
What are the problems with using `run-with-timer'?



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

* Re: desktop.el: autosave?
  2013-04-10  7:05                                       ` Juri Linkov
@ 2013-04-10 10:57                                         ` Reuben Thomas
  2013-04-11  8:29                                           ` Juri Linkov
  0 siblings, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2013-04-10 10:57 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 967 bytes --]

On 10 April 2013 08:05, Juri Linkov <juri@jurta.org> wrote:

> > I've been happily using essentially the above code (mostly Juri's, with a
> > handful of lines by me) since this thread went quiet over five years ago.
>
> The problem is that the time interval to run auto-save-hook is
> not configurable exclusively for desktop mode.  If a user wants
> to auto-save the desktop less often than to auto-save files
> there is no way to do this.
>
> OTOH, I like the simplicity of the auto-saving feature in savehist
> that uses just one option `savehist-autosave-interval' to configure the
> interval between autosaves, or nil to disable timer-based auto-saving.
>
> Savehist uses `run-with-timer'.  Why not to do the same in desktop mode?
> What are the problems with using `run-with-timer'?
>

I don't think anyone had a problem with run-with-timer (I just skimmed back
through the thread to check), so go ahead and change my patch to use it.

-- 
http://rrt.sc3d.org

[-- Attachment #2: Type: text/html, Size: 1477 bytes --]

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

* Re: desktop.el: autosave?
  2013-04-10 10:57                                         ` Reuben Thomas
@ 2013-04-11  8:29                                           ` Juri Linkov
  2013-04-11 11:04                                             ` Reuben Thomas
  0 siblings, 1 reply; 57+ messages in thread
From: Juri Linkov @ 2013-04-11  8:29 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: tomas, emacs-devel

> I don't think anyone had a problem with run-with-timer (I just skimmed back
> through the thread to check), so go ahead and change my patch to use it.

In the patch below a new option is `desktop-auto-save-timeout' instead
of `desktop-auto-save-interval' because it should be more like
`auto-save-timeout' instead of `auto-save-interval'.

`auto-save-timeout' is the number of seconds between auto-saves, but
`auto-save-interval' is the number of characters typed between auto-saves.
In terms of the desktop, an interval would rather mean a number of changes
in the buffer list or something like that.  I'm not sure whether this is
useful, so the following patch implements only timer-based auto-saving:

=== modified file 'lisp/desktop.el'
--- lisp/desktop.el	2013-01-02 16:13:04 +0000
+++ lisp/desktop.el	2013-04-11 08:28:14 +0000
@@ -189,6 +189,17 @@ (defcustom desktop-save 'ask-if-new
   :group 'desktop
   :version "22.1")
 
+(defcustom desktop-auto-save-timeout nil
+  "Number of seconds between auto-saves of the desktop.
+Zero or nil means disable timer-based auto-saving."
+  :type '(choice (const :tag "Off" nil)
+                 (integer :tag "Seconds"))
+  :set (lambda (symbol value)
+         (set-default symbol value)
+         (desktop-auto-save-update))
+  :group 'desktop
+  :version "24.4")
+
 (defcustom desktop-load-locked-desktop 'ask
   "Specifies whether the desktop should be loaded if locked.
 Possible values are:
@@ -539,6 +550,10 @@ (defconst desktop-header
 (defvar desktop-delay-hook nil
   "Hooks run after all buffers are loaded; intended for internal use.")
 
+(defvar desktop-file-checksum nil
+  "Checksum of the last auto-saved contents of the desktop file.
+Used to avoid writing contents unchanged between auto-saves.")
+
 ;; ----------------------------------------------------------------------------
 ;; Desktop file conflict detection
 (defvar desktop-file-modtime nil
@@ -854,11 +869,12 @@ (defun desktop-file-name (filename dirna
 
 ;; ----------------------------------------------------------------------------
 ;;;###autoload
-(defun desktop-save (dirname &optional release)
+(defun desktop-save (dirname &optional release auto-save)
   "Save the desktop in a desktop file.
 Parameter DIRNAME specifies where to save the desktop file.
 Optional parameter RELEASE says whether we're done with this desktop.
-See also `desktop-base-file-name'."
+If AUTO-SAVE is non-nil, compare the saved contents to the one last saved,
+and don't save the buffer if they are the same."
   (interactive "DDirectory to save desktop file in: ")
   (setq desktop-dirname (file-name-as-directory (expand-file-name dirname)))
   (save-excursion
@@ -918,10 +934,17 @@ (defun desktop-save (dirname &optional r
 		(insert ")\n\n"))))
 
 	  (setq default-directory desktop-dirname)
-	  (let ((coding-system-for-write 'emacs-mule))
-	    (write-region (point-min) (point-max) (desktop-full-file-name) nil 'nomessage))
-	  ;; We remember when it was modified (which is presumably just now).
-	  (setq desktop-file-modtime (nth 5 (file-attributes (desktop-full-file-name)))))))))
+	  ;; If auto-saving, avoid writing if nothing has changed since the last write.
+	  ;; Don't check 300 characters of the header that contains the timestamp.
+	  (let ((checksum (and auto-save (md5 (current-buffer)
+					      (+ 300 (point-min)) (point-max)
+					      'emacs-mule))))
+	    (unless (and auto-save (equal checksum desktop-file-checksum))
+	      (let ((coding-system-for-write 'emacs-mule))
+		(write-region (point-min) (point-max) (desktop-full-file-name) nil 'nomessage))
+	      (setq desktop-file-checksum checksum)
+	      ;; We remember when it was modified (which is presumably just now).
+	      (setq desktop-file-modtime (nth 5 (file-attributes (desktop-full-file-name)))))))))))
 
 ;; ----------------------------------------------------------------------------
 ;;;###autoload
@@ -1075,6 +1098,37 @@ (defun desktop-save-in-desktop-dir ()
   (message "Desktop saved in %s" (abbreviate-file-name desktop-dirname)))
 
 ;; ----------------------------------------------------------------------------
+;; Auto-Saving.
+(defvar desktop-auto-save-timer nil)
+
+(defun desktop-auto-save ()
+  "Save the desktop periodically.
+Called by the timer created in `desktop-auto-save-update'."
+  (when (and desktop-save-mode
+	     (integerp desktop-auto-save-timeout)
+	     (> desktop-auto-save-timeout 0)
+	     ;; Avoid desktop saving during lazy loading.
+	     (not desktop-lazy-timer)
+	     ;; Save only to own desktop file.
+	     (eq (emacs-pid) (desktop-owner))
+	     desktop-dirname)
+    (desktop-save desktop-dirname nil t))
+  (desktop-auto-save-update))
+
+(defun desktop-auto-save-update ()
+  "Update the timer for next auto-saving.
+Cancel the previous timer and run a new timer when the number
+of seconds between auto-saves is a positive integer."
+  (when desktop-auto-save-timer
+    (cancel-timer desktop-auto-save-timer)
+    (setq desktop-auto-save-timer nil))
+  (when (and (integerp desktop-auto-save-timeout)
+	     (> desktop-auto-save-timeout 0))
+    (setq desktop-auto-save-timer
+	  (run-with-timer desktop-auto-save-timeout nil
+			  'desktop-auto-save))))
+
+;; ----------------------------------------------------------------------------
 ;;;###autoload
 (defun desktop-revert ()
   "Revert to the last loaded desktop."
@@ -1327,6 +1381,7 @@ (add-hook 'after-init-hook
         (setq desktop-save-mode nil)))
     (when desktop-save-mode
       (desktop-read)
+      (desktop-auto-save-update)
       (setq inhibit-startup-screen t))))
 
 (provide 'desktop)




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

* Re: desktop.el: autosave?
  2013-04-11  8:29                                           ` Juri Linkov
@ 2013-04-11 11:04                                             ` Reuben Thomas
  2013-04-27 20:57                                               ` Juri Linkov
  0 siblings, 1 reply; 57+ messages in thread
From: Reuben Thomas @ 2013-04-11 11:04 UTC (permalink / raw)
  To: Juri Linkov; +Cc: tomas, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 853 bytes --]

On 11 April 2013 09:29, Juri Linkov <juri@jurta.org> wrote:

> Update the timer for next auto-saving.
>
Cancel the previous timer and run a new timer when the number
> of seconds between auto-saves is a positive integer.
>

Thanks very much! The only thing I would say is that to a mathmetician the
above docstring sounds as though the new timer will be run when the number
of seconds between auto-saves is *any* positive integer, wheras presumably
you mean that the argument should be a positive integer. Further, it sounds
as though the timer will not be cancelled if the number of seconds between
auto-saves is not a positive integer. I suggest:

Reset the auto-save timer.
Cancel any previous timer. When `desktop-auto-save-timeout' is a positive
integer, start a new timer to call `desktop-auto-save' in that many seconds.

-- 
http://rrt.sc3d.org

[-- Attachment #2: Type: text/html, Size: 1498 bytes --]

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

* Re: desktop.el: autosave?
  2013-04-11 11:04                                             ` Reuben Thomas
@ 2013-04-27 20:57                                               ` Juri Linkov
  0 siblings, 0 replies; 57+ messages in thread
From: Juri Linkov @ 2013-04-27 20:57 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: tomas, emacs-devel

> I suggest:
>
> Reset the auto-save timer.
> Cancel any previous timer. When `desktop-auto-save-timeout' is a positive
> integer, start a new timer to call `desktop-auto-save' in that many seconds.

Thanks, your docstring is much better.

After testing for some more time I see no problems with `run-with-timer'.
If someone will find it problematic then another option could be added
with a name like `desktop-auto-save-idle-timeout' to use `run-with-idle-timer'
in addition to `run-with-timer'.



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

end of thread, other threads:[~2013-04-27 20:57 UTC | newest]

Thread overview: 57+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-30 14:08 desktop.el: autosave? Reuben Thomas
2007-11-30 23:35 ` Richard Stallman
2007-12-01  0:35   ` Juri Linkov
2007-12-01 23:41     ` Richard Stallman
2007-12-03 22:57       ` Juri Linkov
2007-12-04  7:39         ` martin rudalics
2007-12-05  2:57           ` Richard Stallman
2007-12-05  9:02             ` martin rudalics
2007-12-05 22:28               ` Juri Linkov
2007-12-05 23:09                 ` martin rudalics
2007-12-05 23:41                   ` Juri Linkov
2007-12-06 15:12                     ` Richard Stallman
2007-12-06  2:11               ` Richard Stallman
2007-12-06 23:29                 ` Juri Linkov
2007-12-04 16:55         ` Richard Stallman
2007-12-06 14:58         ` Reuben Thomas
2007-12-06 15:38           ` tomas
2007-12-06 15:47             ` Reuben Thomas
2007-12-06 23:28               ` Juri Linkov
2007-12-06 23:44                 ` Reuben Thomas
2007-12-07  0:03                   ` Juri Linkov
2007-12-07  2:48                     ` Stefan Monnier
2007-12-09 20:35                     ` Reuben Thomas
2007-12-10  0:27                       ` Juri Linkov
2007-12-10  0:35                         ` Reuben Thomas
2007-12-10  0:50                           ` Drew Adams
2007-12-10  0:59                           ` Juri Linkov
2007-12-10  1:10                             ` Reuben Thomas
2007-12-10  3:03                         ` Stefan Monnier
2007-12-10 22:01                           ` Reuben Thomas
2007-12-10 23:55                             ` Juri Linkov
2007-12-11  0:10                               ` Reuben Thomas
2007-12-11  0:23                                 ` Juri Linkov
2007-12-11  0:42                                   ` Reuben Thomas
2013-04-10  1:36                                     ` Reuben Thomas
2013-04-10  7:05                                       ` Juri Linkov
2013-04-10 10:57                                         ` Reuben Thomas
2013-04-11  8:29                                           ` Juri Linkov
2013-04-11 11:04                                             ` Reuben Thomas
2013-04-27 20:57                                               ` Juri Linkov
2007-12-10 22:02                           ` Reuben Thomas
2007-12-10 22:12                             ` Drew Adams
2007-12-10 22:16                               ` Reuben Thomas
2007-12-10 23:57                                 ` Juri Linkov
2007-12-11  0:02                                   ` Reuben Thomas
2007-12-11  0:23                                     ` Juri Linkov
2007-12-11  0:48                                       ` Reuben Thomas
2007-12-11 19:01                                       ` Richard Stallman
2007-12-12  0:50                                         ` Reuben Thomas
2007-12-12 22:53                                           ` Richard Stallman
2007-12-12 23:59                                             ` Juri Linkov
2007-12-14 10:10                                               ` Richard Stallman
2007-12-07  2:47                 ` Stefan Monnier
2007-12-07 17:18             ` Richard Stallman
2007-12-03 21:14     ` Reuben Thomas
2007-12-03 22:57       ` Juri Linkov
2007-12-06 14:56         ` Reuben Thomas

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.