diff options
| author | Richard M. Stallman | 2005-04-30 20:18:10 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2005-04-30 20:18:10 +0000 |
| commit | 0e2846fbad9bf418b652a6ade1cc3ae8d34266df (patch) | |
| tree | 15064155ef024e097ae16cf7b638b7fef3fe2bcc | |
| parent | 216b5993d86b9a74247dee89c3c303988fd762d8 (diff) | |
| download | emacs-0e2846fbad9bf418b652a6ade1cc3ae8d34266df.tar.gz emacs-0e2846fbad9bf418b652a6ade1cc3ae8d34266df.zip | |
Many functions and vars moved to jka-compr-hook.el.
(jka-compr-handler): Add autoload. `put' calls moved
to jka-compr-hook.el.
(compression, jka-compr): defgroups moved to jka-compr-hook.el.
(jka-compr-inhibit): Autoload.
| -rw-r--r-- | lisp/jka-compr.el | 236 |
1 files changed, 2 insertions, 234 deletions
diff --git a/lisp/jka-compr.el b/lisp/jka-compr.el index 5bda4349288..ec2eab463cc 100644 --- a/lisp/jka-compr.el +++ b/lisp/jka-compr.el | |||
| @@ -100,15 +100,6 @@ | |||
| 100 | 100 | ||
| 101 | ;;; Code: | 101 | ;;; Code: |
| 102 | 102 | ||
| 103 | (defgroup compression nil | ||
| 104 | "Data compression utilities" | ||
| 105 | :group 'data) | ||
| 106 | |||
| 107 | (defgroup jka-compr nil | ||
| 108 | "jka-compr customization" | ||
| 109 | :group 'compression) | ||
| 110 | |||
| 111 | |||
| 112 | (defcustom jka-compr-shell "sh" | 103 | (defcustom jka-compr-shell "sh" |
| 113 | "*Shell to be used for calling compression programs. | 104 | "*Shell to be used for calling compression programs. |
| 114 | The value of this variable only matters if you want to discard the | 105 | The value of this variable only matters if you want to discard the |
| @@ -120,118 +111,6 @@ for `jka-compr-compression-info-list')." | |||
| 120 | (defvar jka-compr-use-shell | 111 | (defvar jka-compr-use-shell |
| 121 | (not (memq system-type '(ms-dos windows-nt)))) | 112 | (not (memq system-type '(ms-dos windows-nt)))) |
| 122 | 113 | ||
| 123 | ;;; I have this defined so that .Z files are assumed to be in unix | ||
| 124 | ;;; compress format; and .gz files, in gzip format, and .bz2 files in bzip fmt. | ||
| 125 | (defcustom jka-compr-compression-info-list | ||
| 126 | ;;[regexp | ||
| 127 | ;; compr-message compr-prog compr-args | ||
| 128 | ;; uncomp-message uncomp-prog uncomp-args | ||
| 129 | ;; can-append auto-mode-flag strip-extension-flag file-magic-bytes] | ||
| 130 | '(["\\.Z\\(~\\|\\.~[0-9]+~\\)?\\'" | ||
| 131 | "compressing" "compress" ("-c") | ||
| 132 | "uncompressing" "uncompress" ("-c") | ||
| 133 | nil t "\037\235"] | ||
| 134 | ;; Formerly, these had an additional arg "-c", but that fails with | ||
| 135 | ;; "Version 0.1pl2, 29-Aug-97." (RedHat 5.1 GNU/Linux) and | ||
| 136 | ;; "Version 0.9.0b, 9-Sept-98". | ||
| 137 | ["\\.bz2\\'" | ||
| 138 | "bzip2ing" "bzip2" nil | ||
| 139 | "bunzip2ing" "bzip2" ("-d") | ||
| 140 | nil t "BZh"] | ||
| 141 | ["\\.tbz\\'" | ||
| 142 | "bzip2ing" "bzip2" nil | ||
| 143 | "bunzip2ing" "bzip2" ("-d") | ||
| 144 | nil nil "BZh"] | ||
| 145 | ["\\.tgz\\'" | ||
| 146 | "zipping" "gzip" ("-c" "-q") | ||
| 147 | "unzipping" "gzip" ("-c" "-q" "-d") | ||
| 148 | t nil "\037\213"] | ||
| 149 | ["\\.g?z\\(~\\|\\.~[0-9]+~\\)?\\'" | ||
| 150 | "zipping" "gzip" ("-c" "-q") | ||
| 151 | "unzipping" "gzip" ("-c" "-q" "-d") | ||
| 152 | t t "\037\213"] | ||
| 153 | ;; dzip is gzip with random access. Its compression program can't | ||
| 154 | ;; read/write stdin/out, so .dz files can only be viewed without | ||
| 155 | ;; saving, having their contents decompressed with gzip. | ||
| 156 | ["\\.dz\\'" | ||
| 157 | nil nil nil | ||
| 158 | "unzipping" "gzip" ("-c" "-q" "-d") | ||
| 159 | nil t "\037\213"]) | ||
| 160 | |||
| 161 | "List of vectors that describe available compression techniques. | ||
| 162 | Each element, which describes a compression technique, is a vector of | ||
| 163 | the form [REGEXP COMPRESS-MSG COMPRESS-PROGRAM COMPRESS-ARGS | ||
| 164 | UNCOMPRESS-MSG UNCOMPRESS-PROGRAM UNCOMPRESS-ARGS | ||
| 165 | APPEND-FLAG STRIP-EXTENSION-FLAG FILE-MAGIC-CHARS], where: | ||
| 166 | |||
| 167 | regexp is a regexp that matches filenames that are | ||
| 168 | compressed with this format | ||
| 169 | |||
| 170 | compress-msg is the message to issue to the user when doing this | ||
| 171 | type of compression (nil means no message) | ||
| 172 | |||
| 173 | compress-program is a program that performs this compression | ||
| 174 | (nil means visit file in read-only mode) | ||
| 175 | |||
| 176 | compress-args is a list of args to pass to the compress program | ||
| 177 | |||
| 178 | uncompress-msg is the message to issue to the user when doing this | ||
| 179 | type of uncompression (nil means no message) | ||
| 180 | |||
| 181 | uncompress-program is a program that performs this compression | ||
| 182 | |||
| 183 | uncompress-args is a list of args to pass to the uncompress program | ||
| 184 | |||
| 185 | append-flag is non-nil if this compression technique can be | ||
| 186 | appended | ||
| 187 | |||
| 188 | strip-extension-flag non-nil means strip the regexp from file names | ||
| 189 | before attempting to set the mode. | ||
| 190 | |||
| 191 | file-magic-chars is a string of characters that you would find | ||
| 192 | at the beginning of a file compressed in this way. | ||
| 193 | |||
| 194 | Because of the way `call-process' is defined, discarding the stderr output of | ||
| 195 | a program adds the overhead of starting a shell each time the program is | ||
| 196 | invoked." | ||
| 197 | :type '(repeat (vector regexp | ||
| 198 | (choice :tag "Compress Message" | ||
| 199 | (string :format "%v") | ||
| 200 | (const :tag "No Message" nil)) | ||
| 201 | (choice :tag "Compress Program" | ||
| 202 | (string) | ||
| 203 | (const :tag "None" nil)) | ||
| 204 | (repeat :tag "Compress Arguments" string) | ||
| 205 | (choice :tag "Uncompress Message" | ||
| 206 | (string :format "%v") | ||
| 207 | (const :tag "No Message" nil)) | ||
| 208 | (choice :tag "Uncompress Program" | ||
| 209 | (string) | ||
| 210 | (const :tag "None" nil)) | ||
| 211 | (repeat :tag "Uncompress Arguments" string) | ||
| 212 | (boolean :tag "Append") | ||
| 213 | (boolean :tag "Strip Extension") | ||
| 214 | (string :tag "Magic Bytes"))) | ||
| 215 | :group 'jka-compr) | ||
| 216 | |||
| 217 | (defcustom jka-compr-mode-alist-additions | ||
| 218 | (list (cons "\\.tgz\\'" 'tar-mode) (cons "\\.tbz\\'" 'tar-mode)) | ||
| 219 | "A list of pairs to add to `auto-mode-alist' when jka-compr is installed." | ||
| 220 | :type '(repeat (cons string symbol)) | ||
| 221 | :group 'jka-compr) | ||
| 222 | |||
| 223 | (defcustom jka-compr-load-suffixes '(".gz") | ||
| 224 | "List of suffixes to try when loading files." | ||
| 225 | :type '(repeat string) | ||
| 226 | :group 'jka-compr) | ||
| 227 | |||
| 228 | ;; List of all the elements we actually added to file-coding-system-alist. | ||
| 229 | (defvar jka-compr-added-to-file-coding-system-alist nil) | ||
| 230 | |||
| 231 | (defvar jka-compr-file-name-handler-entry | ||
| 232 | nil | ||
| 233 | "The entry in `file-name-handler-alist' used by the jka-compr I/O functions.") | ||
| 234 | |||
| 235 | (defvar jka-compr-really-do-compress nil | 114 | (defvar jka-compr-really-do-compress nil |
| 236 | "Non-nil in a buffer whose visited file was uncompressed on visiting it. | 115 | "Non-nil in a buffer whose visited file was uncompressed on visiting it. |
| 237 | This means compress the data on writing the file, even if the | 116 | This means compress the data on writing the file, even if the |
| @@ -764,12 +643,13 @@ There should be no more than seven characters after the final `/'." | |||
| 764 | (put 'byte-compiler-base-file-name 'jka-compr | 643 | (put 'byte-compiler-base-file-name 'jka-compr |
| 765 | 'jka-compr-byte-compiler-base-file-name) | 644 | 'jka-compr-byte-compiler-base-file-name) |
| 766 | 645 | ||
| 646 | ;;;###autoload | ||
| 767 | (defvar jka-compr-inhibit nil | 647 | (defvar jka-compr-inhibit nil |
| 768 | "Non-nil means inhibit automatic uncompression temporarily. | 648 | "Non-nil means inhibit automatic uncompression temporarily. |
| 769 | Lisp programs can bind this to t to do that. | 649 | Lisp programs can bind this to t to do that. |
| 770 | It is not recommended to set this variable permanently to anything but nil.") | 650 | It is not recommended to set this variable permanently to anything but nil.") |
| 771 | 651 | ||
| 772 | (put 'jka-compr-handler 'safe-magic t) | 652 | ;;;###autoload |
| 773 | (defun jka-compr-handler (operation &rest args) | 653 | (defun jka-compr-handler (operation &rest args) |
| 774 | (save-match-data | 654 | (save-match-data |
| 775 | (let ((jka-op (get operation 'jka-compr))) | 655 | (let ((jka-op (get operation 'jka-compr))) |
| @@ -790,65 +670,6 @@ It is not recommended to set this variable permanently to anything but nil.") | |||
| 790 | (apply operation args))) | 670 | (apply operation args))) |
| 791 | 671 | ||
| 792 | 672 | ||
| 793 | (defun jka-compr-build-file-regexp () | ||
| 794 | (mapconcat | ||
| 795 | 'jka-compr-info-regexp | ||
| 796 | jka-compr-compression-info-list | ||
| 797 | "\\|")) | ||
| 798 | |||
| 799 | |||
| 800 | (defun jka-compr-install () | ||
| 801 | "Install jka-compr. | ||
| 802 | This adds entries to `file-name-handler-alist' and `auto-mode-alist' | ||
| 803 | and `inhibit-first-line-modes-suffixes'." | ||
| 804 | |||
| 805 | (setq jka-compr-file-name-handler-entry | ||
| 806 | (cons (jka-compr-build-file-regexp) 'jka-compr-handler)) | ||
| 807 | |||
| 808 | (setq file-name-handler-alist (cons jka-compr-file-name-handler-entry | ||
| 809 | file-name-handler-alist)) | ||
| 810 | |||
| 811 | (setq jka-compr-added-to-file-coding-system-alist nil) | ||
| 812 | |||
| 813 | (mapcar | ||
| 814 | (function (lambda (x) | ||
| 815 | ;; Don't do multibyte encoding on the compressed files. | ||
| 816 | (let ((elt (cons (jka-compr-info-regexp x) | ||
| 817 | '(no-conversion . no-conversion)))) | ||
| 818 | (setq file-coding-system-alist | ||
| 819 | (cons elt file-coding-system-alist)) | ||
| 820 | (setq jka-compr-added-to-file-coding-system-alist | ||
| 821 | (cons elt jka-compr-added-to-file-coding-system-alist))) | ||
| 822 | |||
| 823 | (and (jka-compr-info-strip-extension x) | ||
| 824 | ;; Make entries in auto-mode-alist so that modes | ||
| 825 | ;; are chosen right according to the file names | ||
| 826 | ;; sans `.gz'. | ||
| 827 | (setq auto-mode-alist | ||
| 828 | (cons (list (jka-compr-info-regexp x) | ||
| 829 | nil 'jka-compr) | ||
| 830 | auto-mode-alist)) | ||
| 831 | ;; Also add these regexps to | ||
| 832 | ;; inhibit-first-line-modes-suffixes, so that a | ||
| 833 | ;; -*- line in the first file of a compressed tar | ||
| 834 | ;; file doesn't override tar-mode. | ||
| 835 | (setq inhibit-first-line-modes-suffixes | ||
| 836 | (cons (jka-compr-info-regexp x) | ||
| 837 | inhibit-first-line-modes-suffixes))))) | ||
| 838 | jka-compr-compression-info-list) | ||
| 839 | (setq auto-mode-alist | ||
| 840 | (append auto-mode-alist jka-compr-mode-alist-additions)) | ||
| 841 | |||
| 842 | ;; Make sure that (load "foo") will find /bla/foo.el.gz. | ||
| 843 | (setq load-suffixes | ||
| 844 | (apply 'append | ||
| 845 | (mapcar (lambda (suffix) | ||
| 846 | (cons suffix | ||
| 847 | (mapcar (lambda (ext) (concat suffix ext)) | ||
| 848 | jka-compr-load-suffixes))) | ||
| 849 | load-suffixes)))) | ||
| 850 | |||
| 851 | |||
| 852 | (defun jka-compr-uninstall () | 673 | (defun jka-compr-uninstall () |
| 853 | "Uninstall jka-compr. | 674 | "Uninstall jka-compr. |
| 854 | This removes the entries in `file-name-handler-alist' and `auto-mode-alist' | 675 | This removes the entries in `file-name-handler-alist' and `auto-mode-alist' |
| @@ -908,59 +729,6 @@ by `jka-compr-installed'." | |||
| 908 | (push suffix suffixes))) | 729 | (push suffix suffixes))) |
| 909 | (setq load-suffixes (nreverse suffixes)))) | 730 | (setq load-suffixes (nreverse suffixes)))) |
| 910 | 731 | ||
| 911 | |||
| 912 | (defun jka-compr-installed-p () | ||
| 913 | "Return non-nil if jka-compr is installed. | ||
| 914 | The return value is the entry in `file-name-handler-alist' for jka-compr." | ||
| 915 | |||
| 916 | (let ((fnha file-name-handler-alist) | ||
| 917 | (installed nil)) | ||
| 918 | |||
| 919 | (while (and fnha (not installed)) | ||
| 920 | (and (eq (cdr (car fnha)) 'jka-compr-handler) | ||
| 921 | (setq installed (car fnha))) | ||
| 922 | (setq fnha (cdr fnha))) | ||
| 923 | |||
| 924 | installed)) | ||
| 925 | |||
| 926 | |||
| 927 | ;;; Add the file I/O hook if it does not already exist. | ||
| 928 | ;;; Make sure that jka-compr-file-name-handler-entry is eq to the | ||
| 929 | ;;; entry for jka-compr in file-name-handler-alist. | ||
| 930 | (and (jka-compr-installed-p) | ||
| 931 | (jka-compr-uninstall)) | ||
| 932 | |||
| 933 | |||
| 934 | ;;;###autoload | ||
| 935 | (define-minor-mode auto-compression-mode | ||
| 936 | "Toggle automatic file compression and uncompression. | ||
| 937 | With prefix argument ARG, turn auto compression on if positive, else off. | ||
| 938 | Returns the new status of auto compression (non-nil means on)." | ||
| 939 | :global t :group 'jka-compr | ||
| 940 | (let* ((installed (jka-compr-installed-p)) | ||
| 941 | (flag auto-compression-mode)) | ||
| 942 | (cond | ||
| 943 | ((and flag installed) t) ; already installed | ||
| 944 | ((and (not flag) (not installed)) nil) ; already not installed | ||
| 945 | (flag (jka-compr-install)) | ||
| 946 | (t (jka-compr-uninstall))))) | ||
| 947 | |||
| 948 | |||
| 949 | ;;;###autoload | ||
| 950 | (defmacro with-auto-compression-mode (&rest body) | ||
| 951 | "Evalute BODY with automatic file compression and uncompression enabled." | ||
| 952 | (let ((already-installed (make-symbol "already-installed"))) | ||
| 953 | `(let ((,already-installed (jka-compr-installed-p))) | ||
| 954 | (unwind-protect | ||
| 955 | (progn | ||
| 956 | (unless ,already-installed | ||
| 957 | (jka-compr-install)) | ||
| 958 | ,@body) | ||
| 959 | (unless ,already-installed | ||
| 960 | (jka-compr-uninstall)))))) | ||
| 961 | (put 'with-auto-compression-mode 'lisp-indent-function 0) | ||
| 962 | |||
| 963 | |||
| 964 | (provide 'jka-compr) | 732 | (provide 'jka-compr) |
| 965 | 733 | ||
| 966 | ;;; arch-tag: 3f15b630-e9a7-46c4-a22a-94afdde86ebc | 734 | ;;; arch-tag: 3f15b630-e9a7-46c4-a22a-94afdde86ebc |