From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.devel Subject: [PATCH] Reimplement auto-saving to visited files Date: Sat, 29 Apr 2017 20:49:09 +0200 Message-ID: <20170429184909.40204-1-phst@google.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1493491786 14429 195.159.176.226 (29 Apr 2017 18:49:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 29 Apr 2017 18:49:46 +0000 (UTC) Cc: Philipp Stephani To: eliz@gnu.org, emacs-devel@gnu.org, 25478@debbugs.gnu.org, rgm@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Apr 29 20:49:41 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d4XR6-0003cZ-Fi for ged-emacs-devel@m.gmane.org; Sat, 29 Apr 2017 20:49:40 +0200 Original-Received: from localhost ([::1]:42011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4XRC-0003IL-97 for ged-emacs-devel@m.gmane.org; Sat, 29 Apr 2017 14:49:46 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55581) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4XR4-0003IC-06 for emacs-devel@gnu.org; Sat, 29 Apr 2017 14:49:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4XQy-0000MS-8C for emacs-devel@gnu.org; Sat, 29 Apr 2017 14:49:33 -0400 Original-Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:33149) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d4XQr-0000KU-3w; Sat, 29 Apr 2017 14:49:25 -0400 Original-Received: by mail-wm0-x231.google.com with SMTP id n198so2820301wmg.0; Sat, 29 Apr 2017 11:49:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BWoHug3OsCXR1dWsh5QjuPhH6/ncB+wxTisWvDMEDHs=; b=DrZ23E/E0IKr4Xfcw9sCxSr7iUT0cHt6YPMKIAee0L+K1jI0gLI6xjyk2gZ3AZHwR+ eGIzfHw+MW9rdGnUEJOLXOkJ0iQ+C578DXMLKAggPwNvBlmiCwV5joypR28Gcb3/XrbW ItymXlQodcfwEf1RTM5vkX1aBMLjN/QYNdl8yEzUT1+UhO08r8VLPnAieDGWGCDU0mWx MUrX3Mx27EUW6WFoN8d4jEDYgQnPZuSS5jp0c4aXkadmXqu6MDFpFYE9l4L2oXV357tk RHq2b8kRmlv66nVc4/RyLnmIjHmVBK6HcRsqx9y42Aeow9q3EW4a/Eb/6Pc4KMyc0lGG ANSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BWoHug3OsCXR1dWsh5QjuPhH6/ncB+wxTisWvDMEDHs=; b=gX8/LH4CR3MRBpUU8H2dhf3LiIDMvON6rCopaya2IpAPYsilFmCsBuO4vScim+II25 Ru8QV/aksZQDo7cBjuLWeEDbYTr9aVDpqN2iZx3NepTMw9Ik+uONRtFdOA1oou6mCyUD ZNaDVa5S4N1YwIish1cr+DMTn+3CFrEwl+7ZEcyP2Xa6T92z5myQPR3CCqGKOd9+RCR+ 5AlDwW0JGvcFJGB1N54JlbKzrYYtDBTFFy+KR7zk+3ff4cmA3AJTA/Hk3vqrM640nROV v9QDhw1oga2jNkcpD30DA9cj6BePl7tXKCtOUdlnHApgzPkizimaVfcD2q+st6vYrVsu OHAA== X-Gm-Message-State: AN3rC/5fCMC7FECfPn7W0WrgZEpFDV70tI3CeuzcKaCCSAsV8iYqFwmo c1IMoVU0PAwymw== X-Received: by 10.28.48.11 with SMTP id w11mr2020193wmw.77.1493491763847; Sat, 29 Apr 2017 11:49:23 -0700 (PDT) Original-Received: from p.cm.cablesurf.de (46.128.198.151.dynamic.cablesurf.de. [46.128.198.151]) by smtp.gmail.com with ESMTPSA id j124sm11168428wmg.13.2017.04.29.11.49.22 (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 29 Apr 2017 11:49:23 -0700 (PDT) X-Google-Original-From: Philipp Stephani X-Mailer: git-send-email 2.12.2 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::231 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:214420 Archived-At: This reacts to confusing behavior of 'auto-save-visited-file-name', cf. Bug#25478. * lisp/files.el (auto-save-visited-interval): New customization option. (auto-save-visited-mode): New global minor mode. (auto-save-visited-file-name): Make obsolete. (auto-save--timer): New internal helper variable. * doc/emacs/files.texi (Auto Save Files): Document 'auto-save-visited-mode' instead of obsolete 'auto-save-visited-file-name'. (Auto Save Control): Document customization option 'auto-save-visited-interval'. --- doc/emacs/files.texi | 29 ++++++++++++++++++++++------- etc/NEWS | 6 ++++++ lisp/files.el | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index ed17f66ca2..55eda00d0c 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -1040,14 +1040,23 @@ Auto Save Files this happens, save the buffer with @kbd{C-x C-s}, or use @kbd{C-u 1 M-x auto-save-mode}. -@vindex auto-save-visited-file-name +@vindex auto-save-visited-mode If you want auto-saving to be done in the visited file rather than -in a separate auto-save file, set the variable -@code{auto-save-visited-file-name} to a non-@code{nil} value. In this -mode, auto-saving is very similar to explicit saving. However, -differences still exist, in particular for modes which modify the -buffer-saving process in non-trivial ways via various hooks -(@pxref{Saving Buffers,,, elisp, The Emacs Lisp Reference Manual}). +in a separate auto-save file, enable the global minor mode +@code{auto-save-visited-mode}. In this mode, auto-saving is identical +to explicit saving. Note that this mode is orthogonal to the +@code{auto-save} mode described above; you can enable both at the same +time. However, if @code{auto-save} mode is active in some buffer and +the obsolete @code{auto-save-visited-file-name} variable is set to a +non-@code{nil} value, that buffer won't be affected by +@code{auto-save-visited-mode}. + + You can use the variable @code{auto-save-visited-interval} to +customize the interval between auto-save operations in +@code{auto-save-visited-mode}; by default it's five seconds. +@code{auto-save-interval} and @code{auto-save-timeout} have no effect +on @code{auto-save-visited-mode}. See @xref{Auto Save Control} for +details on these variables. @vindex delete-auto-save-files A buffer's auto-save file is deleted when you save the buffer in its @@ -1091,6 +1100,12 @@ Auto Save Control a while; second, it may avoid some auto-saving while you are actually typing. +@vindex auto-save-visited-interval + When @code{auto-save-visited-mode} is enabled, Emacs will auto-save +file-visiting buffers after five seconds of idle time. You can +customize the variable @code{auto-save-visited-interval} to change the +idle time interval. + Emacs also does auto-saving whenever it gets a fatal error. This includes killing the Emacs job with a shell command such as @samp{kill %emacs}, or disconnecting a phone line or network connection. diff --git a/etc/NEWS b/etc/NEWS index 9d4c72d6dc..173c4e466b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -383,6 +383,12 @@ Strings such as ΌΣΟΣ are now correctly converted to Όσος when capitalized instead of incorrect Όσοσ (compare lowercase sigma at the end of the word). +** Emacs can now auto-save buffers to visited files in a more robust +manner via the new mode 'auto-save-visited-mode'. Unlike +'auto-save-visited-file-name', this mode uses the normal saving +procedure and therefore obeys saving hooks. +'auto-save-visited-file-name' is now obsolete. + * Changes in Specialized Modes and Packages in Emacs 26.1 diff --git a/lisp/files.el b/lisp/files.el index 6848818cad..d3958b5643 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -393,6 +393,46 @@ auto-save-file-name-transforms :initialize 'custom-initialize-delay :version "21.1") +(defvar auto-save--timer nil "Timer for `auto-save-visited-mode'.") + +(defcustom auto-save-visited-interval 5 + "Interval in seconds for `auto-save-visited-mode'. +If `auto-save-visited-mode' is enabled, Emacs will save all +buffers visiting a file to the visited file after it has been +idle for `auto-save-visited-interval' seconds." + :group 'auto-save + :type 'number + :version "26.1" + :set (lambda (symbol value) + (set-default symbol value) + (when auto-save--timer + (timer-set-idle-time auto-save--timer value :repeat)))) + +(define-minor-mode auto-save-visited-mode + "Toggle automatic saving to file-visiting buffers on or off. +With a prefix argument ARG, enable regular saving of all buffers +visiting a file if ARG is positive, and disable it otherwise. +Unlike `auto-save-mode', this mode will auto-save buffer contents +to the visited files directly and will also run all save-related +hooks. See Info node `Saving' for details of the save process. + +If called from Lisp, enable the mode if ARG is omitted or nil, +and toggle it if ARG is `toggle'." + :group 'auto-save + :global t + (when auto-save--timer (kill-timer auto-save--timer)) + (setq auto-save--timer + (when auto-save-visited-mode + (run-with-idle-timer + auto-save-visited-interval :repeat + #'save-some-buffers :no-prompt + (lambda () + (not (and buffer-auto-save-file-name + auto-save-visited-file-name))))))) + +(make-obsolete-variable 'auto-save-visited-file-name 'auto-save-visited-mode + "Emacs 26.1") + (defcustom save-abbrevs t "Non-nil means save word abbrevs too when files are saved. If `silently', don't ask the user before saving." -- 2.12.2