%o") ("\\.tar\\.bz2\\'" . "tar -cf - %i | bzip2 -" /> %o") ("\\.tar\\.bz2\\'" . "tar -cf - %i | bzip2 -" /> %o") ("\\.tar\\.bz2\\'" . "tar -cf - %i | bzip2 -"/>

How to customize dired-compress-files-alist?

141 Views Asked by At

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?

1

There are 1 best solutions below

1
Drew On

Just require standard library dired-aux in your init file at the outset (at least before you use Dired). That library defines variable dired-compress-files-alist.

(require 'dired-aux)

(Oh, and don't quote lambdas: just use (lambda...), not '(lambda...).)


(You can also use add-to-list or push instead of setq with cons etc., but that's just a question of style.)