all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Sharon Kimble <boudiccas@skimble.plus.com>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: backup abbrev_defs
Date: Thu, 19 Dec 2019 18:18:40 +0000	[thread overview]
Message-ID: <87woas89hb.fsf@skimble.plus.com> (raw)
In-Reply-To: <875zihy135.fsf@web.de> (Michael Heerdegen's message of "Sun, 15 Dec 2019 18:01:50 +0100")

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

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Sharon Kimble <boudiccas@skimble.plus.com> 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.
>

Thanks for replying Michael.

I've been trying out various things, and I've finally settled on
rewriting my 'abbrev_defs' code, and also backing up my emacs to my
server hourly, as well as with rsnapshot every 3 hours.

My code is now -

#+BEGIN_SRC emacs-lisp
;; turn on abbrev mode globally
(setq-default abbrev-mode t)
(setq save-abbrevs 'silently)
(setq abbrev-file-name "~/.emacs.d/abbrev_defs")
(read-abbrev-file "~/.emacs.d/abbrev_defs")
(abbrev-table-put global-abbrev-table :case-fixed t)
#+END_SRC

I did try adapting your code above but wasn't able to get it to work
successfully, sorry!

Thanks
Sharon.
-- 
A taste of linux = http://www.sharons.org.uk
DrugFacts = https://www.drugfacts.org.uk
Debian 10.1, fluxbox 1.3.7, emacs 26.3, org 9.3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2019-12-19 18:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-14 13:33 backup abbrev_defs Sharon Kimble
2019-12-15 17:01 ` Michael Heerdegen
2019-12-19 18:18   ` Sharon Kimble [this message]
2019-12-19 21:49     ` Michael Heerdegen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87woas89hb.fsf@skimble.plus.com \
    --to=boudiccas@skimble.plus.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=michael_heerdegen@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.