Mercurial > emacs
annotate lisp/jka-compr.el @ 22677:a05b1e5f4389
(dos-printer): Obsolete variable deleted.
(dos-ps-printer): Likewise.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 03 Jul 1998 19:53:47 +0000 |
parents | 661650f543ee |
children | 516b9dfa5d34 |
rev | line source |
---|---|
13337 | 1 ;;; jka-compr.el --- reading/writing/loading compressed files |
2 | |
17411
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
3 ;; Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation, Inc. |
6002 | 4 |
5 ;; Author: jka@ece.cmu.edu (Jay K. Adams) | |
17976 | 6 ;; Maintainer: FSF |
6002 | 7 ;; Keywords: data |
8 | |
13514
0e46e8075a1d
(auto-compression-mode): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
0e46e8075a1d
(auto-compression-mode): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
10 |
0e46e8075a1d
(auto-compression-mode): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
0e46e8075a1d
(auto-compression-mode): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
0e46e8075a1d
(auto-compression-mode): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
0e46e8075a1d
(auto-compression-mode): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
14 ;; any later version. |
0e46e8075a1d
(auto-compression-mode): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
15 |
0e46e8075a1d
(auto-compression-mode): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
0e46e8075a1d
(auto-compression-mode): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
0e46e8075a1d
(auto-compression-mode): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0e46e8075a1d
(auto-compression-mode): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
19 ;; GNU General Public License for more details. |
0e46e8075a1d
(auto-compression-mode): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
20 |
0e46e8075a1d
(auto-compression-mode): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
13514
0e46e8075a1d
(auto-compression-mode): Make arg optional.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
25 |
6002 | 26 ;;; Commentary: |
27 | |
14169 | 28 ;; This package implements low-level support for reading, writing, |
29 ;; and loading compressed files. It hooks into the low-level file | |
30 ;; I/O functions (including write-region and insert-file-contents) so | |
31 ;; that they automatically compress or uncompress a file if the file | |
32 ;; appears to need it (based on the extension of the file name). | |
33 ;; Packages like Rmail, VM, GNUS, and Info should be able to work | |
34 ;; with compressed files without modification. | |
6002 | 35 |
36 | |
14169 | 37 ;; INSTRUCTIONS: |
38 ;; | |
39 ;; To use jka-compr, simply load this package, and edit as usual. | |
40 ;; Its operation should be transparent to the user (except for | |
41 ;; messages appearing when a file is being compressed or | |
42 ;; uncompressed). | |
43 ;; | |
44 ;; The variable, jka-compr-compression-info-list can be used to | |
45 ;; customize jka-compr to work with other compression programs. | |
46 ;; The default value of this variable allows jka-compr to work with | |
47 ;; Unix compress and gzip. | |
48 ;; | |
49 ;; If you are concerned about the stderr output of gzip and other | |
50 ;; compression/decompression programs showing up in your buffers, you | |
51 ;; should set the discard-error flag in the compression-info-list. | |
52 ;; This will cause the stderr of all programs to be discarded. | |
53 ;; However, it also causes emacs to call compression/uncompression | |
54 ;; programs through a shell (which is specified by jka-compr-shell). | |
55 ;; This may be a drag if, on your system, starting up a shell is | |
56 ;; slow. | |
57 ;; | |
58 ;; If you don't want messages about compressing and decompressing | |
59 ;; to show up in the echo area, you can set the compress-name and | |
60 ;; decompress-name fields of the jka-compr-compression-info-list to | |
61 ;; nil. | |
6002 | 62 |
63 | |
14169 | 64 ;; APPLICATION NOTES: |
65 ;; | |
66 ;; crypt++ | |
67 ;; jka-compr can coexist with crpyt++ if you take all the decompression | |
68 ;; entries out of the crypt-encoding-list. Clearly problems will arise if | |
69 ;; you have two programs trying to compress/decompress files. jka-compr | |
70 ;; will not "work with" crypt++ in the following sense: you won't be able to | |
71 ;; decode encrypted compressed files--that is, files that have been | |
72 ;; compressed then encrypted (in that order). Theoretically, crypt++ and | |
73 ;; jka-compr could properly handle a file that has been encrypted then | |
74 ;; compressed, but there is little point in trying to compress an encrypted | |
75 ;; file. | |
76 ;; | |
6002 | 77 |
78 | |
14169 | 79 ;; ACKNOWLEDGMENTS |
80 ;; | |
81 ;; jka-compr is a V19 adaptation of jka-compr for V18 of Emacs. Many people | |
82 ;; have made helpful suggestions, reported bugs, and even fixed bugs in | |
83 ;; jka-compr. I recall the following people as being particularly helpful. | |
84 ;; | |
85 ;; Jean-loup Gailly | |
86 ;; David Hughes | |
87 ;; Richard Pieri | |
88 ;; Daniel Quinlan | |
89 ;; Chris P. Ross | |
90 ;; Rick Sladkey | |
91 ;; | |
92 ;; Andy Norman's ange-ftp was the inspiration for the original jka-compr for | |
93 ;; Version 18 of Emacs. | |
94 ;; | |
95 ;; After I had made progress on the original jka-compr for V18, I learned of a | |
96 ;; package written by Kazushi Jam Marukawa, called jam-zcat, that did exactly | |
97 ;; what I was trying to do. I looked over the jam-zcat source code and | |
98 ;; probably got some ideas from it. | |
99 ;; | |
6002 | 100 |
101 ;;; Code: | |
102 | |
17411
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
103 (defgroup compression nil |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
104 "Data compression utilities" |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
105 :group 'data) |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
106 |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
107 (defgroup jka-compr nil |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
108 "jka-compr customization" |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
109 :group 'compression) |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
110 |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
111 |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
112 (defcustom jka-compr-shell "sh" |
6002 | 113 "*Shell to be used for calling compression programs. |
114 The value of this variable only matters if you want to discard the | |
115 stderr of a compression/decompression program (see the documentation | |
17411
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
116 for `jka-compr-compression-info-list')." |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
117 :type 'string |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
118 :group 'jka-compr) |
6002 | 119 |
21633
185e8e424ee9
(jka-compr-use-shell) [ms-dos, windows-nt]: Do not use a shell.
Richard M. Stallman <rms@gnu.org>
parents:
20893
diff
changeset
|
120 (defvar jka-compr-use-shell |
185e8e424ee9
(jka-compr-use-shell) [ms-dos, windows-nt]: Do not use a shell.
Richard M. Stallman <rms@gnu.org>
parents:
20893
diff
changeset
|
121 (not (memq system-type '(ms-dos windows-nt)))) |
6002 | 122 |
123 ;;; I have this defined so that .Z files are assumed to be in unix | |
20873
d2b5d0e2607e
(jka-compr-compression-info-list): Handle bzip.
Richard M. Stallman <rms@gnu.org>
parents:
20497
diff
changeset
|
124 ;;; compress format; and .gz files, in gzip format, and .bz2 files in bzip fmt. |
17411
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
125 (defcustom jka-compr-compression-info-list |
6002 | 126 ;;[regexp |
7616
b0098553bafe
(jka-compr-compression-info-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
7066
diff
changeset
|
127 ;; compr-message compr-prog compr-args |
b0098553bafe
(jka-compr-compression-info-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
7066
diff
changeset
|
128 ;; uncomp-message uncomp-prog uncomp-args |
6002 | 129 ;; can-append auto-mode-flag] |
8774
ade4b542a74c
(jka-compr-compression-info-list): Expand regular
Richard M. Stallman <rms@gnu.org>
parents:
8593
diff
changeset
|
130 '(["\\.Z\\(~\\|\\.~[0-9]+~\\)?\\'" |
6002 | 131 "compressing" "compress" ("-c") |
132 "uncompressing" "uncompress" ("-c") | |
133 nil t] | |
20873
d2b5d0e2607e
(jka-compr-compression-info-list): Handle bzip.
Richard M. Stallman <rms@gnu.org>
parents:
20497
diff
changeset
|
134 ["\\.bz2\\'" |
22194
376bd8ec20f1
(jka-compr-compression-info-list): Add elts for bzip.
Richard M. Stallman <rms@gnu.org>
parents:
22100
diff
changeset
|
135 "bzip2ing" "bzip2" ("-c") |
376bd8ec20f1
(jka-compr-compression-info-list): Add elts for bzip.
Richard M. Stallman <rms@gnu.org>
parents:
22100
diff
changeset
|
136 "bunzip2ing" "bzip2" ("-d" "-c") |
20893
41ad3e101628
(jka-compr-compression-info-list): Fix previous change:
Richard M. Stallman <rms@gnu.org>
parents:
20873
diff
changeset
|
137 nil t] |
9493
0160fca3dee1
(jka-compr-mode-compression-info-list): Add .tgz extension.
Richard M. Stallman <rms@gnu.org>
parents:
9084
diff
changeset
|
138 ["\\.tgz\\'" |
0160fca3dee1
(jka-compr-mode-compression-info-list): Add .tgz extension.
Richard M. Stallman <rms@gnu.org>
parents:
9084
diff
changeset
|
139 "zipping" "gzip" ("-c" "-q") |
0160fca3dee1
(jka-compr-mode-compression-info-list): Add .tgz extension.
Richard M. Stallman <rms@gnu.org>
parents:
9084
diff
changeset
|
140 "unzipping" "gzip" ("-c" "-q" "-d") |
0160fca3dee1
(jka-compr-mode-compression-info-list): Add .tgz extension.
Richard M. Stallman <rms@gnu.org>
parents:
9084
diff
changeset
|
141 t nil] |
8774
ade4b542a74c
(jka-compr-compression-info-list): Expand regular
Richard M. Stallman <rms@gnu.org>
parents:
8593
diff
changeset
|
142 ["\\.gz\\(~\\|\\.~[0-9]+~\\)?\\'" |
6002 | 143 "zipping" "gzip" ("-c" "-q") |
144 "unzipping" "gzip" ("-c" "-q" "-d") | |
145 t t]) | |
146 | |
147 "List of vectors that describe available compression techniques. | |
148 Each element, which describes a compression technique, is a vector of | |
7616
b0098553bafe
(jka-compr-compression-info-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
7066
diff
changeset
|
149 the form [REGEXP COMPRESS-MSG COMPRESS-PROGRAM COMPRESS-ARGS |
b0098553bafe
(jka-compr-compression-info-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
7066
diff
changeset
|
150 UNCOMPRESS-MSG UNCOMPRESS-PROGRAM UNCOMPRESS-ARGS |
b0098553bafe
(jka-compr-compression-info-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
7066
diff
changeset
|
151 APPEND-FLAG EXTENSION], where: |
6002 | 152 |
153 regexp is a regexp that matches filenames that are | |
154 compressed with this format | |
155 | |
7616
b0098553bafe
(jka-compr-compression-info-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
7066
diff
changeset
|
156 compress-msg is the message to issue to the user when doing this |
b0098553bafe
(jka-compr-compression-info-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
7066
diff
changeset
|
157 type of compression (nil means no message) |
b0098553bafe
(jka-compr-compression-info-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
7066
diff
changeset
|
158 |
6002 | 159 compress-program is a program that performs this compression |
160 | |
161 compress-args is a list of args to pass to the compress program | |
162 | |
7616
b0098553bafe
(jka-compr-compression-info-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
7066
diff
changeset
|
163 uncompress-msg is the message to issue to the user when doing this |
b0098553bafe
(jka-compr-compression-info-list): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
7066
diff
changeset
|
164 type of uncompression (nil means no message) |
6002 | 165 |
166 uncompress-program is a program that performs this compression | |
167 | |
168 uncompress-args is a list of args to pass to the uncompress program | |
169 | |
170 append-flag is non-nil if this compression technique can be | |
171 appended | |
172 | |
173 auto-mode flag non-nil means strip the regexp from file names | |
174 before attempting to set the mode. | |
175 | |
7976
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
176 Because of the way `call-process' is defined, discarding the stderr output of |
6002 | 177 a program adds the overhead of starting a shell each time the program is |
17411
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
178 invoked." |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
179 :type '(repeat (vector regexp |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
180 (choice :tag "Compress Message" |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
181 (string :format "%v") |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
182 (const :tag "No Message" nil)) |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
183 (string :tag "Compress Program") |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
184 (repeat :tag "Compress Arguments" string) |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
185 (choice :tag "Uncompress Message" |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
186 (string :format "%v") |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
187 (const :tag "No Message" nil)) |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
188 (string :tag "Uncompress Program") |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
189 (repeat :tag "Uncompress Arguments" string) |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
190 (boolean :tag "Append") |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
191 (boolean :tag "Auto Mode"))) |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
192 :group 'jka-compr) |
6002 | 193 |
9493
0160fca3dee1
(jka-compr-mode-compression-info-list): Add .tgz extension.
Richard M. Stallman <rms@gnu.org>
parents:
9084
diff
changeset
|
194 (defvar jka-compr-mode-alist-additions |
0160fca3dee1
(jka-compr-mode-compression-info-list): Add .tgz extension.
Richard M. Stallman <rms@gnu.org>
parents:
9084
diff
changeset
|
195 (list (cons "\\.tgz\\'" 'tar-mode)) |
19004
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
196 "A list of pairs to add to `auto-mode-alist' when jka-compr is installed.") |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
197 |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
198 ;; List of all the elements we actually added to file-coding-system-alist. |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
199 (defvar jka-compr-added-to-file-coding-system-alist nil) |
6002 | 200 |
7617
edc853e14f7b
(jka-compr-op-table, jka-compr-file-name-handler-entry): Move defvars.
Richard M. Stallman <rms@gnu.org>
parents:
7616
diff
changeset
|
201 (defvar jka-compr-file-name-handler-entry |
edc853e14f7b
(jka-compr-op-table, jka-compr-file-name-handler-entry): Move defvars.
Richard M. Stallman <rms@gnu.org>
parents:
7616
diff
changeset
|
202 nil |
edc853e14f7b
(jka-compr-op-table, jka-compr-file-name-handler-entry): Move defvars.
Richard M. Stallman <rms@gnu.org>
parents:
7616
diff
changeset
|
203 "The entry in `file-name-handler-alist' used by the jka-compr I/O functions.") |
edc853e14f7b
(jka-compr-op-table, jka-compr-file-name-handler-entry): Move defvars.
Richard M. Stallman <rms@gnu.org>
parents:
7616
diff
changeset
|
204 |
15083 | 205 ;;; Functions for accessing the return value of jka-compr-get-compression-info |
6002 | 206 (defun jka-compr-info-regexp (info) (aref info 0)) |
207 (defun jka-compr-info-compress-message (info) (aref info 1)) | |
208 (defun jka-compr-info-compress-program (info) (aref info 2)) | |
209 (defun jka-compr-info-compress-args (info) (aref info 3)) | |
210 (defun jka-compr-info-uncompress-message (info) (aref info 4)) | |
211 (defun jka-compr-info-uncompress-program (info) (aref info 5)) | |
212 (defun jka-compr-info-uncompress-args (info) (aref info 6)) | |
213 (defun jka-compr-info-can-append (info) (aref info 7)) | |
214 (defun jka-compr-info-strip-extension (info) (aref info 8)) | |
215 | |
216 | |
217 (defun jka-compr-get-compression-info (filename) | |
218 "Return information about the compression scheme of FILENAME. | |
219 The determination as to which compression scheme, if any, to use is | |
7066 | 220 based on the filename itself and `jka-compr-compression-info-list'." |
6002 | 221 (catch 'compression-info |
222 (let ((case-fold-search nil)) | |
223 (mapcar | |
224 (function (lambda (x) | |
225 (and (string-match (jka-compr-info-regexp x) filename) | |
226 (throw 'compression-info x)))) | |
227 jka-compr-compression-info-list) | |
228 nil))) | |
229 | |
230 | |
231 (put 'compression-error 'error-conditions '(compression-error file-error error)) | |
232 | |
233 | |
11635
b56f6afa16ec
(jka-compr-write-region): Handle the append
Richard M. Stallman <rms@gnu.org>
parents:
11621
diff
changeset
|
234 (defvar jka-compr-acceptable-retval-list '(0 2 141)) |
6002 | 235 |
236 | |
237 (defun jka-compr-error (prog args infile message &optional errfile) | |
238 | |
239 (let ((errbuf (get-buffer-create " *jka-compr-error*")) | |
240 (curbuf (current-buffer))) | |
16940
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
241 (with-current-buffer errbuf |
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
242 (widen) (erase-buffer) |
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
243 (insert (format "Error while executing \"%s %s < %s\"\n\n" |
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
244 prog |
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
245 (mapconcat 'identity args " ") |
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
246 infile)) |
6002 | 247 |
16940
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
248 (and errfile |
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
249 (insert-file-contents errfile))) |
6002 | 250 (display-buffer errbuf)) |
251 | |
16940
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
252 (signal 'compression-error |
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
253 (list "Opening input file" (format "error %s" message) infile))) |
6002 | 254 |
255 | |
256 (defvar jka-compr-dd-program | |
257 "/bin/dd") | |
258 | |
259 | |
6041
649926e9c1a8
(jka-compr-partial-uncompress): Make dd give you
Richard M. Stallman <rms@gnu.org>
parents:
6002
diff
changeset
|
260 (defvar jka-compr-dd-blocksize 256) |
6002 | 261 |
262 | |
263 (defun jka-compr-partial-uncompress (prog message args infile beg len) | |
264 "Call program PROG with ARGS args taking input from INFILE. | |
265 Fourth and fifth args, BEG and LEN, specify which part of the output | |
8065
31eb7a0e2763
(jka-compr-partial-uncompress): Handle the case where
Richard M. Stallman <rms@gnu.org>
parents:
7976
diff
changeset
|
266 to keep: LEN chars starting BEG chars from the beginning." |
6002 | 267 (let* ((skip (/ beg jka-compr-dd-blocksize)) |
268 (prefix (- beg (* skip jka-compr-dd-blocksize))) | |
269 (count (and len (1+ (/ (+ len prefix) jka-compr-dd-blocksize)))) | |
270 (start (point)) | |
271 (err-file (jka-compr-make-temp-name)) | |
272 (run-string (format "%s %s 2> %s | %s bs=%d skip=%d %s 2> /dev/null" | |
273 prog | |
274 (mapconcat 'identity args " ") | |
275 err-file | |
276 jka-compr-dd-program | |
277 jka-compr-dd-blocksize | |
278 skip | |
6041
649926e9c1a8
(jka-compr-partial-uncompress): Make dd give you
Richard M. Stallman <rms@gnu.org>
parents:
6002
diff
changeset
|
279 ;; dd seems to be unreliable about |
649926e9c1a8
(jka-compr-partial-uncompress): Make dd give you
Richard M. Stallman <rms@gnu.org>
parents:
6002
diff
changeset
|
280 ;; providing the last block. So, always |
649926e9c1a8
(jka-compr-partial-uncompress): Make dd give you
Richard M. Stallman <rms@gnu.org>
parents:
6002
diff
changeset
|
281 ;; read one more than you think you need. |
649926e9c1a8
(jka-compr-partial-uncompress): Make dd give you
Richard M. Stallman <rms@gnu.org>
parents:
6002
diff
changeset
|
282 (if count (concat "count=" (1+ count)) "")))) |
6002 | 283 |
284 (unwind-protect | |
285 (or (memq (call-process jka-compr-shell | |
286 infile t nil "-c" | |
287 run-string) | |
288 jka-compr-acceptable-retval-list) | |
289 | |
290 (jka-compr-error prog args infile message err-file)) | |
291 | |
292 (jka-compr-delete-temp-file err-file)) | |
293 | |
8065
31eb7a0e2763
(jka-compr-partial-uncompress): Handle the case where
Richard M. Stallman <rms@gnu.org>
parents:
7976
diff
changeset
|
294 ;; Delete the stuff after what we want, if there is any. |
6002 | 295 (and |
6041
649926e9c1a8
(jka-compr-partial-uncompress): Make dd give you
Richard M. Stallman <rms@gnu.org>
parents:
6002
diff
changeset
|
296 len |
8065
31eb7a0e2763
(jka-compr-partial-uncompress): Handle the case where
Richard M. Stallman <rms@gnu.org>
parents:
7976
diff
changeset
|
297 (< (+ start prefix len) (point)) |
6041
649926e9c1a8
(jka-compr-partial-uncompress): Make dd give you
Richard M. Stallman <rms@gnu.org>
parents:
6002
diff
changeset
|
298 (delete-region (+ start prefix len) (point))) |
6002 | 299 |
8065
31eb7a0e2763
(jka-compr-partial-uncompress): Handle the case where
Richard M. Stallman <rms@gnu.org>
parents:
7976
diff
changeset
|
300 ;; Delete the stuff before what we want. |
6002 | 301 (delete-region start (+ start prefix)))) |
302 | |
303 | |
304 (defun jka-compr-call-process (prog message infile output temp args) | |
305 (if jka-compr-use-shell | |
306 | |
18879
8b226efb9a8b
(jka-compr-insert-file-contents): Bind coding-system-for-read.
Richard M. Stallman <rms@gnu.org>
parents:
17976
diff
changeset
|
307 (let ((err-file (jka-compr-make-temp-name)) |
18906 | 308 (coding-system-for-read (or coding-system-for-read 'undecided)) |
22360
09dbe38a603f
(jka-compr-write-region): Ensure
Karl Heuer <kwzh@gnu.org>
parents:
22194
diff
changeset
|
309 (coding-system-for-write 'no-conversion)) |
18879
8b226efb9a8b
(jka-compr-insert-file-contents): Bind coding-system-for-read.
Richard M. Stallman <rms@gnu.org>
parents:
17976
diff
changeset
|
310 |
6002 | 311 (unwind-protect |
312 | |
313 (or (memq | |
314 (call-process jka-compr-shell infile | |
315 (if (stringp output) nil output) | |
316 nil | |
317 "-c" | |
318 (format "%s %s 2> %s %s" | |
319 prog | |
320 (mapconcat 'identity args " ") | |
321 err-file | |
322 (if (stringp output) | |
323 (concat "> " output) | |
324 ""))) | |
325 jka-compr-acceptable-retval-list) | |
326 | |
327 (jka-compr-error prog args infile message err-file)) | |
328 | |
329 (jka-compr-delete-temp-file err-file))) | |
330 | |
331 (or (zerop | |
332 (apply 'call-process | |
333 prog | |
334 infile | |
335 (if (stringp output) temp output) | |
336 nil | |
337 args)) | |
338 (jka-compr-error prog args infile message)) | |
339 | |
340 (and (stringp output) | |
16940
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
341 (with-current-buffer temp |
6002 | 342 (write-region (point-min) (point-max) output) |
16940
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
343 (erase-buffer))))) |
6002 | 344 |
345 | |
346 ;;; Support for temp files. Much of this was inspired if not lifted | |
347 ;;; from ange-ftp. | |
348 | |
17411
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
349 (defcustom jka-compr-temp-name-template |
22100
eb3f36cc775f
(jka-compr-temp-name-template): Use temporary-file-directory.
Richard M. Stallman <rms@gnu.org>
parents:
22090
diff
changeset
|
350 (expand-file-name "jka-com" temporary-file-directory) |
17441
41a10d128e3b
(jka-compr-temp-name-template): Fix editing error.
Richard M. Stallman <rms@gnu.org>
parents:
17411
diff
changeset
|
351 "Prefix added to all temp files created by jka-compr. |
17411
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
352 There should be no more than seven characters after the final `/'." |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
353 :type 'string |
f0ff96a35eb8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
16940
diff
changeset
|
354 :group 'jka-compr) |
6002 | 355 |
356 (defvar jka-compr-temp-name-table (make-vector 31 nil)) | |
357 | |
358 (defun jka-compr-make-temp-name (&optional local-copy) | |
359 "This routine will return the name of a new file." | |
360 (let* ((lastchar ?a) | |
361 (prevchar ?a) | |
362 (template (concat jka-compr-temp-name-template "aa")) | |
363 (lastpos (1- (length template))) | |
364 (not-done t) | |
365 file | |
366 entry) | |
367 | |
368 (while not-done | |
369 (aset template lastpos lastchar) | |
370 (setq file (concat (make-temp-name template) "#")) | |
371 (setq entry (intern file jka-compr-temp-name-table)) | |
372 (if (or (get entry 'active) | |
373 (file-exists-p file)) | |
374 | |
375 (progn | |
376 (setq lastchar (1+ lastchar)) | |
377 (if (> lastchar ?z) | |
378 (progn | |
379 (setq prevchar (1+ prevchar)) | |
380 (setq lastchar ?a) | |
381 (if (> prevchar ?z) | |
382 (error "Can't allocate temp file.") | |
383 (aset template (1- lastpos) prevchar))))) | |
384 | |
385 (put entry 'active (not local-copy)) | |
386 (setq not-done nil))) | |
387 | |
388 file)) | |
389 | |
390 | |
391 (defun jka-compr-delete-temp-file (temp) | |
392 | |
393 (put (intern temp jka-compr-temp-name-table) | |
394 'active nil) | |
395 | |
396 (condition-case () | |
397 (delete-file temp) | |
398 (error nil))) | |
399 | |
400 | |
401 (defun jka-compr-write-region (start end file &optional append visit) | |
402 (let* ((filename (expand-file-name file)) | |
403 (visit-file (if (stringp visit) (expand-file-name visit) filename)) | |
404 (info (jka-compr-get-compression-info visit-file))) | |
405 | |
406 (if info | |
407 | |
408 (let ((can-append (jka-compr-info-can-append info)) | |
409 (compress-program (jka-compr-info-compress-program info)) | |
410 (compress-message (jka-compr-info-compress-message info)) | |
411 (uncompress-program (jka-compr-info-uncompress-program info)) | |
412 (uncompress-message (jka-compr-info-uncompress-message info)) | |
413 (compress-args (jka-compr-info-compress-args info)) | |
414 (uncompress-args (jka-compr-info-uncompress-args info)) | |
415 (base-name (file-name-nondirectory visit-file)) | |
22360
09dbe38a603f
(jka-compr-write-region): Ensure
Karl Heuer <kwzh@gnu.org>
parents:
22194
diff
changeset
|
416 temp-file temp-buffer |
09dbe38a603f
(jka-compr-write-region): Ensure
Karl Heuer <kwzh@gnu.org>
parents:
22194
diff
changeset
|
417 ;; we need to leave `last-coding-system-used' set to its |
09dbe38a603f
(jka-compr-write-region): Ensure
Karl Heuer <kwzh@gnu.org>
parents:
22194
diff
changeset
|
418 ;; value after calling write-region the first time, so |
09dbe38a603f
(jka-compr-write-region): Ensure
Karl Heuer <kwzh@gnu.org>
parents:
22194
diff
changeset
|
419 ;; that `basic-save-buffer' sees the right value. |
09dbe38a603f
(jka-compr-write-region): Ensure
Karl Heuer <kwzh@gnu.org>
parents:
22194
diff
changeset
|
420 (coding-system-used last-coding-system-used)) |
6002 | 421 |
16940
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
422 (setq temp-buffer (get-buffer-create " *jka-compr-wr-temp*")) |
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
423 (with-current-buffer temp-buffer |
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
424 (widen) (erase-buffer)) |
6002 | 425 |
11635
b56f6afa16ec
(jka-compr-write-region): Handle the append
Richard M. Stallman <rms@gnu.org>
parents:
11621
diff
changeset
|
426 (if (and append |
b56f6afa16ec
(jka-compr-write-region): Handle the append
Richard M. Stallman <rms@gnu.org>
parents:
11621
diff
changeset
|
427 (not can-append) |
b56f6afa16ec
(jka-compr-write-region): Handle the append
Richard M. Stallman <rms@gnu.org>
parents:
11621
diff
changeset
|
428 (file-exists-p filename)) |
b56f6afa16ec
(jka-compr-write-region): Handle the append
Richard M. Stallman <rms@gnu.org>
parents:
11621
diff
changeset
|
429 |
b56f6afa16ec
(jka-compr-write-region): Handle the append
Richard M. Stallman <rms@gnu.org>
parents:
11621
diff
changeset
|
430 (let* ((local-copy (file-local-copy filename)) |
b56f6afa16ec
(jka-compr-write-region): Handle the append
Richard M. Stallman <rms@gnu.org>
parents:
11621
diff
changeset
|
431 (local-file (or local-copy filename))) |
b56f6afa16ec
(jka-compr-write-region): Handle the append
Richard M. Stallman <rms@gnu.org>
parents:
11621
diff
changeset
|
432 |
b56f6afa16ec
(jka-compr-write-region): Handle the append
Richard M. Stallman <rms@gnu.org>
parents:
11621
diff
changeset
|
433 (setq temp-file local-file)) |
6002 | 434 |
11635
b56f6afa16ec
(jka-compr-write-region): Handle the append
Richard M. Stallman <rms@gnu.org>
parents:
11621
diff
changeset
|
435 (setq temp-file (jka-compr-make-temp-name))) |
6002 | 436 |
437 (and | |
438 compress-message | |
439 (message "%s %s..." compress-message base-name)) | |
11635
b56f6afa16ec
(jka-compr-write-region): Handle the append
Richard M. Stallman <rms@gnu.org>
parents:
11621
diff
changeset
|
440 |
7976
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
441 (jka-compr-run-real-handler 'write-region |
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
442 (list start end temp-file t 'dont)) |
22360
09dbe38a603f
(jka-compr-write-region): Ensure
Karl Heuer <kwzh@gnu.org>
parents:
22194
diff
changeset
|
443 ;; save value used by the real write-region |
09dbe38a603f
(jka-compr-write-region): Ensure
Karl Heuer <kwzh@gnu.org>
parents:
22194
diff
changeset
|
444 (setq coding-system-used last-coding-system-used) |
6002 | 445 |
18906 | 446 ;; Here we must read the output of compress program as is |
447 ;; without any code conversion. | |
448 (let ((coding-system-for-read 'no-conversion)) | |
449 (jka-compr-call-process compress-program | |
450 (concat compress-message | |
451 " " base-name) | |
452 temp-file | |
453 temp-buffer | |
454 nil | |
455 compress-args)) | |
6002 | 456 |
16940
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
457 (with-current-buffer temp-buffer |
18879
8b226efb9a8b
(jka-compr-insert-file-contents): Bind coding-system-for-read.
Richard M. Stallman <rms@gnu.org>
parents:
17976
diff
changeset
|
458 (let ((coding-system-for-write 'no-conversion)) |
8b226efb9a8b
(jka-compr-insert-file-contents): Bind coding-system-for-read.
Richard M. Stallman <rms@gnu.org>
parents:
17976
diff
changeset
|
459 (if (memq system-type '(ms-dos windows-nt)) |
8b226efb9a8b
(jka-compr-insert-file-contents): Bind coding-system-for-read.
Richard M. Stallman <rms@gnu.org>
parents:
17976
diff
changeset
|
460 (setq buffer-file-type t) ) |
8b226efb9a8b
(jka-compr-insert-file-contents): Bind coding-system-for-read.
Richard M. Stallman <rms@gnu.org>
parents:
17976
diff
changeset
|
461 (jka-compr-run-real-handler 'write-region |
8b226efb9a8b
(jka-compr-insert-file-contents): Bind coding-system-for-read.
Richard M. Stallman <rms@gnu.org>
parents:
17976
diff
changeset
|
462 (list (point-min) (point-max) |
8b226efb9a8b
(jka-compr-insert-file-contents): Bind coding-system-for-read.
Richard M. Stallman <rms@gnu.org>
parents:
17976
diff
changeset
|
463 filename |
8b226efb9a8b
(jka-compr-insert-file-contents): Bind coding-system-for-read.
Richard M. Stallman <rms@gnu.org>
parents:
17976
diff
changeset
|
464 (and append can-append) 'dont)) |
8b226efb9a8b
(jka-compr-insert-file-contents): Bind coding-system-for-read.
Richard M. Stallman <rms@gnu.org>
parents:
17976
diff
changeset
|
465 (erase-buffer)) ) |
6002 | 466 |
467 (jka-compr-delete-temp-file temp-file) | |
468 | |
469 (and | |
470 compress-message | |
471 (message "%s %s...done" compress-message base-name)) | |
472 | |
473 (cond | |
474 ((eq visit t) | |
475 (setq buffer-file-name filename) | |
476 (set-visited-file-modtime)) | |
477 ((stringp visit) | |
478 (setq buffer-file-name visit) | |
479 (let ((buffer-file-name filename)) | |
480 (set-visited-file-modtime)))) | |
481 | |
482 (and (or (eq visit t) | |
483 (eq visit nil) | |
484 (stringp visit)) | |
485 (message "Wrote %s" visit-file)) | |
486 | |
22360
09dbe38a603f
(jka-compr-write-region): Ensure
Karl Heuer <kwzh@gnu.org>
parents:
22194
diff
changeset
|
487 ;; ensure `last-coding-system-used' has an appropriate value |
09dbe38a603f
(jka-compr-write-region): Ensure
Karl Heuer <kwzh@gnu.org>
parents:
22194
diff
changeset
|
488 (setq last-coding-system-used coding-system-used) |
09dbe38a603f
(jka-compr-write-region): Ensure
Karl Heuer <kwzh@gnu.org>
parents:
22194
diff
changeset
|
489 |
6002 | 490 nil) |
491 | |
7976
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
492 (jka-compr-run-real-handler 'write-region |
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
493 (list start end filename append visit))))) |
6002 | 494 |
495 | |
6218
f4d5338c2142
(jka-compr-insert-file-contents): Handle 5th arg.
Richard M. Stallman <rms@gnu.org>
parents:
6041
diff
changeset
|
496 (defun jka-compr-insert-file-contents (file &optional visit beg end replace) |
6002 | 497 (barf-if-buffer-read-only) |
498 | |
499 (and (or beg end) | |
500 visit | |
501 (error "Attempt to visit less than an entire file")) | |
502 | |
503 (let* ((filename (expand-file-name file)) | |
504 (info (jka-compr-get-compression-info filename))) | |
505 | |
506 (if info | |
507 | |
508 (let ((uncompress-message (jka-compr-info-uncompress-message info)) | |
509 (uncompress-program (jka-compr-info-uncompress-program info)) | |
510 (uncompress-args (jka-compr-info-uncompress-args info)) | |
511 (base-name (file-name-nondirectory filename)) | |
512 (notfound nil) | |
7976
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
513 (local-copy |
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
514 (jka-compr-run-real-handler 'file-local-copy (list filename))) |
6002 | 515 local-file |
18879
8b226efb9a8b
(jka-compr-insert-file-contents): Bind coding-system-for-read.
Richard M. Stallman <rms@gnu.org>
parents:
17976
diff
changeset
|
516 size start |
19004
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
517 (coding-system-for-read |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
518 (or coding-system-for-read |
20497
0d0951bf17fa
(jka-compr-insert-file-contents):
Richard M. Stallman <rms@gnu.org>
parents:
20132
diff
changeset
|
519 ;; If multibyte characters are disabled, |
0d0951bf17fa
(jka-compr-insert-file-contents):
Richard M. Stallman <rms@gnu.org>
parents:
20132
diff
changeset
|
520 ;; don't do that conversion. |
0d0951bf17fa
(jka-compr-insert-file-contents):
Richard M. Stallman <rms@gnu.org>
parents:
20132
diff
changeset
|
521 (and (null enable-multibyte-characters) |
0d0951bf17fa
(jka-compr-insert-file-contents):
Richard M. Stallman <rms@gnu.org>
parents:
20132
diff
changeset
|
522 'raw-text) |
19004
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
523 (let ((tail file-coding-system-alist) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
524 (newfile |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
525 (jka-compr-byte-compiler-base-file-name file)) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
526 result) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
527 (while tail |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
528 (if (string-match (car (car tail)) newfile) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
529 (setq result (car (cdr (car tail))) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
530 tail nil)) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
531 (setq tail (cdr tail))) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
532 result) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
533 'undecided)) ) |
6002 | 534 |
535 (setq local-file (or local-copy filename)) | |
536 | |
537 (and | |
538 visit | |
539 (setq buffer-file-name filename)) | |
540 | |
541 (unwind-protect ; to make sure local-copy gets deleted | |
542 | |
543 (progn | |
544 | |
545 (and | |
546 uncompress-message | |
547 (message "%s %s..." uncompress-message base-name)) | |
548 | |
549 (condition-case error-code | |
550 | |
551 (progn | |
8774
ade4b542a74c
(jka-compr-compression-info-list): Expand regular
Richard M. Stallman <rms@gnu.org>
parents:
8593
diff
changeset
|
552 (if replace |
ade4b542a74c
(jka-compr-compression-info-list): Expand regular
Richard M. Stallman <rms@gnu.org>
parents:
8593
diff
changeset
|
553 (goto-char (point-min))) |
6002 | 554 (setq start (point)) |
555 (if (or beg end) | |
556 (jka-compr-partial-uncompress uncompress-program | |
557 (concat uncompress-message | |
558 " " base-name) | |
559 uncompress-args | |
560 local-file | |
561 (or beg 0) | |
562 (if (and beg end) | |
563 (- end beg) | |
564 end)) | |
11621
710b5ce824c2
(jka-compr-insert-file-contents): When visiting,
Richard M. Stallman <rms@gnu.org>
parents:
11296
diff
changeset
|
565 ;; If visiting, bind off buffer-file-name so that |
710b5ce824c2
(jka-compr-insert-file-contents): When visiting,
Richard M. Stallman <rms@gnu.org>
parents:
11296
diff
changeset
|
566 ;; file-locking will not ask whether we should |
710b5ce824c2
(jka-compr-insert-file-contents): When visiting,
Richard M. Stallman <rms@gnu.org>
parents:
11296
diff
changeset
|
567 ;; really edit the buffer. |
710b5ce824c2
(jka-compr-insert-file-contents): When visiting,
Richard M. Stallman <rms@gnu.org>
parents:
11296
diff
changeset
|
568 (let ((buffer-file-name |
710b5ce824c2
(jka-compr-insert-file-contents): When visiting,
Richard M. Stallman <rms@gnu.org>
parents:
11296
diff
changeset
|
569 (if visit nil buffer-file-name))) |
710b5ce824c2
(jka-compr-insert-file-contents): When visiting,
Richard M. Stallman <rms@gnu.org>
parents:
11296
diff
changeset
|
570 (jka-compr-call-process uncompress-program |
710b5ce824c2
(jka-compr-insert-file-contents): When visiting,
Richard M. Stallman <rms@gnu.org>
parents:
11296
diff
changeset
|
571 (concat uncompress-message |
710b5ce824c2
(jka-compr-insert-file-contents): When visiting,
Richard M. Stallman <rms@gnu.org>
parents:
11296
diff
changeset
|
572 " " base-name) |
710b5ce824c2
(jka-compr-insert-file-contents): When visiting,
Richard M. Stallman <rms@gnu.org>
parents:
11296
diff
changeset
|
573 local-file |
710b5ce824c2
(jka-compr-insert-file-contents): When visiting,
Richard M. Stallman <rms@gnu.org>
parents:
11296
diff
changeset
|
574 t |
710b5ce824c2
(jka-compr-insert-file-contents): When visiting,
Richard M. Stallman <rms@gnu.org>
parents:
11296
diff
changeset
|
575 nil |
710b5ce824c2
(jka-compr-insert-file-contents): When visiting,
Richard M. Stallman <rms@gnu.org>
parents:
11296
diff
changeset
|
576 uncompress-args))) |
6002 | 577 (setq size (- (point) start)) |
8774
ade4b542a74c
(jka-compr-compression-info-list): Expand regular
Richard M. Stallman <rms@gnu.org>
parents:
8593
diff
changeset
|
578 (if replace |
ade4b542a74c
(jka-compr-compression-info-list): Expand regular
Richard M. Stallman <rms@gnu.org>
parents:
8593
diff
changeset
|
579 (let* ((del-beg (point)) |
ade4b542a74c
(jka-compr-compression-info-list): Expand regular
Richard M. Stallman <rms@gnu.org>
parents:
8593
diff
changeset
|
580 (del-end (+ del-beg size))) |
ade4b542a74c
(jka-compr-compression-info-list): Expand regular
Richard M. Stallman <rms@gnu.org>
parents:
8593
diff
changeset
|
581 (delete-region del-beg |
ade4b542a74c
(jka-compr-compression-info-list): Expand regular
Richard M. Stallman <rms@gnu.org>
parents:
8593
diff
changeset
|
582 (min del-end (point-max))))) |
ade4b542a74c
(jka-compr-compression-info-list): Expand regular
Richard M. Stallman <rms@gnu.org>
parents:
8593
diff
changeset
|
583 (goto-char start)) |
6002 | 584 (error |
585 (if (and (eq (car error-code) 'file-error) | |
586 (eq (nth 3 error-code) local-file)) | |
587 (if visit | |
588 (setq notfound error-code) | |
589 (signal 'file-error | |
590 (cons "Opening input file" | |
591 (nthcdr 2 error-code)))) | |
592 (signal (car error-code) (cdr error-code)))))) | |
593 | |
594 (and | |
595 local-copy | |
596 (file-exists-p local-copy) | |
597 (delete-file local-copy))) | |
598 | |
599 (and | |
600 visit | |
601 (progn | |
7976
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
602 (unlock-buffer) |
6002 | 603 (setq buffer-file-name filename) |
604 (set-visited-file-modtime))) | |
605 | |
606 (and | |
607 uncompress-message | |
608 (message "%s %s...done" uncompress-message base-name)) | |
609 | |
610 (and | |
611 visit | |
612 notfound | |
613 (signal 'file-error | |
614 (cons "Opening input file" (nth 2 notfound)))) | |
615 | |
22484
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
616 ;; This is done in insert-file-contents after we return. |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
617 ;; That is a little weird, but better to go along with it now |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
618 ;; than to change it now. |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
619 |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
620 ;;; ;; Run the functions that insert-file-contents would. |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
621 ;;; (let ((p after-insert-file-functions) |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
622 ;;; (insval size)) |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
623 ;;; (while p |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
624 ;;; (setq insval (funcall (car p) size)) |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
625 ;;; (if insval |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
626 ;;; (progn |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
627 ;;; (or (integerp insval) |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
628 ;;; (signal 'wrong-type-argument |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
629 ;;; (list 'integerp insval))) |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
630 ;;; (setq size insval))) |
661650f543ee
(jka-compr-insert-file-contents): Don't run
Richard M. Stallman <rms@gnu.org>
parents:
22360
diff
changeset
|
631 ;;; (setq p (cdr p)))) |
8774
ade4b542a74c
(jka-compr-compression-info-list): Expand regular
Richard M. Stallman <rms@gnu.org>
parents:
8593
diff
changeset
|
632 |
6002 | 633 (list filename size)) |
634 | |
7976
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
635 (jka-compr-run-real-handler 'insert-file-contents |
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
636 (list file visit beg end replace))))) |
6002 | 637 |
638 | |
639 (defun jka-compr-file-local-copy (file) | |
640 (let* ((filename (expand-file-name file)) | |
641 (info (jka-compr-get-compression-info filename))) | |
642 | |
643 (if info | |
644 | |
645 (let ((uncompress-message (jka-compr-info-uncompress-message info)) | |
646 (uncompress-program (jka-compr-info-uncompress-program info)) | |
647 (uncompress-args (jka-compr-info-uncompress-args info)) | |
648 (base-name (file-name-nondirectory filename)) | |
7976
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
649 (local-copy |
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
650 (jka-compr-run-real-handler 'file-local-copy (list filename))) |
6002 | 651 (temp-file (jka-compr-make-temp-name t)) |
11635
b56f6afa16ec
(jka-compr-write-region): Handle the append
Richard M. Stallman <rms@gnu.org>
parents:
11621
diff
changeset
|
652 (temp-buffer (get-buffer-create " *jka-compr-flc-temp*")) |
6002 | 653 (notfound nil) |
654 local-file) | |
655 | |
656 (setq local-file (or local-copy filename)) | |
657 | |
658 (unwind-protect | |
659 | |
16940
6d680b18a47b
(jka-compr-error): Use with-current-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
16630
diff
changeset
|
660 (with-current-buffer temp-buffer |
6002 | 661 |
662 (and | |
663 uncompress-message | |
664 (message "%s %s..." uncompress-message base-name)) | |
665 | |
18906 | 666 ;; Here we must read the output of uncompress program |
667 ;; and write it to TEMP-FILE without any code | |
668 ;; conversion. An appropriate code conversion (if | |
669 ;; necessary) is done by the later I/O operation | |
670 ;; (e.g. load). | |
671 (let ((coding-system-for-read 'no-conversion) | |
672 (coding-system-for-write 'no-conversion)) | |
6002 | 673 |
18906 | 674 (jka-compr-call-process uncompress-program |
675 (concat uncompress-message | |
676 " " base-name) | |
677 local-file | |
678 t | |
679 nil | |
680 uncompress-args) | |
6002 | 681 |
18906 | 682 (and |
683 uncompress-message | |
684 (message "%s %s...done" uncompress-message base-name)) | |
685 | |
686 (write-region | |
687 (point-min) (point-max) temp-file nil 'dont))) | |
6002 | 688 |
689 (and | |
690 local-copy | |
691 (file-exists-p local-copy) | |
692 (delete-file local-copy)) | |
693 | |
694 (kill-buffer temp-buffer)) | |
695 | |
696 temp-file) | |
697 | |
7976
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
698 (jka-compr-run-real-handler 'file-local-copy (list filename))))) |
6002 | 699 |
700 | |
701 ;;; Support for loading compressed files. | |
702 (defun jka-compr-load (file &optional noerror nomessage nosuffix) | |
703 "Documented as original." | |
704 | |
705 (let* ((local-copy (jka-compr-file-local-copy file)) | |
706 (load-file (or local-copy file))) | |
707 | |
708 (unwind-protect | |
709 | |
7976
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
710 (let (inhibit-file-name-operation |
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
711 inhibit-file-name-handlers) |
6002 | 712 (or nomessage |
713 (message "Loading %s..." file)) | |
714 | |
12758
a285eaa710ac
(jka-compr-load): Bind load-force-doc-strings.
Richard M. Stallman <rms@gnu.org>
parents:
11635
diff
changeset
|
715 (let ((load-force-doc-strings t)) |
a285eaa710ac
(jka-compr-load): Bind load-force-doc-strings.
Richard M. Stallman <rms@gnu.org>
parents:
11635
diff
changeset
|
716 (load load-file noerror t t)) |
6002 | 717 |
718 (or nomessage | |
719 (message "Loading %s...done." file))) | |
720 | |
721 (jka-compr-delete-temp-file local-copy)) | |
722 | |
723 t)) | |
12922
e171a85fd6b0
(jka-compr-byte-compiler-base-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
12758
diff
changeset
|
724 |
e171a85fd6b0
(jka-compr-byte-compiler-base-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
12758
diff
changeset
|
725 (defun jka-compr-byte-compiler-base-file-name (file) |
e171a85fd6b0
(jka-compr-byte-compiler-base-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
12758
diff
changeset
|
726 (let ((info (jka-compr-get-compression-info file))) |
e171a85fd6b0
(jka-compr-byte-compiler-base-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
12758
diff
changeset
|
727 (if (and info (jka-compr-info-strip-extension info)) |
e171a85fd6b0
(jka-compr-byte-compiler-base-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
12758
diff
changeset
|
728 (save-match-data |
e171a85fd6b0
(jka-compr-byte-compiler-base-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
12758
diff
changeset
|
729 (substring file 0 (string-match (jka-compr-info-regexp info) file))) |
e171a85fd6b0
(jka-compr-byte-compiler-base-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
12758
diff
changeset
|
730 file))) |
7976
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
731 |
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
732 (put 'write-region 'jka-compr 'jka-compr-write-region) |
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
733 (put 'insert-file-contents 'jka-compr 'jka-compr-insert-file-contents) |
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
734 (put 'file-local-copy 'jka-compr 'jka-compr-file-local-copy) |
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
735 (put 'load 'jka-compr 'jka-compr-load) |
12922
e171a85fd6b0
(jka-compr-byte-compiler-base-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
12758
diff
changeset
|
736 (put 'byte-compiler-base-file-name 'jka-compr |
e171a85fd6b0
(jka-compr-byte-compiler-base-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
12758
diff
changeset
|
737 'jka-compr-byte-compiler-base-file-name) |
6002 | 738 |
20132
b691f68b0757
(jka-compr-inhibit): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
19004
diff
changeset
|
739 (defvar jka-compr-inhibit nil |
b691f68b0757
(jka-compr-inhibit): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
19004
diff
changeset
|
740 "Non-nil means inhibit automatic uncompression temporarily. |
b691f68b0757
(jka-compr-inhibit): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
19004
diff
changeset
|
741 Lisp programs can bind this to t to do that. |
b691f68b0757
(jka-compr-inhibit): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
19004
diff
changeset
|
742 It is not recommended to set this variable permanently to anything but nil.") |
b691f68b0757
(jka-compr-inhibit): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
19004
diff
changeset
|
743 |
6002 | 744 (defun jka-compr-handler (operation &rest args) |
7976
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
745 (save-match-data |
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
746 (let ((jka-op (get operation 'jka-compr))) |
20132
b691f68b0757
(jka-compr-inhibit): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
19004
diff
changeset
|
747 (if (and jka-op (not jka-compr-inhibit)) |
7976
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
748 (apply jka-op args) |
b72b84744a85
Use plists to record handlers.
Richard M. Stallman <rms@gnu.org>
parents:
7617
diff
changeset
|
749 (jka-compr-run-real-handler operation args))))) |
6002 | 750 |
7066 | 751 ;; If we are given an operation that we don't handle, |
752 ;; call the Emacs primitive for that operation, | |
753 ;; and manipulate the inhibit variables | |
754 ;; to prevent the primitive from calling our handler again. | |
755 (defun jka-compr-run-real-handler (operation args) | |
756 (let ((inhibit-file-name-handlers | |
757 (cons 'jka-compr-handler | |
758 (and (eq inhibit-file-name-operation operation) | |
759 inhibit-file-name-handlers))) | |
760 (inhibit-file-name-operation operation)) | |
761 (apply operation args))) | |
762 | |
13887
4362f8b4f83c
(auto-compression-mode): This is now a stub function
Richard M. Stallman <rms@gnu.org>
parents:
13514
diff
changeset
|
763 ;;;###autoload(defun auto-compression-mode (&optional arg) |
13900
37c5ece37d71
(auto-compression-mode): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
13887
diff
changeset
|
764 ;;;###autoload "\ |
37c5ece37d71
(auto-compression-mode): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
13887
diff
changeset
|
765 ;;;###autoloadToggle automatic file compression and uncompression. |
13887
4362f8b4f83c
(auto-compression-mode): This is now a stub function
Richard M. Stallman <rms@gnu.org>
parents:
13514
diff
changeset
|
766 ;;;###autoloadWith prefix argument ARG, turn auto compression on if positive, else off. |
4362f8b4f83c
(auto-compression-mode): This is now a stub function
Richard M. Stallman <rms@gnu.org>
parents:
13514
diff
changeset
|
767 ;;;###autoloadReturns the new status of auto compression (non-nil means on)." |
13900
37c5ece37d71
(auto-compression-mode): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
13887
diff
changeset
|
768 ;;;###autoload (interactive "P") |
13887
4362f8b4f83c
(auto-compression-mode): This is now a stub function
Richard M. Stallman <rms@gnu.org>
parents:
13514
diff
changeset
|
769 ;;;###autoload (if (not (fboundp 'jka-compr-installed-p)) |
4362f8b4f83c
(auto-compression-mode): This is now a stub function
Richard M. Stallman <rms@gnu.org>
parents:
13514
diff
changeset
|
770 ;;;###autoload (progn |
4362f8b4f83c
(auto-compression-mode): This is now a stub function
Richard M. Stallman <rms@gnu.org>
parents:
13514
diff
changeset
|
771 ;;;###autoload (require 'jka-compr) |
4362f8b4f83c
(auto-compression-mode): This is now a stub function
Richard M. Stallman <rms@gnu.org>
parents:
13514
diff
changeset
|
772 ;;;###autoload ;; That turned the mode on, so make it initially off. |
4362f8b4f83c
(auto-compression-mode): This is now a stub function
Richard M. Stallman <rms@gnu.org>
parents:
13514
diff
changeset
|
773 ;;;###autoload (toggle-auto-compression))) |
13900
37c5ece37d71
(auto-compression-mode): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
13887
diff
changeset
|
774 ;;;###autoload (toggle-auto-compression arg t)) |
13887
4362f8b4f83c
(auto-compression-mode): This is now a stub function
Richard M. Stallman <rms@gnu.org>
parents:
13514
diff
changeset
|
775 |
13900
37c5ece37d71
(auto-compression-mode): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
13887
diff
changeset
|
776 (defun toggle-auto-compression (&optional arg message) |
13067
fef2a9095f0c
(auto-compression-mode): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
12922
diff
changeset
|
777 "Toggle automatic file compression and uncompression. |
6002 | 778 With prefix argument ARG, turn auto compression on if positive, else off. |
13900
37c5ece37d71
(auto-compression-mode): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
13887
diff
changeset
|
779 Returns the new status of auto compression (non-nil means on). |
37c5ece37d71
(auto-compression-mode): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
13887
diff
changeset
|
780 If the argument MESSAGE is non-nil, it means to print a message |
37c5ece37d71
(auto-compression-mode): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
13887
diff
changeset
|
781 saying whether the mode is now on or off." |
37c5ece37d71
(auto-compression-mode): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
13887
diff
changeset
|
782 (interactive "P\np") |
6002 | 783 (let* ((installed (jka-compr-installed-p)) |
784 (flag (if (null arg) | |
785 (not installed) | |
786 (or (eq arg t) (listp arg) (and (integerp arg) (> arg 0)))))) | |
787 | |
788 (cond | |
789 ((and flag installed) t) ; already installed | |
790 | |
791 ((and (not flag) (not installed)) nil) ; already not installed | |
792 | |
793 (flag | |
794 (jka-compr-install)) | |
795 | |
796 (t | |
797 (jka-compr-uninstall))) | |
798 | |
799 | |
13900
37c5ece37d71
(auto-compression-mode): Add `interactive'.
Richard M. Stallman <rms@gnu.org>
parents:
13887
diff
changeset
|
800 (and message |
6002 | 801 (if flag |
802 (message "Automatic file (de)compression is now ON.") | |
803 (message "Automatic file (de)compression is now OFF."))) | |
804 | |
805 flag)) | |
806 | |
807 (defun jka-compr-build-file-regexp () | |
808 (concat | |
809 "\\(" | |
810 (mapconcat | |
811 'jka-compr-info-regexp | |
812 jka-compr-compression-info-list | |
813 "\\)\\|\\(") | |
814 "\\)")) | |
815 | |
816 | |
817 (defun jka-compr-install () | |
818 "Install jka-compr. | |
11296
c271ed10f874
(jka-compr-install): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11179
diff
changeset
|
819 This adds entries to `file-name-handler-alist' and `auto-mode-alist' |
c271ed10f874
(jka-compr-install): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11179
diff
changeset
|
820 and `inhibit-first-line-modes-suffixes'." |
6002 | 821 |
822 (setq jka-compr-file-name-handler-entry | |
823 (cons (jka-compr-build-file-regexp) 'jka-compr-handler)) | |
824 | |
825 (setq file-name-handler-alist (cons jka-compr-file-name-handler-entry | |
826 file-name-handler-alist)) | |
827 | |
19004
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
828 (setq jka-compr-added-to-file-coding-system-alist nil) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
829 |
6002 | 830 (mapcar |
831 (function (lambda (x) | |
19004
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
832 ;; Don't do multibyte encoding on the compressed files. |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
833 (let ((elt (cons (jka-compr-info-regexp x) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
834 '(no-conversion . no-conversion)))) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
835 (setq file-coding-system-alist |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
836 (cons elt file-coding-system-alist)) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
837 (setq jka-compr-added-to-file-coding-system-alist |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
838 (cons elt jka-compr-added-to-file-coding-system-alist))) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
839 |
11179
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
840 (and (jka-compr-info-strip-extension x) |
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
841 ;; Make entries in auto-mode-alist so that modes |
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
842 ;; are chosen right according to the file names |
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
843 ;; sans `.gz'. |
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
844 (setq auto-mode-alist |
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
845 (cons (list (jka-compr-info-regexp x) |
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
846 nil 'jka-compr) |
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
847 auto-mode-alist)) |
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
848 ;; Also add these regexps to |
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
849 ;; inhibit-first-line-modes-suffixes, so that a |
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
850 ;; -*- line in the first file of a compressed tar |
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
851 ;; file doesn't override tar-mode. |
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
852 (setq inhibit-first-line-modes-suffixes |
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
853 (cons (jka-compr-info-regexp x) |
9ff0cfb97106
(jka-compr-install): Add items to inhibit-first-line-modes-suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
9493
diff
changeset
|
854 inhibit-first-line-modes-suffixes))))) |
9493
0160fca3dee1
(jka-compr-mode-compression-info-list): Add .tgz extension.
Richard M. Stallman <rms@gnu.org>
parents:
9084
diff
changeset
|
855 jka-compr-compression-info-list) |
0160fca3dee1
(jka-compr-mode-compression-info-list): Add .tgz extension.
Richard M. Stallman <rms@gnu.org>
parents:
9084
diff
changeset
|
856 (setq auto-mode-alist |
0160fca3dee1
(jka-compr-mode-compression-info-list): Add .tgz extension.
Richard M. Stallman <rms@gnu.org>
parents:
9084
diff
changeset
|
857 (append auto-mode-alist jka-compr-mode-alist-additions))) |
6002 | 858 |
859 | |
860 (defun jka-compr-uninstall () | |
861 "Uninstall jka-compr. | |
7066 | 862 This removes the entries in `file-name-handler-alist' and `auto-mode-alist' |
11296
c271ed10f874
(jka-compr-install): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11179
diff
changeset
|
863 and `inhibit-first-line-modes-suffixes' that were added |
c271ed10f874
(jka-compr-install): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11179
diff
changeset
|
864 by `jka-compr-installed'." |
c271ed10f874
(jka-compr-install): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11179
diff
changeset
|
865 ;; Delete from inhibit-first-line-modes-suffixes |
c271ed10f874
(jka-compr-install): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11179
diff
changeset
|
866 ;; what jka-compr-install added. |
c271ed10f874
(jka-compr-install): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11179
diff
changeset
|
867 (mapcar |
c271ed10f874
(jka-compr-install): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11179
diff
changeset
|
868 (function (lambda (x) |
c271ed10f874
(jka-compr-install): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11179
diff
changeset
|
869 (and (jka-compr-info-strip-extension x) |
c271ed10f874
(jka-compr-install): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11179
diff
changeset
|
870 (setq inhibit-first-line-modes-suffixes |
c271ed10f874
(jka-compr-install): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11179
diff
changeset
|
871 (delete (jka-compr-info-regexp x) |
c271ed10f874
(jka-compr-install): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11179
diff
changeset
|
872 inhibit-first-line-modes-suffixes))))) |
c271ed10f874
(jka-compr-install): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
11179
diff
changeset
|
873 jka-compr-compression-info-list) |
6002 | 874 |
875 (let* ((fnha (cons nil file-name-handler-alist)) | |
876 (last fnha)) | |
877 | |
878 (while (cdr last) | |
879 (if (eq (cdr (car (cdr last))) 'jka-compr-handler) | |
880 (setcdr last (cdr (cdr last))) | |
881 (setq last (cdr last)))) | |
882 | |
883 (setq file-name-handler-alist (cdr fnha))) | |
884 | |
885 (let* ((ama (cons nil auto-mode-alist)) | |
886 (last ama) | |
887 entry) | |
888 | |
889 (while (cdr last) | |
890 (setq entry (car (cdr last))) | |
9493
0160fca3dee1
(jka-compr-mode-compression-info-list): Add .tgz extension.
Richard M. Stallman <rms@gnu.org>
parents:
9084
diff
changeset
|
891 (if (or (member entry jka-compr-mode-alist-additions) |
0160fca3dee1
(jka-compr-mode-compression-info-list): Add .tgz extension.
Richard M. Stallman <rms@gnu.org>
parents:
9084
diff
changeset
|
892 (and (consp (cdr entry)) |
0160fca3dee1
(jka-compr-mode-compression-info-list): Add .tgz extension.
Richard M. Stallman <rms@gnu.org>
parents:
9084
diff
changeset
|
893 (eq (nth 2 entry) 'jka-compr))) |
6002 | 894 (setcdr last (cdr (cdr last))) |
895 (setq last (cdr last)))) | |
896 | |
19004
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
897 (setq auto-mode-alist (cdr ama))) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
898 |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
899 (let* ((ama (cons nil file-coding-system-alist)) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
900 (last ama) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
901 entry) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
902 |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
903 (while (cdr last) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
904 (setq entry (car (cdr last))) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
905 (if (member entry jka-compr-added-to-file-coding-system-alist) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
906 (setcdr last (cdr (cdr last))) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
907 (setq last (cdr last)))) |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
908 |
f2ce7e947ec9
(jka-compr-added-to-file-coding-system-alist): New var.
Richard M. Stallman <rms@gnu.org>
parents:
18906
diff
changeset
|
909 (setq file-coding-system-alist (cdr ama)))) |
6002 | 910 |
911 | |
912 (defun jka-compr-installed-p () | |
913 "Return non-nil if jka-compr is installed. | |
7066 | 914 The return value is the entry in `file-name-handler-alist' for jka-compr." |
6002 | 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 (jka-compr-install) | |
934 | |
935 | |
936 (provide 'jka-compr) | |
937 | |
938 ;; jka-compr.el ends here. |