diff options
| author | Oleh Krehel | 2015-10-13 14:07:10 +0200 |
|---|---|---|
| committer | Oleh Krehel | 2015-10-13 15:51:47 +0200 |
| commit | 787028839bd2a5887f8dcb53da801b6075d2e67e (patch) | |
| tree | 47f6bf83f5272d02f56bd58a3508870d51fefe7d | |
| parent | 8610bd16e92c1a8639206847bd8c6ea523727cd5 (diff) | |
| download | emacs-787028839bd2a5887f8dcb53da801b6075d2e67e.tar.gz emacs-787028839bd2a5887f8dcb53da801b6075d2e67e.zip | |
Make dired-do-compress work for directories
* lisp/dired-aux.el (dired-compress-file): When FILE is a directory,
instead of emitting an error, call "tar -czf FILE.tar.gz FILE".
Also convert the top comment into a docstring.
| -rw-r--r-- | lisp/dired-aux.el | 93 |
1 files changed, 50 insertions, 43 deletions
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index a67b11fb6a6..8e714c7d8a3 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el | |||
| @@ -888,56 +888,63 @@ Otherwise, the rule is a compression rule, and compression is done with gzip.") | |||
| 888 | 888 | ||
| 889 | ;;;###autoload | 889 | ;;;###autoload |
| 890 | (defun dired-compress-file (file) | 890 | (defun dired-compress-file (file) |
| 891 | ;; Compress or uncompress FILE. | 891 | "Compress or uncompress FILE. |
| 892 | ;; Return the name of the compressed or uncompressed file. | 892 | Return the name of the compressed or uncompressed file. |
| 893 | ;; Return nil if no change in files. | 893 | Return nil if no change in files." |
| 894 | (let ((handler (find-file-name-handler file 'dired-compress-file)) | 894 | (let ((handler (find-file-name-handler file 'dired-compress-file)) |
| 895 | suffix newname | 895 | suffix newname |
| 896 | (suffixes dired-compress-file-suffixes)) | 896 | (suffixes dired-compress-file-suffixes)) |
| 897 | ;; See if any suffix rule matches this file name. | 897 | ;; See if any suffix rule matches this file name. |
| 898 | (while suffixes | 898 | (while suffixes |
| 899 | (let (case-fold-search) | 899 | (let (case-fold-search) |
| 900 | (if (string-match (car (car suffixes)) file) | 900 | (if (string-match (car (car suffixes)) file) |
| 901 | (setq suffix (car suffixes) suffixes nil)) | 901 | (setq suffix (car suffixes) suffixes nil)) |
| 902 | (setq suffixes (cdr suffixes)))) | 902 | (setq suffixes (cdr suffixes)))) |
| 903 | ;; If so, compute desired new name. | 903 | ;; If so, compute desired new name. |
| 904 | (if suffix | 904 | (if suffix |
| 905 | (setq newname (concat (substring file 0 (match-beginning 0)) | 905 | (setq newname (concat (substring file 0 (match-beginning 0)) |
| 906 | (nth 1 suffix)))) | 906 | (nth 1 suffix)))) |
| 907 | (cond (handler | 907 | (cond (handler |
| 908 | (funcall handler 'dired-compress-file file)) | 908 | (funcall handler 'dired-compress-file file)) |
| 909 | ((file-symlink-p file) | 909 | ((file-symlink-p file) |
| 910 | nil) | 910 | nil) |
| 911 | ((and suffix (nth 2 suffix)) | 911 | ((and suffix (nth 2 suffix)) |
| 912 | ;; We found an uncompression rule. | 912 | ;; We found an uncompression rule. |
| 913 | (if (not (dired-check-process (concat "Uncompressing " file) | 913 | (if (not (dired-check-process (concat "Uncompressing " file) |
| 914 | (nth 2 suffix) file)) | 914 | (nth 2 suffix) file)) |
| 915 | newname)) | 915 | newname)) |
| 916 | (t | 916 | (t |
| 917 | ;;; We don't recognize the file as compressed, so compress it. | 917 | ;; We don't recognize the file as compressed, so compress it. |
| 918 | ;;; Try gzip; if we don't have that, use compress. | 918 | ;; Try gzip; if we don't have that, use compress. |
| 919 | (condition-case nil | 919 | (condition-case nil |
| 920 | (let ((out-name (concat file ".gz"))) | 920 | (let ((out-name (concat file (if (file-directory-p file) |
| 921 | (and (or (not (file-exists-p out-name)) | 921 | ".tar.gz" |
| 922 | (y-or-n-p | 922 | ".gz")))) |
| 923 | (format "File %s already exists. Really compress? " | 923 | (and (or (not (file-exists-p out-name)) |
| 924 | out-name))) | 924 | (y-or-n-p |
| 925 | (not (dired-check-process (concat "Compressing " file) | 925 | (format "File %s already exists. Really compress? " |
| 926 | "gzip" "-f" file)) | 926 | out-name))) |
| 927 | (or (file-exists-p out-name) | 927 | (not |
| 928 | (setq out-name (concat file ".z"))) | 928 | (if (file-directory-p file) |
| 929 | ;; Rename the compressed file to NEWNAME | 929 | (let ((default-directory (file-name-directory file))) |
| 930 | ;; if it hasn't got that name already. | 930 | (dired-check-process (concat "Compressing " file) |
| 931 | (if (and newname (not (equal newname out-name))) | 931 | "tar" "-czf" out-name (file-name-nondirectory file))) |
| 932 | (progn | 932 | (dired-check-process (concat "Compressing " file) |
| 933 | (rename-file out-name newname t) | 933 | "gzip" "-f" file))) |
| 934 | newname) | 934 | (or (file-exists-p out-name) |
| 935 | out-name))) | 935 | (setq out-name (concat file ".z"))) |
| 936 | (file-error | 936 | ;; Rename the compressed file to NEWNAME |
| 937 | (if (not (dired-check-process (concat "Compressing " file) | 937 | ;; if it hasn't got that name already. |
| 938 | "compress" "-f" file)) | 938 | (if (and newname (not (equal newname out-name))) |
| 939 | ;; Don't use NEWNAME with `compress'. | 939 | (progn |
| 940 | (concat file ".Z")))))))) | 940 | (rename-file out-name newname t) |
| 941 | newname) | ||
| 942 | out-name))) | ||
| 943 | (file-error | ||
| 944 | (if (not (dired-check-process (concat "Compressing " file) | ||
| 945 | "compress" "-f" file)) | ||
| 946 | ;; Don't use NEWNAME with `compress'. | ||
| 947 | (concat file ".Z")))))))) | ||
| 941 | 948 | ||
| 942 | (defun dired-mark-confirm (op-symbol arg) | 949 | (defun dired-mark-confirm (op-symbol arg) |
| 943 | ;; Request confirmation from the user that the operation described | 950 | ;; Request confirmation from the user that the operation described |