help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing name format for backup files


From: Alex Kost
Subject: Re: Changing name format for backup files
Date: Fri, 15 Jan 2016 12:53:29 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Nick Helm (2016-01-15 07:53 +0300) wrote:

>> When I was messing with backing up, I also noticed this thing.  So what
>> I did is: I just replaced `make-backup-file-name-1' with my own
>> `utl-make-backup-file-name-1' function¹ that does what I need:
>>
>>   (advice-add 'make-backup-file-name-1
>>     :override 'utl-make-backup-file-name-1)
>>
>> I didn't follow this thread closely, so I'm sorry if this reply is useless.
>
> Ok, this is a good excuse to learn to use advice. This is what I tried:
>
>    (defun nick-add-prefix-dot (file)
>       "Inject a prefix dot into file name FILE."
>       (concat (file-name-directory file) "." (file-name-nondirectory file)))
>
>    (defun nick-auto-save-file-name-p (file)
>        "Return non-nil if FILE is an auto-save file name."
>        (string-match "\\`\\.#.*#\\'" file))
>
>    (advice-add 'make-backup-file-name-1 :filter-return #'nick-add-prefix-dot)
>    (advice-add 'make-auto-save-file-name :filter-return #'nick-add-prefix-dot)
>    (advice-add 'auto-save-file-name-p :override #'nick-auto-save-file-name-p)
>
> Which seems to work well. I don't think `backup-file-name-p' doesn't
> need override advice in this case as it only checks that files end with ~.

Oh great, I didn't notice :filter-return before.  It can be very useful, thanks!

-- 
Alex



reply via email to

[Prev in Thread] Current Thread [Next in Thread]