all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nick Helm <nick@tenpoint.co.nz>
To: <help-gnu-emacs@gnu.org>
Subject: Changing name format for backup files
Date: Tue, 12 Jan 2016 11:21:33 +1300	[thread overview]
Message-ID: <m2lh7v2217.fsf@tenpoint.co.nz> (raw)

I like to keep my emacs backup files in the same directory as the file I'm
editing, but I want the backups to be hidden in the GUI by default. I achieve
this by adding a prefix dot to the backup filenames by tweaking
`make-backup-file-name-1' like this:

 (defun make-backup-file-name-1 (file)
   "Subroutine of `make-backup-file-name--default-function'.
 The function `find-backup-file-name' also uses this."
   (let ((alist backup-directory-alist)
 	elt backup-directory abs-backup-directory)
     (while alist
       (setq elt (pop alist))
       (if (string-match (car elt) file)
 	  (setq backup-directory (cdr elt)
 		alist nil)))
     ;; If backup-directory is relative, it should be relative to the
     ;; file's directory.  By expanding explicitly here, we avoid
     ;; depending on default-directory.
     (if backup-directory
 	(setq abs-backup-directory
 	      (expand-file-name backup-directory
 				(file-name-directory file))))
     (if (and abs-backup-directory (not (file-exists-p abs-backup-directory)))
 	(condition-case nil
 	    (make-directory abs-backup-directory 'parents)
 	  (file-error (setq backup-directory nil
 			    abs-backup-directory nil))))
     (if (null backup-directory)
 ;; -----------8<------------------CHANGE HERE-----------------8<-------------
 ;;    file
                        (let* ((file-path (file-name-directory file))
                               (file-name (file-name-nondirectory file)))
                            (concat file-path "." file-name))
 ;; -----------8<------------------CHANGE HERE-----------------8<-------------
       (if (file-name-absolute-p backup-directory)
 	  (progn
 	    (when (memq system-type '(windows-nt ms-dos cygwin))
 	      ;; Normalize DOSish file names: downcase the drive
 	      ;; letter, if any, and replace the leading "x:" with
 	      ;; "/drive_x".
 	      (or (file-name-absolute-p file)
 		  (setq file (expand-file-name file))) ; make defaults explicit
 	      ;; Replace any invalid file-name characters (for the
 	      ;; case of backing up remote files).
 	      (setq file (expand-file-name (convert-standard-filename file)))
 	      (if (eq (aref file 1) ?:)
 		  (setq file (concat "/"
 				     "drive_"
 				     (char-to-string (downcase (aref file 0)))
 				     (if (eq (aref file 2) ?/)
 					 ""
 				       "/")
 				     (substring file 2)))))
 	    ;; Make the name unique by substituting directory
 	    ;; separators.  It may not really be worth bothering about
 	    ;; doubling `!'s in the original name...
 	    (expand-file-name
 	     (subst-char-in-string
 	      ?/ ?!
 	      (replace-regexp-in-string "!" "!!" file))
 	     backup-directory))
 	(expand-file-name (file-name-nondirectory file)
 			  (file-name-as-directory abs-backup-directory))))))

I do something similar to `make-auto-save-file-name' to achieve the same result
for auto save files.

Redefining core functions seems like a pretty heavy handed approach to the
problem though. Is there better way to achieve the same result? Or perhaps
there's a user option I missed in the manual?

Thanks, 
Nick



             reply	other threads:[~2016-01-11 22:21 UTC|newest]

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

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

  git send-email \
    --in-reply-to=m2lh7v2217.fsf@tenpoint.co.nz \
    --to=nick@tenpoint.co.nz \
    --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.
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.