]> code.delx.au - gnu-emacs/blobdiff - lisp/arc-mode.el
(proced-after-send-signal-hook): Use defcustom.
[gnu-emacs] / lisp / arc-mode.el
index 1bb4d2d477b5f159817474befd5cdcdc2e87b429..d3e4c9f3e36997e90d6b027dfd6fda6e22bf2c78 100644 (file)
@@ -1,7 +1,7 @@
 ;;; arc-mode.el --- simple editing of archives
 
 ;; Copyright (C) 1995, 1997, 1998, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 ;; Author: Morten Welinder <terra@gnu.org>
 ;; Keywords: archives msdog editing major-mode
@@ -9,10 +9,10 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,9 +20,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
   :group 'archive)
 
 (defcustom archive-remote-regexp "^/[^/:]*[^/:.]:"
-  "*Regexp recognizing archive files names that are not local.
+  "Regexp recognizing archive files names that are not local.
 A non-local file is one whose file name is not proper outside Emacs.
 A local copy of the archive will be used when updating."
   :type 'regexp
   :group 'archive)
 
 (defcustom archive-extract-hooks nil
-  "*Hooks to run when an archive member has been extracted."
+  "Hooks to run when an archive member has been extracted."
   :type 'hook
   :group 'archive)
 ;; ------------------------------
@@ -154,7 +152,7 @@ A local copy of the archive will be used when updating."
 ;; to extract to stdout without junk getting added.
 (defcustom archive-arc-extract
   '("arc" "x")
-  "*Program and its options to run in order to extract an arc file member.
+  "Program and its options to run in order to extract an arc file member.
 Extraction should happen to the current directory.  Archive and member
 name will be added."
   :type '(list (string :tag "Program")
@@ -165,7 +163,7 @@ name will be added."
 
 (defcustom archive-arc-expunge
   '("arc" "d")
-  "*Program and its options to run in order to delete arc file members.
+  "Program and its options to run in order to delete arc file members.
 Archive and member names will be added."
   :type '(list (string :tag "Program")
                (repeat :tag "Options"
@@ -175,7 +173,7 @@ Archive and member names will be added."
 
 (defcustom archive-arc-write-file-member
   '("arc" "u")
-  "*Program and its options to run in order to update an arc file member.
+  "Program and its options to run in order to update an arc file member.
 Archive and member name will be added."
   :type '(list (string :tag "Program")
                (repeat :tag "Options"
@@ -187,7 +185,7 @@ Archive and member name will be added."
 
 (defcustom archive-lzh-extract
   '("lha" "pq")
-  "*Program and its options to run in order to extract an lzh file member.
+  "Program and its options to run in order to extract an lzh file member.
 Extraction should happen to standard output.  Archive and member name will
 be added."
   :type '(list (string :tag "Program")
@@ -198,7 +196,7 @@ be added."
 
 (defcustom archive-lzh-expunge
   '("lha" "d")
-  "*Program and its options to run in order to delete lzh file members.
+  "Program and its options to run in order to delete lzh file members.
 Archive and member names will be added."
   :type '(list (string :tag "Program")
                (repeat :tag "Options"
@@ -208,7 +206,7 @@ Archive and member names will be added."
 
 (defcustom archive-lzh-write-file-member
   '("lha" "a")
-  "*Program and its options to run in order to update an lzh file member.
+  "Program and its options to run in order to update an lzh file member.
 Archive and member name will be added."
   :type '(list (string :tag "Program")
                (repeat :tag "Options"
@@ -223,7 +221,7 @@ Archive and member name will be added."
            (executable-find "pkunzip"))
       '("pkunzip" "-e" "-o-")
     '("unzip" "-qq" "-c"))
-  "*Program and its options to run in order to extract a zip file member.
+  "Program and its options to run in order to extract a zip file member.
 Extraction should happen to standard output.  Archive and member name will
 be added."
   :type '(list (string :tag "Program")
@@ -232,7 +230,7 @@ be added."
                        (string :format "%v")))
   :group 'archive-zip)
 
-;; For several reasons the latter behaviour is not desirable in general.
+;; For several reasons the latter behavior is not desirable in general.
 ;; (1) It uses more disk space.  (2) Error checking is worse or non-
 ;; existent.  (3) It tends to do funny things with other systems' file
 ;; names.
@@ -242,7 +240,7 @@ be added."
            (executable-find "pkzip"))
       '("pkzip" "-d")
     '("zip" "-d" "-q"))
-  "*Program and its options to run in order to delete zip file members.
+  "Program and its options to run in order to delete zip file members.
 Archive and member names will be added."
   :type '(list (string :tag "Program")
                (repeat :tag "Options"
@@ -255,7 +253,7 @@ Archive and member names will be added."
            (executable-find "pkzip"))
       '("pkzip" "-u" "-P")
     '("zip" "-q"))
-  "*Program and its options to run in order to update a zip file member.
+  "Program and its options to run in order to update a zip file member.
 Options should ensure that specified directory will be put into the zip
 file.  Archive and member name will be added."
   :type '(list (string :tag "Program")
@@ -269,7 +267,7 @@ file.  Archive and member name will be added."
            (executable-find "pkzip"))
       '("pkzip" "-u" "-P")
     '("zip" "-q" "-k"))
-  "*Program and its options to run in order to update a case fiddled zip member.
+  "Program and its options to run in order to update a case fiddled zip member.
 Options should ensure that specified directory will be put into the zip file.
 Archive and member name will be added."
   :type '(list (string :tag "Program")
@@ -279,7 +277,7 @@ Archive and member name will be added."
   :group 'archive-zip)
 
 (defcustom archive-zip-case-fiddle t
-  "*If non-nil then zip file members may be down-cased.
+  "If non-nil then zip file members may be down-cased.
 This case fiddling will only happen for members created by a system
 that uses caseless file names."
   :type 'boolean
@@ -289,7 +287,7 @@ that uses caseless file names."
 
 (defcustom archive-zoo-extract
   '("zoo" "xpq")
-  "*Program and its options to run in order to extract a zoo file member.
+  "Program and its options to run in order to extract a zoo file member.
 Extraction should happen to standard output.  Archive and member name will
 be added."
   :type '(list (string :tag "Program")
@@ -300,7 +298,7 @@ be added."
 
 (defcustom archive-zoo-expunge
   '("zoo" "DqPP")
-  "*Program and its options to run in order to delete zoo file members.
+  "Program and its options to run in order to delete zoo file members.
 Archive and member names will be added."
   :type '(list (string :tag "Program")
                (repeat :tag "Options"
@@ -310,7 +308,7 @@ Archive and member names will be added."
 
 (defcustom archive-zoo-write-file-member
   '("zoo" "a")
-  "*Program and its options to run in order to update a zoo file member.
+  "Program and its options to run in order to update a zoo file member.
 Archive and member name will be added."
   :type '(list (string :tag "Program")
                (repeat :tag "Options"
@@ -358,6 +356,8 @@ Archive and member name will be added."
     (define-key map "M" 'archive-chmod-entry)
     (define-key map "G" 'archive-chgrp-entry)
     (define-key map "O" 'archive-chown-entry)
+    ;; Let mouse-1 follow the link.
+    (define-key map [follow-link] 'mouse-face)
 
     (if (fboundp 'command-remapping)
         (progn
@@ -723,7 +723,7 @@ archive.
                (string-match "\\.[aA][rR][cC]$"
                              (or buffer-file-name (buffer-name))))
           'arc)
-          ;; This pattern modelled on the BSD/GNU+Linux `file' command.
+          ;; This pattern modeled on the BSD/GNU+Linux `file' command.
           ;; Have seen capital "LHA's", and file has lower case "LHa's" too.
           ;; Note this regexp is also in archive-exe-p.
           ((looking-at "MZ\\(.\\|\n\\)\\{34\\}LH[aA]'s SFX ") 'lzh-exe)
@@ -892,6 +892,26 @@ using `make-temp-file', and the generated name is returned."
 ;; -------------------------------------------------------------------------
 ;;; Section: Member extraction
 
+(defun archive-try-jka-compr ()
+  (when (and auto-compression-mode
+             (jka-compr-get-compression-info buffer-file-name))
+    (let* ((basename (file-name-nondirectory buffer-file-name))
+           (tmpname (if (string-match ":\\([^:]+\\)\\'" basename)
+                        (match-string 1 basename) basename))
+           (tmpfile (make-temp-file (file-name-sans-extension tmpname)
+                                    nil
+                                    (file-name-extension tmpname 'period))))
+      (unwind-protect
+          (progn
+            (let ((coding-system-for-write 'no-conversion)
+                  ;; Don't re-compress this data just before decompressing it.
+                  (jka-compr-inhibit t))
+              (write-region (point-min) (point-max) tmpfile nil 'quiet))
+            (erase-buffer)
+            (let ((coding-system-for-read 'no-conversion))
+              (insert-file-contents tmpfile)))
+        (delete-file tmpfile)))))
+
 (defun archive-file-name-handler (op &rest args)
   (or (eq op 'file-exists-p)
       (let ((file-name-handler-alist nil))
@@ -921,13 +941,12 @@ using `make-temp-file', and the generated name is returned."
                 (car (find-operation-coding-system
                       'insert-file-contents
                       (cons filename (current-buffer)) t))))))
-      (if (and (not coding-system-for-read)
-              (not enable-multibyte-characters))
-         (setq coding
-               (coding-system-change-text-conversion coding 'raw-text)))
-      (if (and coding
-              (not (eq coding 'no-conversion)))
-         (decode-coding-region (point-min) (point-max) coding)
+      (unless (or coding-system-for-read
+                  enable-multibyte-characters)
+        (setq coding
+              (coding-system-change-text-conversion coding 'raw-text)))
+      (unless (memq coding '(nil no-conversion))
+        (decode-coding-region (point-min) (point-max) coding)
        (setq last-coding-system-used coding))
       (set-buffer-modified-p nil)
       (kill-local-variable 'buffer-file-coding-system)
@@ -999,6 +1018,7 @@ using `make-temp-file', and the generated name is returned."
              (progn
                (set-buffer-modified-p nil)
                (kill-buffer buffer))
+            (archive-try-jka-compr)     ;Pretty ugly hack :-(
            (archive-set-buffer-as-visiting-file ename)
            (goto-char (point-min))
            (rename-buffer bufname)
@@ -1039,7 +1059,7 @@ using `make-temp-file', and the generated name is returned."
                 nil
                 nil
                 (append (cdr command) (list archive name))))
-    (cond ((and (numberp exit-status) (= exit-status 0))
+    (cond ((and (numberp exit-status) (zerop exit-status))
           (if (not (file-exists-p tmpfile))
               (ding (message "`%s': no such file or directory" tmpfile))
             (insert-file-contents tmpfile)
@@ -1097,7 +1117,7 @@ using `make-temp-file', and the generated name is returned."
                          (file-name-nondirectory buffer-file-name)
                        ""))))
   (with-current-buffer arcbuf
-    (or (eq major-mode 'archive-mode)
+    (or (derived-mode-p 'archive-mode)
        (error "Buffer is not an archive buffer"))
     (if archive-read-only
        (error "Archive is read-only")))
@@ -1151,7 +1171,7 @@ using `make-temp-file', and the generated name is returned."
          ;; the dired-like listing we created.
          (if (eq major-mode 'archive-mode)
              (archive-write-file tmpfile)
-           (write-region (point-min) (point-max) tmpfile nil 'nomessage))
+           (write-region nil nil tmpfile nil 'nomessage))
          ;; basic-save-buffer needs last-coding-system-used to have
          ;; the value used to write the file, so save it before any
          ;; further processing clobbers it (we restore it in
@@ -1170,9 +1190,8 @@ using `make-temp-file', and the generated name is returned."
                                  nil
                                  (append (cdr command)
                                          (list archive ename)))))
-            (if (equal exitcode 0)
-                nil
-              (error "Updating was unsuccessful (%S)" exitcode))))
+            (or (zerop exitcode)
+               (error "Updating was unsuccessful (%S)" exitcode))))
       (archive-delete-local tmpfile))))
 
 (defun archive-write-file (&optional file)
@@ -1712,7 +1731,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself."
                         str archive-file-name-coding-system)))
             (isdir   (and (= ucsize 0)
                           (string= (file-name-nondirectory efnname) "")))
-            (mode    (cond ((memq creator '(2 3)) ; Unix + VMS
+            (mode    (cond ((memq creator '(2 3)) ; Unix
                             (archive-l-e (+ p 40) 2))
                            ((memq creator '(0 5 6 7 10 11 15)) ; Dos etc.
                             (logior ?\444
@@ -1781,7 +1800,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself."
               (oldmode (aref fil 3))
               (newval  (archive-calc-mode oldmode newmode t))
               (inhibit-read-only t))
-         (cond ((memq creator '(2 3)) ; Unix + VMS
+         (cond ((memq creator '(2 3)) ; Unix
                 (goto-char (+ p 40))
                 (delete-char 2)
                 (insert-unibyte (logand newval 255) (lsh newval -8)))
@@ -2088,7 +2107,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself."
           (with-current-buffer destbuf
             ;; Do it within the `widen'.
             (insert-buffer-substring archivebuf from (+ from size)))
-          (set-buffer-multibyte t)
+          (set-buffer-multibyte 'to)
           ;; Inform the caller that the call succeeded.
           t)))))