Subject: bug#33005: 27.0.50; Data loss with Gnus registry

From: Michael Heerdegen <[email-masked]>
Date: Sun, 15 Dec 2019 18:07:00 +0100

Eric Abrahamsen <[email-masked]> writes:

> > #+begin_src emacs-lisp
> > (setf (alist-get (regexp-quote ".gnus.registry.eieio") file-name-handler-alist)
> >       (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))))
> >         (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
>
> Huh. Seems like a fair amount of work, but it's certainly low level!
> Nice to have it integrated into all of Emacs' regular save-file
> mechanisms.

Caveat: if anybody wants to use this: please specify a `testfn' argument
(e.g. `equal') of `alist-get' to prevent repeated pushing to
`file-name-handler-alist' when the code is loaded repeatedly (which is
the case for the gnus init file AFAIK).

Michael.