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: Wed, 13 Jan 2016 17:34:10 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Nick Helm (2016-01-13 01:32 +0300) wrote:

>> However, often there are variables that control how some feature works.
>> For your case, those seems to apply:
>>
>> C-h v make-backup-file-name-function
>
> Thanks,
>
> The trouble is, I also use numbered backups and in this case, when I set
> make-backup-file-name-function to a custom function (as described in help), it
> has no effect. For example, if I eval this:
>
>   (defun nick-backup-file-naming-function (file)
>      "Return a backup file name with prefix dot and suffix tilde."
>      (concat (file-name-directory file) "." (file-name-nondirectory file) 
> "~"))
>
>   (setq make-backup-file-name-function 'nick-backup-file-naming-function)
>
>   (setq version-control 'never) ;; or nil
>
>   (make-backup-file-name "/Users/nick/Desktop/sample.txt")
>
> it returns "/Users/nick/Desktop/.sample.txt~" as expected. However, with
>
>   (setq version-control t)
>
> it returns "/Users/nick/Desktop/sample.txt.~1~" , that is, backup names are
> correctly versioned, but the name is missing the prefix dot. It appears as if
> `make-backup-file-name' is not being called in this case.
>
> Looking at `files.el' it seems like `find-backup-file-name' calls
> `make-backup-file-name-1' directly, bypassing the custom fuction.

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.

¹ https://github.com/alezost/emacs-utils/blob/master/utl-file.el#L76-L102

-- 
Alex



reply via email to

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