+2012-09-28 Juri Linkov <juri@jurta.org>
+
+ Display archive errors in the echo area instead of inserting
+ to the file buffer.
+
+ * arc-mode.el (archive-extract-by-stdout): Change arg STDERR-FILE
+ to STDERR-TEST that can be a regexp matching a successful output.
+ Create a temporary file and redirect stderr to it. Search for
+ STDERR-TEST in the stderr output and display it in the echo area
+ if no match is found.
+ (archive-extract-by-file): New function like
+ `archive-extract-by-stdout' but extracting archives to files
+ and looking for successful matches in stdout. Function body is
+ mostly copied from `archive-rar-extract'.
+ (archive-rar-extract): Use `archive-extract-by-file'.
+ (archive-7z-extract): Use `archive-extract-by-stdout'. (Bug#10347)
+
2012-09-28 Leo Liu <sdl.web@gmail.com>
* pcomplete.el (pcomplete-show-completions): Use
(archive-delete-local tmpfile)
success))
-(defun archive-extract-by-stdout (archive name command &optional stderr-file)
- (apply 'call-process
- (car command)
- nil
- (if stderr-file (list t stderr-file) t)
- nil
- (append (cdr command) (list archive name))))
+(defun archive-extract-by-stdout (archive name command &optional stderr-test)
+ (let ((stderr-file (make-temp-file "arc-stderr")))
+ (unwind-protect
+ (prog1
+ (apply 'call-process
+ (car command)
+ nil
+ (if stderr-file (list t stderr-file) t)
+ nil
+ (append (cdr command) (list archive name)))
+ (with-temp-buffer
+ (insert-file-contents stderr-file)
+ (goto-char (point-min))
+ (when (if (stringp stderr-test)
+ (not (re-search-forward stderr-test nil t))
+ (> (buffer-size) 0))
+ (message "%s" (buffer-string)))))
+ (if (file-exists-p stderr-file)
+ (delete-file stderr-file)))))
+
+(defun archive-extract-by-file (archive name command &optional stdout-test)
+ (let ((dest (make-temp-file "arc-dir" 'dir))
+ (stdout-file (make-temp-file "arc-stdout")))
+ (unwind-protect
+ (prog1
+ (apply 'call-process
+ (car command)
+ nil
+ `(:file ,stdout-file)
+ nil
+ (append (cdr command) (list archive name dest)))
+ (with-temp-buffer
+ (insert-file-contents stdout-file)
+ (goto-char (point-min))
+ (when (if (stringp stdout-test)
+ (not (re-search-forward stdout-test nil t))
+ (> (buffer-size) 0))
+ (message "%s" (buffer-string))))
+ (if (file-exists-p (expand-file-name name dest))
+ (insert-file-contents-literally (expand-file-name name dest))))
+ (if (file-exists-p stdout-file)
+ (delete-file stdout-file))
+ (if (file-exists-p (expand-file-name name dest))
+ (delete-file (expand-file-name name dest)))
+ (while (file-name-directory name)
+ (setq name (directory-file-name (file-name-directory name)))
+ (delete-directory (expand-file-name name dest)))
+ (delete-directory dest))))
(defun archive-extract-other-window ()
"In archive mode, find this member in another window."
;; The code below assumes the name is relative and may do undesirable
;; things otherwise.
(error "Can't extract files with non-relative names")
- (let ((dest (make-temp-file "arc-rar" 'dir)))
- (unwind-protect
- (progn
- (call-process "unrar-free" nil nil nil
- "--extract" archive name dest)
- (insert-file-contents-literally (expand-file-name name dest)))
- (delete-file (expand-file-name name dest))
- (while (file-name-directory name)
- (setq name (directory-file-name (file-name-directory name)))
- (delete-directory (expand-file-name name dest)))
- (delete-directory dest)))))
+ (archive-extract-by-file archive name '("unrar-free" "--extract") "All OK")))
;;; Section: Rar self-extracting .exe archives.
(apply 'vector files))))
(defun archive-7z-extract (archive name)
- (let ((tmpfile (make-temp-file "7z-stderr")))
- ;; 7z doesn't provide a `quiet' option to suppress non-essential
- ;; stderr messages. So redirect stderr to a temp file and display it
- ;; in the echo area when it contains error messages.
- (prog1 (archive-extract-by-stdout
- archive name archive-7z-extract tmpfile)
- (with-temp-buffer
- (insert-file-contents tmpfile)
- (unless (search-forward "Everything is Ok" nil t)
- (message "%s" (buffer-string)))
- (delete-file tmpfile)))))
+ ;; 7z doesn't provide a `quiet' option to suppress non-essential
+ ;; stderr messages. So redirect stderr to a temp file and display it
+ ;; in the echo area when it contains no message indicating success.
+ (archive-extract-by-stdout
+ archive name archive-7z-extract "Everything is Ok"))
(defun archive-7z-write-file-member (archive descr)
(archive-*-write-file-member