diff options
| author | Oleh Krehel | 2015-10-21 16:39:36 +0200 |
|---|---|---|
| committer | Oleh Krehel | 2015-10-21 16:54:25 +0200 |
| commit | f6ece2420c3dc6f3dde06c7f8722f5b0b7e1ef4a (patch) | |
| tree | 28d9281d40b214b1ea218f0b14d3919e4296a0f3 | |
| parent | d60e5a9da157f452d891d92f7337d254a1775787 (diff) | |
| download | emacs-f6ece2420c3dc6f3dde06c7f8722f5b0b7e1ef4a.tar.gz emacs-f6ece2420c3dc6f3dde06c7f8722f5b0b7e1ef4a.zip | |
Add dired-do-compress-to command bound to "c"
* lisp/dired-aux.el (dired-shell-command): Use the caller's
`default-directory', return the result of `process-file'.
(dired-compress-file-suffixes): Add comment on why "tar -zxf" isn't
used by default.
(dired-compress-files-alist): New defvar.
(dired-do-compress-to): New command.
* lisp/dired.el (dired-mode-map): Bind `dired-do-compress-to' to "c".
(dired-do-compress-to): Add an autoload entry.
* etc/NEWS: Add two entries.
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/dired-aux.el | 76 | ||||
| -rw-r--r-- | lisp/dired.el | 11 |
3 files changed, 81 insertions, 12 deletions
| @@ -275,6 +275,12 @@ header. | |||
| 275 | ** `tabulated-list-print' takes a second optional argument, update, | 275 | ** `tabulated-list-print' takes a second optional argument, update, |
| 276 | which specifies an alternative printing method which is faster when | 276 | which specifies an alternative printing method which is faster when |
| 277 | few or no entries have changed. | 277 | few or no entries have changed. |
| 278 | ** The command `dired-do-compress' bound to `Z' now can compress | ||
| 279 | directories and decompress zip files. | ||
| 280 | ** New command `dired-do-compress-to' bound to `c' can be used to compress | ||
| 281 | many marked files into a single named archive. The compression | ||
| 282 | command is determined from the new `dired-compress-files-alist' | ||
| 283 | variable. | ||
| 278 | 284 | ||
| 279 | 285 | ||
| 280 | * Editing Changes in Emacs 25.1 | 286 | * Editing Changes in Emacs 25.1 |
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 98a974a8223..5cece27948f 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el | |||
| @@ -788,19 +788,23 @@ Else returns nil for success." | |||
| 788 | 788 | ||
| 789 | (defun dired-shell-command (cmd) | 789 | (defun dired-shell-command (cmd) |
| 790 | "Run CMD, and check for output. | 790 | "Run CMD, and check for output. |
| 791 | On error, pop up the log buffer." | 791 | On error, pop up the log buffer. |
| 792 | (let ((out-buffer " *dired-check-process output*")) | 792 | Return the result of `process-file' - zero for success." |
| 793 | (let ((out-buffer " *dired-check-process output*") | ||
| 794 | (dir default-directory)) | ||
| 793 | (with-current-buffer (get-buffer-create out-buffer) | 795 | (with-current-buffer (get-buffer-create out-buffer) |
| 794 | (erase-buffer) | 796 | (erase-buffer) |
| 795 | (let ((res (process-file | 797 | (let* ((default-directory dir) |
| 796 | shell-file-name | 798 | (res (process-file |
| 797 | nil | 799 | shell-file-name |
| 798 | t | 800 | nil |
| 799 | nil | 801 | t |
| 800 | shell-command-switch | 802 | nil |
| 801 | cmd))) | 803 | shell-command-switch |
| 804 | cmd))) | ||
| 802 | (unless (zerop res) | 805 | (unless (zerop res) |
| 803 | (pop-to-buffer out-buffer)))))) | 806 | (pop-to-buffer out-buffer)) |
| 807 | res)))) | ||
| 804 | 808 | ||
| 805 | ;; Commands that delete or redisplay part of the dired buffer. | 809 | ;; Commands that delete or redisplay part of the dired buffer. |
| 806 | 810 | ||
| @@ -880,7 +884,11 @@ command with a prefix argument (the value does not matter)." | |||
| 880 | from-file))) | 884 | from-file))) |
| 881 | 885 | ||
| 882 | (defvar dired-compress-file-suffixes | 886 | (defvar dired-compress-file-suffixes |
| 883 | '(("\\.tar\\.gz\\'" "" "gzip -dc %i | tar -xv") | 887 | '( |
| 888 | ;; "tar -zxf" isn't used because it's not available the on | ||
| 889 | ;; Solaris10 version of tar. Solaris10 becomes obsolete in 2021. | ||
| 890 | ;; Same thing on AIX 7.1. | ||
| 891 | ("\\.tar\\.gz\\'" "" "gzip -dc %i | tar -xv") | ||
| 884 | ("\\.gz\\'" "" "gunzip") | 892 | ("\\.gz\\'" "" "gunzip") |
| 885 | ("\\.tgz\\'" ".tar" "gunzip") | 893 | ("\\.tgz\\'" ".tar" "gunzip") |
| 886 | ("\\.Z\\'" "" "uncompress") | 894 | ("\\.Z\\'" "" "uncompress") |
| @@ -911,6 +919,52 @@ output file. | |||
| 911 | Otherwise, the rule is a compression rule, and compression is done with gzip. | 919 | Otherwise, the rule is a compression rule, and compression is done with gzip. |
| 912 | ARGS are command switches passed to PROGRAM.") | 920 | ARGS are command switches passed to PROGRAM.") |
| 913 | 921 | ||
| 922 | (defvar dired-compress-files-alist | ||
| 923 | '(("\\.tar\\.gz\\'" . "tar -c %i | gzip -c9 > %o") | ||
| 924 | ("\\.zip\\'" . "zip %o -r --filesync %i")) | ||
| 925 | "Control the compression shell command for `dired-do-compress-to'. | ||
| 926 | |||
| 927 | Each element is (REGEXP . CMD), where REGEXP is the name of the | ||
| 928 | archive to which you want to compress, and CMD the the | ||
| 929 | corresponding command. | ||
| 930 | |||
| 931 | Within CMD, %i denotes the input file(s), and %o denotes the | ||
| 932 | output file. %i path(s) are relative, while %o is absolute.") | ||
| 933 | |||
| 934 | ;;;###autoload | ||
| 935 | (defun dired-do-compress-to () | ||
| 936 | "Compress selected files and directories to an archive. | ||
| 937 | You are prompted for the archive name. | ||
| 938 | The archiving command is chosen based on the archive name extension and | ||
| 939 | `dired-compress-files-alist'." | ||
| 940 | (interactive) | ||
| 941 | (let* ((in-files (dired-get-marked-files)) | ||
| 942 | (out-file (read-file-name "Compress to: ")) | ||
| 943 | (rule (cl-find-if | ||
| 944 | (lambda (x) | ||
| 945 | (string-match (car x) out-file)) | ||
| 946 | dired-compress-files-alist))) | ||
| 947 | (cond ((not rule) | ||
| 948 | (error | ||
| 949 | "No compression rule found for %s, see `dired-compress-files-alist'" | ||
| 950 | out-file)) | ||
| 951 | ((and (file-exists-p out-file) | ||
| 952 | (not (y-or-n-p | ||
| 953 | (format "%s exists, overwrite?" | ||
| 954 | (abbreviate-file-name out-file))))) | ||
| 955 | (message "Compression aborted")) | ||
| 956 | (t | ||
| 957 | (when (zerop | ||
| 958 | (dired-shell-command | ||
| 959 | (replace-regexp-in-string | ||
| 960 | "%o" out-file | ||
| 961 | (replace-regexp-in-string | ||
| 962 | "%i" (mapconcat #'file-name-nondirectory in-files " ") | ||
| 963 | (cdr rule))))) | ||
| 964 | (message "Compressed %d file(s) to %s" | ||
| 965 | (length in-files) | ||
| 966 | (file-name-nondirectory out-file))))))) | ||
| 967 | |||
| 914 | ;;;###autoload | 968 | ;;;###autoload |
| 915 | (defun dired-compress-file (file) | 969 | (defun dired-compress-file (file) |
| 916 | "Compress or uncompress FILE. | 970 | "Compress or uncompress FILE. |
diff --git a/lisp/dired.el b/lisp/dired.el index e8791f8b320..bc0139f84e5 100644 --- a/lisp/dired.el +++ b/lisp/dired.el | |||
| @@ -1466,6 +1466,7 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST." | |||
| 1466 | (define-key map "T" 'dired-do-touch) | 1466 | (define-key map "T" 'dired-do-touch) |
| 1467 | (define-key map "X" 'dired-do-shell-command) | 1467 | (define-key map "X" 'dired-do-shell-command) |
| 1468 | (define-key map "Z" 'dired-do-compress) | 1468 | (define-key map "Z" 'dired-do-compress) |
| 1469 | (define-key map "c" 'dired-do-compress-to) | ||
| 1469 | (define-key map "!" 'dired-do-shell-command) | 1470 | (define-key map "!" 'dired-do-shell-command) |
| 1470 | (define-key map "&" 'dired-do-async-shell-command) | 1471 | (define-key map "&" 'dired-do-async-shell-command) |
| 1471 | ;; Comparison commands | 1472 | ;; Comparison commands |
| @@ -3896,7 +3897,7 @@ Ask means pop up a menu for the user to select one of copy, move or link." | |||
| 3896 | 3897 | ||
| 3897 | ;;; Start of automatically extracted autoloads. | 3898 | ;;; Start of automatically extracted autoloads. |
| 3898 | 3899 | ||
| 3899 | ;;;### (autoloads nil "dired-aux" "dired-aux.el" "c4ed2cda4c70d4b38ab52ad03fa9dfda") | 3900 | ;;;### (autoloads nil "dired-aux" "dired-aux.el" "b946c1770b736ddc39eeef00c39425e7") |
| 3900 | ;;; Generated autoloads from dired-aux.el | 3901 | ;;; Generated autoloads from dired-aux.el |
| 3901 | 3902 | ||
| 3902 | (autoload 'dired-diff "dired-aux" "\ | 3903 | (autoload 'dired-diff "dired-aux" "\ |
| @@ -4088,6 +4089,14 @@ command with a prefix argument (the value does not matter). | |||
| 4088 | 4089 | ||
| 4089 | \(fn &optional ARG FMT)" t nil) | 4090 | \(fn &optional ARG FMT)" t nil) |
| 4090 | 4091 | ||
| 4092 | (autoload 'dired-do-compress-to "dired-aux" "\ | ||
| 4093 | Compress selected files and directories to an archive. | ||
| 4094 | You are prompted for the archive name. | ||
| 4095 | The archiving command is chosen based on the archive name extension and | ||
| 4096 | `dired-compress-files-alist'. | ||
| 4097 | |||
| 4098 | \(fn)" t nil) | ||
| 4099 | |||
| 4091 | (autoload 'dired-compress-file "dired-aux" "\ | 4100 | (autoload 'dired-compress-file "dired-aux" "\ |
| 4092 | Compress or uncompress FILE. | 4101 | Compress or uncompress FILE. |
| 4093 | Return the name of the compressed or uncompressed file. | 4102 | Return the name of the compressed or uncompressed file. |