unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Nick Helm <nick@tenpoint.co.nz>
To: <help-gnu-emacs@gnu.org>
Cc: Alex Kost <alezost@gmail.com>
Subject: Re: Changing name format for backup files
Date: Fri, 15 Jan 2016 17:53:14 +1300	[thread overview]
Message-ID: <m28u3r5tqd.fsf@tenpoint.co.nz> (raw)
In-Reply-To: <874mehblb1.fsf@gmail.com>


> 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 ~.




  reply	other threads:[~2016-01-15  4:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-11 22:21 Changing name format for backup files Nick Helm
2016-01-11 23:26 ` Óscar Fuentes
2016-01-12 22:32   ` Nick Helm
2016-01-13 14:34     ` Alex Kost
2016-01-15  4:53       ` Nick Helm [this message]
2016-01-15  9:53         ` Alex Kost

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=m28u3r5tqd.fsf@tenpoint.co.nz \
    --to=nick@tenpoint.co.nz \
    --cc=alezost@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).