How can I hide the backup files that emacs creates?

前端 未结 4 1032
野趣味
野趣味 2021-02-05 13:20

I just started using emacs after having used vi for a long time. :)

One thing which is annoying me is that whenever I modify a file, save it and exit emacs, I see a back

相关标签:
4条回答
  • 2021-02-05 13:35

    In your .emacs:

    (setq make-backup-files nil)
    

    Edit: If you're unfamiliar with the .emacs file, it's a file named .emacs that resides in your user $HOME directory. If you don't have one already, you can just create it and emacs will load it on startup.

    0 讨论(0)
  • 2021-02-05 13:43

    The following lines in ~/.emacs will put all of the auto-save and backup files in /tmp:

    (setq backup-directory-alist
          `((".*" . ,temporary-file-directory)))
    (setq auto-save-file-name-transforms
          `((".*" ,temporary-file-directory t)))
    
    0 讨论(0)
  • 2021-02-05 13:44

    Here is a link to the same question answered on SuperUser and my response. And a StackOverflow question entitled Emacs: Don’t create #these# files when not saving modified buffer

    And for completeness, as stated by others; to stop the backup files being created put this in your .emacs

    (setq make-backup-files nil)
    
    0 讨论(0)
  • 2021-02-05 13:55

    You can either move them to their own folder with the following code:

    ;; Don't clutter up directories with files~
    (setq backup-directory-alist `(("." . ,(expand-file-name
                                        (concat dotfiles-dir "backups")))))
    
    ;; Don't clutter with #files either
    (setq auto-save-file-name-transforms
          `((".*" ,(expand-file-name (concat dotfiles-dir "backups")))))
    

    Or you can remove them completely, like so:

    (setq make-backup-files nil)
    (setq auto-save-default nil)
    

    Personally I would be wary of removing them as they can come in useful. Further discussion is here:

    • http://www.emacswiki.org/emacs/BackupDirectory
    • http://www.emacswiki.org/emacs/AutoSave

    I would recommend checking out the emacs-starter-kit it sorts out a load of issues that people have when coming to emacs, and is pretty heavily used.

    http://github.com/technomancy/emacs-starter-kit/blob/master/starter-kit-misc.el


    Update:

    There seems to be much confusion over how to use the functions. I'm going to have a little play around later but here is some more information. Note that auto-save-file-name-transforms:

    lets you specify a series of regular expressions and replacements to transform the auto save file name [emacs-manual]

    so it's not just as simple as adding in a folder name. That said it seems from a quick google search the following might just do what you all want:

    ;;; backup/autosave
    (defvar backup-dir (expand-file-name "~/.emacs.d/backup/"))
    (defvar autosave-dir (expand-file-name "~/.emacs.d/autosave/"))
    (setq backup-directory-alist (list (cons ".*" backup-dir)))
    (setq auto-save-list-file-prefix autosave-dir)
    (setq auto-save-file-name-transforms `((".*" ,autosave-dir t)))
    

    http://www.google.com/codesearch?hl=en&lr=&q=auto-save-file-name-transforms&sbtn=Search

    0 讨论(0)
提交回复
热议问题