Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Cool idea. Here's a start that works for me: just need to change a few lines in <code>dired-compress-file</code>. I've highlighted the changes with <code>BEGIN EDIT</code> and <code>END EDIT</code> comments (sorry if there's a better way to highlight a diff). I'm sure this isn't robust, but maybe it can point you in the right direction.</p> <p>EDIT: I should say that the below works for me in GNU Emacs 24.3.1.</p> <pre><code>(defun dired-compress-file (file) ;; Compress or uncompress FILE. ;; Return the name of the compressed or uncompressed file. ;; Return nil if no change in files. (let ((handler (find-file-name-handler file 'dired-compress-file)) suffix newname (suffixes dired-compress-file-suffixes)) ;; See if any suffix rule matches this file name. (while suffixes (let (case-fold-search) (if (string-match (car (car suffixes)) file) (setq suffix (car suffixes) suffixes nil)) (setq suffixes (cdr suffixes)))) ;; If so, compute desired new name. (if suffix (setq newname (concat (substring file 0 (match-beginning 0)) (nth 1 suffix)))) (cond (handler (funcall handler 'dired-compress-file file)) ((file-symlink-p file) nil) ((and suffix (nth 2 suffix)) ;; We found an uncompression rule. (if (not (dired-check-process (concat "Uncompressing " file) (nth 2 suffix) file)) newname)) (t ;;; We don't recognize the file as compressed, so compress it. ;;; Try gzip; if we don't have that, use compress. (condition-case nil ;; BEGIN EDIT - choose the correct name if looking at a directory (let ((out-name (if (file-directory-p file) (concat file ".tar.gz") (concat file ".gz")))) ;; END EDIT (and (or (not (file-exists-p out-name)) (y-or-n-p (format "File %s already exists. Really compress? " out-name))) ;; BEGIN EDIT: create a tarball if we're looking at a directory (not (if (file-directory-p file) (dired-check-process (concat "Compressing " file) "tar" "-zcf" out-name file) (dired-check-process (concat "Compressing " file) "gzip" "-f" file))) ;; END EDIT (or (file-exists-p out-name) (setq out-name (concat file ".z"))) ;; Rename the compressed file to NEWNAME ;; if it hasn't got that name already. (if (and newname (not (equal newname out-name))) (progn (rename-file out-name newname t) newname) out-name))) (file-error (if (not (dired-check-process (concat "Compressing " file) "compress" "-f" file)) ;; Don't use NEWNAME with `compress'. (concat file ".Z")))))))) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload