バックアップファイルの保存場所
メインのテキストエディタを秀丸エディタからEmacsへ移行する。
理由は
Emacsへの移行を考えていたところにちょうどよい本が発売された。
Emacs実践入門 ?思考を直感的にコード化し、開発を加速する (WEB+DB PRESS plus)
- 作者: 大竹智也
- 出版社/メーカー: 技術評論社
- 発売日: 2012/03/07
- メディア: 単行本(ソフトカバー)
- 購入: 22人 クリック: 396回
- この商品を含むブログ (1件) を見る
ざっと読んだ感じでは、これからEmacsを使おうとする人にとってかなりよさげ。
逆に最初に「入門GNU Emacs」なんかを手に取ってしまうと結構しんどいかな。
私は買ってしまったけど・・・
- 作者: Debra Cameron,James Elliott,Marc Loy,Eric Raymond,Bill Rosenblatt,宮下尚,半田剣一,新井貴之,鈴木和也
- 出版社/メーカー: オライリー・ジャパン
- 発売日: 2007/03/12
- メディア: 大型本
- 購入: 14人 クリック: 331回
- この商品を含むブログ (117件) を見る
Emacs の挙動としてまず気になるのが、カレントディレクトリにバックアップファイルが作成されること。
なので、手始めにバックアップファイルとオートセーブファイルを一カ所 (~/.emacs.d/backups/) へ保存することにした。
~/.emacs.d/init.el
;;; --- バックアップとオートセーブ --- ;; バックアップファイルとオートセーブファイルを ~/.emacs.d/backups/ へ集める (add-to-list 'backup-directory-alist (cons "." "~/.emacs.d/backups/")) (setq auto-save-file-name-transforms `((".*" ,(expand-file-name "~/.emacs.d/backups/") t)))
入門書を参考にほぼそのまま設定しているのできちんと理解できていない部分もあるのだが、解釈した内容を以下に書いておく。
backup-directory-alist の説明
Alist of filename patterns and backup directory names.
Each element looks like (REGEXP . DIRECTORY). Backups of files with
names matching REGEXP will be made in DIRECTORY. DIRECTORY may be
relative or absolute. If it is absolute, so that all matching files
are backed up into the same directory, the file names in this
directory will be the full name of the file backed up with all
directory separators changed to `!' to prevent clashes. This will not
work correctly if your filesystem truncates the resulting name.For the common case of all backups going into one directory, the alist
should contain a single element pairing "." with the appropriate
directory name.If this variable is nil, or it fails to match a filename, the backup
is made in the original file's directory.On MS-DOS filesystems without long names this variable is always
ignored.
要約すると
- 全てのバックアップを一つのディレクトリへ放り込みたい場合は "." とディレクトリのペアを設定すればよい
ということかな。
auto-save-file-name-transforms の説明
Transforms to apply to buffer file name before making auto-save file name.
Each transform is a list (REGEXP REPLACEMENT UNIQUIFY):
REGEXP is a regular expression to match against the file name.
If it matches, `replace-match' is used to replace the
matching part with REPLACEMENT.
If the optional element UNIQUIFY is non-nil, the auto-save file name is
constructed by taking the directory part of the replaced file-name,
concatenated with the buffer file name with all directory separators
changed to `!' to prevent clashes. This will not work
correctly if your filesystem truncates the resulting name.All the transforms in the list are tried, in the order they are listed.
When one transform applies, its result is final;
no further transforms are tried.The default value is set up to put the auto-save file into the
temporary directory (see the variable `temporary-file-directory') for
editing a remote file.On MS-DOS filesystems without long names this variable is always
ignored.
要約するとこんな感じだろうか。
- ファイル名が REGEXP に一致したファイルが対象
- 対象ファイルは REPLACEMENT に指定されたディレクトリへ保存される
- UNIQUIFY が non-nil の場合はファイル名にディレクトリ名を含む。その際ディレクトリの区切り文字は '!' に置き換えられる