を使用して、アーカイブ(* .zip、*。gzなど)から個々のファイルやマークされたファイルをハードドライブに(バッファーで開かずに)抽出する手段を探していますarchive-mode。(この新しい機能を許可する)そのメジャーモードの提案された変更は非常に高く評価されます。
http://www.gnu.org/software/emacs/manual/html_node/emacs/File-Archives.html
を使用して、アーカイブ(* .zip、*。gzなど)から個々のファイルやマークされたファイルをハードドライブに(バッファーで開かずに)抽出する手段を探していますarchive-mode。(この新しい機能を許可する)そのメジャーモードの提案された変更は非常に高く評価されます。
http://www.gnu.org/software/emacs/manual/html_node/emacs/File-Archives.html
回答:
これが実装のスケッチです。
アーカイブモードは、アーカイブタイプから変数内のデータを抽出するために使用されるコマンドへのマップを保存しますarchive-TYPE-extract。を使用して適切な変数を見つけることができます(archive-name "extract")。
すべてのコマンドは、標準出力に抽出するように調整されています。幸運なことにstdout、私たちが選択したファイルにリダイレクトした場合でも、それらを使用できます。
(defun archive-extract-to-file (archive-name item-name command dir)
"Extract ITEM-NAME from ARCHIVE-NAME using COMMAND. Save to
DIR."
(unwind-protect
;; remove the leading / from the file name to force
;; expand-file-name to interpret its path as relative to dir
(let* ((file-name (if (string-match "\\`/" item-name)
(substring item-name 1)
item-name))
(output-file (expand-file-name file-name dir))
(output-dir (file-name-directory output-file)))
;; create the output directory (and its parents) if it does
;; not exist yet
(unless (file-directory-p output-dir)
(make-directory output-dir t))
;; execute COMMAND, redirecting output to output-file
(apply #'call-process
(car command) ;program
nil ;infile
`(:file ,output-file) ;destination
nil ;display
(append (cdr command) (list archive-name item-name))))
;; FIXME: add unwind forms
nil))
archive-extract-by-fileこれを取得するように変更しました。
(defun archive-extract-marked-to-file (output-dir)
"Extract marked archive items to OUTPUT-DIR."
(interactive "sOutput directory: ")
(let ((command (symbol-value (archive-name "extract")))
(archive (buffer-file-name))
(items (archive-get-marked ?* t))) ; get marked items; t means
; get item under point if
; nothing is marked
(mapc
(lambda (item)
(archive-extract-to-file archive
(aref item 0) ; get the name from the descriptor
command output-dir))
items)))
ここではmapc、マークされたすべてのファイルをループして抽出します。
ここで、キーバインディングを追加するだけです。
(require 'arc-mode)
(define-key archive-mode-map "F" #'archive-extract-marked-to-file)
.zipサブディレクトリを含むダミーファイルでこれをテストしましたが、実際の距離は異なる場合があります。
なお、archive-modeサポートArc、Lzh、Zip、Zoo、Rar、と7z。それはないないサポート.tgz、.tbz、.tar.gzおよび使用して開かれ、友人、tar-modeそしてuncompress.el。
copyright-clerk@fsf.org(Lars Ingebrigtsenからこのメールを受け取った)からの返信を待っています。それまでの間、これをクリーンアップしてGitHubに配置します。
(interactive "G...")、それは、現在のディレクトリを提案します、プラスそれはなどを自動補完し、イドモードと対話します。この方法
foo/bar.txtアーカイブではにoutput-dir/foo/bar.txtではなくに抽出されoutput-dir/bar.txtます。もちろん後者も可能ですが、さらにコードが必要になります。