]> code.delx.au - gnu-emacs/blobdiff - lisp/jka-compr.el
Add a provide statement.
[gnu-emacs] / lisp / jka-compr.el
index a13f43faf19d9e6b0bf6c3c350f6152405e5a569..fa852bd19b60f6485933efb74e7a206694427881 100644 (file)
@@ -1,6 +1,6 @@
 ;;; jka-compr.el --- reading/writing/loading compressed files
 
-;; Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000  Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2003, 2004  Free Software Foundation, Inc.
 
 ;; Author: jka@ece.cmu.edu (Jay K. Adams)
 ;; Maintainer: FSF
@@ -64,7 +64,7 @@
 ;; APPLICATION NOTES:
 ;;
 ;; crypt++
-;;   jka-compr can coexist with crpyt++ if you take all the decompression
+;;   jka-compr can coexist with crypt++ if you take all the decompression
 ;;   entries out of the crypt-encoding-list.  Clearly problems will arise if
 ;;   you have two programs trying to compress/decompress files.  jka-compr
 ;;   will not "work with" crypt++ in the following sense: you won't be able to
@@ -77,9 +77,9 @@
 
 
 ;; ACKNOWLEDGMENTS
-;; 
+;;
 ;; jka-compr is a V19 adaptation of jka-compr for V18 of Emacs.  Many people
-;; have made helpful suggestions, reported bugs, and even fixed bugs in 
+;; have made helpful suggestions, reported bugs, and even fixed bugs in
 ;; jka-compr.  I recall the following people as being particularly helpful.
 ;;
 ;;   Jean-loup Gailly
@@ -117,7 +117,7 @@ for `jka-compr-compression-info-list')."
   :type 'string
   :group 'jka-compr)
 
-(defvar jka-compr-use-shell 
+(defvar jka-compr-use-shell
   (not (memq system-type '(ms-dos windows-nt))))
 
 ;;; I have this defined so that .Z files are assumed to be in unix
@@ -138,6 +138,10 @@ for `jka-compr-compression-info-list')."
      "bzip2ing"        "bzip2"         nil
      "bunzip2ing"      "bzip2"         ("-d")
      nil t "BZh"]
+    ["\\.tbz\\'"
+     "bzip2ing"        "bzip2"         nil
+     "bunzip2ing"      "bzip2"         ("-d")
+     nil nil "BZh"]
     ["\\.tgz\\'"
      "zipping"        "gzip"         ("-c" "-q")
      "unzipping"      "gzip"         ("-c" "-q" "-d")
@@ -145,7 +149,14 @@ for `jka-compr-compression-info-list')."
     ["\\.g?z\\(~\\|\\.~[0-9]+~\\)?\\'"
      "zipping"        "gzip"         ("-c" "-q")
      "unzipping"      "gzip"         ("-c" "-q" "-d")
-     t t "\037\213"])
+     t t "\037\213"]
+    ;; dzip is gzip with random access.  Its compression program can't
+    ;; read/write stdin/out, so .dz files can only be viewed without
+    ;; saving, having their contents decompressed with gzip.
+    ["\\.dz\\'"
+     nil              nil            nil
+     "unzipping"      "gzip"         ("-c" "-q" "-d")
+     nil t "\037\213"])
 
   "List of vectors that describe available compression techniques.
 Each element, which describes a compression technique, is a vector of
@@ -160,6 +171,7 @@ APPEND-FLAG STRIP-EXTENSION-FLAG FILE-MAGIC-CHARS], where:
                          type of compression (nil means no message)
 
    compress-program      is a program that performs this compression
+                         (nil means visit file in read-only mode)
 
    compress-args         is a list of args to pass to the compress program
 
@@ -199,7 +211,7 @@ invoked."
   :group 'jka-compr)
 
 (defcustom jka-compr-mode-alist-additions
-  (list (cons "\\.tgz\\'" 'tar-mode))
+  (list (cons "\\.tgz\\'" 'tar-mode) (cons "\\.tbz\\'" 'tar-mode))
   "A list of pairs to add to `auto-mode-alist' when jka-compr is installed."
   :type '(repeat (cons string symbol))
   :group 'jka-compr)
@@ -270,8 +282,8 @@ based on the filename itself and `jka-compr-compression-info-list'."
 
   (signal 'compression-error
          (list "Opening input file" (format "error %s" message) infile)))
-                       
-   
+
+
 (defcustom jka-compr-dd-program "/bin/dd"
   "How to invoke `dd'."
   :type 'string
@@ -356,7 +368,7 @@ to keep: LEN chars starting BEG chars from the beginning."
 
          (jka-compr-delete-temp-file err-file)))
 
