The original value of dired-compress-files-alist is:
(("\\.tar\\.gz\\'" . "tar -cf - %i | gzip -c9 > %o") ("\\.tar\\.bz2\\'" . "tar -cf - %i | bzip2 -c9 > %o") ("\\.tar\\.xz\\'" . "tar -cf - %i | xz -c9 > %o") ("\\.tar\\.zst\\'" . "tar -cf - %i | zstd -19 -o %o") ("\\.zip\\'" . "zip %o -r --filesync %i"))
I'd like to add command for .tgz files, so I add a line in .emacs:
(add-hook 'dired-mode
'(lambda ()
(setq dired-compress-files-alist
(cons '("\\.tgz\\'" . "tar -cf - %i | gzip -c9 > %o") dired-compress-files-alist))))
When Emacs starts, it reports error variable dired-compress-files-alist is not found. I found only when I run command `dired-do-compress-to', this variable will appear. So how to set this variable?
Just require standard library
dired-auxin your init file at the outset (at least before you use Dired). That library defines variabledired-compress-files-alist.(Oh, and don't quote lambdas: just use
(lambda...), not'(lambda...).)(You can also use
add-to-listorpushinstead ofsetqwithconsetc., but that's just a question of style.)