From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Reuben Thomas Newsgroups: gmane.emacs.devel Subject: Re: desktop.el: autosave? Date: Wed, 10 Apr 2013 02:36:35 +0100 Message-ID: References: <8763zjfe0v.fsf@jurta.org> <87mysridxt.fsf@jurta.org> <20071206153806.GA20731@www.trapp.net> <87d4tjbh0g.fsf@jurta.org> <87abon5q1f.fsf@jurta.org> <87lk835rb7.fsf@jurta.org> <87ejdu6rna.fsf@jurta.org> <87mysi3wx7.fsf@jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=bcaec5524516516a7804d9f7b353 X-Trace: ger.gmane.org 1365557809 26493 80.91.229.3 (10 Apr 2013 01:36:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 10 Apr 2013 01:36:49 +0000 (UTC) Cc: tomas@tuxteam.de, emacs-devel@gnu.org To: Juri Linkov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 10 03:36:53 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UPjy0-0008K4-7g for ged-emacs-devel@m.gmane.org; Wed, 10 Apr 2013 03:36:52 +0200 Original-Received: from localhost ([::1]:58679 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPjxz-000216-Pp for ged-emacs-devel@m.gmane.org; Tue, 09 Apr 2013 21:36:51 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:50460) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UPjxs-00020y-Eg for emacs-devel@gnu.org; Tue, 09 Apr 2013 21:36:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UPjxo-0001mk-Cu for emacs-devel@gnu.org; Tue, 09 Apr 2013 21:36:44 -0400 Original-Received: from exprod7og114.obsmtp.com ([64.18.2.215]:51013) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1UPjxo-0001mJ-1l for emacs-devel@gnu.org; Tue, 09 Apr 2013 21:36:40 -0400 Original-Received: from mail-we0-f197.google.com ([74.125.82.197]) (using TLSv1) by exprod7ob114.postini.com ([64.18.6.12]) with SMTP ID DSNKUWTCJCks/pu9XKfCzIxhlrZYZLtft7aP@postini.com; Tue, 09 Apr 2013 18:36:39 PDT Original-Received: by mail-we0-f197.google.com with SMTP id p43so9642302wea.0 for ; Tue, 09 Apr 2013 18:36:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-received:in-reply-to:references:date :message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=OuPVvg/83dB/O62HknmoezYKU7PaeEB43z6gZpnrp3U=; b=mucX8EJyla9AeKaE00qxEzpNz1cbw1kxq60+XpEb3k5W/maaBMOXwbCbcE4vsl79+8 m9jMBQwKGb6DvcL6be8MhXh92rA8MiyEgsWODrjDrJrzTMta23ZimVG7SzX/jFeSFPgV 4nlZwWEn+bTB/jSLrEvQBWdvPXFsZmuYdO3di8sFeZ7FY8W1DR8Wdfs+NGT3yPdo7OcQ ccznnftTar93T/ZjNBcc/6FSVv9+3VRudl0yGhNeBe2R+FPB0WSZN3axaj3YweH4ESU3 a+8NDKY95ZaAwNAozAbfWkkdlnYBJctlQffRf035dhtOb+JS8b5ylfj3/UIo8TpZBcHI FHEg== X-Received: by 10.152.45.140 with SMTP id n12mr15260127lam.36.1365557795623; Tue, 09 Apr 2013 18:36:35 -0700 (PDT) X-Received: by 10.152.45.140 with SMTP id n12mr15260121lam.36.1365557795442; Tue, 09 Apr 2013 18:36:35 -0700 (PDT) Original-Received: by 10.152.5.40 with HTTP; Tue, 9 Apr 2013 18:36:35 -0700 (PDT) In-Reply-To: X-Gm-Message-State: ALoCoQnLSrZoWJy731UapBtzs3l6eHFLlB1G98zI6Ne5QVsruBuNSLnhEtgweSbhwmyJE4YyTK6uxsU86lScTwWTQo8C2x6draJSYIgyBTYI42QX0P3sF4Wp7JfaxIfxW1qvJo9/LLWXhAocTjJFkh/7EiPmEgGeJg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 64.18.2.215 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:158816 Archived-At: --bcaec5524516516a7804d9f7b353 Content-Type: text/plain; charset=ISO-8859-1 On 11 December 2007 00:42, Reuben Thomas 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 --bcaec5524516516a7804d9f7b353 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
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 th= e mean time.

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

(defun desktop-save-in-desktop-dir (&= optional dirname)
=A0 "Save the desktop in directory `desktop-dirna= me'."
=A0 (interactive
=A0=A0 (list (or desktop-dirname
=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 (read-directory-name "Directory to save desktop fil= e in: "))))
=A0 (when (and (null dirname) desktop-dirname)
=A0= =A0=A0 (setq dirname desktop-dirname))
=A0 (when dirname
=A0=A0=A0 (desktop-save dirname)
=A0=A0=A0 (when (c= alled-interactively-p 'interactive)
=A0=A0=A0=A0=A0=A0=A0 (message &= quot;Desktop saved in %s" (abbreviate-file-name dirname)))))

(d= efun desktop-owner-save-in-desktop-dir ()
=A0 "Save the desktop if we are its owner."
<= div>=A0 (if (eq (desktop-owner) (emacs-pid))
=A0=A0=A0=A0=A0 (desktop-sa= ve-in-desktop-dir)))

(define-minor-mode desktop-save-mode
=A0 &qu= ot;Toggle desktop saving (Desktop Save mode).
With a prefix argument ARG, enable Desktop Save mode if ARG is
positive,= and disable it otherwise.=A0 If called from Lisp, enable
the mode if AR= G is omitted or nil.

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

Remaining issues:

1. Here I h= ave added the function desktop-owner-save-in-desktop-dir which only saves t= he desktop if the current process owns it.

2. There was some discussion over whether by default we shou= ld 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 chan= ged. Juri Linkov previously said "This is easy to do once we will deci= de 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&#= 39;t implement that yet.

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

--
http://rrt.sc3d.org
--bcaec5524516516a7804d9f7b353--