-    (or (zerop
+    (or (eq 0
         (apply 'call-process
                prog
                infile
@@ -421,10 +433,7 @@ There should be no more than seven characters after the final `/'."
        (let ((can-append (jka-compr-info-can-append info))
              (compress-program (jka-compr-info-compress-program info))
              (compress-message (jka-compr-info-compress-message info))
-             (uncompress-program (jka-compr-info-uncompress-program info))
-             (uncompress-message (jka-compr-info-uncompress-message info))
              (compress-args (jka-compr-info-compress-args info))
-             (uncompress-args (jka-compr-info-uncompress-args info))
              (base-name (file-name-nondirectory visit-file))
              temp-file temp-buffer
              ;; we need to leave `last-coding-system-used' set to its
@@ -432,6 +441,9 @@ There should be no more than seven characters after the final `/'."
              ;; that `basic-save-buffer' sees the right value.
              (coding-system-used last-coding-system-used))
 
+          (or compress-program
+              (error "No compression program defined"))
+
          (setq temp-buffer (get-buffer-create " *jka-compr-wr-temp*"))
          (with-current-buffer temp-buffer
            (widen) (erase-buffer))
@@ -447,7 +459,7 @@ There should be no more than seven characters after the final `/'."
 
            (setq temp-file (jka-compr-make-temp-name)))
 
-         (and 
+         (and
           compress-message
           (message "%s %s..." compress-message base-name))
 
@@ -502,7 +514,7 @@ There should be no more than seven characters after the final `/'."
          (setq last-coding-system-used coding-system-used)
 
          nil)
-             
+
       (jka-compr-run-real-handler 'write-region
                                  (list start end filename append visit)))))
 
