all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 5475@debbugs.gnu.org
Subject: bug#5475: Archives with filenames with square brackets
Date: Mon, 01 Feb 2010 23:55:35 +0200	[thread overview]
Message-ID: <87r5p4k4dk.fsf@mail.jurta.org> (raw)
In-Reply-To: <jwvy6jdc69c.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 01 Feb 2010 10:43:01 -0500")

> AFAIK 7zip is Free Software, but adding 7z support would be a new
> feature, so we would probably be better off insalling it into the
> `pending' branch.

Below is minimal support for the 7z format for the `pending' branch.

Fortunately, 7z provides so-called "technical" mode for the list
command (-slt) that outputs file information in a simple fixed format,
so we could rely on it.  In `archive-7z-extract' stderr is thrown away
because 7z doesn't have a switch to make it silent.

=== modified file 'lisp/arc-mode.el'
--- lisp/arc-mode.el	2010-01-28 20:06:36 +0000
+++ lisp/arc-mode.el	2010-02-01 21:48:09 +0000
@@ -52,17 +52,17 @@
 ;; ARCHIVE TYPES: Currently only the archives below are handled, but the
 ;; structure for handling just about anything is in place.
 ;;
-;;			Arc	Lzh	Zip	Zoo	 Rar
-;;			----------------------------------------
-;; View listing		Intern	Intern	Intern	Intern   Y
-;; Extract member	Y	Y	Y	Y        Y
-;; Save changed member	Y	Y	Y	Y        N
-;; Add new member	N	N	N	N        N
-;; Delete member	Y	Y	Y	Y        N
-;; Rename member	Y	Y	N	N        N
-;; Chmod		-	Y	Y	-        N
-;; Chown		-	Y	-	-        N
-;; Chgrp		-	Y	-	-        N
+;;			Arc	Lzh	Zip	Zoo	Rar	7z
+;;			--------------------------------------------
+;; View listing		Intern	Intern	Intern	Intern	Y	Y
+;; Extract member	Y	Y	Y	Y	Y	Y
+;; Save changed member	Y	Y	Y	Y	N	N
+;; Add new member	N	N	N	N	N	N
+;; Delete member	Y	Y	Y	Y	N	N
+;; Rename member	Y	Y	N	N	N	N
+;; Chmod		-	Y	Y	-	N	N
+;; Chown		-	Y	-	-	N	N
+;; Chgrp		-	Y	-	-	N	N
 ;;
 ;; Special thanks to Bill Brodie <wbrodie@panix.com> for very useful tips
 ;; on the first released version of this package.
@@ -315,6 +315,20 @@ (defcustom archive-zoo-write-file-member
 			:inline t
 			(string :format "%v")))
   :group 'archive-zoo)
+;; ------------------------------
+;; 7z archive configuration
+
+(defcustom archive-7z-extract
+  '("7z" "x" "-so")
+  "Program and its options to run in order to extract a 7z file member.
+Extraction should happen to standard output.  Archive and member name will
+be added."
+  :type '(list (string :tag "Program")
+		(repeat :tag "Options"
+			:inline t
+			(string :format "%v")))
+  :group 'archive-7z)
+
 ;; -------------------------------------------------------------------------
 ;;; Section: Variables
 
@@ -732,6 +746,7 @@ (defun archive-find-type ()
           ((and (looking-at "MZ")
                 (re-search-forward "Rar!" (+ (point) 100000) t))
            'rar-exe)
+	  ((looking-at "7z\274\257\047\034") '7z)
 	  (t (error "Buffer format not recognized")))))
 ;; -------------------------------------------------------------------------
 
@@ -1084,6 +1099,14 @@ (defun archive-extract-by-stdout (archiv
 	 nil
 	 (append (cdr command) (list archive name))))
 
+(defun archive-extract-by-stdout-without-stderr (archive name command)
+  (apply 'call-process
+	 (car command)
+	 nil
+	 '(t nil)
+	 nil
+	 (append (cdr command) (list archive name))))
+
 (defun archive-extract-other-window ()
   "In archive mode, find this member in another window."
   (interactive)
@@ -1995,7 +2023,57 @@ (defun archive-rar-exe-extract (archive 
       (if tmpbuf (kill-buffer tmpbuf))
       (delete-file tmpfile))))
 
+;; -------------------------------------------------------------------------
+;;; Section: 7z Archives
+
+(defun archive-7z-summarize ()
+  (let ((maxname 10)
+	(maxsize 5)
+	(file buffer-file-name)
+	(files ()))
+    (with-temp-buffer
+      (call-process "7z" nil t nil "l" "-slt" file)
+      (goto-char (point-min))
+      (re-search-forward "^-+\n")
+      (while (re-search-forward "^Path = \\(.*\\)\n" nil t)
+        (goto-char (match-end 0))
+        (let ((name (match-string 1))
+              (size (save-excursion
+		      (and (re-search-forward "^Size = \\(.*\\)\n")
+			   (match-string 1))))
+	      (time (save-excursion
+		      (and (re-search-forward "^Modified = \\(.*\\)\n")
+			   (match-string 1)))))
+          (if (> (length name) maxname) (setq maxname (length name)))
+          (if (> (length size) maxsize) (setq maxsize (length size)))
+          (push (vector name name nil nil time nil nil size)
+                files))))
+    (setq files (nreverse files))
+    (goto-char (point-min))
+    (let* ((format (format " %%%ds %%s %%s" maxsize))
+           (sep (format format (make-string maxsize ?-) "-------------------" ""))
+           (column (length sep)))
+      (insert (format format "Size " "Date       Time    " " Filename") "\n")
+      (insert sep (make-string maxname ?-) "\n")
+      (archive-summarize-files (mapcar (lambda (desc)
+                                         (let ((text
+                                                (format format
+							(aref desc 7)
+							(aref desc 4)
+							(aref desc 1))))
+                                           (vector text
+                                                   column
+                                                   (length text))))
+                                       files))
+      (insert sep (make-string maxname ?-) "\n")
+      (apply 'vector files))))
+
+(defun archive-7z-extract (archive name)
+  ;; Throw away stderr because 7z doesn't have a switch to make it silent.
+  (archive-extract-by-stdout-without-stderr
+   archive name archive-7z-extract))
 
+;; -------------------------------------------------------------------------
 ;;; Section `ar' archives.
 
 ;; TODO: we currently only handle the basic format of ar archives,

