【问题标题】:How do I uncompress/unzip within Emacs如何在 Emacs 中解压缩/解压缩
【发布时间】:2009-09-16 06:48:55
【问题描述】:

我想在 dired 或类似 dired 的缓冲区中运行 unzip(甚至 zip)。有这样的吗?我想要类似于 Nautilus 文件管理器中的内容:即选择文件,然后按一个键将这些文件放入一个新的存档文件中。

谢谢

【问题讨论】:

    标签: emacs zip dired


    【解决方案1】:

    你有选择......

    要解压 .zip 文件,您只需添加变量'dired-compress-file-suffixes

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

    现在 dired 中的 Z 键将识别 .zip 扩展名并解压缩 .zip 存档。已经支持gunzipbunzip2uncompressdictunzip

    如果您想标记文件并将它们添加到 .zip 存档中,您可以使用以下命令将 z 绑定到 zip 标记文件集:

    (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 " ")) 
    

    【讨论】:

    • “Z”不是开箱即用的吗? (或用“m”标记,然后按“Z”)。我记得它在不久前对我有用。我在这里看到了:xahlee.org/emacs/file_management.html
    • Z 将单独压缩文件。它不会将它们添加到存档/zip。
    • 好像concat-string-list不存在:concat: Symbol的函数定义为void:concat-string-list
    • 对不起,我忘了我自己的辅助函数中有这个,我将它添加到答案代码中。
    • 我认为上面的代码需要对文件名进行一些转义,尝试标记几个文件,如2010_12_HEAD_Seminar (1).pdf,看看会发生什么。
    【解决方案2】:

    要压缩文件,请打开目录中的目录。使用m 标记您要压缩的文件。然后输入

    ! zip foo.zip * <RET>
    

    要从 dired 中提取整个存档,您可以标记一个文件并运行 &amp; unzip,就像在 shell 中一样。

    zip-archive 模式将允许您以类似 dired 的方式浏览 zip 文件。它应该随最新版本的 GNU emacs 一起提供,并且在您访问具有 .zip 扩展名的文件时默认使用。在此模式下,您可以将单个文件提取到缓冲区中,然后使用C-x C-s 保存它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-12
      • 1970-01-01
      • 2019-01-29
      • 1970-01-01
      • 2011-07-06
      • 2011-10-30
      • 1970-01-01
      • 2019-12-06
      相关资源
      最近更新 更多