@@ -527,20 +539,7 @@ There should be no more than seven characters after the final `/'."
              (local-copy
               (jka-compr-run-real-handler 'file-local-copy (list filename)))
              local-file
-             size start
-              (coding-system-for-read
-              (or coding-system-for-read
-                  ;; If multibyte characters are disabled,
-                  ;; don't do that conversion.
-                  (and (null enable-multibyte-characters)
-                       (or (auto-coding-alist-lookup
-                            (jka-compr-byte-compiler-base-file-name file))
-                           'raw-text))
-                  (let ((coding (find-operation-coding-system
-                                 'insert-file-contents
-                                 (jka-compr-byte-compiler-base-file-name file))))
-                    (and (consp coding) (car coding)))
-                  'undecided)) )
+             size start)
 
          (setq local-file (or local-copy filename))
 
@@ -551,14 +550,14 @@ There should be no more than seven characters after the final `/'."
          (unwind-protect               ; to make sure local-copy gets deleted
 
              (progn
-                 
+
                (and
                 uncompress-message
                 (message "%s %s..." uncompress-message base-name))
 
                (condition-case error-code
 
-                   (progn
+                   (let ((coding-system-for-read 'no-conversion))
                      (if replace
                          (goto-char (point-min)))
                      (setq start (point))
@@ -586,17 +585,14 @@ There should be no more than seven characters after the final `/'."
                                                  uncompress-args)))
                      (setq size (- (point) start))
                      (if replace
-                         (let* ((del-beg (point))
-                                (del-end (+ del-beg size)))
-                           (delete-region del-beg
-                                          (min del-end (point-max)))))
+                         (delete-region (point) (point-max)))
                      (goto-char start))
                  (error
                   (if (and (eq (car error-code) 'file-error)
                            (eq (nth 3 error-code) local-file))
                       (if visit
                           (setq notfound error-code)
-                        (signal 'file-error 
+                        (signal 'file-error
                                 (cons "Opening input file"
                                       (nthcdr 2 error-code))))
                     (signal (car error-code) (cdr error-code))))))
@@ -606,6 +602,12 @@ There should be no more than seven characters after the final `/'."
             (file-exists-p local-copy)
             (delete-file local-copy)))
 
+         (unless notfound
+           (decode-coding-inserted-region
+            (point) (+ (point) size)
+            (jka-compr-byte-compiler-base-file-name file)
+            visit beg end replace))
+
          (and
           visit
           (progn
@@ -613,7 +615,7 @@ There should be no more than seven characters after the final `/'."
             (setq buffer-file-name filename)
             (setq jka-compr-really-do-compress t)
             (set-visited-file-modtime)))
-           
+
          (and
           uncompress-message
           (message "%s %s...done" uncompress-message base-name))
@@ -641,6 +643,9 @@ There should be no more than seven characters after the final `/'."
 ;;;                (setq size insval)))
 ;;;          (setq p (cdr p))))
 
+          (or (jka-compr-info-compress-program info)
+              (message "You can't save this buffer because compression program is not defined"))
+
          (list filename size))
 
       (jka-compr-run-real-handler 'insert-file-contents
@@ -669,11 +674,11 @@ There should be no more than seven characters after the final `/'."
          (unwind-protect
 
              (with-current-buffer temp-buffer
-                 
+
                (and
                 uncompress-message
                 (message "%s %s..." uncompress-message base-name))
-                 
+
                ;; Here we must read the output of uncompress program
                ;; and write it to TEMP-FILE without any code
                ;; conversion.  An appropriate code conversion (if
@@ -705,7 +710,7 @@ There should be no more than seven characters after the final `/'."
            (kill-buffer temp-buffer))
 
          temp-file)
-           
+
       (jka-compr-run-real-handler 'file-local-copy (list filename)))))
 
 
@@ -757,6 +762,7 @@ There should be no more than seven characters after the final `/'."
 Lisp programs can bind this to t to do that.
 It is not recommended to set this variable permanently to anything but nil.")
 
+(put 'jka-compr-handler 'safe-magic t)
 (defun jka-compr-handler (operation &rest args)
   (save-match-data
     (let ((jka-op (get operation 'jka-compr)))
@@ -872,7 +878,7 @@ by `jka-compr-installed'."
                   (eq (nth 2 entry) 'jka-compr)))
          (setcdr last (cdr (cdr last)))
        (setq last (cdr last))))
-    
+
     (setq auto-mode-alist (cdr ama)))
 
   (let* ((ama (cons nil file-coding-system-alist))
@@ -884,7 +890,7 @@ by `jka-compr-installed'."
       (if (member entry jka-compr-added-to-file-coding-system-alist)
          (setcdr last (cdr (cdr last)))
        (setq last (cdr last))))
-    
+
     (setq file-coding-system-alist (cdr ama)))
 
   ;; Remove the suffixes that were added by jka-compr.
@@ -895,7 +901,7 @@ by `jka-compr-installed'."
        (push suffix suffixes)))
     (setq load-suffixes (nreverse suffixes))))
 
-      
+
 (defun jka-compr-installed-p ()
   "Return non-nil if jka-compr is installed.
 The return value is the entry in `file-name-handler-alist' for jka-compr."
@@ -950,4 +956,5 @@ Returns the new status of auto compression (non-nil means on)."
 
 (provide 'jka-compr)
 
+;;; arch-tag: 3f15b630-e9a7-46c4-a22a-94afdde86ebc
 ;;; jka-compr.el ends here