aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1996-03-03 06:10:06 +0000
committerRichard M. Stallman1996-03-03 06:10:06 +0000
commit077d52839d699d9b3e8e48eecbe2cb58adcc5f20 (patch)
tree2ad0033b375a7423a6b7299a51e3e4b474fe513f
parente643c5beab11c0141827e593dbd0e3889e0cfb0f (diff)
downloademacs-077d52839d699d9b3e8e48eecbe2cb58adcc5f20.tar.gz
emacs-077d52839d699d9b3e8e48eecbe2cb58adcc5f20.zip
(dired-compress-file-suffixes): New variable.
(dired-compress-file): Use that to control file naming.
-rw-r--r--lisp/dired-aux.el70
1 files changed, 49 insertions, 21 deletions
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 0e3b0f26f12..dca2ca488ed 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -514,45 +514,73 @@ and use this command with a prefix argument (the value does not matter)."
514 (dired-log (concat "Failed to compress" from-file)) 514 (dired-log (concat "Failed to compress" from-file))
515 from-file))) 515 from-file)))
516 516
517(defvar dired-compress-file-suffixes
518 '(("\\.gz\\'" "" "gunzip")
519 ("\\.tgz\\'" ".tar" "gunzip")
520 ("\\.Z\\'" "" "uncompress")
521 ;; For .z, try gunzip. It might be an old gzip file,
522 ;; or it might be from compact? pack? (which?) but gunzip handles both.
523 ("\\.z\\'" "" "gunzip")
524 ;; This item controls naming for compression.
525 ("\\.tar\\'" ".tgz" nil))
526 "Control changes in file name suffixes for compression and uncompression.
527Each element specifies one transformation rule, and has the form:
528 (REGEXP NEW-SUFFIX PROGRAM)
529The rule applies when the old file name matches REGEXP.
530The new file name is computed by deleting the part that matches REGEXP
531 (as well as anything after that), then adding NEW-SUFFIX in its place.
532If PROGRAM is non-nil, the rule is an uncompression rule,
533and uncompression is done by running PROGRAM.
534Otherwise, the rule is a compression rule, and compression is done with gzip.")
535
517;;;###autoload 536;;;###autoload
518(defun dired-compress-file (file) 537(defun dired-compress-file (file)
519 ;; Compress or uncompress FILE. 538 ;; Compress or uncompress FILE.
520 ;; Return the name of the compressed or uncompressed file. 539 ;; Return the name of the compressed or uncompressed file.
521 ;; Return nil if no change in files. 540 ;; Return nil if no change in files.
522 (let ((handler (find-file-name-handler file 'dired-compress-file))) 541 (let ((handler (find-file-name-handler file 'dired-compress-file))
542 suffix newname
543 (suffixes dired-compress-file-suffixes))
544 ;; See if any suffix rule matches this file name.
545 (while suffixes
546 (let (case-fold-search)
547 (if (string-match (car (car suffixes)) file)
548 (setq suffix (car suffixes) suffixes nil))
549 (setq suffixes (cdr suffixes))))
550 ;; If so, compute desired new name.
551 (if suffix
552 (setq newname (concat (substring file 0 (match-beginning 0))
553 (nth 1 suffix))))
523 (cond (handler 554 (cond (handler
524 (funcall handler 'dired-compress-file file)) 555 (funcall handler 'dired-compress-file file))
525 ((file-symlink-p file) 556 ((file-symlink-p file)
526 nil) 557 nil)
527 ((let (case-fold-search) 558 ((and suffix (nth 2 suffix))
528 (string-match "\\.Z$" file)) 559 ;; We found an uncompression rule.
529 (if (not (dired-check-process (concat "Uncompressing " file)
530 "uncompress" file))
531 (substring file 0 -2)))
532 ((let (case-fold-search)
533 (string-match "\\.gz$" file))
534 (if (not (dired-check-process (concat "Uncompressing " file)
535 "gunzip" file))
536 (substring file 0 -3)))
537 ;; For .z, try gunzip. It might be an old gzip file,
538 ;; or it might be from compact? pack? (which?) but gunzip handles
539 ;; both.
540 ((let (case-fold-search)
541 (string-match "\\.z$" file))
542 (if (not (dired-check-process (concat "Uncompressing " file) 560 (if (not (dired-check-process (concat "Uncompressing " file)
543 "gunzip" file)) 561 (nth 2 suffix) file))
544 (substring file 0 -2))) 562 newname))
545 (t 563 (t
564 ;;; We don't recognize the file as compressed, so compress it.
546 ;;; Try gzip; if we don't have that, use compress. 565 ;;; Try gzip; if we don't have that, use compress.
547 (condition-case nil 566 (condition-case nil
548 (if (not (dired-check-process (concat "Compressing " file) 567 (if (not (dired-check-process (concat "Compressing " file)
549 "gzip" "-f" file)) 568 "gzip" "-f" file))
550 (cond ((file-exists-p (concat file ".gz")) 569 (let ((out-name
551 (concat file ".gz")) 570 (if (file-exists-p (concat file ".gz"))
552 (t (concat file ".z")))) 571 (concat file ".gz")
572 (concat file ".z"))))
573 ;; Rename the compressed file to NEWNAME
574 ;; if it hasn't got that name already.
575 (if (and newname (not (equal newname out-name)))
576 (progn
577 (rename-file out-name newname t)
578 newname)
579 out-name)))
553 (file-error 580 (file-error
554 (if (not (dired-check-process (concat "Compressing " file) 581 (if (not (dired-check-process (concat "Compressing " file)
555 "compress" "-f" file)) 582 "compress" "-f" file))
583 ;; Don't use NEWNAME with `compress'.
556 (concat file ".Z")))))))) 584 (concat file ".Z"))))))))
557 585
558(defun dired-mark-confirm (op-symbol arg) 586(defun dired-mark-confirm (op-symbol arg)