=== modified file 'lisp/files.el'
--- lisp/files.el	2010-01-27 03:36:36 +0000
+++ lisp/files.el	2010-02-01 21:45:39 +0000
@@ -2252,8 +2252,8 @@ (defvar auto-mode-alist
      ;; The list of archive file extensions should be in sync with
      ;; `auto-coding-alist' with `no-conversion' coding system.
      ("\\.\\(\
-arc\\|zip\\|lzh\\|lha\\|zoo\\|[jew]ar\\|xpi\\|rar\\|\
-ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\|RAR\\)\\'" . archive-mode)
+arc\\|zip\\|lzh\\|lha\\|zoo\\|[jew]ar\\|xpi\\|rar\\|7z\\|\
+ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\|RAR\\|7Z\\)\\'" . archive-mode)
      ("\\.\\(sx[dmicw]\\|od[fgpst]\\|oxt\\)\\'" . archive-mode) ;OpenOffice.org
      ("\\.\\(deb\\|[oi]pk\\)\\'" . archive-mode) ; Debian/Opkg packages.
      ;; Mailer puts message to be edited in

=== modified file 'lisp/international/mule.el'
--- lisp/international/mule.el	2010-01-13 08:35:10 +0000
+++ lisp/international/mule.el	2010-02-01 21:43:42 +0000
@@ -1626,8 +1626,8 @@ (defcustom auto-coding-alist
   ;; .exe and .EXE are added to support archive-mode looking at DOS
   ;; self-extracting exe archives.
   (purecopy '(("\\.\\(\
-arc\\|zip\\|lzh\\|lha\\|zoo\\|[jew]ar\\|xpi\\|rar\\|\
-ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\|RAR\\)\\'"
+arc\\|zip\\|lzh\\|lha\\|zoo\\|[jew]ar\\|xpi\\|rar\\|7z\\|\
+ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\|RAR\\|7z\\)\\'"
      . no-conversion-multibyte)
     ("\\.\\(exe\\|EXE\\)\\'" . no-conversion)
     ("\\.\\(sx[dmicw]\\|odt\\|tar\\|tgz\\)\\'" . no-conversion)

-- 
Juri Linkov
http://www.jurta.org/emacs/






  reply	other threads:[~2010-02-01 21:55 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-25 17:48 bug#5475: Archives with filenames with square brackets Juri Linkov
2010-01-26 21:05 ` Chong Yidong
2010-01-26 21:47   ` Eli Zaretskii
2010-01-27 16:57     ` Chong Yidong
2010-01-27 17:35       ` Eli Zaretskii
2010-01-28 20:07         ` Chong Yidong
2010-01-28 21:05           ` Eli Zaretskii
2010-01-28 21:24             ` Lennart Borgman
2010-01-28 22:00               ` Eli Zaretskii
2010-01-30 22:59             ` Juri Linkov
2010-01-31  4:18               ` Eli Zaretskii
2010-01-31 10:56                 ` Juri Linkov
2010-01-31 18:04                   ` Eli Zaretskii
2010-01-31 21:59                     ` Juri Linkov
2010-02-01  4:15                       ` Eli Zaretskii
2010-02-01 10:34                         ` Juri Linkov
2010-02-01 11:48                           ` Lennart Borgman
2010-02-01 15:43                           ` Stefan Monnier
2010-02-01 21:55                             ` Juri Linkov [this message]
2010-02-02  0:11                               ` Lennart Borgman
2010-02-02  0:46                                 ` Juri Linkov
2010-02-02  4:03                               ` Eli Zaretskii
2010-04-18 23:14                               ` Juri Linkov
2010-02-01 19:49                           ` Eli Zaretskii
2010-02-01 21:21                             ` Drew Adams
2010-02-01 21:52                               ` Eli Zaretskii
2010-02-01 22:04                                 ` Drew Adams
2010-02-01 22:39                             ` Juri Linkov
2010-02-01 22:41                             ` Lennart Borgman
2010-02-02  0:10                               ` Lennart Borgman
2010-02-02  0:42                                 ` Juri Linkov
2010-02-02  1:30                                   ` Lennart Borgman
2010-02-02 10:03                                     ` Juri Linkov
2010-02-03  0:17                                       ` Lennart Borgman
2010-02-03  0:35                                         ` Juri Linkov
2010-02-03 23:54                                           ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r5p4k4dk.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=5475@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.