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

From: Matthew Leach <[email-masked]>
Date: Fri, 14 Nov 2014 11:06:45 +0000

Hi Eli,

Eli Zaretskii <[email-masked]> writes:

>> From: Matthew Leach <[email-masked]>
>> Cc: [email-masked],  [email-masked],  [email-masked]
>> Date: Thu, 13 Nov 2014 20:50:21 +0000
>> 
>> > Do we want to disable decompression when auto-compression-mode is off,
>> > for example?
>> 
>> I think in the case that the user has auto-compression-mode off, the
>> archive summary should be shown instead.
>
> I agree.  So this needs to be part of the patch, if the rationale is
> what you proposed.

Thank you for the review.  The attached patch should take care of
everything mentioned.
-- 
Matt

lisp/ChangeLog:

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

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

etc/ChangeLog:

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

	* NEWS: Mention archive will now visit the file in singular-file
	archives.
>From fb5402f8fe3e5bdd7e6994cc7fc744d75b0da1da 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 (archive-visit-single-files): New.
(archive-mode): Visit file if archive contains a single file.
* etc/NEWS: Mention archive will now visit the file in singular-file
archives.
---
 etc/NEWS         |  6 ++++++
 lisp/arc-mode.el | 17 ++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 05210df..2083127 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -184,6 +184,12 @@ appending FUN to `minibuffer-setup-hook'.
 ** cl-lib
 *** New functions cl-fresh-line, cl-digit-char-p and cl-parse-integer.
 
+** Archive
+*** When visiting an archive that contains a single file automatically
+visit that file, rather than displaying the archive summary.  To
+revert to the original behaviour, set `archive-visit-single-files' to
+nil.
+
 ** Calendar and diary
 
 +++
diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el
index ef155ee..80f6564 100644
--- a/lisp/arc-mode.el
+++ b/lisp/arc-mode.el
@@ -147,6 +147,15 @@ 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 archive-visit-single-files t
+  "If non-nil, opening an archive with a single file visits that file.
+
+  If this option's value is nil, visiting such archives will
+  display the archive summary."
+  :type '(choice (const :tag "Visit the single file" t)
+                 (const :tag "Show the archive summary" nil))
+  :group 'archive)
 ;; ------------------------------
 ;; Arc archive configuration
 
@@ -742,7 +751,13 @@ 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 archive-visit-single-files
+                 auto-compression-mode
+                 (= (length archive-files) 1))
+        (let ((archive-buffer (current-buffer)))
+          (rename-buffer (concat " " (buffer-name)))
+          (archive-extract))))))
 
 ;; Archive mode is suitable only for specially formatted data.
 (put 'archive-mode 'mode-class 'special)
-- 
2.1.3