From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.help Subject: Re: backup abbrev_defs Date: Sun, 15 Dec 2019 18:01:50 +0100 Message-ID: <875zihy135.fsf@web.de> References: <87sglnt4jx.fsf@skimble.plus.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="44205"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: Sharon Kimble Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 15 18:04:19 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1igXJZ-000BMk-PP for geh-help-gnu-emacs@m.gmane.org; Sun, 15 Dec 2019 18:04:18 +0100 Original-Received: from localhost ([::1]:41482 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1igXJY-0000wu-Af for geh-help-gnu-emacs@m.gmane.org; Sun, 15 Dec 2019 12:04:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45224) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1igXHO-0008Gt-Rz for help-gnu-emacs@gnu.org; Sun, 15 Dec 2019 12:02:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1igXHN-0006mo-EV for help-gnu-emacs@gnu.org; Sun, 15 Dec 2019 12:02:02 -0500 Original-Received: from mout.web.de ([212.227.17.12]:52493) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1igXHN-0006bd-0G for help-gnu-emacs@gnu.org; Sun, 15 Dec 2019 12:02:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1576429311; bh=E/lwmg2bv8dPjEVVHy+barzeoq00508XlRWCCwRdDM8=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=hOyANqiuahdHloJpWRwKwQeJB0MI1hnx1nR/R9U7gQDl3S6wORUj/YzYqbPcj+PXl LCTk1d/YeLDbZCdKz4iD/YBFo6Y0M+4RTtrgPjQE3URUgF3hgYWiBPiMoQkTr7EFtA Cov1SHeV1cE0C6zQ5f2aMX95Sn/Sc1b5wXOLbVQU= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Original-Received: from drachen.dragon ([94.218.222.9]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LqUXd-1i3Mty17dB-00e4Gp; Sun, 15 Dec 2019 18:01:51 +0100 In-Reply-To: <87sglnt4jx.fsf@skimble.plus.com> (Sharon Kimble's message of "Sat, 14 Dec 2019 13:33:38 +0000") X-Provags-ID: V03:K1:73TiRaI3AvLw727Ss5mkc/urk0r0TQPA0IaPssYw+TnHwkEaskV fEIYXzd+HDeOP4+6zID3oXvqRW8mxV4CnLO5F4mvggtnxdmgH/7qqSJHHPd+Qj2lqwdcpjo cUEnPgd7zLUw68SUTC1P/PxZvzlewX9jHRRqbSUyK20uBOYG90BCSHHaaMTEebHtDyNs4eE GzdM735vJm1s4CqTCZpvg== X-UI-Out-Filterresults: notjunk:1;V03:K0:+/222CGs6IE=:1Zfqa6x7UE6nvG2TnUBqxn 037OGwF2Kvq/ij0MVpCqQ2NGRctjTh1ZsSKbeVSamkZgSHa0jbNC11VSJLBqeBr8YtDgT5LkP EPaW6pqntinbK6vDW5ne/3oxY0Dx+Y5LMpf+otfLL4u4wPUSmVJxBWkfzaJUXahfj+VmGFgWN W+xzc44HpaCDvW9/1o9GpZVkTP+0jtHZ3llZv65/mi0CeBHSbLInBqkITvSRYpdgfDlqfrQw/ K0p62jwj9mWYP4HDVnLswWedF46qrFG+atrKkAr6QKBiaF9BtGzTD2sMyKYLOh3GECkSa5IT2 NanHFqk4UcaoGkEHVHA1TyclcxklkG97oqfa2rCQeB3AHaFf7V86r5vKoRT7BCAFK6nDx9X8r UwoFFBRjPTlYu73NAmUfVHB8vDeuGnhzVOlKobBkn9AJVGV2it7xoVJfcTGdP1QwWWaWIbVjn XRMEh1NuNd8lPRPuSbS8ZajEhW6RDWe4xouPNAKEcCtFUBMb+yDXhQeHhmw03EzdEDjkOao0H lkGOJcXV70qRYdjNhlDnIAuVZRa0gQpF59kQXR0le30BDpiRLPZTTJnTWo74SSAoobetErtIr kZrG38WKFRUsRIqtOsN2pbI1+MYD/xd06EikoR/5xaHr3KK63CYp/ywtZCA7n9BYXnyRtEpXQ UGoXYVSFhOgf0GCUQ9lcquFfHKLPp+PgRhxw1c/d6BiV/EOn2xoLlRfsY7TTYS33Vl4Eoedyz 4u6mVQGXKgfZ7WM72CRJAhN542XPLS1q+8gvWDwIDotk7TcaLgzB7ADE4GRnIqjOgHpEBLhq X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.12 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:122051 Archived-At: Sharon Kimble writes: > How can I backup my abbrev_defs file every time it is changed, just > like any other file in emacs, please? And, logically, to the same > place, my '~/.emacs.d/backups' directory? Recently I had a similar requirement for the Gnus Registry save file. Like `write-abbrev-file' saving is done there with a `write-region' call from within a temporary helper buffer so no backups are created automatically. My solution (canonical I think) was to register a file name handler for that save file and the `write-region` operation. For information about `file-name-handler-alist' see (info "(elisp) Magic File Names") Code: #+begin_src emacs-lisp (setf (alist-get (regexp-quote ".gnus.registry.eieio") file-name-handler-alist nil nil #'equal) (defun my-gnus-registry-save-file-handler (operation &rest args) (pcase-let ((`(,_start ,_end ,filename . ,_rest) args)) (when (eq operation 'write-region) (let ((buffer-backed-up nil) (buffer-file-name filename) (file-precious-flag t) (kept-new-versions 300)) (backup-buffer)))) ;; Invoke original handler (let ((inhibit-file-name-handlers (cons 'my-gnus-registry-save-file-handler inhibit-file-name-handlers)) (inhibit-file-name-operation operation)) (apply operation args)))) #+end_src It should be obvious how to translate it for your file. The backup is created with `backup-buffer' which doesn't refer to the temp buffer but to the file named by `buffer-file-name' (thus the let-binding). Since `backup-buffer' is a high-level function, all your settings concerning backup creation are respected. To control where the backup is created `backup-directory-alist' is consulted - you can also add a binding in the above defun of course. The `kept-new-versions' binding to 300 I use above is only because Gnus registry saving is currently still a bit buggy and I want to force the creation of so many backup files that I can be sure I don't lose anything even if I notice problems after a longer time has passed. I don't know if the above solution is the simplest one btw, it's just the one that came to my mind at first. Michael.