Subject: bug#1702: [PATCH]: feature request: correctly display single file zip archive

From: Matthew Leach <[email-masked]>
Date: Thu, 13 Nov 2014 18:39:43 +0000

Hi all,

xah lee <[email-masked]> writes:

> When opening a zip archive of a single file, emacs displays the zip
> archive's index (which is just a single file), as opposed to the
> decompressed file content.
>
> I think when the zip file is a single file, it is more useful to
> display file content and allow transparent editing.

Please see the attached patch to implement this.

Any comments welcome!

Thanks,
-- 
Matt

ChangeLog entry:

2014-11-13  Matthew Leach  <[email-masked]>

	* arc-mode.el (singular-file-archive-action): New.
	(archive-mode): Visit file if archive contains a single file.

>From 1c84ec04f024f9de44b0bb57d60d009b9738c899 Mon Sep 17 00:00:00 2001
From: Matthew Leach <[email-masked]>
Date: Thu, 13 Nov 2014 18:30:24 +0000
Subject: [PATCH] Don't show summary for single-file archives.

* arc-mode.el (singular-file-archive-action): New.
(archive-mode): Visit file if archive contains a single file.
---
 lisp/arc-mode.el | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el
index ef155ee..279b9a1 100644
--- a/lisp/arc-mode.el
+++ b/lisp/arc-mode.el
@@ -147,6 +147,13 @@ A local copy of the archive will be used when updating."
   "Hook run when an archive member has been extracted."
   :type 'hook
   :group 'archive)
+
+(defcustom singular-file-archive-action 'visit-file
+  "When opening an archive that contains a single file choose
+whether to open the file or display the archive summary."
+  :type '(choice (const :tag "Show archive summary" show-summary)
+                 (const :tag "Visit the single file" visit-file))
+  :group 'archive)
 ;; ------------------------------
 ;; Arc archive configuration
 
@@ -742,7 +749,12 @@ archive.
       (if (default-value 'enable-multibyte-characters)
 	  (set-buffer-multibyte 'to))
       (archive-summarize nil)
-      (setq buffer-read-only t))))
+      (setq buffer-read-only t)
+      (when (and (= (length archive-files) 1)
+                 (eq singular-file-archive-action 'visit-file))
+        (let ((archive-buffer (current-buffer)))
+          (archive-extract)
+          (kill-buffer archive-buffer))))))
 
 ;; Archive mode is suitable only for specially formatted data.
 (put 'archive-mode 'mode-class 'special)
-- 
2.1.3