2009-09-16 109 views
17

我想在dired或dired-like緩衝區內運行解壓縮(甚至zip)。有沒有這樣的事情?我想要類似於Nautilus文件管理器中的內容:即選擇文件,然後按下按鍵以將這些文件轉換爲新的存檔文件。如何在Emacs中解壓縮/解壓縮

謝謝

回答

26

你得選擇......

要解壓縮的.zip文件,你只需要添加的變量現在'dired-compress-file-suffixes

(eval-after-load "dired-aux" 
    '(add-to-list 'dired-compress-file-suffixes 
       '("\\.zip\\'" ".zip" "unzip"))) 

在dired的Z鍵將識別的.zip擴展並解壓縮.zip壓縮文件。已經支持gunzip,bunzip2,uncompressdictunzip

如果你想標記文件,並將它們添加到一個.zip存檔,您可以使用下列項目以z勢必壓縮了一套帶標記文件:

(eval-after-load "dired" 
    '(define-key dired-mode-map "z" 'dired-zip-files)) 
(defun dired-zip-files (zip-file) 
    "Create an archive containing the marked files." 
    (interactive "sEnter name of zip file: ") 

    ;; create the zip file 
    (let ((zip-file (if (string-match ".zip$" zip-file) zip-file (concat zip-file ".zip")))) 
    (shell-command 
    (concat "zip " 
      zip-file 
      " " 
      (concat-string-list 
       (mapcar 
       '(lambda (filename) 
        (file-name-nondirectory filename)) 
       (dired-get-marked-files)))))) 

    (revert-buffer) 

    ;; remove the mark on all the files "*" to " " 
    ;; (dired-change-marks 42 ?\040) 
    ;; mark zip file 
    ;; (dired-mark-files-regexp (filename-to-regexp zip-file)) 
) 

(defun concat-string-list (list) 
    "Return a string which is a concatenation of all elements of the list separated by spaces" 
    (mapconcat '(lambda (obj) (format "%s" obj)) list " ")) 
+0

沒有「Z」做出來-of即用? (或用'm'標記,然後按'Z')。我記得它在一段時間後對我有用。我在這裏看到它: http://xahlee.org/emacs/file_management.html – hatmatrix 2009-09-17 05:02:40

+1

'Z'會壓縮文件,每個文件都是單獨的。它不會將它們添加到存檔/ zip。 – 2009-09-17 05:48:02

+0

看來Concat的字符串列表不存在: CONCAT:符號的功能定義是無效:CONCAT字符串列表 – 2009-09-18 11:05:06

16

要壓縮的文件,在dired打開目錄。用m標記要壓縮的文件。然後鍵入

! zip foo.zip * <RET> 

爲了從dired你可以標記一個文件並運行& unzip整個檔案,就像你在一個外殼。

zip-archive模式將允許您以直接類似的方式瀏覽zip文件。它應該包含最新版本的GNU emacs,並且在您訪問帶有.zip擴展名的文件時將默認使用。在這種模式下,您可以將單個文件提取到緩衝區中,然後從中保存C-x C-s